Search in sources :

Example 21 with CloudConnector

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

the class TemplateHandler method accept.

@Override
public void accept(Event<GetPlatformTemplateRequest> platformTemplateRequestEvent) {
    LOGGER.info("Received event: {}", platformTemplateRequestEvent);
    GetPlatformTemplateRequest request = platformTemplateRequestEvent.getData();
    String template = null;
    try {
        CloudConnector connector = cloudPlatformConnectors.get(request.getCloudContext().getPlatformVariant());
        if (connector != null) {
            template = connector.resources().getStackTemplate();
        }
    } catch (TemplatingDoesNotSupportedException ignored) {
    }
    GetPlatformTemplateResult getPlatformTemplateResult = new GetPlatformTemplateResult(request, template);
    request.getResult().onNext(getPlatformTemplateResult);
    LOGGER.info("Get template finished.");
}
Also used : GetPlatformTemplateResult(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformTemplateResult) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) TemplatingDoesNotSupportedException(com.sequenceiq.cloudbreak.cloud.exception.TemplatingDoesNotSupportedException) GetPlatformTemplateRequest(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformTemplateRequest)

Example 22 with CloudConnector

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

the class UpscaleStackHandler method accept.

@Override
public void accept(Event<UpscaleStackRequest> upscaleStackRequestEvent) {
    LOGGER.info("Received event: {}", upscaleStackRequestEvent);
    UpscaleStackRequest request = upscaleStackRequestEvent.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
        List<CloudResourceStatus> resourceStatus = connector.resources().upscale(ac, request.getCloudStack(), request.getResourceList());
        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);
        }
        UpscaleStackResult result = ResourcesStatePollerResults.transformToUpscaleStackResult(statePollerResult, request);
        request.getResult().onNext(result);
        eventBus.notify(result.selector(), new Event<>(upscaleStackRequestEvent.getHeaders(), result));
        LOGGER.info("Upscale successfully finished for {}", cloudContext);
    } catch (Exception e) {
        UpscaleStackResult result = new UpscaleStackResult(e.getMessage(), e, request);
        request.getResult().onNext(result);
        eventBus.notify(CloudPlatformResult.failureSelector(UpscaleStackResult.class), new Event<>(upscaleStackRequestEvent.getHeaders(), result));
    }
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) UpscaleStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackResult) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Event(reactor.bus.Event) UpscaleStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ResourcesStatePollerResult(com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)

Example 23 with CloudConnector

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

the class CloudPlatformConnectors method cloudPlatformConnectors.

@PostConstruct
public void cloudPlatformConnectors() {
    platformToVariants = HashMultimap.create();
    for (CloudConnector connector : cloudConnectors) {
        map.put(new CloudPlatformVariant(connector.platform(), connector.variant()), connector);
        platformToVariants.put(connector.platform(), connector.variant());
    }
    Map<Platform, Variant> environmentDefaults = extractEnvironmentDefaultVariants();
    setupDefaultVariants(platformToVariants, environmentDefaults);
    LOGGER.debug(map.toString());
    LOGGER.debug(defaultVariants.toString());
}
Also used : Variant(com.sequenceiq.cloudbreak.cloud.model.Variant) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) PostConstruct(javax.annotation.PostConstruct)

Example 24 with CloudConnector

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

the class LaunchStackHandler method accept.

@Override
public void accept(Event<LaunchStackRequest> launchStackRequestEvent) {
    LOGGER.info("Received event: {}", launchStackRequestEvent);
    LaunchStackRequest request = launchStackRequestEvent.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
        List<CloudResourceStatus> resourceStatus = connector.resources().launch(ac, request.getCloudStack(), persistenceNotifier, request.getAdjustmentType(), request.getThreshold());
        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);
        }
        LaunchStackResult result = ResourcesStatePollerResults.transformToLaunchStackResult(request, statePollerResult);
        request.getResult().onNext(result);
        eventBus.notify(result.selector(), new Event<>(launchStackRequestEvent.getHeaders(), result));
        LOGGER.info("Launching the stack successfully finished for {}", cloudContext);
    } catch (Exception e) {
        LaunchStackResult failure = new LaunchStackResult(e, request);
        LOGGER.error("Error during launching the stack:", e);
        request.getResult().onNext(failure);
        eventBus.notify(failure.selector(), new Event<>(launchStackRequestEvent.getHeaders(), failure));
    }
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) LaunchStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.LaunchStackResult) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Event(reactor.bus.Event) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ResourcesStatePollerResult(com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult) LaunchStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.LaunchStackRequest)

Example 25 with CloudConnector

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

the class PlatformParameterHandler method accept.

@Override
public void accept(Event<PlatformParameterRequest> platformParameterRequestEvent) {
    LOGGER.info("Received event: {}", platformParameterRequestEvent);
    PlatformParameterRequest request = platformParameterRequestEvent.getData();
    try {
        CloudConnector connector = cloudPlatformConnectors.get(request.getCloudContext().getPlatformVariant());
        PlatformParameters platformParameters = connector.parameters();
        PlatformParameterResult platformParameterResult = new PlatformParameterResult(request, platformParameters);
        request.getResult().onNext(platformParameterResult);
        LOGGER.info("Query platform parameters finished.");
    } catch (RuntimeException e) {
        request.getResult().onNext(new PlatformParameterResult(e.getMessage(), e, request));
    }
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) PlatformParameterRequest(com.sequenceiq.cloudbreak.cloud.event.platform.PlatformParameterRequest) PlatformParameters(com.sequenceiq.cloudbreak.cloud.PlatformParameters) PlatformParameterResult(com.sequenceiq.cloudbreak.cloud.event.platform.PlatformParameterResult)

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