com.amazonaws.services.autoscaling.model.LaunchConfiguration Java Examples

The following examples show how to use com.amazonaws.services.autoscaling.model.LaunchConfiguration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LaunchConfigurationHandlerTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test
public void createNewLaunchConfiguration() {
    String lName = "lName";
    when(launchConfigurationMapper.mapExistingLaunchConfigToRequest(any(LaunchConfiguration.class)))
            .thenReturn(new CreateLaunchConfigurationRequest().withLaunchConfigurationName(lName));

    CloudContext cloudContext = new CloudContext(1L, "cloudContext", "AWS", USER_ID, WORKSPACE_ID);
    String imageName = "imageName";
    String launchConfigurationName = underTest.createNewLaunchConfiguration(imageName, autoScalingClient,
            new LaunchConfiguration().withLaunchConfigurationName(lName), cloudContext, null);
    ArgumentCaptor<CreateLaunchConfigurationRequest> captor = ArgumentCaptor.forClass(CreateLaunchConfigurationRequest.class);
    verify(autoScalingClient).createLaunchConfiguration(captor.capture());
    assertTrue(captor.getValue().getLaunchConfigurationName().startsWith(lName));
    assertTrue(captor.getValue().getLaunchConfigurationName().endsWith(imageName));
    assertEquals(lName + '-' + imageName, launchConfigurationName);
    verify(resourceNotifier, times(1)).notifyAllocation(any(CloudResource.class), eq(cloudContext));
}
 
Example #2
Source File: LaunchConfigurationTransformer.java    From sequenceiq-samples with Apache License 2.0 6 votes vote down vote up
public AwsLaunchConfiguration transform(LaunchConfiguration configuration) {
	AwsLaunchConfiguration awsLaunchConfiguration = new AwsLaunchConfiguration();
	awsLaunchConfiguration.setKeyName(configuration.getKeyName());
	awsLaunchConfiguration.setImageId(configuration.getImageId());
	awsLaunchConfiguration.setInstanceType(configuration.getInstanceType());
	awsLaunchConfiguration.setAssociatePublicIpAddress(configuration.getAssociatePublicIpAddress());
	awsLaunchConfiguration.setBlockDeviceMappings(configuration.getBlockDeviceMappings());
	awsLaunchConfiguration.setCreatedTime(configuration.getCreatedTime());
	awsLaunchConfiguration.setEbsOptimized(configuration.getEbsOptimized());
	awsLaunchConfiguration.setIamInstanceProfile(configuration.getIamInstanceProfile());
	awsLaunchConfiguration.setKernelId(configuration.getKernelId());
	awsLaunchConfiguration.setLaunchConfigurationName(configuration.getLaunchConfigurationName());
	awsLaunchConfiguration.setLaunchConfigurationARN(configuration.getLaunchConfigurationARN());
	awsLaunchConfiguration.setSecurityGroups(configuration.getSecurityGroups());
	awsLaunchConfiguration.setUserData(configuration.getUserData());
	awsLaunchConfiguration.setRamdiskId(configuration.getRamdiskId());
	awsLaunchConfiguration.setInstanceMonitoring(configuration.getInstanceMonitoring().getEnabled());
	awsLaunchConfiguration.setSpotPrice(configuration.getSpotPrice());
	awsLaunchConfiguration.setAssociatePublicIpAddress(configuration.getAssociatePublicIpAddress());

	return awsLaunchConfiguration;
}
 
