Search in sources :

Example 6 with InstanceStateChange

use of software.amazon.awssdk.services.ec2.model.InstanceStateChange in project onebusaway-application-modules by camsys.

the class BundleServerServiceImpl method stop.

@Override
public String stop(String instanceId) {
    if (!_isAws) {
        return LOCAL_HOST;
    }
    if (LOCAL_HOST.equalsIgnoreCase(instanceId)) {
        return instanceId;
    }
    List<String> instances = new ArrayList<String>();
    instances.add(instanceId);
    StopInstancesRequest stopInstancesRequest = new StopInstancesRequest(instances);
    StopInstancesResult stopInstancesResult = _ec2.stopInstances(stopInstancesRequest);
    InstanceStateChange change = null;
    if (!stopInstancesResult.getStoppingInstances().isEmpty()) {
        change = stopInstancesResult.getStoppingInstances().get(0);
        _log.info("from state=" + change.getPreviousState() + " to state=" + change.getCurrentState());
        return change.getInstanceId();
    }
    return null;
}
Also used : StopInstancesResult(com.amazonaws.services.ec2.model.StopInstancesResult) ArrayList(java.util.ArrayList) StopInstancesRequest(com.amazonaws.services.ec2.model.StopInstancesRequest) InstanceStateChange(com.amazonaws.services.ec2.model.InstanceStateChange)

Example 7 with InstanceStateChange

use of software.amazon.awssdk.services.ec2.model.InstanceStateChange in project onebusaway-application-modules by camsys.

the class BundleServerServiceImpl method start.

@Override
public String start(String instanceId) {
    if (!_isAws) {
        return LOCAL_HOST;
    }
    if (LOCAL_HOST.equalsIgnoreCase(instanceId)) {
        return instanceId;
    }
    List<String> instances = new ArrayList<String>();
    instances.add(instanceId);
    StartInstancesRequest startInstancesRequest = new StartInstancesRequest(instances);
    StartInstancesResult startInstancesResult = _ec2.startInstances(startInstancesRequest);
    InstanceStateChange change = null;
    if (!startInstancesResult.getStartingInstances().isEmpty()) {
        change = startInstancesResult.getStartingInstances().get(0);
        _log.info("from state=" + change.getPreviousState() + " to state=" + change.getCurrentState());
        return change.getInstanceId();
    }
    return null;
}
Also used : StartInstancesResult(com.amazonaws.services.ec2.model.StartInstancesResult) StartInstancesRequest(com.amazonaws.services.ec2.model.StartInstancesRequest) ArrayList(java.util.ArrayList) InstanceStateChange(com.amazonaws.services.ec2.model.InstanceStateChange)

Aggregations

InstanceStateChange (com.amazonaws.services.ec2.model.InstanceStateChange)6 ArrayList (java.util.ArrayList)6 AmazonServiceException (com.amazonaws.AmazonServiceException)4 InstanceState (com.amazonaws.services.ec2.model.InstanceState)4 StopInstancesResult (com.amazonaws.services.ec2.model.StopInstancesResult)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