Search in sources :

Example 1 with CreateCredentialRequest

use of com.sequenceiq.cloudbreak.cloud.event.resource.CreateCredentialRequest in project cloudbreak by hortonworks.

the class StackCreationActions method createCredentialAction.

@Bean(name = "CREATE_CREDENTIAL_STATE")
public Action<?, ?> createCredentialAction() {
    return new AbstractStackCreationAction<StackEvent>(StackEvent.class) {

        @Override
        protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
            variables.put(START_DATE, new Date());
            stackCreationService.startProvisioning(context);
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(StackContext context) {
            return new CreateCredentialRequest(context.getCloudContext(), context.getCloudCredential(), context.getCloudStack());
        }
    };
}
Also used : CreateCredentialRequest(com.sequenceiq.cloudbreak.cloud.event.resource.CreateCredentialRequest) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) StackContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackContext) Map(java.util.Map) Date(java.util.Date) Bean(org.springframework.context.annotation.Bean)

Example 2 with CreateCredentialRequest

use of com.sequenceiq.cloudbreak.cloud.event.resource.CreateCredentialRequest 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)

Aggregations

CreateCredentialRequest (com.sequenceiq.cloudbreak.cloud.event.resource.CreateCredentialRequest)2 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)1 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 CreateCredentialResult (com.sequenceiq.cloudbreak.cloud.event.resource.CreateCredentialResult)1 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 CloudCredentialStatus (com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus)1 StackContext (com.sequenceiq.cloudbreak.core.flow2.stack.StackContext)1 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)1 Date (java.util.Date)1 Map (java.util.Map)1 Bean (org.springframework.context.annotation.Bean)1 Event (reactor.bus.Event)1