Example #3
Source File: FileManager.java    From pacbot with Apache License 2.0 6 votes vote down vote up
/**
 * Generate launch configurations files.
 *
 * @param launchConfigurationMap the launch configuration map
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static void generateLaunchConfigurationsFiles(Map<String, List<LaunchConfiguration>> launchConfigurationMap) throws IOException {
	String fieldNames;
	String keys;
	fieldNames = "launchConfigurationName`launchConfigurationARN`imageId`keyName`classicLinkVPCId`userData`instanceType`kernelId`ramdiskId`spotPrice`iamInstanceProfile`createdTime`ebsOptimized`associatePublicIpAddress`placementTenancy"
			+"`securityGroups`classicLinkVPCSecurityGroups`instanceMonitoring.enabled";
	keys = "discoverydate`accountid`accountname`region`launchconfigurationname`launchconfigurationarn`imageid`keyname`classiclinkvpcid`userdata`instancetype`kernelid`ramdiskid`spotprice`iaminstanceprofile`createdtime`ebsoptimized`associatepublicipaddress`placementtenancy"
			+"`securitygroups`classiclinkvpcsecuritygroups`instancemonitoringenabled";
	FileGenerator.generateJson(launchConfigurationMap, fieldNames, "aws-launchconfig.data",keys);

	fieldNames = "launchConfigurationName`blockDeviceMappings.virtualName`blockDeviceMappings.deviceName`blockDeviceMappings.ebs.snapshotId`blockDeviceMappings.ebs.volumeSize"
			+"`blockDeviceMappings.ebs.volumeType`blockDeviceMappings.ebs.deleteOnTermination`blockDeviceMappings.ebs.iops`blockDeviceMappings.ebs.encrypted`blockDeviceMappings.noDevice";
	keys = "discoverydate`accountid`accountname`region`launchconfigurationname`virtualname`devicename`ebssnapshotid`ebsvolumesize"
			+"`ebsvolumetype`ebsdeleteontermination`ebsiops`ebsencrypted`nodevice";
	FileGenerator.generateJson(launchConfigurationMap, fieldNames, "aws-launchconfig-blockdevicemappings.data",keys);
}
 
Example #4
Source File: AwsLaunchConfigurationImageUpdateService.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private void changeImageInAutoscalingGroup(AuthenticatedContext authenticatedContext, CloudStack stack, AmazonAutoScalingClient autoScalingClient,
        Map<AutoScalingGroup, String> scalingGroups, Map<String, String> encryptedImages, LaunchConfiguration oldLaunchConfiguration) {

    Map.Entry<AutoScalingGroup, String> autoScalingGroup = getAutoScalingGroupForLaunchConfiguration(scalingGroups, oldLaunchConfiguration);

    String encryptedImageName = encryptedImages.get(autoScalingGroup.getValue());
    String launchConfigurationName = launchConfigurationHandler.createNewLaunchConfiguration(
            stack.getImage().getImageName(), autoScalingClient, oldLaunchConfiguration, authenticatedContext.getCloudContext(), encryptedImageName);

    autoScalingGroupHandler.updateAutoScalingGroupWithLaunchConfiguration(autoScalingClient, autoScalingGroup.getKey().getAutoScalingGroupName(),
            oldLaunchConfiguration, launchConfigurationName);

    launchConfigurationHandler.removeOldLaunchConfiguration(oldLaunchConfiguration, autoScalingClient, authenticatedContext.getCloudContext());
}
 
Example #5
Source File: AutoScalingGroupHandlerTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdateAutoScalingGroupWithLaunchConfiguration() {
    String autoScalingGroupName = "autoScalingGroupName";
    String launchConfigurationName = "launchConfigurationName";
    LaunchConfiguration oldLaunchConfiguration = new LaunchConfiguration();
    underTest.updateAutoScalingGroupWithLaunchConfiguration(autoScalingClient, autoScalingGroupName, oldLaunchConfiguration, launchConfigurationName);
    ArgumentCaptor<UpdateAutoScalingGroupRequest> captor = ArgumentCaptor.forClass(UpdateAutoScalingGroupRequest.class);
    verify(autoScalingClient, times(1)).updateAutoScalingGroup(captor.capture());
    UpdateAutoScalingGroupRequest request = captor.getValue();

    assertNotNull(request);
    assertEquals(autoScalingGroupName, request.getAutoScalingGroupName());
    assertEquals(launchConfigurationName, request.getLaunchConfigurationName());
}
 
Example #6
Source File: AwsLaunchConfigurationImageUpdateServiceTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldUpdateImage() {
    String lcName = "lcName";
    CloudResource cfResource = CloudResource.builder()
            .type(ResourceType.CLOUDFORMATION_STACK)
            .name("cf")
            .build();
    String autoScalingGroupName = "autoScalingGroupName";
    Map<AutoScalingGroup, String> scalingGroupStringMap =
            Collections.singletonMap(new AutoScalingGroup().withLaunchConfigurationName(lcName)
                    .withAutoScalingGroupName(autoScalingGroupName), autoScalingGroupName);
    when(cloudFormationClient.getTemplate(any())).thenReturn(new GetTemplateResult().withTemplateBody("AWS::AutoScaling::LaunchConfiguration"));
    when(autoScalingGroupHandler.getAutoScalingGroups(cloudFormationClient, autoScalingClient, cfResource))
            .thenReturn(scalingGroupStringMap);
    List<LaunchConfiguration> oldLaunchConfigs = Collections.singletonList(new LaunchConfiguration().withLaunchConfigurationName(lcName));
    when(launchConfigurationHandler.getLaunchConfigurations(autoScalingClient, scalingGroupStringMap.keySet()))
            .thenReturn(oldLaunchConfigs);
    String newLCName = "newLCName";
    when(launchConfigurationHandler.createNewLaunchConfiguration(eq("imageName"), eq(autoScalingClient), eq(oldLaunchConfigs.get(0)),
            eq(ac.getCloudContext()), eq(null))).thenReturn(newLCName);

    underTest.updateImage(ac, stack, cfResource);

    verify(autoScalingGroupHandler, times(1)).getAutoScalingGroups(cloudFormationClient, autoScalingClient, cfResource);
    verify(launchConfigurationHandler, times(1)).getLaunchConfigurations(autoScalingClient, scalingGroupStringMap.keySet());
    verify(launchConfigurationHandler, times(1)).createNewLaunchConfiguration(anyString(), eq(autoScalingClient),
            eq(oldLaunchConfigs.get(0)), eq(ac.getCloudContext()), eq(null));
    verify(autoScalingGroupHandler, times(1)).updateAutoScalingGroupWithLaunchConfiguration(autoScalingClient,
            autoScalingGroupName, oldLaunchConfigs.get(0), newLCName);
    verify(launchConfigurationHandler, times(1)).removeOldLaunchConfiguration(oldLaunchConfigs.get(0), autoScalingClient,
            ac.getCloudContext());
}
 
Example #7
Source File: LaunchConfigurationHandlerTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void removeOldLaunchConfiguration() {
    CloudContext cloudContext = new CloudContext(1L, "cloudContext", "AWS", USER_ID, WORKSPACE_ID);
    String launchConfigurationName = "old";
    underTest.removeOldLaunchConfiguration(new LaunchConfiguration().withLaunchConfigurationName(launchConfigurationName), autoScalingClient, cloudContext);
    ArgumentCaptor<DeleteLaunchConfigurationRequest> captor = ArgumentCaptor.forClass(DeleteLaunchConfigurationRequest.class);
    verify(autoScalingClient, times(1)).deleteLaunchConfiguration(captor.capture());
    assertEquals(launchConfigurationName, captor.getValue().getLaunchConfigurationName());
    verify(resourceNotifier, times(1)).notifyDeletion(any(CloudResource.class), eq(cloudContext));
}
 
Example #8
Source File: LaunchConfigurationHandler.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public void removeOldLaunchConfiguration(LaunchConfiguration oldLaunchConfiguration, AmazonAutoScalingClient autoScalingClient,
        CloudContext cloudContext) {
    autoScalingClient.deleteLaunchConfiguration(
            new DeleteLaunchConfigurationRequest().withLaunchConfigurationName(oldLaunchConfiguration.getLaunchConfigurationName()));
    CloudResource cloudResource = CloudResource.builder()
            .name(oldLaunchConfiguration.getLaunchConfigurationName())
            .type(ResourceType.AWS_LAUNCHCONFIGURATION)
            .build();
    resourceNotifier.notifyDeletion(cloudResource, cloudContext);
}
 
Example #9
Source File: LaunchConfigurationHandler.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private CreateLaunchConfigurationRequest getCreateLaunchConfigurationRequest(String imageName, LaunchConfiguration oldLaunchConfiguration) {
    CreateLaunchConfigurationRequest createLaunchConfigurationRequest =
            launchConfigurationMapper.mapExistingLaunchConfigToRequest(oldLaunchConfiguration);
    createLaunchConfigurationRequest.setImageId(imageName);
    createLaunchConfigurationRequest.setLaunchConfigurationName(
            oldLaunchConfiguration.getLaunchConfigurationName().replaceAll("-ami-[a-z0-9]+", "") + '-' + imageName);
    return createLaunchConfigurationRequest;
}
 
Example #10
Source File: LaunchConfigurationHandler.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public String createNewLaunchConfiguration(String imageName, AmazonAutoScalingClient autoScalingClient,
        LaunchConfiguration oldLaunchConfiguration, CloudContext cloudContext, String encryptedImageName) {
    String selectedImageName = StringUtils.isBlank(encryptedImageName) ? imageName : encryptedImageName;
    CreateLaunchConfigurationRequest createLaunchConfigurationRequest = getCreateLaunchConfigurationRequest(selectedImageName, oldLaunchConfiguration);
    LOGGER.debug("Create LaunchConfiguration {} with image {}",
            createLaunchConfigurationRequest.getLaunchConfigurationName(), selectedImageName);
    autoScalingClient.createLaunchConfiguration(createLaunchConfigurationRequest);
    CloudResource cloudResource = CloudResource.builder()
            .type(ResourceType.AWS_LAUNCHCONFIGURATION)
            .params(Collections.emptyMap())
            .name(createLaunchConfigurationRequest.getLaunchConfigurationName())
            .build();
    resourceNotifier.notifyAllocation(cloudResource, cloudContext);
    return createLaunchConfigurationRequest.getLaunchConfigurationName();
}
 
Example #11
Source File: AwsLaunchConfigurationImageUpdateService.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private Map.Entry<AutoScalingGroup, String> getAutoScalingGroupForLaunchConfiguration(Map<AutoScalingGroup, String> scalingGroups,
        LaunchConfiguration oldLaunchConfiguration) {
    return scalingGroups.entrySet().stream()
            .filter(entry -> entry.getKey().getLaunchConfigurationName()
                    .equalsIgnoreCase(oldLaunchConfiguration.getLaunchConfigurationName()))
            .findFirst().orElseThrow(() -> new NoSuchElementException("Launch configuration not found for: "
                    + oldLaunchConfiguration.getLaunchConfigurationName()));
}
 
Example #12
Source File: AwsLaunchConfigurationImageUpdateService.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public void updateImage(AuthenticatedContext authenticatedContext, CloudStack stack, CloudResource cfResource) {
    AwsCredentialView credentialView = new AwsCredentialView(authenticatedContext.getCloudCredential());
    String regionName = authenticatedContext.getCloudContext().getLocation().getRegion().getRegionName();
    AmazonCloudFormationClient cloudFormationClient = awsClient.createCloudFormationClient(credentialView, regionName);
    AmazonAutoScalingClient autoScalingClient = awsClient.createAutoScalingClient(credentialView, regionName);

    Map<String, String> encryptedImages = getEncryptedImagesMappedByAutoscalingGroupName(authenticatedContext, stack);
    Map<AutoScalingGroup, String> scalingGroups = autoScalingGroupHandler.getAutoScalingGroups(cloudFormationClient, autoScalingClient, cfResource);
    List<LaunchConfiguration> oldLaunchConfigurations = launchConfigurationHandler.getLaunchConfigurations(autoScalingClient, scalingGroups.keySet());
    for (LaunchConfiguration oldLaunchConfiguration : oldLaunchConfigurations) {
        changeImageInAutoscalingGroup(authenticatedContext, stack, autoScalingClient, scalingGroups, encryptedImages, oldLaunchConfiguration);
    }
}
 
Example #13
Source File: AutoScalingGroupHandler.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public void updateAutoScalingGroupWithLaunchConfiguration(AmazonAutoScalingClient autoScalingClient, String autoScalingGroupName,
        LaunchConfiguration oldLaunchConfiguration, String launchConfigurationName) {
    UpdateAutoScalingGroupRequest updateAutoScalingGroupRequest = new UpdateAutoScalingGroupRequest();
    updateAutoScalingGroupRequest.setAutoScalingGroupName(autoScalingGroupName);
    updateAutoScalingGroupRequest.setLaunchConfigurationName(launchConfigurationName);
    LOGGER.debug("Update AutoScalingGroup {} with LaunchConfiguration {}",
            updateAutoScalingGroupRequest.getAutoScalingGroupName(), updateAutoScalingGroupRequest.getLaunchConfigurationName());
    autoScalingClient.updateAutoScalingGroup(updateAutoScalingGroupRequest);
}
 
Example #14
Source File: AutoScalingController.java    From sequenceiq-samples with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/launchconfig", method = RequestMethod.GET)
@ResponseBody
public List<AwsLaunchConfiguration> listLaunchConfigurations(@RequestParam("accessKey") String accessKey, @RequestParam("secretKey") String secretKey) {
	List<AwsLaunchConfiguration> list = new ArrayList<>();
	for (LaunchConfiguration item : awsec2Service
	        .describeAmazonLaunchConfigurations(awsCredentialsFactory.createSimpleAWSCredentials(accessKey, secretKey))) {
		list.add(transformer.transform(item));
	}
	return list;
}
 
Example #15
Source File: ASGInventoryUtilTest.java    From pacbot with Apache License 2.0 5 votes vote down vote up
/**
 * Fetch launch configurations test.
 *
 * @throws Exception the exception
 */
