Example usage for com.amazonaws.services.autoscaling.model AutoScalingGroup getLaunchConfigurationName

List of usage examples for com.amazonaws.services.autoscaling.model AutoScalingGroup getLaunchConfigurationName

Introduction

In this page you can find the example usage for com.amazonaws.services.autoscaling.model AutoScalingGroup getLaunchConfigurationName.

Prototype


public String getLaunchConfigurationName() 

Source Link

Document

The name of the associated launch configuration.

Usage

From source file:com.haskins.cloudtrailviewer.dialog.resourcedetail.detailpanels.AsGroupDetail.java

License:Open Source License

private void buildUI(DescribeAutoScalingGroupsResult detail) {

    JTabbedPane tabs = new JTabbedPane();
    tabs.add("AS Group", primaryScrollPane);
    tabs.add("Tags", tagsScrollPane);

    this.add(tabs, BorderLayout.CENTER);

    List<AutoScalingGroup> groups = detail.getAutoScalingGroups();
    if (!groups.isEmpty()) {
        AutoScalingGroup group = groups.get(0);

        if (group.getAutoScalingGroupARN() != null) {
            primaryTableModel.addRow(new Object[] { "AutoScaling Group Arn", group.getAutoScalingGroupARN() });
        }/*from   w  w w .j  a v a  2s  .  co  m*/
        if (group.getAutoScalingGroupName() != null) {
            primaryTableModel
                    .addRow(new Object[] { "AutoScaling Group Name", group.getAutoScalingGroupName() });
        }

        if (!group.getAvailabilityZones().isEmpty()) {

            StringBuilder azs = new StringBuilder();
            for (String az : group.getAvailabilityZones()) {
                azs.append(az).append(", ");
            }

            primaryTableModel.addRow(new Object[] { "Availability Zones", azs.toString() });
        }

        if (group.getCreatedTime() != null) {
            primaryTableModel.addRow(new Object[] { "Created", getDateString(group.getCreatedTime()) });
        }
        if (group.getDefaultCooldown() != null) {
            primaryTableModel.addRow(new Object[] { "Default Cooldown", group.getDefaultCooldown() });
        }
        if (group.getDesiredCapacity() != null) {
            primaryTableModel.addRow(new Object[] { "Desired Capacity", group.getDesiredCapacity() });
        }
        if (group.getHealthCheckGracePeriod() != null) {
            primaryTableModel
                    .addRow(new Object[] { "HealthCheck Grace Period", group.getHealthCheckGracePeriod() });
        }
        if (group.getHealthCheckType() != null) {
            primaryTableModel.addRow(new Object[] { "HealthCheck Type", group.getHealthCheckType() });
        }

        if (!group.getInstances().isEmpty()) {

            StringBuilder instances = new StringBuilder();
            for (Instance instance : group.getInstances()) {
                instances.append(instance.getInstanceId()).append(", ");
            }

            primaryTableModel.addRow(new Object[] { "Instances", instances.toString() });
        }

        if (group.getLaunchConfigurationName() != null) {
            primaryTableModel
                    .addRow(new Object[] { "Launch Configuration Name", group.getLaunchConfigurationName() });
        }

        if (!group.getLoadBalancerNames().isEmpty()) {

            StringBuilder instances = new StringBuilder();
            for (String instance : group.getLoadBalancerNames()) {
                instances.append(instance).append(", ");
            }

            primaryTableModel.addRow(new Object[] { "LoadBalancer names", instances.toString() });
        }

        if (group.getMaxSize() != null) {
            primaryTableModel.addRow(new Object[] { "Max Size", group.getMaxSize() });
        }
        if (group.getMinSize() != null) {
            primaryTableModel.addRow(new Object[] { "Min Size", group.getMinSize() });
        }
        if (group.getPlacementGroup() != null) {
            primaryTableModel.addRow(new Object[] { "Placement Group", group.getPlacementGroup() });
        }
        if (group.getVPCZoneIdentifier() != null) {
            primaryTableModel.addRow(new Object[] { "VPC Zone Identifier", group.getVPCZoneIdentifier() });
        }

        List<TagDescription> tags = group.getTags();
        for (TagDescription tag : tags) {
            tagsTableModel.addRow(new Object[] { tag.getKey(), tag.getValue() });
        }
    }
}

