Search in sources :

Example 11 with StopInstancesRequest

use of software.amazon.awssdk.services.ec2.model.StopInstancesRequest 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)

Aggregations

StopInstancesRequest (com.amazonaws.services.ec2.model.StopInstancesRequest)10 StopInstancesResult (com.amazonaws.services.ec2.model.StopInstancesResult)6 StartInstancesRequest (com.amazonaws.services.ec2.model.StartInstancesRequest)4 AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)3 StartInstancesResult (com.amazonaws.services.ec2.model.StartInstancesResult)3 AWSClientManager (com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManager)3 AWSClientManagerFactory (com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManagerFactory)3 BaseAdapterStage (com.vmware.photon.controller.model.adapters.util.BaseAdapterContext.BaseAdapterStage)3 DefaultAdapterContext (com.vmware.photon.controller.model.adapters.util.BaseAdapterContext.DefaultAdapterContext)3 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)3 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)2 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)2 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)2 AWSAsyncHandler (com.vmware.photon.controller.model.adapters.awsadapter.util.AWSAsyncHandler)2 ResourceOperation (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation)2 Operation (com.vmware.xenon.common.Operation)2 StatelessService (com.vmware.xenon.common.StatelessService)2 ArrayList (java.util.ArrayList)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)1