use of com.sequenceiq.cloudbreak.cloud.event.instance.StartInstancesRequest in project cloudbreak by hortonworks.
the class StartStackHandler method accept.
@Override
public void accept(Event<StartInstancesRequest> event) {
LOGGER.info("Received event: {}", event);
StartInstancesRequest request = event.getData();
CloudContext cloudContext = request.getCloudContext();
try {
CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
AuthenticatedContext authenticatedContext = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
List<CloudInstance> instances = request.getCloudInstances();
List<CloudVmInstanceStatus> instanceStatuses = connector.instances().start(authenticatedContext, request.getResources(), instances);
PollTask<InstancesStatusResult> task = statusCheckFactory.newPollInstanceStateTask(authenticatedContext, instances, Sets.newHashSet(InstanceStatus.STARTED, InstanceStatus.FAILED));
InstancesStatusResult statusResult = new InstancesStatusResult(cloudContext, instanceStatuses);
if (!task.completed(statusResult)) {
statusResult = syncPollingScheduler.schedule(task);
}
StartInstancesResult result = new StartInstancesResult(request, cloudContext, statusResult);
request.getResult().onNext(result);
eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
} catch (Exception e) {
StartInstancesResult failure = new StartInstancesResult("Failed to start stack", e, request);
request.getResult().onNext(failure);
eventBus.notify(failure.selector(), new Event<>(event.getHeaders(), failure));
}
}
Aggregations