Search in sources :

Example 11 with DefaultAdapterContext

use of com.vmware.photon.controller.model.adapters.util.BaseAdapterContext.DefaultAdapterContext in project photon-model by vmware.

the class AWSResetService method reset.

private void reset(AmazonEC2AsyncClient client, ResourceOperationRequest pr, DefaultAdapterContext c) {
    if (!c.child.powerState.equals(ComputeService.PowerState.ON)) {
        logWarning(() -> String.format("Cannot perform a reset on this EC2 instance. " + "The machine should be in powered on state"));
        c.taskManager.patchTaskToFailure(new IllegalStateException("Incorrect power state. Expected the machine " + "to be powered on "));
        return;
    }
    // The stop action for reset is a force stop. So we use the withForce method to set the force parameter to TRUE
    // This is similar to unplugging the machine from the power circuit.
    // The OS and the applications are forcefully stopped.
    StopInstancesRequest stopRequest = new StopInstancesRequest();
    stopRequest.withInstanceIds(c.child.id).withForce(Boolean.TRUE);
    client.stopInstancesAsync(stopRequest, new AWSAsyncHandler<StopInstancesRequest, StopInstancesResult>() {

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

        @Override
        protected void handleSuccess(StopInstancesRequest request, StopInstancesResult result) {
            AWSUtils.waitForTransitionCompletion(getHost(), result.getStoppingInstances(), "stopped", client, (is, e) -> {
                if (e != null) {
                    onError(e);
                    return;
                }
                // Instances will be started only if they're successfully stopped
                startInstance(client, c);
            });
        }
    });
}
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) StopInstancesResult(com.amazonaws.services.ec2.model.StopInstancesResult) StopInstancesRequest(com.amazonaws.services.ec2.model.StopInstancesRequest)

Aggregations

DefaultAdapterContext (com.vmware.photon.controller.model.adapters.util.BaseAdapterContext.DefaultAdapterContext)11 AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)8 AWSClientManager (com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManager)8 AWSClientManagerFactory (com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManagerFactory)8 BaseAdapterStage (com.vmware.photon.controller.model.adapters.util.BaseAdapterContext.BaseAdapterStage)8 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)8 Operation (com.vmware.xenon.common.Operation)8 StatelessService (com.vmware.xenon.common.StatelessService)8 StartInstancesRequest (com.amazonaws.services.ec2.model.StartInstancesRequest)7 StartInstancesResult (com.amazonaws.services.ec2.model.StartInstancesResult)7 StopInstancesRequest (com.amazonaws.services.ec2.model.StopInstancesRequest)7 StopInstancesResult (com.amazonaws.services.ec2.model.StopInstancesResult)7 ResourceOperationRequest (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest)7 ResourceOperation (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation)5 ResourceOperationUtils.handleAdapterResourceOperationRegistration (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationUtils.handleAdapterResourceOperationRegistration)5 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)5 FactoryService (com.vmware.xenon.common.FactoryService)5 Service (com.vmware.xenon.common.Service)5 ServiceDocument (com.vmware.xenon.common.ServiceDocument)5 AsyncHandler (com.amazonaws.handlers.AsyncHandler)4