@SuppressWarnings("static-access")
@Test
public void fetchLaunchConfigurationsTest() throws Exception {
    
    mockStatic(AmazonAutoScalingClientBuilder.class);
    AmazonAutoScaling asgClient = PowerMockito.mock(AmazonAutoScaling.class);
    AmazonAutoScalingClientBuilder amazonAutoScalingClientBuilder = PowerMockito.mock(AmazonAutoScalingClientBuilder.class);
    AWSStaticCredentialsProvider awsStaticCredentialsProvider = PowerMockito.mock(AWSStaticCredentialsProvider.class);
    PowerMockito.whenNew(AWSStaticCredentialsProvider.class).withAnyArguments().thenReturn(awsStaticCredentialsProvider);
    when(amazonAutoScalingClientBuilder.standard()).thenReturn(amazonAutoScalingClientBuilder);
    when(amazonAutoScalingClientBuilder.withCredentials(anyObject())).thenReturn(amazonAutoScalingClientBuilder);
    when(amazonAutoScalingClientBuilder.withRegion(anyString())).thenReturn(amazonAutoScalingClientBuilder);
    when(amazonAutoScalingClientBuilder.build()).thenReturn(asgClient);
    
    DescribeAutoScalingGroupsResult autoScalingGroupsResult = new DescribeAutoScalingGroupsResult();
    List<AutoScalingGroup> asgList = new ArrayList<>();
    AutoScalingGroup autoScalingGroup = new AutoScalingGroup();
    autoScalingGroup.setLaunchConfigurationName("launchConfigurationName");
    asgList.add(autoScalingGroup);
    autoScalingGroupsResult.setAutoScalingGroups(asgList);
    when(asgClient.describeAutoScalingGroups(anyObject())).thenReturn(autoScalingGroupsResult);
    
    DescribeLaunchConfigurationsResult launchConfigurationsResult = new DescribeLaunchConfigurationsResult();
    List<LaunchConfiguration> launchConfigurations = new ArrayList<>();
    launchConfigurations.add(new LaunchConfiguration());
    
    launchConfigurationsResult.setLaunchConfigurations(launchConfigurations);
    when(asgClient.describeLaunchConfigurations(anyObject())).thenReturn(launchConfigurationsResult);
    assertThat(asgInventoryUtil.fetchLaunchConfigurations(new BasicSessionCredentials("awsAccessKey", "awsSecretKey", "sessionToken"), 
            "skipRegions", "account","accountName").size(), is(1));
    
}
 