From source file:com.liferay.amazontools.S3Cleaner.java

License:Open Source License

protected List<String> getLaunchConfigurationNames() {
    List<String> launchConfigurationNames = new ArrayList<>();

    DescribeAutoScalingGroupsResult describeAutoScalingGroupsResult = amazonAutoScalingClient
            .describeAutoScalingGroups();

    List<AutoScalingGroup> autoScalingGroups = describeAutoScalingGroupsResult.getAutoScalingGroups();

    for (AutoScalingGroup autoScalingGroup : autoScalingGroups) {
        launchConfigurationNames.add(autoScalingGroup.getLaunchConfigurationName());
    }/*from   www.  j  a v a  2s.c o  m*/

    return launchConfigurationNames;
}

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  ww  w  .  jav a  2s .c  om

    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. jav  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.netflix.spinnaker.clouddriver.aws.deploy.handlers.MigrateServerGroupStrategy.java

License:Apache License

/**
 * Migrates a server group and its associated load balancers and security groups from one location to another
 *
 * @param source                       the source server group
 * @param target                       the target location in which to migrate
 * @param sourceLookup                 a security group lookup cache for the source region
 * @param targetLookup                 a security group lookup cache for the target region (may be the same object as the sourceLookup)
 * @param migrateLoadBalancerStrategy  the load balancer migration strategy
 * @param migrateSecurityGroupStrategy the security group migration strategy
 * @param subnetType                   the subnetType in which to migrate the server group (should be null for EC Classic migrations)
 * @param elbSubnetType                the subnetType in which to migrate load balancers
 * @param iamRole                      the iamRole to use when migrating (optional)
 * @param keyPair                      the keyPair to use when migrating (optional)
 * @param targetAmi                    the target imageId to use when migrating (optional)
 * @param loadBalancerNameMapping      a mapping of source-to-target load balancer names
 * @param allowIngressFromClassic      if subnetType is present, and this is true, and app security groups are created
 *                                     via the deployDefaults, will add broad (80-65535) ingress from the classic link
 *                                     security group
 * @param dryRun                       whether to perform the migration or simply calculate the migration
 * @return a result set indicating the components required to perform the migration (if a dry run), or the objects
 * updated by the migration (if not a dry run)
 *///from w  w w  . jav  a2 s.c om
