Search in sources :

Example 1 with DescribeScalableTargetsRequest

use of com.amazonaws.services.applicationautoscaling.model.DescribeScalableTargetsRequest in project aws-doc-sdk-examples by awsdocs.

the class DisableDynamoDBAutoscaling method main.

public static void main(String[] args) {
    ServiceNamespace ns = ServiceNamespace.Dynamodb;
    ScalableDimension tableWCUs = ScalableDimension.DynamodbTableWriteCapacityUnits;
    String resourceID = "table/TestTable";
    // Delete the scaling policy
    DeleteScalingPolicyRequest delSPRequest = new DeleteScalingPolicyRequest().withServiceNamespace(ns).withScalableDimension(tableWCUs).withResourceId(resourceID).withPolicyName("MyScalingPolicy");
    try {
        aaClient.deleteScalingPolicy(delSPRequest);
    } catch (Exception e) {
        System.err.println("Unable to delete scaling policy: ");
        System.err.println(e.getMessage());
    }
    // Verify that the scaling policy was deleted
    DescribeScalingPoliciesRequest descSPRequest = new DescribeScalingPoliciesRequest().withServiceNamespace(ns).withScalableDimension(tableWCUs).withResourceId(resourceID);
    try {
        DescribeScalingPoliciesResult dspResult = aaClient.describeScalingPolicies(descSPRequest);
        System.out.println("DescribeScalingPolicies result: ");
        System.out.println(dspResult);
    } catch (Exception e) {
        e.printStackTrace();
        System.err.println("Unable to describe scaling policy: ");
        System.err.println(e.getMessage());
    }
    System.out.println();
    // Remove the scalable target
    DeregisterScalableTargetRequest delSTRequest = new DeregisterScalableTargetRequest().withServiceNamespace(ns).withScalableDimension(tableWCUs).withResourceId(resourceID);
    try {
        aaClient.deregisterScalableTarget(delSTRequest);
    } catch (Exception e) {
        System.err.println("Unable to deregister scalable target: ");
        System.err.println(e.getMessage());
    }
    // Verify that the scalable target was removed
    DescribeScalableTargetsRequest dscRequest = new DescribeScalableTargetsRequest().withServiceNamespace(ns).withScalableDimension(tableWCUs).withResourceIds(resourceID);
    try {
        DescribeScalableTargetsResult dsaResult = aaClient.describeScalableTargets(dscRequest);
        System.out.println("DescribeScalableTargets result: ");
        System.out.println(dsaResult);
        System.out.println();
    } catch (Exception e) {
        System.err.println("Unable to describe scalable target: ");
        System.err.println(e.getMessage());
    }
}
Also used : DeregisterScalableTargetRequest(com.amazonaws.services.applicationautoscaling.model.DeregisterScalableTargetRequest) ServiceNamespace(com.amazonaws.services.applicationautoscaling.model.ServiceNamespace) ScalableDimension(com.amazonaws.services.applicationautoscaling.model.ScalableDimension) DeleteScalingPolicyRequest(com.amazonaws.services.applicationautoscaling.model.DeleteScalingPolicyRequest) DescribeScalingPoliciesRequest(com.amazonaws.services.applicationautoscaling.model.DescribeScalingPoliciesRequest) DescribeScalingPoliciesResult(com.amazonaws.services.applicationautoscaling.model.DescribeScalingPoliciesResult) DescribeScalableTargetsRequest(com.amazonaws.services.applicationautoscaling.model.DescribeScalableTargetsRequest) DescribeScalableTargetsResult(com.amazonaws.services.applicationautoscaling.model.DescribeScalableTargetsResult)

Example 2 with DescribeScalableTargetsRequest

use of com.amazonaws.services.applicationautoscaling.model.DescribeScalableTargetsRequest in project aws-doc-sdk-examples by awsdocs.

the class EnableDynamoDBAutoscaling method main.

