Search in sources :

Example 1 with InstanceState

use of com.amazonaws.services.ec2.model.InstanceState in project camel by apache.

the class AmazonEC2ClientMock method startInstances.

@Override
public StartInstancesResult startInstances(StartInstancesRequest startInstancesRequest) {
    StartInstancesResult result = new StartInstancesResult();
    if (startInstancesRequest.getInstanceIds().get(0).equals("test-1")) {
        Collection<InstanceStateChange> coll = new ArrayList<InstanceStateChange>();
        InstanceStateChange sc = new InstanceStateChange();
        InstanceState previousState = new InstanceState();
        previousState.setCode(80);
        previousState.setName(InstanceStateName.Stopped);
        InstanceState newState = new InstanceState();
        newState.setCode(16);
        newState.setName(InstanceStateName.Running);
        sc.setPreviousState(previousState);
        sc.setCurrentState(newState);
        sc.setInstanceId("test-1");
        coll.add(sc);
        result.setStartingInstances(coll);
    } else {
        throw new AmazonServiceException("The image-id doesn't exists");
    }
    return result;
}
Also used : InstanceState(com.amazonaws.services.ec2.model.InstanceState) StartInstancesResult(com.amazonaws.services.ec2.model.StartInstancesResult) ArrayList(java.util.ArrayList) AmazonServiceException(com.amazonaws.AmazonServiceException) InstanceStateChange(com.amazonaws.services.ec2.model.InstanceStateChange)

Example 2 with InstanceState

use of com.amazonaws.services.ec2.model.InstanceState in project camel by apache.

the class AmazonEC2ClientMock method describeInstanceStatus.

@Override
public DescribeInstanceStatusResult describeInstanceStatus(DescribeInstanceStatusRequest describeInstanceStatusRequest) {
    DescribeInstanceStatusResult result = new DescribeInstanceStatusResult();
    Collection<InstanceStatus> instanceStatuses = new ArrayList();
    if (describeInstanceStatusRequest.getInstanceIds().isEmpty()) {
        InstanceStatus status = new InstanceStatus();
        status.setInstanceId("test-1");
        status.setInstanceState(new InstanceState().withName(InstanceStateName.Running));
        instanceStatuses.add(status);
        status.setInstanceId("test-2");
        status.setInstanceState(new InstanceState().withName(InstanceStateName.Stopped));
        instanceStatuses.add(status);
    } else {
        if (describeInstanceStatusRequest.getInstanceIds().contains("test-1")) {
            InstanceStatus status = new InstanceStatus();
            status.setInstanceId("test-1");
            status.setInstanceState(new InstanceState().withName(InstanceStateName.Running));
            instanceStatuses.add(status);
        }
        if (describeInstanceStatusRequest.getInstanceIds().contains("test-2")) {
            InstanceStatus status = new InstanceStatus();
            status.setInstanceId("test-2");
            status.setInstanceState(new InstanceState().withName(InstanceStateName.Stopped));
            instanceStatuses.add(status);
        }
    }
    result.setInstanceStatuses(instanceStatuses);
    return result;
}
Also used : DescribeInstanceStatusResult(com.amazonaws.services.ec2.model.DescribeInstanceStatusResult) InstanceState(com.amazonaws.services.ec2.model.InstanceState) InstanceStatus(com.amazonaws.services.ec2.model.InstanceStatus) ArrayList(java.util.ArrayList)

Example 3 with InstanceState

use of com.amazonaws.services.ec2.model.InstanceState in project cloudbreak by hortonworks.

the class ASGroupStatusCheckerTaskTest method returnInstanceStatus.

private List<InstanceStatus> returnInstanceStatus(int start, int end) {
    List<InstanceStatus> instanceStatuses = new ArrayList<>();
    for (int i = start; i < end; i++) {
        InstanceStatus instanceStatus = new InstanceStatus();
        InstanceState instanceState = new InstanceState();
        instanceState.setCode(16);
        instanceStatus.setInstanceState(instanceState);
        instanceStatus.setInstanceId(Integer.toString(i));
        instanceStatuses.add(instanceStatus);
    }
    return instanceStatuses;
}
Also used : InstanceState(com.amazonaws.services.ec2.model.InstanceState) InstanceStatus(com.amazonaws.services.ec2.model.InstanceStatus) ArrayList(java.util.ArrayList)

