Search in sources :

Example 1 with ClusterCredentialChangeRequest

use of com.sequenceiq.cloudbreak.reactor.api.event.resource.ClusterCredentialChangeRequest in project cloudbreak by hortonworks.

the class ClusterCredentialChangeHandler method accept.

@Override
public void accept(Event<ClusterCredentialChangeRequest> event) {
    ClusterCredentialChangeRequest request = event.getData();
    ClusterCredentialChangeResult result;
    try {
        Stack stack = stackService.getByIdWithLists(request.getStackId());
        switch(request.getType()) {
            case REPLACE:
                ambariClusterConnector.replaceUserNamePassword(stack, request.getUser(), request.getPassword());
                break;
            case UPDATE:
                ambariClusterConnector.updateUserNamePassword(stack, request.getPassword());
                break;
            default:
                throw new UnsupportedOperationException("Ambari credential update request not supported: " + request.getType());
        }
        result = new ClusterCredentialChangeResult(request);
    } catch (Exception e) {
        result = new ClusterCredentialChangeResult(e.getMessage(), e, request);
    }
    eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
}
Also used : ClusterCredentialChangeRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.ClusterCredentialChangeRequest) ClusterCredentialChangeResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.ClusterCredentialChangeResult) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 2 with ClusterCredentialChangeRequest

use of com.sequenceiq.cloudbreak.reactor.api.event.resource.ClusterCredentialChangeRequest in project cloudbreak by hortonworks.

the class ClusterCredentialChangeActions method changingClusterCredential.

@Bean(name = "CLUSTER_CREDENTIALCHANGE_STATE")
public Action<?, ?> changingClusterCredential() {
    return new AbstractClusterAction<ClusterCredentialChangeTriggerEvent>(ClusterCredentialChangeTriggerEvent.class) {

        @Override
        protected void doExecute(ClusterViewContext ctx, ClusterCredentialChangeTriggerEvent payload, Map<Object, Object> variables) {
            clusterCredentialChangeService.credentialChange(ctx.getStackId());
            ClusterCredentialChangeRequest request;
            switch(payload.getType()) {
                case REPLACE:
                    request = ClusterCredentialChangeRequest.replaceUserRequest(ctx.getStackId(), payload.getUser(), payload.getPassword());
                    break;
                case UPDATE:
                    request = ClusterCredentialChangeRequest.changePasswordRequest(ctx.getStackId(), payload.getPassword());
                    break;
                default:
                    throw new UnsupportedOperationException("Ambari credential update request not supported: " + payload.getType());
            }
            sendEvent(ctx.getFlowId(), request);
        }
    };
}
Also used : ClusterCredentialChangeTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.ClusterCredentialChangeTriggerEvent) ClusterCredentialChangeRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.ClusterCredentialChangeRequest) AbstractClusterAction(com.sequenceiq.cloudbreak.core.flow2.cluster.AbstractClusterAction) Map(java.util.Map) ClusterViewContext(com.sequenceiq.cloudbreak.core.flow2.cluster.ClusterViewContext) Bean(org.springframework.context.annotation.Bean)

Aggregations

ClusterCredentialChangeRequest (com.sequenceiq.cloudbreak.reactor.api.event.resource.ClusterCredentialChangeRequest)2 AbstractClusterAction (com.sequenceiq.cloudbreak.core.flow2.cluster.AbstractClusterAction)1 ClusterViewContext (com.sequenceiq.cloudbreak.core.flow2.cluster.ClusterViewContext)1 ClusterCredentialChangeTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.ClusterCredentialChangeTriggerEvent)1 Stack (com.sequenceiq.cloudbreak.domain.Stack)1 ClusterCredentialChangeResult (com.sequenceiq.cloudbreak.reactor.api.event.resource.ClusterCredentialChangeResult)1 Map (java.util.Map)1 Bean (org.springframework.context.annotation.Bean)1