Search in sources :

Example 26 with CloudConnector

use of com.sequenceiq.cloudbreak.cloud.CloudConnector in project cloudbreak by hortonworks.

the class PrepareImageHandler method accept.

@Override
public void accept(Event<PrepareImageRequest> event) {
    LOGGER.info("Received event: {}", event);
    PrepareImageRequest request = event.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        CloudConnector connector = cloudPlatformConnectors.get(request.getCloudContext().getPlatformVariant());
        AuthenticatedContext auth = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
        Image image = request.getImage();
        CloudStack stack = request.getStack();
        connector.setup().prepareImage(auth, stack, image);
        PrepareImageResult result = new PrepareImageResult(request);
        request.getResult().onNext(result);
        eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
        LOGGER.info("Prepare image finished for {}", cloudContext);
    } catch (RuntimeException e) {
        PrepareImageResult failure = new PrepareImageResult(e, request);
        request.getResult().onNext(failure);
        eventBus.notify(failure.selector(), new Event<>(event.getHeaders(), failure));
    }
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Event(reactor.bus.Event) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) PrepareImageResult(com.sequenceiq.cloudbreak.cloud.event.setup.PrepareImageResult) Image(com.sequenceiq.cloudbreak.cloud.model.Image) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) PrepareImageRequest(com.sequenceiq.cloudbreak.cloud.event.setup.PrepareImageRequest)

Example 27 with CloudConnector

use of com.sequenceiq.cloudbreak.cloud.CloudConnector in project cloudbreak by hortonworks.

the class ProvisionValidationHandler method accept.

@Override
public void accept(Event<ValidationRequest> event) {
    LOGGER.info("Received event: {}", event);
    ValidationRequest request = event.getData();
    CloudContext cloudContext = request.getCloudContext();
    ValidationResult result;
    try {
        CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        AuthenticatedContext ac = connector.authentication().authenticate(request.getCloudContext(), request.getCloudCredential());
        CloudStack cloudStack = request.getCloudStack();
        for (Validator v : connector.validators()) {
            v.validate(ac, cloudStack);
        }
        result = new ValidationResult(request);
    } catch (RuntimeException e) {
        result = new ValidationResult(e, request);
    }
    request.getResult().onNext(result);
    eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) ValidationRequest(com.sequenceiq.cloudbreak.cloud.event.setup.ValidationRequest) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) ValidationResult(com.sequenceiq.cloudbreak.cloud.event.setup.ValidationResult) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Validator(com.sequenceiq.cloudbreak.cloud.Validator)

Example 28 with CloudConnector

use of com.sequenceiq.cloudbreak.cloud.CloudConnector in project cloudbreak by hortonworks.

the class DownscaleStackHandler method accept.

@Override
public void accept(Event<DownscaleStackRequest> downscaleStackRequestEvent) {
    LOGGER.info("Received event: {}", downscaleStackRequestEvent);
    DownscaleStackRequest request = downscaleStackRequestEvent.getData();
    DownscaleStackResult 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(), request.getResourcesToScale());
        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("Downscale successfully finished for {}", cloudContext);
        result = new DownscaleStackResult(request, ResourceLists.transform(statePollerResult.getResults()));
    } catch (Exception e) {
        LOGGER.error("Failed to handle DownscaleStackRequest.", e);
        result = new DownscaleStackResult(e.getMessage(), e, request);
    }
    request.getResult().onNext(result);
    eventBus.notify(result.selector(), new Event<>(downscaleStackRequestEvent.getHeaders(), result));
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) DownscaleStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackResult) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) DownscaleStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ResourcesStatePollerResult(com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)

Example 29 with CloudConnector

use of com.sequenceiq.cloudbreak.cloud.CloudConnector in project cloudbreak by hortonworks.

the class CheckImageHandler method accept.

@Override
public void accept(Event<CheckImageRequest> event) {
    LOGGER.info("Received event: {}", event);
    CheckImageRequest request = event.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        CloudConnector connector = cloudPlatformConnectors.get(request.getCloudContext().getPlatformVariant());
        AuthenticatedContext auth = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
        Image image = request.getImage();
        CloudStack stack = request.getStack();
        ImageStatusResult progress = connector.setup().checkImageStatus(auth, stack, image);
        CheckImageResult imageResult = new CheckImageResult(request, progress.getImageStatus(), progress.getStatusProgressValue());
        request.getResult().onNext(imageResult);
        LOGGER.info("Provision setup finished for {}", cloudContext);
    } catch (RuntimeException e) {
        CheckImageResult failure = new CheckImageResult(e, request, ImageStatus.CREATE_FAILED);
        request.getResult().onNext(failure);
    }
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CheckImageResult(com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageResult) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Image(com.sequenceiq.cloudbreak.cloud.model.Image) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) CheckImageRequest(com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageRequest) ImageStatusResult(com.sequenceiq.cloudbreak.common.type.ImageStatusResult)

Example 30 with CloudConnector

use of com.sequenceiq.cloudbreak.cloud.CloudConnector in project cloudbreak by hortonworks.

the class CheckPlatformVariantHandler method accept.

@Override
public void accept(Event<CheckPlatformVariantRequest> defaultPlatformVariantRequestEvent) {
    LOGGER.info("Received event: {}", defaultPlatformVariantRequestEvent);
    CheckPlatformVariantRequest request = defaultPlatformVariantRequestEvent.getData();
    try {
        CloudConnector cc = cloudPlatformConnectors.get(request.getCloudContext().getPlatform(), request.getCloudContext().getVariant());
        Variant defaultVariant = cc.variant();
        CheckPlatformVariantResult platformParameterResult = new CheckPlatformVariantResult(request, defaultVariant);
        request.getResult().onNext(platformParameterResult);
        LOGGER.info("Query platform variant finished.");
    } catch (RuntimeException e) {
        request.getResult().onNext(new CheckPlatformVariantResult(e.getMessage(), e, request));
    }
}
Also used : Variant(com.sequenceiq.cloudbreak.cloud.model.Variant) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CheckPlatformVariantRequest(com.sequenceiq.cloudbreak.cloud.event.platform.CheckPlatformVariantRequest) CheckPlatformVariantResult(com.sequenceiq.cloudbreak.cloud.event.platform.CheckPlatformVariantResult)

Aggregations

CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)32 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)18 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)15 Event (reactor.bus.Event)10 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)5 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)5 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)5 ResourcesStatePollerResult (com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)5 Test (org.junit.Test)5 CloudCredentialStatus (com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus)3 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)3 InstancesStatusResult (com.sequenceiq.cloudbreak.cloud.event.instance.InstancesStatusResult)2 Image (com.sequenceiq.cloudbreak.cloud.model.Image)2 Variant (com.sequenceiq.cloudbreak.cloud.model.Variant)2 PlatformParameters (com.sequenceiq.cloudbreak.cloud.PlatformParameters)1 Validator (com.sequenceiq.cloudbreak.cloud.Validator)1 CredentialVerificationException (com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationException)1 CredentialVerificationRequest (com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationRequest)1 CredentialVerificationResult (com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationResult)1 InteractiveLoginRequest (com.sequenceiq.cloudbreak.cloud.event.credential.InteractiveLoginRequest)1