Search in sources :

Example 11 with AbstractStackCreationAction

use of com.sequenceiq.cloudbreak.core.flow2.stack.provision.action.AbstractStackCreationAction in project cloudbreak by hortonworks.

the class CloudConfigValidationActions method cloudConfigValidationAction.

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

        @Override
        protected void doExecute(StackCreationContext context, StackEvent payload, Map<Object, Object> variables) throws Exception {
            ValidateCloudConfigRequest request = new ValidateCloudConfigRequest(payload.getResourceId());
            sendEvent(context, request.selector(), request);
        }

        @Override
        protected Object getFailurePayload(StackEvent payload, Optional<StackCreationContext> flowContext, Exception ex) {
            return new StackFailureEvent(CloudConfigValidationEvent.VALIDATE_CLOUD_CONFIG_FAILED_EVENT.selector(), payload.getResourceId(), ex);
        }
    };
}
Also used : StackCreationContext(com.sequenceiq.cloudbreak.core.flow2.stack.start.StackCreationContext) AbstractStackCreationAction(com.sequenceiq.cloudbreak.core.flow2.stack.provision.action.AbstractStackCreationAction) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) Optional(java.util.Optional) ValidateCloudConfigRequest(com.sequenceiq.cloudbreak.core.flow2.validate.cloud.event.ValidateCloudConfigRequest) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 12 with AbstractStackCreationAction

use of com.sequenceiq.cloudbreak.core.flow2.stack.provision.action.AbstractStackCreationAction in project cloudbreak by hortonworks.

the class KerberosConfigValidationActions method checkFreeIpaExistsAction.

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

        @Override
        protected void doExecute(StackCreationContext context, StackEvent payload, Map<Object, Object> variables) {
            CheckFreeIpaExistsEvent event = new CheckFreeIpaExistsEvent(payload.getResourceId());
            sendEvent(context, event);
        }

        @Override
        protected Object getFailurePayload(StackEvent payload, Optional<StackCreationContext> flowContext, Exception ex) {
            return new StackFailureEvent(KerberosConfigValidationEvent.VALIDATE_KERBEROS_CONFIG_FAILED_EVENT.selector(), payload.getResourceId(), ex);
        }
    };
}
Also used : CheckFreeIpaExistsEvent(com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.event.CheckFreeIpaExistsEvent) StackCreationContext(com.sequenceiq.cloudbreak.core.flow2.stack.start.StackCreationContext) AbstractStackCreationAction(com.sequenceiq.cloudbreak.core.flow2.stack.provision.action.AbstractStackCreationAction) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) Optional(java.util.Optional) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 13 with AbstractStackCreationAction

use of com.sequenceiq.cloudbreak.core.flow2.stack.provision.action.AbstractStackCreationAction in project cloudbreak by hortonworks.

the class KerberosConfigValidationActions method kerberosConfigValidationAction.

@Bean(name = "VALIDATE_KERBEROS_CONFIG_STATE")
public Action<?, ?> kerberosConfigValidationAction() {
    return new AbstractStackCreationAction<>(ValidateKerberosConfigEvent.class) {

        @Override
        protected void doExecute(StackCreationContext context, ValidateKerberosConfigEvent payload, Map<Object, Object> variables) {
            decorateStackWithCustomDomainIfAdOrIpaJoinable(context.getStack());
            Cluster cluster = context.getStack().getCluster();
            if ((cluster != null && Boolean.TRUE.equals(cluster.getAutoTlsEnabled())) || payload.doesFreeipaExistsForEnv()) {
                boolean hasFreeIpaKerberosConfig = clusterCreationEnvironmentValidator.hasFreeIpaKerberosConfig(context.getStack());
                if (!hasFreeIpaKerberosConfig) {
                    throw new IllegalStateException("AutoTLS works only with FreeIPA. No FreeIPA Kerberos configuration is found.");
                }
            }
            sendEvent(context, KerberosConfigValidationEvent.VALIDATE_KERBEROS_CONFIG_FINISHED_EVENT.selector(), payload);
        }

        @Override
        protected Object getFailurePayload(ValidateKerberosConfigEvent payload, Optional<StackCreationContext> flowContext, Exception ex) {
            return new StackFailureEvent(KerberosConfigValidationEvent.VALIDATE_KERBEROS_CONFIG_FAILED_EVENT.selector(), payload.getResourceId(), ex);
        }

        private void decorateStackWithCustomDomainIfAdOrIpaJoinable(Stack stack) {
            Optional<KerberosConfig> kerberosConfig = measure(() -> kerberosConfigService.get(stack.getEnvironmentCrn(), stack.getName()), LOGGER, "kerberosConfigService get {} ms");
            if (kerberosConfig.isPresent() && StringUtils.isNotBlank(kerberosConfig.get().getDomain())) {
                LOGGER.info("Setting custom domain [{}] for cluster [{}]", kerberosConfig.get().getDomain(), stack.getName());
                stack.setCustomDomain(kerberosConfig.get().getDomain());
                stackService.save(stack);
            } else {
                LOGGER.info("No kerberos config or no  custom domain found");
            }
        }
    };
}
Also used : StackCreationContext(com.sequenceiq.cloudbreak.core.flow2.stack.start.StackCreationContext) AbstractStackCreationAction(com.sequenceiq.cloudbreak.core.flow2.stack.provision.action.AbstractStackCreationAction) Optional(java.util.Optional) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) KerberosConfig(com.sequenceiq.cloudbreak.dto.KerberosConfig) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) ValidateKerberosConfigEvent(com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.event.ValidateKerberosConfigEvent) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Aggregations

StackCreationContext (com.sequenceiq.cloudbreak.core.flow2.stack.start.StackCreationContext)13 Map (java.util.Map)13 Bean (org.springframework.context.annotation.Bean)13 StackFailureEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent)7 Optional (java.util.Optional)7 AbstractStackCreationAction (com.sequenceiq.cloudbreak.core.flow2.stack.provision.action.AbstractStackCreationAction)6 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)6 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)5 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)5 GetTlsInfoResult (com.sequenceiq.cloudbreak.cloud.event.instance.GetTlsInfoResult)4 GetSSHFingerprintsRequest (com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsRequest)3 GetSSHFingerprintsResult (com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsResult)3 GetTlsInfoRequest (com.sequenceiq.cloudbreak.cloud.event.instance.GetTlsInfoRequest)3 CollectLoadBalancerMetadataResult (com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataResult)3 CreateCredentialRequest (com.sequenceiq.cloudbreak.cloud.event.resource.CreateCredentialRequest)3 PrepareImageRequest (com.sequenceiq.cloudbreak.cloud.event.setup.PrepareImageRequest)3 SetupResult (com.sequenceiq.cloudbreak.cloud.event.setup.SetupResult)3 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)3 Image (com.sequenceiq.cloudbreak.cloud.model.Image)3 TlsInfo (com.sequenceiq.cloudbreak.cloud.model.TlsInfo)3