Example #16
Source File: LaunchConfigurationHandler.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
public List<LaunchConfiguration> getLaunchConfigurations(AmazonAutoScalingClient autoScalingClient, Collection<AutoScalingGroup> scalingGroups) {
    DescribeLaunchConfigurationsRequest launchConfigurationsRequest = new DescribeLaunchConfigurationsRequest();
    launchConfigurationsRequest.setLaunchConfigurationNames(
            scalingGroups.stream().map(AutoScalingGroup::getLaunchConfigurationName).collect(Collectors.toList()));
    return autoScalingClient.describeLaunchConfigurations(launchConfigurationsRequest).getLaunchConfigurations();
}
 
Example #17
Source File: LaunchConfigurationMapper.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
public CreateLaunchConfigurationRequest mapExistingLaunchConfigToRequest(LaunchConfiguration launchConfiguration) {
    if (launchConfiguration == null) {
        return null;
    }

    CreateLaunchConfigurationRequest createLaunchConfigurationRequest = new CreateLaunchConfigurationRequest();

    createLaunchConfigurationRequest.setLaunchConfigurationName(emptyToNullStringMapper.map(launchConfiguration.getLaunchConfigurationName()));
    createLaunchConfigurationRequest.setImageId(emptyToNullStringMapper.map(launchConfiguration.getImageId()));
    createLaunchConfigurationRequest.setKeyName(emptyToNullStringMapper.map(launchConfiguration.getKeyName()));
    List<String> list = launchConfiguration.getSecurityGroups();
    if (list != null) {
        createLaunchConfigurationRequest.setSecurityGroups(new ArrayList<String>(list));
    } else {
        createLaunchConfigurationRequest.setSecurityGroups(null);
    }
    createLaunchConfigurationRequest.setClassicLinkVPCId(emptyToNullStringMapper.map(launchConfiguration.getClassicLinkVPCId()));
    List<String> list1 = launchConfiguration.getClassicLinkVPCSecurityGroups();
    if (list1 != null) {
        createLaunchConfigurationRequest.setClassicLinkVPCSecurityGroups(new ArrayList<String>(list1));
    } else {
        createLaunchConfigurationRequest.setClassicLinkVPCSecurityGroups(null);
    }
    createLaunchConfigurationRequest.setUserData(emptyToNullStringMapper.map(launchConfiguration.getUserData()));
    createLaunchConfigurationRequest.setInstanceType(emptyToNullStringMapper.map(launchConfiguration.getInstanceType()));
    createLaunchConfigurationRequest.setKernelId(emptyToNullStringMapper.map(launchConfiguration.getKernelId()));
    createLaunchConfigurationRequest.setRamdiskId(emptyToNullStringMapper.map(launchConfiguration.getRamdiskId()));
    List<BlockDeviceMapping> list2 = launchConfiguration.getBlockDeviceMappings();
    if (list2 != null) {
        createLaunchConfigurationRequest.setBlockDeviceMappings(new ArrayList<BlockDeviceMapping>(list2));
    } else {
        createLaunchConfigurationRequest.setBlockDeviceMappings(null);
    }
    createLaunchConfigurationRequest.setInstanceMonitoring(launchConfiguration.getInstanceMonitoring());
    createLaunchConfigurationRequest.setSpotPrice(emptyToNullStringMapper.map(launchConfiguration.getSpotPrice()));
    createLaunchConfigurationRequest.setIamInstanceProfile(emptyToNullStringMapper.map(launchConfiguration.getIamInstanceProfile()));
    createLaunchConfigurationRequest.setEbsOptimized(launchConfiguration.getEbsOptimized());
    createLaunchConfigurationRequest.setAssociatePublicIpAddress(launchConfiguration.getAssociatePublicIpAddress());
    createLaunchConfigurationRequest.setPlacementTenancy(emptyToNullStringMapper.map(launchConfiguration.getPlacementTenancy()));

    return createLaunchConfigurationRequest;
}
 