public static void main(String[] args) {
    ServiceNamespace ns = ServiceNamespace.Dynamodb;
    ScalableDimension tableWCUs = ScalableDimension.DynamodbTableWriteCapacityUnits;
    String resourceID = "table/TestTable";
    // Define the scalable target
    RegisterScalableTargetRequest rstRequest = new RegisterScalableTargetRequest().withServiceNamespace(ns).withResourceId(resourceID).withScalableDimension(tableWCUs).withMinCapacity(5).withMaxCapacity(10).withRoleARN("SERVICE_ROLE_ARN_GOES_HERE");
    try {
        aaClient.registerScalableTarget(rstRequest);
    } catch (Exception e) {
        System.err.println("Unable to register scalable target: ");
        System.err.println(e.getMessage());
    }
    // Verify that the target was created
    DescribeScalableTargetsRequest dscRequest = new DescribeScalableTargetsRequest().withServiceNamespace(ns).withScalableDimension(tableWCUs).withResourceIds(resourceID);
    try {
        DescribeScalableTargetsResult dsaResult = aaClient.describeScalableTargets(dscRequest);
        System.out.println("DescribeScalableTargets result: ");
        System.out.println(dsaResult);
        System.out.println();
    } catch (Exception e) {
        System.err.println("Unable to describe scalable target: ");
        System.err.println(e.getMessage());
    }
    System.out.println();
    // Configure a scaling policy
    TargetTrackingScalingPolicyConfiguration targetTrackingScalingPolicyConfiguration = new TargetTrackingScalingPolicyConfiguration().withPredefinedMetricSpecification(new PredefinedMetricSpecification().withPredefinedMetricType(MetricType.DynamoDBWriteCapacityUtilization)).withTargetValue(50.0).withScaleInCooldown(60).withScaleOutCooldown(60);
    // Create the scaling policy, based on your configuration
    PutScalingPolicyRequest pspRequest = new PutScalingPolicyRequest().withServiceNamespace(ns).withScalableDimension(tableWCUs).withResourceId(resourceID).withPolicyName("MyScalingPolicy").withPolicyType(PolicyType.TargetTrackingScaling).withTargetTrackingScalingPolicyConfiguration(targetTrackingScalingPolicyConfiguration);
    try {
        aaClient.putScalingPolicy(pspRequest);
    } catch (Exception e) {
        System.err.println("Unable to put scaling policy: ");
        System.err.println(e.getMessage());
    }
    // Verify that the scaling policy was created
    DescribeScalingPoliciesRequest dspRequest = new DescribeScalingPoliciesRequest().withServiceNamespace(ns).withScalableDimension(tableWCUs).withResourceId(resourceID);
    try {
        DescribeScalingPoliciesResult dspResult = aaClient.describeScalingPolicies(dspRequest);
        System.out.println("DescribeScalingPolicies result: ");
        System.out.println(dspResult);
    } catch (Exception e) {
        e.printStackTrace();
        System.err.println("Unable to describe scaling policy: ");
        System.err.println(e.getMessage());
    }
}
Also used : RegisterScalableTargetRequest(com.amazonaws.services.applicationautoscaling.model.RegisterScalableTargetRequest) ServiceNamespace(com.amazonaws.services.applicationautoscaling.model.ServiceNamespace) PutScalingPolicyRequest(com.amazonaws.services.applicationautoscaling.model.PutScalingPolicyRequest) ScalableDimension(com.amazonaws.services.applicationautoscaling.model.ScalableDimension) DescribeScalingPoliciesRequest(com.amazonaws.services.applicationautoscaling.model.DescribeScalingPoliciesRequest) DescribeScalingPoliciesResult(com.amazonaws.services.applicationautoscaling.model.DescribeScalingPoliciesResult) DescribeScalableTargetsRequest(com.amazonaws.services.applicationautoscaling.model.DescribeScalableTargetsRequest) TargetTrackingScalingPolicyConfiguration(com.amazonaws.services.applicationautoscaling.model.TargetTrackingScalingPolicyConfiguration) DescribeScalableTargetsResult(com.amazonaws.services.applicationautoscaling.model.DescribeScalableTargetsResult) PredefinedMetricSpecification(com.amazonaws.services.applicationautoscaling.model.PredefinedMetricSpecification)

Example 3 with DescribeScalableTargetsRequest

use of com.amazonaws.services.applicationautoscaling.model.DescribeScalableTargetsRequest in project titus-control-plane by Netflix.

the class AWSAppAutoScalingClient method getScalableTargetsForJob.

