Search in sources :

Example 1 with CredentialVerificationResult

use of com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationResult in project cloudbreak by hortonworks.

the class ServiceProviderCredentialAdapter method init.

public Credential init(Credential credential) {
    CloudContext cloudContext = new CloudContext(credential.getId(), credential.getName(), credential.cloudPlatform(), credential.getOwner());
    CloudCredential cloudCredential = credentialConverter.convert(credential);
    CredentialVerificationRequest request = new CredentialVerificationRequest(cloudContext, cloudCredential);
    LOGGER.info("Triggering event: {}", request);
    eventBus.notify(request.selector(), eventFactory.createEvent(request));
    try {
        CredentialVerificationResult res = request.await();
        String message = "Failed to verify the credential: ";
        LOGGER.info("Result: {}", res);
        if (res.getStatus() != EventStatus.OK) {
            LOGGER.error(message, res.getErrorDetails());
            throw new BadRequestException(message + res.getErrorDetails(), res.getErrorDetails());
        }
        if (CredentialStatus.FAILED.equals(res.getCloudCredentialStatus().getStatus())) {
            throw new BadRequestException(message + res.getCloudCredentialStatus().getStatusReason(), res.getCloudCredentialStatus().getException());
        }
        CloudCredential cloudCredentialResponse = res.getCloudCredentialStatus().getCloudCredential();
        mergeSmartSenseAttributeIfExists(credential, cloudCredentialResponse);
    } catch (InterruptedException e) {
        LOGGER.error("Error while executing credential verification", e);
        throw new OperationException(e);
    }
    return credential;
}
Also used : CredentialVerificationRequest(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationRequest) CredentialVerificationResult(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationResult) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) OperationException(com.sequenceiq.cloudbreak.service.stack.connector.OperationException)

Example 2 with CredentialVerificationResult

use of com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationResult 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

CredentialVerificationRequest (com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationRequest)2 CredentialVerificationResult (com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationResult)2 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)1 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 CredentialVerificationException (com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationException)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 CloudCredentialStatus (com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus)1 ExtendedCloudCredential (com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential)1 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)1 OperationException (com.sequenceiq.cloudbreak.service.stack.connector.OperationException)1