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));
}
Aggregations