@Override
public Observable<AutoScalableTarget> getScalableTargetsForJob(String jobId) {
    DescribeScalableTargetsRequest describeScalableTargetsRequest = new DescribeScalableTargetsRequest();
    describeScalableTargetsRequest.setServiceNamespace(SERVICE_NAMESPACE);
    describeScalableTargetsRequest.setScalableDimension(SCALABLE_DIMENSION);
    describeScalableTargetsRequest.setResourceIds(Collections.singletonList(AWSAppAutoScalingUtil.buildGatewayResourceId(jobId, awsAppScalingConfig.getAWSGatewayEndpointPrefix(), awsAppScalingConfig.getRegion(), awsAppScalingConfig.getAWSGatewayEndpointTargetStage())));
    return RetryWrapper.wrapWithExponentialRetry(String.format("getScalableTargetsForJob for job %s", jobId), Observable.create(emitter -> awsAppAutoScalingClientAsync.describeScalableTargetsAsync(describeScalableTargetsRequest, new AsyncHandler<DescribeScalableTargetsRequest, DescribeScalableTargetsResult>() {

        @Override
        public void onError(Exception exception) {
            logger.error("Get scalable target exception for {} - {}", jobId, exception.getMessage());
            awsAppAutoScalingMetrics.registerAwsGetTargetError(exception);
            emitter.onError(exception);
        }

        @Override
        public void onSuccess(DescribeScalableTargetsRequest request, DescribeScalableTargetsResult describeScalableTargetsResult) {
            awsAppAutoScalingMetrics.registerAwsGetTargetSuccess();
            List<ScalableTarget> scalableTargets = describeScalableTargetsResult.getScalableTargets();
            scalableTargets.stream().map(AWSAppAutoScalingUtil::toAutoScalableTarget).forEach(emitter::onNext);
            emitter.onCompleted();
        }
    }), Emitter.BackpressureMode.NONE));
}
Also used : ScalableTarget(com.amazonaws.services.applicationautoscaling.model.ScalableTarget) AutoScalePolicyException(com.netflix.titus.api.appscale.service.AutoScalePolicyException) Completable(rx.Completable) CustomizedMetricSpecification(com.amazonaws.services.applicationautoscaling.model.CustomizedMetricSpecification) DeleteScalingPolicyRequest(com.amazonaws.services.applicationautoscaling.model.DeleteScalingPolicyRequest) StepScalingPolicyConfiguration(com.amazonaws.services.applicationautoscaling.model.StepScalingPolicyConfiguration) LoggerFactory(org.slf4j.LoggerFactory) AutoScalableTarget(com.netflix.titus.api.appscale.model.AutoScalableTarget) AWSApplicationAutoScalingAsyncClientBuilder(com.amazonaws.services.applicationautoscaling.AWSApplicationAutoScalingAsyncClientBuilder) Singleton(javax.inject.Singleton) DescribeScalableTargetsRequest(com.amazonaws.services.applicationautoscaling.model.DescribeScalableTargetsRequest) TargetTrackingPolicy(com.netflix.titus.api.appscale.model.TargetTrackingPolicy) Observable(rx.Observable) Inject(javax.inject.Inject) DeleteScalingPolicyResult(com.amazonaws.services.applicationautoscaling.model.DeleteScalingPolicyResult) AWSApplicationAutoScalingAsync(com.amazonaws.services.applicationautoscaling.AWSApplicationAutoScalingAsync) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) ValidationException(com.amazonaws.services.applicationautoscaling.model.ValidationException) ObjectNotFoundException(com.amazonaws.services.applicationautoscaling.model.ObjectNotFoundException) PutScalingPolicyResult(com.amazonaws.services.applicationautoscaling.model.PutScalingPolicyResult) RegisterScalableTargetResult(com.amazonaws.services.applicationautoscaling.model.RegisterScalableTargetResult) RetryWrapper(com.netflix.titus.ext.aws.RetryWrapper) Logger(org.slf4j.Logger) DeregisterScalableTargetResult(com.amazonaws.services.applicationautoscaling.model.DeregisterScalableTargetResult) StepAdjustment(com.amazonaws.services.applicationautoscaling.model.StepAdjustment) TargetTrackingScalingPolicyConfiguration(com.amazonaws.services.applicationautoscaling.model.TargetTrackingScalingPolicyConfiguration) AppAutoScalingClient(com.netflix.titus.api.connector.cloud.AppAutoScalingClient) Emitter(rx.Emitter) Collectors(java.util.stream.Collectors) PolicyType(com.netflix.titus.api.appscale.model.PolicyType) DescribeScalableTargetsResult(com.amazonaws.services.applicationautoscaling.model.DescribeScalableTargetsResult) List(java.util.List) AWSAppAutoScalingUtil.buildScalingPolicyName(com.netflix.titus.ext.aws.appscale.AWSAppAutoScalingUtil.buildScalingPolicyName) RegisterScalableTargetRequest(com.amazonaws.services.applicationautoscaling.model.RegisterScalableTargetRequest) AsyncHandler(com.amazonaws.handlers.AsyncHandler) Registry(com.netflix.spectator.api.Registry) DeregisterScalableTargetRequest(com.amazonaws.services.applicationautoscaling.model.DeregisterScalableTargetRequest) VisibleForTesting(com.google.common.annotations.VisibleForTesting) MetricDimension(com.amazonaws.services.applicationautoscaling.model.MetricDimension) PutScalingPolicyRequest(com.amazonaws.services.applicationautoscaling.model.PutScalingPolicyRequest) Collections(java.util.Collections) PolicyConfiguration(com.netflix.titus.api.appscale.model.PolicyConfiguration) DescribeScalableTargetsRequest(com.amazonaws.services.applicationautoscaling.model.DescribeScalableTargetsRequest) List(java.util.List) DescribeScalableTargetsResult(com.amazonaws.services.applicationautoscaling.model.DescribeScalableTargetsResult) AutoScalePolicyException(com.netflix.titus.api.appscale.service.AutoScalePolicyException) ValidationException(com.amazonaws.services.applicationautoscaling.model.ValidationException) ObjectNotFoundException(com.amazonaws.services.applicationautoscaling.model.ObjectNotFoundException)

