use of com.sequenceiq.cloudbreak.cloud.event.resource.CreateCredentialResult 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));
}
}
Aggregations