Example 4 with InstanceState

use of com.amazonaws.services.ec2.model.InstanceState in project camel by apache.

the class AmazonEC2ClientMock method stopInstances.

@Override
public StopInstancesResult stopInstances(StopInstancesRequest stopInstancesRequest) {
    StopInstancesResult result = new StopInstancesResult();
    if (stopInstancesRequest.getInstanceIds().get(0).equals("test-1")) {
        Collection<InstanceStateChange> coll = new ArrayList<InstanceStateChange>();
        InstanceStateChange sc = new InstanceStateChange();
        InstanceState previousState = new InstanceState();
        previousState.setCode(80);
        previousState.setName(InstanceStateName.Running);
        InstanceState newState = new InstanceState();
        newState.setCode(16);
        newState.setName(InstanceStateName.Stopped);
        sc.setPreviousState(previousState);
        sc.setCurrentState(newState);
        sc.setInstanceId("test-1");
        coll.add(sc);
        result.setStoppingInstances(coll);
    } else {
        throw new AmazonServiceException("The image-id doesn't exists");
    }
    return result;
}
Also used : InstanceState(com.amazonaws.services.ec2.model.InstanceState) StopInstancesResult(com.amazonaws.services.ec2.model.StopInstancesResult) ArrayList(java.util.ArrayList) AmazonServiceException(com.amazonaws.AmazonServiceException) InstanceStateChange(com.amazonaws.services.ec2.model.InstanceStateChange)

Example 5 with InstanceState

use of com.amazonaws.services.ec2.model.InstanceState in project camel by apache.

the class AmazonEC2ClientMock method terminateInstances.

@Override
public TerminateInstancesResult terminateInstances(TerminateInstancesRequest terminateInstancesRequest) {
    TerminateInstancesResult result = new TerminateInstancesResult();
    if (terminateInstancesRequest.getInstanceIds().contains("test-1")) {
        Collection<InstanceStateChange> coll = new ArrayList<InstanceStateChange>();
        InstanceStateChange sc = new InstanceStateChange();
        InstanceState previousState = new InstanceState();
        previousState.setCode(80);
        previousState.setName(InstanceStateName.Running);
        InstanceState newState = new InstanceState();
        newState.setCode(16);
        newState.setName(InstanceStateName.Terminated);
        sc.setPreviousState(previousState);
        sc.setCurrentState(newState);
        sc.setInstanceId("test-1");
        coll.add(sc);
        result.setTerminatingInstances(coll);
    } else {
        throw new AmazonServiceException("The image-id doesn't exists");
    }
    return result;
}
Also used : InstanceState(com.amazonaws.services.ec2.model.InstanceState) ArrayList(java.util.ArrayList) AmazonServiceException(com.amazonaws.AmazonServiceException) TerminateInstancesResult(com.amazonaws.services.ec2.model.TerminateInstancesResult) InstanceStateChange(com.amazonaws.services.ec2.model.InstanceStateChange)

Aggregations

InstanceState (com.amazonaws.services.ec2.model.InstanceState)6 ArrayList (java.util.ArrayList)6 AmazonServiceException (com.amazonaws.AmazonServiceException)4 InstanceStateChange (com.amazonaws.services.ec2.model.InstanceStateChange)4 InstanceStatus (com.amazonaws.services.ec2.model.InstanceStatus)2 AmazonClientException (com.amazonaws.AmazonClientException)1 AmazonWebServiceRequest (com.amazonaws.AmazonWebServiceRequest)1 ClientConfiguration (com.amazonaws.ClientConfiguration)1 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)1 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)1 AwsClientBuilder (com.amazonaws.client.builder.AwsClientBuilder)1 AsyncHandler (com.amazonaws.handlers.AsyncHandler)1 Regions (com.amazonaws.regions.Regions)1 DEFAULT_BACKOFF_STRATEGY (com.amazonaws.retry.PredefinedRetryPolicies.DEFAULT_BACKOFF_STRATEGY)1 DEFAULT_RETRY_CONDITION (com.amazonaws.retry.PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION)1 RetryPolicy (com.amazonaws.retry.RetryPolicy)1 BackoffStrategy (com.amazonaws.retry.RetryPolicy.BackoffStrategy)1 AmazonCloudWatchAsyncClient (com.amazonaws.services.cloudwatch.AmazonCloudWatchAsyncClient)1