use of com.sequenceiq.cloudbreak.cloud.CloudConnector in project cloudbreak by hortonworks.
the class CollectMetadataHandler method accept.
@Override
public void accept(Event<CollectMetadataRequest> collectMetadataRequestEvent) {
LOGGER.info("Received event: {}", collectMetadataRequestEvent);
CollectMetadataRequest request = collectMetadataRequestEvent.getData();
try {
CloudConnector connector = cloudPlatformConnectors.get(request.getCloudContext().getPlatformVariant());
AuthenticatedContext ac = connector.authentication().authenticate(request.getCloudContext(), request.getCloudCredential());
List<CloudVmMetaDataStatus> instanceStatuses = connector.metadata().collect(ac, request.getCloudResource(), request.getVms());
CollectMetadataResult collectMetadataResult = new CollectMetadataResult(request, instanceStatuses);
request.getResult().onNext(collectMetadataResult);
eventBus.notify(collectMetadataResult.selector(), new Event<>(collectMetadataRequestEvent.getHeaders(), collectMetadataResult));
LOGGER.info("Metadata collection successfully finished");
} catch (RuntimeException e) {
CollectMetadataResult failure = new CollectMetadataResult(e, request);
request.getResult().onNext(failure);
eventBus.notify(failure.selector(), new Event<>(collectMetadataRequestEvent.getHeaders(), failure));
}
}
use of com.sequenceiq.cloudbreak.cloud.CloudConnector in project cloudbreak by hortonworks.
the class DownscaleStackCollectResourcesHandler method accept.
@Override
public void accept(Event<DownscaleStackCollectResourcesRequest> collectResourcesRequestEvent) {
LOGGER.info("Received event: {}", collectResourcesRequestEvent);
DownscaleStackCollectResourcesRequest request = collectResourcesRequestEvent.getData();
DownscaleStackCollectResourcesResult result;
try {
CloudContext cloudContext = request.getCloudContext();
CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
Object resourcesToScale = connector.resources().collectResourcesToRemove(ac, request.getCloudStack(), request.getCloudResources(), request.getInstances());
LOGGER.info("Collect resources successfully finished for {}", cloudContext);
result = new DownscaleStackCollectResourcesResult(request, resourcesToScale);
} catch (RuntimeException e) {
LOGGER.error("Failed to handle DownscaleStackCollectResourcesRequest.", e);
result = new DownscaleStackCollectResourcesResult(e.getMessage(), e, request);
}
request.getResult().onNext(result);
LOGGER.info("DownscaleStackCollectResourcesRequest finished");
eventBus.notify(result.selector(), new Event<>(collectResourcesRequestEvent.getHeaders(), result));
}
use of com.sequenceiq.cloudbreak.cloud.CloudConnector in project cloudbreak by hortonworks.
the class FileSystemValidationHandler method accept.
@Override
public void accept(Event<FileSystemValidationRequest> requestEvent) {
LOGGER.info("Received event: {}", requestEvent);
FileSystemValidationRequest request = requestEvent.getData();
try {
CloudConnector connector = cloudPlatformConnectors.get(request.getCloudContext().getPlatformVariant());
connector.setup().validateFileSystem(request.getCredential(), request.getFileSystem());
request.getResult().onNext(new FileSystemValidationResult(request));
} catch (Exception e) {
request.getResult().onNext(new FileSystemValidationResult(e.getMessage(), e, request));
}
}
use of com.sequenceiq.cloudbreak.cloud.CloudConnector 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));
}
}
use of com.sequenceiq.cloudbreak.cloud.CloudConnector in project cloudbreak by hortonworks.
the class TerminateStackHandler method accept.
@Override
public void accept(Event<TerminateStackRequest> terminateStackRequestEvent) {
LOGGER.info("Received event: {}", terminateStackRequestEvent);
TerminateStackRequest request = terminateStackRequestEvent.getData();
try {
CloudConnector connector = cloudPlatformConnectors.get(request.getCloudContext().getPlatformVariant());
AuthenticatedContext ac = connector.authentication().authenticate(request.getCloudContext(), request.getCloudCredential());
List<CloudResourceStatus> resourceStatus = connector.resources().terminate(ac, request.getCloudStack(), request.getCloudResources());
List<CloudResource> resources = ResourceLists.transform(resourceStatus);
TerminateStackResult result;
if (!resources.isEmpty()) {
PollTask<ResourcesStatePollerResult> task = statusCheckFactory.newPollResourcesStateTask(ac, resources, false);
ResourcesStatePollerResult statePollerResult = ResourcesStatePollerResults.build(request.getCloudContext(), resourceStatus);
if (!task.completed(statePollerResult)) {
statePollerResult = syncPollingScheduler.schedule(task);
}
if (!statePollerResult.getStatus().equals(ResourceStatus.DELETED)) {
throw new CloudConnectorException("Stack could not be terminated, Resource(s) could not be deleted on the provider side.");
} else {
result = new TerminateStackResult(request);
}
} else {
result = new TerminateStackResult(request);
}
CloudCredentialStatus credentialStatus = connector.credentials().delete(ac);
if (CredentialStatus.FAILED == credentialStatus.getStatus()) {
if (credentialStatus.getException() != null) {
throw new CloudConnectorException(credentialStatus.getException());
}
throw new CloudConnectorException(credentialStatus.getStatusReason());
}
request.getResult().onNext(result);
LOGGER.info("TerminateStackHandler finished");
eventBus.notify(result.selector(), new Event<>(terminateStackRequestEvent.getHeaders(), result));
} catch (Exception e) {
LOGGER.error("Failed to handle TerminateStackRequest", e);
TerminateStackResult terminateStackResult = new TerminateStackResult("Stack termination failed.", e, request);
request.getResult().onNext(terminateStackResult);
eventBus.notify(terminateStackResult.selector(), new Event<>(terminateStackRequestEvent.getHeaders(), terminateStackResult));
}
}
Aggregations