public synchronized MigrateServerGroupResult generateResults(ServerGroupLocation source,
        ServerGroupLocation target, SecurityGroupLookup sourceLookup, SecurityGroupLookup targetLookup,
        MigrateLoadBalancerStrategy migrateLoadBalancerStrategy,
        MigrateSecurityGroupStrategy migrateSecurityGroupStrategy, String subnetType, String elbSubnetType,
        String iamRole, String keyPair, String targetAmi, Map<String, String> loadBalancerNameMapping,
        boolean allowIngressFromClassic, boolean dryRun) {

    this.sourceLookup = sourceLookup;
    this.targetLookup = targetLookup;
    this.source = source;
    this.target = target;
    this.subnetType = subnetType;
    this.elbSubnetType = elbSubnetType;
    this.allowIngressFromClassic = allowIngressFromClassic;
    this.loadBalancerNameMapping = loadBalancerNameMapping;
    this.dryRun = dryRun;
    this.migrateSecurityGroupStrategy = migrateSecurityGroupStrategy;
    this.getMigrateLoadBalancerStrategy = migrateLoadBalancerStrategy;

    AsgService asgService = getRegionScopedProviderFactory()
            .forRegion(source.getCredentials(), source.getRegion()).getAsgService();

    AutoScalingGroup sourceGroup = asgService.getAutoScalingGroup(source.getName());

    if (sourceGroup == null) {
        throw new IllegalStateException("Error retrieving source server group: " + source.getName());
    }

    LaunchConfiguration launchConfig = asgService
            .getLaunchConfiguration(sourceGroup.getLaunchConfigurationName());

    if (launchConfig == null) {
        throw new IllegalStateException(
                "Could not find launch config: " + sourceGroup.getLaunchConfigurationName());
    }

    Names names = Names.parseName(source.getName());

    List<MigrateLoadBalancerResult> targetLoadBalancers = generateTargetLoadBalancers(sourceGroup);

    MigrateServerGroupResult migrateResult = new MigrateServerGroupResult();

    List<MigrateSecurityGroupResult> targetSecurityGroups = generateTargetSecurityGroups(launchConfig,
            migrateResult);

    Map<String, List<String>> zones = new HashMap<>();
    zones.put(target.getRegion(), target.getAvailabilityZones());

    DeploymentResult result;
    if (!dryRun) {
        Capacity capacity = getCapacity();
        BasicAmazonDeployDescription deployDescription = new BasicAmazonDeployDescription();
        deployDescription.setSource(getSource(source));
        deployDescription.setCredentials(target.getCredentials());
        deployDescription.setAmiName(targetAmi != null ? targetAmi : launchConfig.getImageId());
        deployDescription.setApplication(names.getApp());
        deployDescription.setStack(names.getStack());
        deployDescription.setFreeFormDetails(names.getDetail());
        deployDescription.setInstanceMonitoring(launchConfig.getInstanceMonitoring().getEnabled());
        deployDescription.setInstanceType(launchConfig.getInstanceType());
        deployDescription.setIamRole(iamRole != null ? iamRole : launchConfig.getIamInstanceProfile());
        deployDescription.setKeyPair(keyPair != null ? keyPair : launchConfig.getKeyName());
        deployDescription.setAssociatePublicIpAddress(launchConfig.getAssociatePublicIpAddress());
        deployDescription.setCooldown(sourceGroup.getDefaultCooldown());
        deployDescription.setHealthCheckGracePeriod(sourceGroup.getHealthCheckGracePeriod());
        deployDescription.setHealthCheckType(sourceGroup.getHealthCheckType());
        deployDescription.setSuspendedProcesses(sourceGroup.getSuspendedProcesses().stream()
                .map(SuspendedProcess::getProcessName).collect(Collectors.toSet()));
        deployDescription.setTerminationPolicies(sourceGroup.getTerminationPolicies());
        deployDescription.setKernelId(launchConfig.getKernelId());
        deployDescription.setEbsOptimized(launchConfig.getEbsOptimized());
        deployDescription.setLoadBalancers(targetLoadBalancers.stream()
                .map(MigrateLoadBalancerResult::getTargetName).collect(Collectors.toList()));
        deployDescription.setSecurityGroups(
                targetSecurityGroups.stream().filter(sg -> !sg.getSkipped().contains(sg.getTarget()))
                        .map(sg -> sg.getTarget().getTargetName()).collect(Collectors.toList()));
        deployDescription.setAvailabilityZones(zones);
        deployDescription.setStartDisabled(true);
        deployDescription.setCapacity(capacity);
        deployDescription.setSubnetType(subnetType);

        BasicAmazonDeployDescription description = generateDescription(deployDescription);

        if (!source.getCredentialAccount().equals(target.getCredentialAccount())) {
            Map<String, String> allowLaunchMap = new HashMap<>();
            allowLaunchMap.put("credentials", source.getCredentialAccount());
            allowLaunchMap.put("account", target.getCredentialAccount());
            allowLaunchMap.put("region", target.getRegion());
            allowLaunchMap.put("amiName", deployDescription.getAmiName());
            AllowLaunchAtomicOperation operation = getAllowLaunchAtomicOperationConverter()
                    .convertOperation(allowLaunchMap);

            operation.operate(null);
        }

        result = getBasicAmazonDeployHandler().handle(description, new ArrayList());
    } else {
        result = new DeploymentResult();
        String targetName = getRegionScopedProviderFactory()
                .forRegion(target.getCredentials(), target.getRegion()).getAWSServerGroupNameResolver()
                .resolveNextServerGroupName(names.getApp(), names.getStack(), names.getDetail(), false);

        result.setServerGroupNames(Collections.singletonList(targetName));
    }
    migrateResult.setServerGroupNames(result.getServerGroupNames());
    migrateResult.setLoadBalancers(targetLoadBalancers);
    migrateResult.setSecurityGroups(targetSecurityGroups);
    return migrateResult;
}

From source file:com.pinterest.arcee.autoscaling.AwsAutoScalingManager.java

License:Apache License

