List of usage examples for com.amazonaws.services.autoscaling.model LaunchConfiguration getLaunchConfigurationName
public String getLaunchConfigurationName()
The name of the launch configuration.
From source file:com.eucalyptus.tests.awssdk.CloudCleaner.java
License:Open Source License
@Test public void clean() throws Exception { testInfo(this.getClass().getSimpleName()); getCloudInfo();//from ww w. java 2 s. c o m //Terminate All instances List<String> instancesToTerminate = new ArrayList<String>(); DescribeInstancesResult result = ec2.describeInstances(); List<Reservation> reservations = result.getReservations(); if (reservations.size() > 0) { print("Found instances to terminate"); for (Reservation reservation : reservations) { List<Instance> instances = reservation.getInstances(); for (Instance instance : instances) { print("Terminating: " + instance.getInstanceId()); instancesToTerminate.add(instance.getInstanceId()); } } TerminateInstancesRequest term = new TerminateInstancesRequest(); term.setInstanceIds(instancesToTerminate); ec2.terminateInstances(term); } else { print("No instances found"); } // delete all keypairs if (getKeyPairCount() > 0) { print("Found Keypairs to delete"); DescribeKeyPairsResult describeKeyPairsResult = ec2.describeKeyPairs(); for (KeyPairInfo keypair : describeKeyPairsResult.getKeyPairs()) { deleteKeyPair(keypair.getKeyName()); } } else { print("No keypairs found"); } // delete all groups except default group List<SecurityGroup> groups = describeSecurityGroups(); if (groups.size() > 1) { print("Found security groups to delete"); for (SecurityGroup group : groups) { if (!group.getGroupName().equals("default")) { deleteSecurityGroup(group.getGroupName()); } } } else { print("No Security Groups found (other than default)"); } // delete all policies List<ScalingPolicy> policies = describePolicies(); if (policies.size() > 0) { print("Found Policies to delete"); for (ScalingPolicy policy : policies) { deletePolicy(policy.getPolicyName()); } } else { print("No auto scaling policies found"); } // delete launch configs List<LaunchConfiguration> lcs = describeLaunchConfigs(); if (lcs.size() > 0) { print("Found Launch Configs to delete"); for (LaunchConfiguration lc : lcs) { deleteLaunchConfig(lc.getLaunchConfigurationName()); } } else { print("No launch configs found"); } // delete autoscaling groups List<AutoScalingGroup> asGroups = describeAutoScalingGroups(); if (asGroups.size() > 0) { print("Found Auto Scaling Groups to delete"); for (AutoScalingGroup asg : asGroups) { deleteAutoScalingGroup(asg.getAutoScalingGroupName(), true); } } else { print("No auto scaling groups found"); } // delete volumes List<Volume> volumes = ec2.describeVolumes().getVolumes(); if (volumes.size() > 0) { print("Found volumes to delete"); for (Volume vol : volumes) { deleteVolume(vol.getVolumeId()); } } else { print("No volumes found"); } //delete snapshots List<Snapshot> snapshots = ec2.describeSnapshots().getSnapshots(); if (snapshots.size() > 0) { print("Found snapshots to delete"); for (Snapshot snap : snapshots) { deleteSnapshot(snap.getSnapshotId()); } } else { print("No volumes found"); } }
From source file:com.haskins.cloudtrailviewer.dialog.resourcedetail.detailpanels.AsLaunchDetail.java
License:Open Source License
private void buildUI(DescribeLaunchConfigurationsResult detail) { this.add(primaryScrollPane, BorderLayout.CENTER); if (!detail.getLaunchConfigurations().isEmpty()) { List<LaunchConfiguration> lcs = detail.getLaunchConfigurations(); LaunchConfiguration lc = lcs.get(0); if (lc.getAssociatePublicIpAddress() != null) { primaryTableModel.addRow(new Object[] { "Has EIP", lc.getAssociatePublicIpAddress() }); }// w w w. j a va 2 s .c o m if (lc.getClassicLinkVPCId() != null) { primaryTableModel.addRow(new Object[] { "Classic Link VPC Id", lc.getClassicLinkVPCId() }); } if (!lc.getClassicLinkVPCSecurityGroups().isEmpty()) { StringBuilder sgs = new StringBuilder(); for (String sg : lc.getClassicLinkVPCSecurityGroups()) { sgs.append(sg).append(", "); } primaryTableModel.addRow(new Object[] { "Classic Link VPC Security Groups", sgs.toString() }); } if (lc.getCreatedTime() != null) { primaryTableModel.addRow(new Object[] { "Created", getDateString(lc.getCreatedTime()) }); } if (lc.getEbsOptimized() != null) { primaryTableModel.addRow(new Object[] { "EBS Optimised", lc.getEbsOptimized() }); } if (lc.getIamInstanceProfile() != null) { primaryTableModel.addRow(new Object[] { "Instance Profile", lc.getIamInstanceProfile() }); } if (lc.getImageId() != null) { primaryTableModel.addRow(new Object[] { "Image Id", lc.getImageId() }); } if (lc.getInstanceType() != null) { primaryTableModel.addRow(new Object[] { "Instance Type", lc.getInstanceType() }); } if (lc.getKernelId() != null) { primaryTableModel.addRow(new Object[] { "Kernal Id", lc.getKernelId() }); } if (lc.getKeyName() != null) { primaryTableModel.addRow(new Object[] { "Key Name", lc.getKeyName() }); } if (lc.getLaunchConfigurationARN() != null) { primaryTableModel .addRow(new Object[] { "Launch Configuration Arn", lc.getLaunchConfigurationARN() }); } if (lc.getLaunchConfigurationName() != null) { primaryTableModel .addRow(new Object[] { "Launch Configuration Name", lc.getLaunchConfigurationName() }); } if (lc.getPlacementTenancy() != null) { primaryTableModel.addRow(new Object[] { "Placement Tenancy", lc.getPlacementTenancy() }); } if (lc.getRamdiskId() != null) { primaryTableModel.addRow(new Object[] { "Ram Disk ID", lc.getRamdiskId() }); } if (!lc.getSecurityGroups().isEmpty()) { StringBuilder sgs = new StringBuilder(); for (String sg : lc.getSecurityGroups()) { sgs.append(sg).append(", "); } primaryTableModel.addRow(new Object[] { "Security Groups", sgs.toString() }); } if (lc.getSpotPrice() != null) { primaryTableModel.addRow(new Object[] { "Spot Price", lc.getSpotPrice() }); } } }
From source file:com.liferay.amazontools.AMICleaner.java
License:Open Source License
protected void deleteOldLaunchConfigurations() { DescribeLaunchConfigurationsRequest describeLaunchConfigurationsRequest = new DescribeLaunchConfigurationsRequest(); DescribeLaunchConfigurationsResult describeLaunchConfigurationsResult = amazonAutoScalingClient .describeLaunchConfigurations(describeLaunchConfigurationsRequest); List<LaunchConfiguration> launchConfigurations = describeLaunchConfigurationsResult .getLaunchConfigurations();//w w w . ja va 2 s .c o m for (int i = 0; i < launchConfigurations.size(); i++) { DeleteLaunchConfigurationRequest deleteLaunchConfigurationRequest = new DeleteLaunchConfigurationRequest(); LaunchConfiguration launchConfiguration = launchConfigurations.get(i); deleteLaunchConfigurationRequest .setLaunchConfigurationName(launchConfiguration.getLaunchConfigurationName()); try { amazonAutoScalingClient.deleteLaunchConfiguration(deleteLaunchConfigurationRequest); } catch (ResourceInUseException riue) { } } }
From source file:com.netflix.edda.EddaAutoScalingClient.java
License:Apache License
public DescribeLaunchConfigurationsResult describeLaunchConfigurations( DescribeLaunchConfigurationsRequest request) { TypeReference<List<LaunchConfiguration>> ref = new TypeReference<List<LaunchConfiguration>>() { };/* w w w.jav a2 s .c o m*/ String url = config.url() + "/api/v2/aws/launchConfigurations;_expand"; try { List<LaunchConfiguration> launchConfigurations = parse(ref, doGet(url)); List<String> names = request.getLaunchConfigurationNames(); if (shouldFilter(names)) { List<LaunchConfiguration> lcs = new ArrayList<LaunchConfiguration>(); for (LaunchConfiguration lc : launchConfigurations) { if (matches(names, lc.getLaunchConfigurationName())) lcs.add(lc); } launchConfigurations = lcs; } return new DescribeLaunchConfigurationsResult().withLaunchConfigurations(launchConfigurations); } catch (IOException e) { throw new AmazonClientException("Faled to parse " + url, e); } }
From source file:com.netflix.simianarmy.aws.janitor.crawler.ASGJanitorCrawler.java
License:Apache License
private List<Resource> getASGResources(String... asgNames) { AWSClient awsClient = getAWSClient(); List<LaunchConfiguration> launchConfigurations = awsClient.describeLaunchConfigurations(); for (LaunchConfiguration lc : launchConfigurations) { nameToLaunchConfig.put(lc.getLaunchConfigurationName(), lc); }/*from w w w. j a v a2 s. co m*/ List<Resource> resources = new LinkedList<Resource>(); for (AutoScalingGroup asg : awsClient.describeAutoScalingGroups(asgNames)) { Resource asgResource = new AWSResource().withId(asg.getAutoScalingGroupName()) .withResourceType(AWSResourceType.ASG).withRegion(awsClient.region()) .withLaunchTime(asg.getCreatedTime()); for (TagDescription tag : asg.getTags()) { asgResource.setTag(tag.getKey(), tag.getValue()); } asgResource.setDescription(String.format("%d instances", asg.getInstances().size())); asgResource.setOwnerEmail(getOwnerEmailForResource(asgResource)); if (asg.getStatus() != null) { ((AWSResource) asgResource).setAWSResourceState(asg.getStatus()); } Integer maxSize = asg.getMaxSize(); if (maxSize != null) { asgResource.setAdditionalField(ASG_FIELD_MAX_SIZE, String.valueOf(maxSize)); } // Adds instances and ELBs as additional fields. List<String> instances = new ArrayList<String>(); for (Instance instance : asg.getInstances()) { instances.add(instance.getInstanceId()); } asgResource.setAdditionalField(ASG_FIELD_INSTANCES, StringUtils.join(instances, ",")); asgResource.setAdditionalField(ASG_FIELD_ELBS, StringUtils.join(asg.getLoadBalancerNames(), ",")); String lcName = asg.getLaunchConfigurationName(); LaunchConfiguration lc = nameToLaunchConfig.get(lcName); if (lc != null) { asgResource.setAdditionalField(ASG_FIELD_LC_NAME, lcName); } if (lc != null && lc.getCreatedTime() != null) { asgResource.setAdditionalField(ASG_FIELD_LC_CREATION_TIME, String.valueOf(lc.getCreatedTime().getTime())); } // sets the field for the time when the ASG's traffic is suspended from ELB for (SuspendedProcess sp : asg.getSuspendedProcesses()) { if ("AddToLoadBalancer".equals(sp.getProcessName())) { String suspensionTime = getSuspensionTimeString(sp.getSuspensionReason()); if (suspensionTime != null) { LOGGER.info(String.format("Suspension time of ASG %s is %s", asg.getAutoScalingGroupName(), suspensionTime)); asgResource.setAdditionalField(ASG_FIELD_SUSPENSION_TIME, suspensionTime); break; } } } resources.add(asgResource); } return resources; }
From source file:com.netflix.simianarmy.aws.janitor.crawler.LaunchConfigJanitorCrawler.java
License:Apache License
private List<Resource> getLaunchConfigResources(String... launchConfigNames) { List<Resource> resources = Lists.newArrayList(); AWSClient awsClient = getAWSClient(); Set<String> usedLCs = Sets.newHashSet(); for (AutoScalingGroup asg : awsClient.describeAutoScalingGroups()) { usedLCs.add(asg.getLaunchConfigurationName()); }/* ww w . j a v a 2 s .c o m*/ for (LaunchConfiguration launchConfiguration : awsClient.describeLaunchConfigurations(launchConfigNames)) { String lcName = launchConfiguration.getLaunchConfigurationName(); Resource lcResource = new AWSResource().withId(lcName).withRegion(getAWSClient().region()) .withResourceType(AWSResourceType.LAUNCH_CONFIG) .withLaunchTime(launchConfiguration.getCreatedTime()); lcResource.setOwnerEmail(getOwnerEmailForResource(lcResource)); lcResource.setAdditionalField(LAUNCH_CONFIG_FIELD_USED_BY_ASG, String.valueOf(usedLCs.contains(lcName))); resources.add(lcResource); } return resources; }
From source file:com.pinterest.arcee.autoscaling.AwsAutoScalingManager.java
License:Apache License
@Override public AwsVmBean getLaunchConfigInfo(String launchConfigId) throws Exception { DescribeLaunchConfigurationsRequest configRequest = new DescribeLaunchConfigurationsRequest(); configRequest.setLaunchConfigurationNames(Arrays.asList(launchConfigId)); DescribeLaunchConfigurationsResult configResult = aasClient.describeLaunchConfigurations(configRequest); List<LaunchConfiguration> configs = configResult.getLaunchConfigurations(); if (configs.isEmpty()) { LOG.error(String.format("Failed to get cluster: Launch config %s does not exist", launchConfigId)); return null; }//from w w w. j a v a 2 s.c o m LaunchConfiguration config = configs.get(0); AwsVmBean awsVmBean = new AwsVmBean(); awsVmBean.setImage(config.getImageId()); awsVmBean.setHostType(config.getInstanceType()); awsVmBean.setSecurityZone(config.getSecurityGroups().get(0)); awsVmBean.setAssignPublicIp(config.getAssociatePublicIpAddress()); awsVmBean.setLaunchConfigId(config.getLaunchConfigurationName()); String roleName = config.getIamInstanceProfile(); if (roleName.contains("/")) { awsVmBean.setRole(roleName.split("/")[1]); } else { awsVmBean.setRole(roleName); } String userData = new String(Base64.decodeBase64(config.getUserData())); awsVmBean.setRawUserDataString(userData); return awsVmBean; }
From source file:com.pinterest.clusterservice.cm.AwsVmManager.java
License:Apache License
@Override public AwsVmBean getCluster(String clusterName) throws Exception { AutoScalingGroup group = getAutoScalingGroup(clusterName); if (group == null) { LOG.warn(String.format("Failed to get cluster %s: auto scaling group %s does not exist", clusterName, clusterName));//from w w w .j a v a 2s . c om return null; } LaunchConfiguration config = getLaunchConfig(group.getLaunchConfigurationName()); if (config == null) { LOG.warn(String.format("Failed to get cluster: Launch config %s does not exist", group.getLaunchConfigurationName())); return null; } AwsVmBean awsVmBean = new AwsVmBean(); awsVmBean.setClusterName(clusterName); awsVmBean.setImage(config.getImageId()); awsVmBean.setHostType(config.getInstanceType()); awsVmBean.setSecurityZone(config.getSecurityGroups().get(0)); awsVmBean.setAssignPublicIp(config.getAssociatePublicIpAddress()); awsVmBean.setLaunchConfigId(config.getLaunchConfigurationName()); String roleName = config.getIamInstanceProfile(); awsVmBean.setRole(roleName.split("/")[1]); String userData = new String(Base64.decodeBase64(config.getUserData())); awsVmBean.setUserDataConfigs(transformUserDataToConfigMap(clusterName, userData)); awsVmBean.setSubnet(group.getVPCZoneIdentifier()); awsVmBean.setMinSize(group.getMinSize()); awsVmBean.setMaxSize(group.getMaxSize()); return awsVmBean; }