com.amazonaws.services.autoscaling.AmazonAutoScalingClient Java Examples

The following examples show how to use com.amazonaws.services.autoscaling.AmazonAutoScalingClient. 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: CustomAmazonWaiterProvider.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
public Waiter<DescribeAutoScalingGroupsRequest> getAutoscalingInstancesInServiceWaiter(AmazonAutoScalingClient asClient, Integer requiredCount) {
    return new WaiterBuilder<DescribeAutoScalingGroupsRequest, DescribeAutoScalingGroupsResult>()
            .withSdkFunction(new DescribeAutoScalingGroupsFunction(asClient))
            .withAcceptors(new WaiterAcceptor<DescribeAutoScalingGroupsResult>() {
                @Override
                public boolean matches(DescribeAutoScalingGroupsResult describeAutoScalingGroupsResult) {
                    return describeAutoScalingGroupsResult.getAutoScalingGroups().get(0).getInstances()
                            .stream().filter(instance -> IN_SERVICE.equals(instance.getLifecycleState())).count() == requiredCount;
                }

                @Override
                public WaiterState getState() {
                    return WaiterState.SUCCESS;
                }
            })
            .withDefaultPollingStrategy(new PollingStrategy(new MaxAttemptsRetryStrategy(DEFAULT_MAX_ATTEMPTS),
                    new FixedDelayStrategy(DEFAULT_DELAY_IN_SECONDS)))
            .withExecutorService(WaiterExecutorServiceFactory.buildExecutorServiceForWaiter("AmazonRDSWaiters")).build();
}
 
Example #2
Source File: AutoScalingGroupHandler.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public Map<AutoScalingGroup, String> getAutoScalingGroups(AmazonCloudFormationClient cloudFormationClient, AmazonAutoScalingClient autoScalingClient,
        CloudResource cfResource) {
    DescribeStackResourcesRequest resourcesRequest = new DescribeStackResourcesRequest();
    resourcesRequest.setStackName(cfResource.getName());
    DescribeStackResourcesResult resourcesResult = cloudFormationClient.describeStackResources(resourcesRequest);
    Map<String, String> autoScalingGroups = resourcesResult.getStackResources().stream()
            .filter(stackResource -> "AWS::AutoScaling::AutoScalingGroup".equalsIgnoreCase(stackResource.getResourceType()))
            .collect(Collectors.toMap(StackResource::getPhysicalResourceId, StackResource::getLogicalResourceId));
    DescribeAutoScalingGroupsRequest request = new DescribeAutoScalingGroupsRequest();
    request.setAutoScalingGroupNames(autoScalingGroups.keySet());
    List<AutoScalingGroup> scalingGroups = autoScalingClient.describeAutoScalingGroups(request).getAutoScalingGroups();
    return scalingGroups.stream()
            .collect(Collectors.toMap(scalingGroup -> scalingGroup, scalingGroup -> autoScalingGroups.get(scalingGroup.getAutoScalingGroupName())));
}
 
Example #3
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 #4
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 #5
Source File: AwsClient.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public AmazonAutoScalingClient createAutoScalingClient(AwsCredentialView awsCredential, String regionName) {
    AmazonAutoScalingClient client = isRoleAssumeRequired(awsCredential) ?
            new AmazonAutoScalingClient(createAwsSessionCredentialProvider(awsCredential), getDefaultClientConfiguration()) :
            new AmazonAutoScalingClient(createAwsCredentials(awsCredential), getDefaultClientConfiguration());
    client.setRegion(RegionUtils.getRegion(regionName));
    return client;
}
 
Example #6
Source File: AwsTerminateService.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private void deleteLaunchConfiguration(List<CloudResource> resources, AuthenticatedContext ac) {
    if (resources == null) {
        return;
    }
    AmazonAutoScalingClient autoScalingClient = awsClient.createAutoScalingClient(new AwsCredentialView(ac.getCloudCredential()),
            ac.getCloudContext().getLocation().getRegion().value());
    resources.stream().filter(cloudResource -> cloudResource.getType() == ResourceType.AWS_LAUNCHCONFIGURATION).forEach(cloudResource ->
            autoScalingClient.deleteLaunchConfiguration(
                    new DeleteLaunchConfigurationRequest().withLaunchConfigurationName(cloudResource.getName())));
}
 
Example #7
Source File: AwsAutoScalingService.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public void scheduleStatusChecks(Map<String, Integer> groupsWithSize, AuthenticatedContext ac, Date timeBeforeASUpdate)
        throws AmazonAutoscalingFailed {

    AmazonEC2Client amClient = awsClient.createAccess(new AwsCredentialView(ac.getCloudCredential()),
            ac.getCloudContext().getLocation().getRegion().value());
    AmazonAutoScalingClient asClient = awsClient.createAutoScalingClient(new AwsCredentialView(ac.getCloudCredential()),
            ac.getCloudContext().getLocation().getRegion().value());
    AmazonAutoScalingRetryClient asRetryClient = awsClient.createAutoScalingRetryClient(new AwsCredentialView(ac.getCloudCredential()),
            ac.getCloudContext().getLocation().getRegion().value());
    for (Map.Entry<String, Integer> groupWithSize : groupsWithSize.entrySet()) {
        String autoScalingGroupName = groupWithSize.getKey();
        Integer expectedSize = groupWithSize.getValue();
        waitForGroup(amClient, asClient, asRetryClient, autoScalingGroupName, expectedSize, ac.getCloudContext().getId());
    }
}
 
