Search in sources :

Example 16 with CloudConnector

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

the class GetVirtualMachineRecommendationsHandler method accept.

@Override
public void accept(Event<GetVirtualMachineRecommendtaionRequest> gVMRRE) {
    LOGGER.info("Received GetVirtualMachineRecommendtaionRequest event: {}", gVMRRE);
    GetVirtualMachineRecommendtaionRequest request = gVMRRE.getData();
    String cloudPlatform = request.getCloudPlatform();
    try {
        CloudConnector connector = cloudPlatformConnectors.getDefault(Platform.platform(cloudPlatform));
        VmRecommendations recommendations = connector.parameters().recommendedVms();
        GetVirtualMachineRecommendationResponse gVMRResponse = new GetVirtualMachineRecommendationResponse(request, recommendations);
        request.getResult().onNext(gVMRResponse);
        LOGGER.info("Query platform machine recommendations finished.");
    } catch (RuntimeException e) {
        LOGGER.warn("Could not get virtual machine recommendations for platform: " + cloudPlatform, e);
        request.getResult().onNext(new GetVirtualMachineRecommendationResponse(e.getMessage(), e, request));
    }
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) GetVirtualMachineRecommendtaionRequest(com.sequenceiq.cloudbreak.cloud.event.platform.GetVirtualMachineRecommendtaionRequest) VmRecommendations(com.sequenceiq.cloudbreak.cloud.model.VmRecommendations) GetVirtualMachineRecommendationResponse(com.sequenceiq.cloudbreak.cloud.event.platform.GetVirtualMachineRecommendationResponse)

Example 17 with CloudConnector

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

the class InteractiveLoginHandler method accept.

@Override
public void accept(Event<InteractiveLoginRequest> interactiveLoginRequestEvent) {
    LOGGER.info("Received event: {}", interactiveLoginRequestEvent);
    InteractiveLoginRequest request = interactiveLoginRequestEvent.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        CloudConnector connector = cloudPlatformConnectors.getDefault(cloudContext.getPlatform());
        Map<String, String> parameters = connector.credentials().interactiveLogin(cloudContext, request.getExtendedCloudCredential(), credentialNotifier);
        InteractiveLoginResult interactiveLoginResult = new InteractiveLoginResult(request, parameters);
        request.getResult().onNext(interactiveLoginResult);
        LOGGER.info("Interactive login request successfully processed");
    } catch (RuntimeException e) {
        request.getResult().onNext(new InteractiveLoginResult(e.getMessage(), e, request));
    }
}
Also used : InteractiveLoginResult(com.sequenceiq.cloudbreak.cloud.event.credential.InteractiveLoginResult) InteractiveLoginRequest(com.sequenceiq.cloudbreak.cloud.event.credential.InteractiveLoginRequest) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext)

Example 18 with CloudConnector

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

the class CloudPlatformConnectorsTest method getOpenstackNative.

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

Example 19 with CloudConnector

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

the class CloudPlatformConnectorsTest method getWithNullVariant.

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

Example 20 with CloudConnector

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

the class StopStackHandler method accept.

@Override
public void accept(Event<StopInstancesRequest> event) {
    LOGGER.info("Received event: {}", event);
    StopInstancesRequest request = event.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        List<CloudInstance> instances = request.getCloudInstances();
        AuthenticatedContext authenticatedContext = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
        List<CloudVmInstanceStatus> cloudVmInstanceStatuses = connector.instances().stop(authenticatedContext, request.getResources(), instances);
        PollTask<InstancesStatusResult> task = statusCheckFactory.newPollInstanceStateTask(authenticatedContext, instances, Sets.newHashSet(InstanceStatus.STOPPED, InstanceStatus.FAILED));
        InstancesStatusResult statusResult = new InstancesStatusResult(cloudContext, cloudVmInstanceStatuses);
        if (!task.completed(statusResult)) {
            statusResult = syncPollingScheduler.schedule(task);
        }
        StopInstancesResult result = new StopInstancesResult(request, cloudContext, statusResult);
        request.getResult().onNext(result);
        eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
    } catch (Exception e) {
        StopInstancesResult failure = new StopInstancesResult("Failed to stop stack", 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) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) InstancesStatusResult(com.sequenceiq.cloudbreak.cloud.event.instance.InstancesStatusResult) StopInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.StopInstancesResult) Event(reactor.bus.Event) StopInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.StopInstancesRequest)

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