Search in sources :

Example 31 with CloudConnector

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

the class CreateCredentialHandler method accept.

@Override
public void accept(Event<CreateCredentialRequest> credentialRequestEvent) {
    LOGGER.info("Received event: {}", credentialRequestEvent);
    CreateCredentialRequest request = credentialRequestEvent.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
        CloudCredentialStatus credentialStatus = connector.credentials().create(ac);
        if (CredentialStatus.FAILED == credentialStatus.getStatus()) {
            if (credentialStatus.getException() != null) {
                throw new CloudConnectorException(credentialStatus.getException());
            }
            throw new CloudConnectorException(credentialStatus.getStatusReason());
        }
        CreateCredentialResult result = new CreateCredentialResult(request);
        request.getResult().onNext(result);
        eventBus.notify(result.selector(), new Event<>(credentialRequestEvent.getHeaders(), result));
        LOGGER.info("Creating credential successfully finished for {}", cloudContext);
    } catch (RuntimeException e) {
        CreateCredentialResult failure = new CreateCredentialResult(e, request);
        request.getResult().onNext(failure);
        eventBus.notify(failure.selector(), new Event<>(credentialRequestEvent.getHeaders(), failure));
    }
}
Also used : CreateCredentialRequest(com.sequenceiq.cloudbreak.cloud.event.resource.CreateCredentialRequest) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Event(reactor.bus.Event) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus) CreateCredentialResult(com.sequenceiq.cloudbreak.cloud.event.resource.CreateCredentialResult)

Example 32 with CloudConnector

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

the class CredentialVerificationHandler method accept.

@Override
public void accept(Event<CredentialVerificationRequest> createCredentialRequestEvent) {
    LOGGER.info("Received event: {}", createCredentialRequestEvent);
    CredentialVerificationRequest request = createCredentialRequestEvent.getData();
    try {
        CloudConnector connector = cloudPlatformConnectors.getDefault(request.getCloudContext().getPlatform());
        AuthenticatedContext ac;
        CloudCredentialStatus cloudCredentialStatus;
        try {
            ac = connector.authentication().authenticate(request.getCloudContext(), request.getCloudCredential());
            cloudCredentialStatus = connector.credentials().verify(ac);
        } catch (CredentialVerificationException e) {
            String errorMessage = e.getMessage();
            LOGGER.error(errorMessage, e);
            cloudCredentialStatus = new CloudCredentialStatus(request.getCloudCredential(), CredentialStatus.FAILED, e, errorMessage);
        } catch (RuntimeException e) {
            String errorMessage = String.format("Could not verify credential [credential: '%s'], detailed message: %s", request.getCloudContext().getName(), e.getMessage());
            LOGGER.error(errorMessage, e);
            cloudCredentialStatus = new CloudCredentialStatus(request.getCloudCredential(), CredentialStatus.FAILED, e, errorMessage);
        }
        CredentialVerificationResult credentialVerificationResult = new CredentialVerificationResult(request, cloudCredentialStatus);
        request.getResult().onNext(credentialVerificationResult);
        LOGGER.info("Credential verification successfully finished");
    } catch (RuntimeException e) {
        request.getResult().onNext(new CredentialVerificationResult(e.getMessage(), e, request));
    }
}
Also used : CredentialVerificationRequest(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationRequest) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CredentialVerificationResult(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationResult) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CredentialVerificationException(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationException) CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus)

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