Search in sources :

Example 16 with CloudCredentialStatus

use of com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus 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

CloudCredentialStatus (com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus)16 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)9 Test (org.junit.Test)7 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)3 AmazonClientException (com.amazonaws.AmazonClientException)2 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)2 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)2 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)2 ExtendedCloudCredential (com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential)2 Event (reactor.bus.Event)2 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)1 DescribeRegionsRequest (com.amazonaws.services.ec2.model.DescribeRegionsRequest)1 TokenResponseException (com.google.api.client.auth.oauth2.TokenResponseException)1 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)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