Example usage for com.amazonaws.services.autoscaling.model LaunchConfiguration getImageId

List of usage examples for com.amazonaws.services.autoscaling.model LaunchConfiguration getImageId

Introduction

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

Prototype


public String getImageId() 

Source Link

Document

The ID of the Amazon Machine Image (AMI) to use to launch your EC2 instances.

Usage

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() });
        }/*from ww w  . j  a  v  a  2  s  .co  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.S3Cleaner.java

License:Open Source License

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

    DescribeLaunchConfigurationsRequest describeLaunchConfigurationsRequest = new DescribeLaunchConfigurationsRequest();

    describeLaunchConfigurationsRequest.setLaunchConfigurationNames(launchConfigurationNames);

    DescribeLaunchConfigurationsResult describeLaunchConfigurationsResult = amazonAutoScalingClient
            .describeLaunchConfigurations(describeLaunchConfigurationsRequest);

    for (LaunchConfiguration launchConfiguration : describeLaunchConfigurationsResult
            .getLaunchConfigurations()) {

        imageIds.add(launchConfiguration.getImageId());
    }/* ww  w  .  j  a v  a2 s .com*/

    return imageIds;
}

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.  ja  va2  s. c o  m
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.AwsAutoScaleGroupManager.java

License:Apache License

@Override
public GroupBean getLaunchConfigByName(String configId) throws Exception {
    GroupBean groupBean = new GroupBean();
    if (configId == null) {
        return groupBean;
    }/*from  ww w.  j  av a2s  .  c om*/

    DescribeLaunchConfigurationsRequest configurationsRequest = new DescribeLaunchConfigurationsRequest();
    configurationsRequest.setLaunchConfigurationNames(Arrays.asList(configId));
    DescribeLaunchConfigurationsResult configurationsResult = aasClient
            .describeLaunchConfigurations(configurationsRequest);
    List<LaunchConfiguration> configs = configurationsResult.getLaunchConfigurations();
    if (configs.isEmpty()) {
        return groupBean;
    }

    LaunchConfiguration config = configs.get(0);
    groupBean.setInstance_type(config.getInstanceType());
    groupBean.setImage_id(config.getImageId());
    if (!config.getSecurityGroups().isEmpty()) {
        groupBean.setSecurity_group(config.getSecurityGroups().get(0));
    }

    groupBean.setUser_data(new String(Base64.decodeBase64(config.getUserData())));
    groupBean.setIam_role(config.getIamInstanceProfile());

    if (config.isAssociatePublicIpAddress() != null) {
        groupBean.setAssign_public_ip(config.getAssociatePublicIpAddress());
    } else {
        // default value to false
        groupBean.setAssign_public_ip(false);
    }
    return groupBean;
}

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  va  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 .  co  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;
}