Search in sources :

Example 6 with StartInstancesResult

use of com.amazonaws.services.ec2.model.StartInstancesResult in project photon-model by vmware.

the class AWSResetService method startInstance.

private void startInstance(AmazonEC2AsyncClient client, DefaultAdapterContext c) {
    StartInstancesRequest startRequest = new StartInstancesRequest();
    startRequest.withInstanceIds(c.child.id);
    client.startInstancesAsync(startRequest, new AWSAsyncHandler<StartInstancesRequest, StartInstancesResult>() {

        @Override
        protected void handleError(Exception e) {
            c.taskManager.patchTaskToFailure(e);
        }

        @Override
        protected void handleSuccess(StartInstancesRequest request, StartInstancesResult result) {
            AWSUtils.waitForTransitionCompletion(getHost(), result.getStartingInstances(), "running", client, (is, e) -> {
                if (e == null) {
                    c.taskManager.finishTask();
                } else {
                    c.taskManager.patchTaskToFailure(e);
                }
            });
        }
    });
}
Also used : Service(com.vmware.xenon.common.Service) ResourceOperationSpec(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceOperationSpec) ResourceOperationUtils.handleAdapterResourceOperationRegistration(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationUtils.handleAdapterResourceOperationRegistration) StopInstancesResult(com.amazonaws.services.ec2.model.StopInstancesResult) AWSAsyncHandler(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSAsyncHandler) StatelessService(com.vmware.xenon.common.StatelessService) Operation(com.vmware.xenon.common.Operation) StartInstancesResult(com.amazonaws.services.ec2.model.StartInstancesResult) ServiceDocument(com.vmware.xenon.common.ServiceDocument) BaseAdapterStage(com.vmware.photon.controller.model.adapters.util.BaseAdapterContext.BaseAdapterStage) StopInstancesRequest(com.amazonaws.services.ec2.model.StopInstancesRequest) ResourceOperationRequest(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest) ResourceOperation(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation) StartInstancesRequest(com.amazonaws.services.ec2.model.StartInstancesRequest) DefaultAdapterContext(com.vmware.photon.controller.model.adapters.util.BaseAdapterContext.DefaultAdapterContext) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) FactoryService(com.vmware.xenon.common.FactoryService) AWSClientManagerFactory(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManagerFactory) ResourceType(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceType) ResourceOperationUtils(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationUtils) AWSClientManager(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManager) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) StartInstancesResult(com.amazonaws.services.ec2.model.StartInstancesResult) StartInstancesRequest(com.amazonaws.services.ec2.model.StartInstancesRequest)

Example 7 with StartInstancesResult

use of com.amazonaws.services.ec2.model.StartInstancesResult in project photon-model by vmware.

the class AWSComputeDiskDay2Service method startInstance.

/**
 * start the instance and on success updates the disk and compute state to reflect the detach information.
 */