Example #8
Source File: AwsAutoScalingService.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public void scheduleStatusChecks(List<Group> groups, AuthenticatedContext ac, AmazonCloudFormationRetryClient cloudFormationClient, Date timeBeforeASUpdate)
        throws AmazonAutoscalingFailed {
    AmazonEC2Client amClient = awsClient.createAccess(new AwsCredentialView(ac.getCloudCredential()),
            ac.getCloudContext().getLocation().getRegion().value());
    AmazonAutoScalingClient asClient = awsClient.createAutoScalingClient(new AwsCredentialView(ac.getCloudCredential()),
            ac.getCloudContext().getLocation().getRegion().value());
    AmazonAutoScalingRetryClient asRetryClient = awsClient.createAutoScalingRetryClient(new AwsCredentialView(ac.getCloudCredential()),
            ac.getCloudContext().getLocation().getRegion().value());
    for (Group group : groups) {
        String asGroupName = cfStackUtil.getAutoscalingGroupName(ac, cloudFormationClient, group.getName());
        LOGGER.debug("Polling Auto Scaling group until new instances are ready. [stack: {}, asGroup: {}]", ac.getCloudContext().getId(),
                asGroupName);
        waitForGroup(amClient, asClient, asRetryClient, asGroupName, group.getInstancesSize(), ac.getCloudContext().getId());
    }
}
 
Example #9
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 #10
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 #11
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 #12
Source File: SimpleAutoScalingService.java    From sequenceiq-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void updateAmazonAutoScalingGroupMinSize(AWSCredentials credentials, String name, int minSize) {
    AmazonAutoScalingClient amazonAutoScalingClient = amazonAutoScalingClientFactory.createAmazonAutoScalingClient(credentials);
    UpdateAutoScalingGroupRequest updateAutoScalingGroupRequest = new UpdateAutoScalingGroupRequest()
            .withAutoScalingGroupName(name)
            .withMinSize(minSize);
    amazonAutoScalingClient.updateAutoScalingGroup(updateAutoScalingGroupRequest);
}
 
Example #13
Source File: SimpleAutoScalingService.java    From sequenceiq-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void updateAmazonAutoScalingGroupMaxSize(AWSCredentials credentials, String name, int maxSize) {
    AmazonAutoScalingClient amazonAutoScalingClient = amazonAutoScalingClientFactory.createAmazonAutoScalingClient(credentials);
    UpdateAutoScalingGroupRequest updateAutoScalingGroupRequest = new UpdateAutoScalingGroupRequest()
            .withAutoScalingGroupName(name)
            .withMaxSize(maxSize);
    amazonAutoScalingClient.updateAutoScalingGroup(updateAutoScalingGroupRequest);
}
 
Example #14
Source File: SimpleAutoScalingService.java    From sequenceiq-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void updateAmazonAutoScalingGroupCoolDown(AWSCredentials credentials, String name, int coolDown) {
    AmazonAutoScalingClient amazonAutoScalingClient = amazonAutoScalingClientFactory.createAmazonAutoScalingClient(credentials);
    UpdateAutoScalingGroupRequest updateAutoScalingGroupRequest = new UpdateAutoScalingGroupRequest()
            .withAutoScalingGroupName(name)
            .withDefaultCooldown(coolDown);
    amazonAutoScalingClient.updateAutoScalingGroup(updateAutoScalingGroupRequest);
}
 
Example #15
Source File: SimpleAutoScalingService.java    From sequenceiq-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void createAmazonAutoScalingGroup(AWSCredentials credentials, String name, int maxsize, int minsize, int coolDown, String configName,
                                         Collection<String> loadBalancerNames, Collection<com.amazonaws.services.autoscaling.model.Tag> tags) {
    AmazonAutoScalingClient amazonAutoScalingClient = amazonAutoScalingClientFactory.createAmazonAutoScalingClient(credentials);
    CreateAutoScalingGroupRequest createAutoScalingGroupRequest = new CreateAutoScalingGroupRequest().withAutoScalingGroupName(name)
            .withDefaultCooldown(coolDown).withLaunchConfigurationName(configName).withMaxSize(maxsize).withMinSize(minsize).withTags(tags)
            .withLoadBalancerNames(loadBalancerNames).withAvailabilityZones(Arrays.asList("us-west-2b"));
    amazonAutoScalingClient.createAutoScalingGroup(createAutoScalingGroupRequest);
}
 