Aggregations

DescribeScalableTargetsRequest (com.amazonaws.services.applicationautoscaling.model.DescribeScalableTargetsRequest)3 DescribeScalableTargetsResult (com.amazonaws.services.applicationautoscaling.model.DescribeScalableTargetsResult)3 DeleteScalingPolicyRequest (com.amazonaws.services.applicationautoscaling.model.DeleteScalingPolicyRequest)2 DeregisterScalableTargetRequest (com.amazonaws.services.applicationautoscaling.model.DeregisterScalableTargetRequest)2 DescribeScalingPoliciesRequest (com.amazonaws.services.applicationautoscaling.model.DescribeScalingPoliciesRequest)2 DescribeScalingPoliciesResult (com.amazonaws.services.applicationautoscaling.model.DescribeScalingPoliciesResult)2 PutScalingPolicyRequest (com.amazonaws.services.applicationautoscaling.model.PutScalingPolicyRequest)2 RegisterScalableTargetRequest (com.amazonaws.services.applicationautoscaling.model.RegisterScalableTargetRequest)2 ScalableDimension (com.amazonaws.services.applicationautoscaling.model.ScalableDimension)2 ServiceNamespace (com.amazonaws.services.applicationautoscaling.model.ServiceNamespace)2 TargetTrackingScalingPolicyConfiguration (com.amazonaws.services.applicationautoscaling.model.TargetTrackingScalingPolicyConfiguration)2 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)1 AsyncHandler (com.amazonaws.handlers.AsyncHandler)1 AWSApplicationAutoScalingAsync (com.amazonaws.services.applicationautoscaling.AWSApplicationAutoScalingAsync)1 AWSApplicationAutoScalingAsyncClientBuilder (com.amazonaws.services.applicationautoscaling.AWSApplicationAutoScalingAsyncClientBuilder)1 CustomizedMetricSpecification (com.amazonaws.services.applicationautoscaling.model.CustomizedMetricSpecification)1 DeleteScalingPolicyResult (com.amazonaws.services.applicationautoscaling.model.DeleteScalingPolicyResult)1 DeregisterScalableTargetResult (com.amazonaws.services.applicationautoscaling.model.DeregisterScalableTargetResult)1 MetricDimension (com.amazonaws.services.applicationautoscaling.model.MetricDimension)1 ObjectNotFoundException (com.amazonaws.services.applicationautoscaling.model.ObjectNotFoundException)1