private void startInstance(AmazonEC2AsyncClient client, DiskContext c, DeferredResult<DiskContext> dr, OperationContext opCtx) {
    StartInstancesRequest startRequest = new StartInstancesRequest();
    startRequest.withInstanceIds(c.baseAdapterContext.child.id);
    client.startInstancesAsync(startRequest, new AWSAsyncHandler<StartInstancesRequest, StartInstancesResult>() {

        @Override
        protected void handleError(Exception e) {
            service.logSevere(() -> String.format("[AWSComputeDiskDay2Service] Failed to start the instance %s. %s", c.baseAdapterContext.child.id, Utils.toString(e)));
            OperationContext.restoreOperationContext(opCtx);
            c.error = e;
            dr.complete(c);
        }

        @Override
        protected void handleSuccess(StartInstancesRequest request, StartInstancesResult result) {
            AWSUtils.waitForTransitionCompletion(getHost(), result.getStartingInstances(), "running", client, (is, e) -> {
                if (e != null) {
                    service.logSevere(() -> String.format("[AWSComputeDiskDay2Service] Instance %s failed to reach " + "running state. %s", c.baseAdapterContext.child.id, Utils.toString(e)));
                    OperationContext.restoreOperationContext(opCtx);
                    c.error = e;
                    dr.complete(c);
                    return;
                }
                logInfo(() -> String.format("[AWSComputeDiskDay2Service] Successfully started the " + "instance %s", result.getStartingInstances().get(0).getInstanceId()));
                updateComputeAndDiskState(dr, c, opCtx);
            });
        }
    });
}
Also used : Service(com.vmware.xenon.common.Service) Arrays(java.util.Arrays) DetachVolumeRequest(com.amazonaws.services.ec2.model.DetachVolumeRequest) Pair(com.vmware.photon.controller.model.adapters.util.Pair) ResourceOperationUtils.handleAdapterResourceOperationRegistration(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationUtils.handleAdapterResourceOperationRegistration) StopInstancesResult(com.amazonaws.services.ec2.model.StopInstancesResult) AttachVolumeRequest(com.amazonaws.services.ec2.model.AttachVolumeRequest) ResourceOperationSpecService(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService) ServiceDocument(com.vmware.xenon.common.ServiceDocument) DetachVolumeResult(com.amazonaws.services.ec2.model.DetachVolumeResult) StopInstancesRequest(com.amazonaws.services.ec2.model.StopInstancesRequest) AWS_DISK_OPERATION_TIMEOUT_MINUTES(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_DISK_OPERATION_TIMEOUT_MINUTES) DEVICE_NAME(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.DEVICE_NAME) ResourceOperationRequest(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest) Utils(com.vmware.xenon.common.Utils) AttachVolumeResult(com.amazonaws.services.ec2.model.AttachVolumeResult) DescribeInstancesRequest(com.amazonaws.services.ec2.model.DescribeInstancesRequest) AWSBlockDeviceNameMapper(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSBlockDeviceNameMapper) Map(java.util.Map) AWSClientManager(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManager) Reservation(com.amazonaws.services.ec2.model.Reservation) AWSAsyncHandler(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSAsyncHandler) StatelessService(com.vmware.xenon.common.StatelessService) StartInstancesResult(com.amazonaws.services.ec2.model.StartInstancesResult) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) AWS_INSTANCE_ID_PREFIX(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_INSTANCE_ID_PREFIX) List(java.util.List) AWSSupportedOS(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWSSupportedOS) ResourceOperation(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation) DeferredResult(com.vmware.xenon.common.DeferredResult) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) Optional(java.util.Optional) FactoryService(com.vmware.xenon.common.FactoryService) DiskService(com.vmware.photon.controller.model.resources.DiskService) OperationContext(com.vmware.xenon.common.OperationContext) HashMap(java.util.HashMap) AWS_VOLUME_ID_PREFIX(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_VOLUME_ID_PREFIX) Function(java.util.function.Function) ArrayList(java.util.ArrayList) InstanceBlockDeviceMapping(com.amazonaws.services.ec2.model.InstanceBlockDeviceMapping) StartInstancesRequest(com.amazonaws.services.ec2.model.StartInstancesRequest) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) Volume(com.amazonaws.services.ec2.model.Volume) Instance(com.amazonaws.services.ec2.model.Instance) AWSStorageType(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWSStorageType) Operation(com.vmware.xenon.common.Operation) BaseAdapterStage(com.vmware.photon.controller.model.adapters.util.BaseAdapterContext.BaseAdapterStage) AWSSupportedVirtualizationTypes(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWSSupportedVirtualizationTypes) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) DefaultAdapterContext(com.vmware.photon.controller.model.adapters.util.BaseAdapterContext.DefaultAdapterContext) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) AWSClientManagerFactory(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManagerFactory) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) StartInstancesResult(com.amazonaws.services.ec2.model.StartInstancesResult) StartInstancesRequest(com.amazonaws.services.ec2.model.StartInstancesRequest)

Example 8 with StartInstancesResult

use of com.amazonaws.services.ec2.model.StartInstancesResult 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

StartInstancesResult (com.amazonaws.services.ec2.model.StartInstancesResult)8 StartInstancesRequest (com.amazonaws.services.ec2.model.StartInstancesRequest)5 ArrayList (java.util.ArrayList)5 AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)3 StopInstancesRequest (com.amazonaws.services.ec2.model.StopInstancesRequest)3 StopInstancesResult (com.amazonaws.services.ec2.model.StopInstancesResult)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 Operation (com.vmware.xenon.common.Operation)3 StatelessService (com.vmware.xenon.common.StatelessService)3 Collection (java.util.Collection)3 AmazonServiceException (com.amazonaws.AmazonServiceException)2 InstanceStateChange (com.amazonaws.services.ec2.model.InstanceStateChange)2 AWSAsyncHandler (com.vmware.photon.controller.model.adapters.awsadapter.util.AWSAsyncHandler)2 ResourceOperation (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation)2 ResourceOperationRequest (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest)2 ResourceOperationUtils.handleAdapterResourceOperationRegistration (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationUtils.handleAdapterResourceOperationRegistration)2