Example #18
Source File: AwsInstanceCloudConnector.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
private InstanceLaunchConfiguration toInstanceLaunchConfiguration(LaunchConfiguration awsLaunchConfiguration) {
    return new InstanceLaunchConfiguration(
            awsLaunchConfiguration.getLaunchConfigurationName(),
            awsLaunchConfiguration.getInstanceType()
    );
}
 
Example #19
Source File: AwsInstanceCloudConnector.java    From titus-control-plane with Apache License 2.0 4 votes vote down vote up
private List<InstanceLaunchConfiguration> toInstanceLaunchConfigurations(List<LaunchConfiguration> awsLaunchConfigurations) {
    return awsLaunchConfigurations.stream().map(this::toInstanceLaunchConfiguration).collect(Collectors.toList());
}
 
Example #20
Source File: ASGInventoryUtil.java    From pacbot with Apache License 2.0 4 votes vote down vote up
/**
 * Fetch launch configurations.
 *
 * @param temporaryCredentials the temporary credentials
 * @param skipRegions the skip regions
 * @param accountId the accountId
 * @return the map
 */
public static Map<String,List<LaunchConfiguration>> fetchLaunchConfigurations(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){
	
	AmazonAutoScaling asgClient;
	Map<String,List<LaunchConfiguration>> launchConfigurationList = new LinkedHashMap<>();
	List<String> launchConfigurationNames = new ArrayList<>();
	
	String expPrefix = "{\"errcode\": \"NO_RES_REG\" ,\"accountId\": \""+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"ASG\" , \"region\":\"" ;
	for(Region region : RegionUtils.getRegions()){ 
		try{
			if(!skipRegions.contains(region.getName())){ //!skipRegions
				List<LaunchConfiguration> launchConfigurationListTemp = new ArrayList<>();
				asgClient = AmazonAutoScalingClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build();
				String nextToken = null;
				DescribeAutoScalingGroupsResult  describeResult ;
				do{
					describeResult =  asgClient.describeAutoScalingGroups(new DescribeAutoScalingGroupsRequest().withNextToken(nextToken).withMaxRecords(asgMaxRecord));
					for(AutoScalingGroup _asg : describeResult.getAutoScalingGroups()) {
						launchConfigurationNames.add(_asg.getLaunchConfigurationName());
					}
					nextToken = describeResult.getNextToken();
				}while(nextToken!=null);
				List<String> launchConfigurationNamesTemp = new ArrayList<>();
				
				for(int i =0 ; i<launchConfigurationNames.size();i++){
					launchConfigurationNamesTemp.add(launchConfigurationNames.get(i));
					if((i+1)%50==0 || i == launchConfigurationNames.size()-1){
						launchConfigurationListTemp.addAll(asgClient.describeLaunchConfigurations(new DescribeLaunchConfigurationsRequest().withLaunchConfigurationNames(launchConfigurationNamesTemp)).getLaunchConfigurations());
						launchConfigurationNamesTemp = new ArrayList<>();
					}
					
				}
				
				if(!launchConfigurationListTemp.isEmpty() ){
					log.debug("Account : " + accountId + " Type : ASG Launch Configurations "+region.getName()+" >> " + launchConfigurationListTemp.size());
					launchConfigurationList.put(accountId+delimiter+accountName+delimiter+region.getName(), launchConfigurationListTemp);
				}
		   	}
		}catch(Exception e){
			log.warn(expPrefix+ region.getName()+"\", \"cause\":\"" +e.getMessage()+"\"}");
			ErrorManageUtil.uploadError(accountId,region.getName(),"launchconfig",e.getMessage());
		}
	}
	return launchConfigurationList;
}
 
Example #21
Source File: AutoScalingService.java    From sequenceiq-samples with Apache License 2.0 votes vote down vote up
List<LaunchConfiguration> describeAmazonLaunchConfigurations(AWSCredentials credentials);