Search in sources :

Example 6 with CloudConnector

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

the class ProvisionSetupHandler method accept.

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

Example 7 with CloudConnector

use of com.sequenceiq.cloudbreak.cloud.CloudConnector 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));
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) RemoveInstanceResult(com.sequenceiq.cloudbreak.cloud.event.resource.RemoveInstanceResult) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) DownscaleStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackResult) RemoveInstanceRequest(com.sequenceiq.cloudbreak.cloud.event.resource.RemoveInstanceRequest) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ResourcesStatePollerResult(com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)

Example 8 with CloudConnector

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

the class ResourceDefinitionHandler method accept.

@Override
public void accept(Event<ResourceDefinitionRequest> getRegionsRequestEvent) {
    LOGGER.info("Received event: {}", getRegionsRequestEvent);
    ResourceDefinitionRequest request = getRegionsRequestEvent.getData();
    try {
        CloudConnector connector = cloudPlatformConnectors.get(request.getPlatform());
        String resource = request.getResource();
        String definition = connector.parameters().resourceDefinition(request.getResource());
        if (definition == null) {
            Exception exception = new Exception("Failed to find resource definition for " + resource);
            request.getResult().onNext(new ResourceDefinitionResult(exception.getMessage(), exception, request));
        } else {
            request.getResult().onNext(new ResourceDefinitionResult(request, definition));
        }
    } catch (RuntimeException e) {
        request.getResult().onNext(new ResourceDefinitionResult(e.getMessage(), e, request));
    }
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) ResourceDefinitionResult(com.sequenceiq.cloudbreak.cloud.event.platform.ResourceDefinitionResult) ResourceDefinitionRequest(com.sequenceiq.cloudbreak.cloud.event.platform.ResourceDefinitionRequest)

Example 9 with CloudConnector

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

the class CloudPlatformConnectorsTest method getDefaultForGcp.

@Test
public void getDefaultForGcp() {
    CloudConnector conn = c.getDefault(platform("SINGLE"));
    assertEquals("SINGLE", conn.variant().value());
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) Test(org.junit.Test)

Example 10 with CloudConnector

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

the class CloudPlatformConnectorsTest method getWithEmptyVariant.

@Test
public void getWithEmptyVariant() {
    CloudConnector conn = c.get(platform("MULTIWITHDEFAULT"), variant(""));
    // should fall back to default
    assertEquals("ONE", conn.variant().value());
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) Test(org.junit.Test)

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