Search in sources :

Example 1 with RemoveInstanceResult

use of com.sequenceiq.cloudbreak.cloud.event.resource.RemoveInstanceResult in project cloudbreak by hortonworks.

the class RemoveInstanceHandler method accept.

@Override
public void accept(Event<RemoveInstanceRequest> removeInstanceRequestEvent) {
    RemoveInstanceRequest request = removeInstanceRequestEvent.getData();
    RemoveInstanceResult result;
    try {
        CloudContext cloudContext = request.getCloudContext();
        CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
        List<CloudResourceStatus> resourceStatus = connector.resources().downscale(ac, request.getCloudStack(), request.getCloudResources(), request.getInstances(), Collections.emptyMap());
        List<CloudResource> resources = ResourceLists.transform(resourceStatus);
        PollTask<ResourcesStatePollerResult> task = statusCheckFactory.newPollResourcesStateTask(ac, resources, true);
        ResourcesStatePollerResult statePollerResult = ResourcesStatePollerResults.build(cloudContext, resourceStatus);
        if (!task.completed(statePollerResult)) {
            statePollerResult = syncPollingScheduler.schedule(task);
        }
        LOGGER.info("Instance remove successfully finished for {}", cloudContext);
        result = new RemoveInstanceResult(new DownscaleStackResult(request, ResourceLists.transform(statePollerResult.getResults())), request);
    } catch (Exception e) {
        LOGGER.error("Failed to handle RemoveInstanceRequest.", e);
        result = new RemoveInstanceResult(e.getMessage(), e, request);
    }
    eventBus.notify(result.selector(), new Event<>(removeInstanceRequestEvent.getHeaders(), result));
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) RemoveInstanceResult(com.sequenceiq.cloudbreak.cloud.event.resource.RemoveInstanceResult) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) DownscaleStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackResult) RemoveInstanceRequest(com.sequenceiq.cloudbreak.cloud.event.resource.RemoveInstanceRequest) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ResourcesStatePollerResult(com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)

Aggregations

CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)1 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 DownscaleStackResult (com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackResult)1 RemoveInstanceRequest (com.sequenceiq.cloudbreak.cloud.event.resource.RemoveInstanceRequest)1 RemoveInstanceResult (com.sequenceiq.cloudbreak.cloud.event.resource.RemoveInstanceResult)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)1 ResourcesStatePollerResult (com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)1