Example #16
Source File: AWSSdkClient.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
/***
 * Initialize the AWS SDK Client
 *
 * @param awsClusterSecurityManager The {@link AWSClusterSecurityManager} to fetch AWS credentials
 * @param region The Amazon AWS {@link Region}
 */
public AWSSdkClient(final AWSClusterSecurityManager awsClusterSecurityManager, final Region region) {
  this.amazonEC2Supplier = Suppliers.memoize(new Supplier<AmazonEC2>() {
    @Override
    public AmazonEC2 get() {
      AmazonEC2Client amazonEC2 = new AmazonEC2Client(awsClusterSecurityManager.getCredentialsProvider());
      amazonEC2.setRegion(region);
      return amazonEC2;
    }
  });
  this.amazonS3Supplier = Suppliers.memoize(new Supplier<AmazonS3>() {
    @Override
    public AmazonS3 get() {
      AmazonS3Client amazonS3 = new AmazonS3Client(awsClusterSecurityManager.getCredentialsProvider());
      amazonS3.setRegion(region);
      return amazonS3;
    }
  });
  this.amazonAutoScalingSupplier = Suppliers.memoize(new Supplier<AmazonAutoScaling>() {
    @Override
    public AmazonAutoScaling get() {
      AmazonAutoScalingClient amazonAutoScaling =
              new AmazonAutoScalingClient(awsClusterSecurityManager.getCredentialsProvider());
      amazonAutoScaling.setRegion(region);
      return amazonAutoScaling;
    }
  });
}
 
Example #17
Source File: MvcConfiguration.java    From aws-codedeploy-sample-tomcat with Apache License 2.0 4 votes vote down vote up
@Bean
public AmazonAutoScaling autoScaling() {
    AmazonAutoScaling client = new AmazonAutoScalingClient();
    client.setRegion(region);
    return client;
}
 
Example #18
Source File: SimpleAutoScalingService.java    From sequenceiq-samples with Apache License 2.0 4 votes vote down vote up
@Override
public List<AutoScalingInstanceDetails> describeAmazonAutoScalingInstances(AWSCredentials credentials) {
    AmazonAutoScalingClient amazonAutoScalingClient = amazonAutoScalingClientFactory.createAmazonAutoScalingClient(credentials);
    DescribeAutoScalingInstancesResult describeAutoScalingInstancesResult = amazonAutoScalingClient.describeAutoScalingInstances();
    return describeAutoScalingInstancesResult.getAutoScalingInstances();
}
 
Example #19
Source File: SimpleAutoScalingService.java    From sequenceiq-samples with Apache License 2.0 4 votes vote down vote up
@Override
public List<AutoScalingGroup> describeAmazonAutoScalingGroups(AWSCredentials credentials) {
    AmazonAutoScalingClient amazonAutoScalingClient = amazonAutoScalingClientFactory.createAmazonAutoScalingClient(credentials);
    DescribeAutoScalingGroupsResult describeAutoScalingGroupsResult = amazonAutoScalingClient.describeAutoScalingGroups();
    return describeAutoScalingGroupsResult.getAutoScalingGroups();
}
 
Example #20
Source File: SimpleAutoScalingService.java    From sequenceiq-samples with Apache License 2.0 4 votes vote down vote up
@Override
public List<LaunchConfiguration> describeAmazonLaunchConfigurations(AWSCredentials credentials) {
    AmazonAutoScalingClient amazonAutoScalingClient = amazonAutoScalingClientFactory.createAmazonAutoScalingClient(credentials);
    DescribeLaunchConfigurationsResult describeLaunchConfigurationsResult = amazonAutoScalingClient.describeLaunchConfigurations();
    return describeLaunchConfigurationsResult.getLaunchConfigurations();
}
 
Example #21
Source File: AmazonAutoScalingRetryClient.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
public AmazonAutoScalingRetryClient(AmazonAutoScalingClient client, Retry retry) {
    this.client = client;
    this.retry = retry;
}
 
Example #22
Source File: AmazonAutoScalingClientFactory.java    From sequenceiq-samples with Apache License 2.0 4 votes vote down vote up
public AmazonAutoScalingClient createAmazonAutoScalingClient(AWSCredentials crendentials) {
	AmazonAutoScalingClient amazonEC2Client = new AmazonAutoScalingClient(new SimpleAWSCredentialsProvider(crendentials));
	amazonEC2Client.setRegion(region);
	return amazonEC2Client;
}
 
Example #23
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 #24
Source File: AWSMembership.java    From Raigad with Apache License 2.0 4 votes vote down vote up
protected AmazonAutoScaling getAutoScalingClient() {
    AmazonAutoScaling client = new AmazonAutoScalingClient(provider.getAwsCredentialProvider());
    client.setEndpoint("autoscaling." + config.getDC() + ".amazonaws.com");
    return client;
}