@Override
public AwsVmBean getAutoScalingGroupInfo(String clusterName) throws Exception {
    AutoScalingGroup autoScalingGroup = getAutoScalingGroup(clusterName);
    if (autoScalingGroup == null) {
        LOG.warn(String.format("Failed to get cluster %s: auto scaling group %s does not exist", clusterName,
                clusterName));/*from   w  w w.  j  av a2  s.  c o  m*/
        return null;
    }

    AwsVmBean launchConfigInfo = getLaunchConfigInfo(autoScalingGroup.getLaunchConfigurationName());
    AwsVmBean awsVmBean = new AwsVmBean();
    awsVmBean.setClusterName(clusterName);
    awsVmBean.setImage(launchConfigInfo.getImage());
    awsVmBean.setHostType(launchConfigInfo.getHostType());
    awsVmBean.setSecurityZone(launchConfigInfo.getSecurityZone());
    awsVmBean.setAssignPublicIp(launchConfigInfo.getAssignPublicIp());
    awsVmBean.setLaunchConfigId(launchConfigInfo.getLaunchConfigId());
    awsVmBean.setRole(launchConfigInfo.getRole());
    awsVmBean.setUserDataConfigs(
            transformUserDataToConfigMap(clusterName, launchConfigInfo.getRawUserDataString()));
    awsVmBean.setSubnet(autoScalingGroup.getVPCZoneIdentifier());
    awsVmBean.setMinSize(autoScalingGroup.getMinSize());
    awsVmBean.setMaxSize(autoScalingGroup.getMaxSize());
    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  .  ja  va 2  s.  c  o m*/
        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;
}

From source file:com.zotoh.cloudapi.aws.EC2AutoScale.java

License:Open Source License

private ScalingGroup toSG(AutoScalingGroup g) {
    ScalingGroup s = null;/* w w w .jav a2  s .c o m*/
    if (g != null) {
        s = new ScalingGroup();
        s.setCooldown(g.getDefaultCooldown());
        s.setCreationTimestamp(g.getCreatedTime().getTime());
        s.setDescription("");
        s.setMaxServers(g.getMaxSize());
        s.setMinServers(g.getMinSize());
        s.setName(g.getAutoScalingGroupName());
        s.setProviderDataCenterIds(g.getAvailabilityZones().toArray(new String[0]));
        s.setProviderLaunchConfigurationId(g.getLaunchConfigurationName());
        s.setProviderOwnerId(_svc.getCloud().getContext().getAccountNumber());
        s.setProviderRegionId(_svc.getCloud().getContext().getRegionId());
        s.setProviderScalingGroupId(s.getName());
        List<com.amazonaws.services.autoscaling.model.Instance> lst = g.getInstances();
        List<String> ls = new ArrayList<String>();
        if (lst != null)
            for (int i = 0; i < lst.size(); ++i) {
                ls.add(lst.get(i).getInstanceId());
            }
        s.setProviderServerIds(ls.toArray(new String[0]));
        s.setTargetCapacity(g.getDesiredCapacity());
    }
    return s;
}

From source file:org.xmlsh.aws.asDescribeGroups.java

License:BSD License

private void write(AutoScalingGroup group) throws XMLStreamException {
    startElement("group");
    attribute("group-arn", group.getAutoScalingGroupARN());
    attribute("name", group.getAutoScalingGroupName());

    attribute("create-time", group.getCreatedTime());
    attribute("default-cooldown", group.getDefaultCooldown());
    attribute("desired-capacity", group.getDesiredCapacity());

    attribute("health-check-grace-period", group.getHealthCheckGracePeriod());
    attribute("health-check-type", group.getHealthCheckType());

    attribute("launch-configuration-name", group.getLaunchConfigurationName());

    attribute("max-size", group.getMaxSize());
    attribute("min-size", group.getMinSize());
    attribute("placement-group", group.getPlacementGroup());

    attribute("status", group.getStatus());

    attribute("vpc-zone-id", group.getVPCZoneIdentifier());
    writeStringList("termination-policies", "termination-policy", "name", group.getTerminationPolicies());

    writeZones(group.getAvailabilityZones());
    writeMetrics(group.getEnabledMetrics());
    writeInstances(group.getInstances());
    writeELBNames(group.getLoadBalancerNames());
    writeSuspendedProcesses(group.getSuspendedProcesses());
    writeTagDescriptions(group.getTags());
    endElement();// w w w .  j  a  v a2  s .c o m

}