Search in sources :

Example 31 with StackEvent

use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.

the class FreeIpaUpscaleActions method tlsSetupAction.

@Bean(name = "UPSCALE_TLS_SETUP_STATE")
public Action<?, ?> tlsSetupAction() {
    return new AbstractUpscaleAction<>(StackEvent.class) {

        @Override
        protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Setting up TLS");
            StackEvent event;
            try {
                if (!stack.getTunnel().useCcm()) {
                    Set<InstanceMetaData> newInstancesMetaData = stack.getInstanceGroups().stream().flatMap(instanceGroup -> instanceGroup.getAllInstanceMetaData().stream()).filter(this::isNewInstancesWithoutTlsCert).collect(Collectors.toSet());
                    for (InstanceMetaData gwInstance : newInstancesMetaData) {
                        tlsSetupService.setupTls(stack.getId(), gwInstance);
                    }
                }
                event = new StackEvent(UpscaleFlowEvent.UPSCALE_TLS_SETUP_FINISHED_EVENT.event(), stack.getId());
            } catch (Exception e) {
                LOGGER.error("Failed to setup TLS", e);
                event = new UpscaleFailureEvent(stack.getId(), "Setting ups TLS", Set.of(), Map.of(), e);
            }
            sendEvent(context, event.selector(), event);
        }

        private boolean isNewInstancesWithoutTlsCert(InstanceMetaData instanceMetaData) {
            return instanceMetaData.getInstanceStatus().equals(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus.CREATED) && Objects.isNull(instanceMetaData.getServerCert());
        }
    };
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) UpscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.upscale.event.UpscaleFailureEvent) Map(java.util.Map) ClientErrorException(javax.ws.rs.ClientErrorException) OperationException(com.sequenceiq.cloudbreak.service.OperationException) Stack(com.sequenceiq.freeipa.entity.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Bean(org.springframework.context.annotation.Bean)

Example 32 with StackEvent

use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.

the class FreeIpaUpscaleActions method orchestratorConfig.

@Bean(name = "UPSCALE_ORCHESTRATOR_CONFIG_STATE")
public Action<?, ?> orchestratorConfig() {
    return new AbstractUpscaleAction<>(StackEvent.class) {

        @Override
        protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Configuring the orchestrator");
            OrchestratorConfigRequest request = new OrchestratorConfigRequest(stack.getId());
            sendEvent(context, request.selector(), request);
        }
    };
}
Also used : StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) OrchestratorConfigRequest(com.sequenceiq.freeipa.flow.freeipa.provision.event.orchestrator.OrchestratorConfigRequest) Map(java.util.Map) Stack(com.sequenceiq.freeipa.entity.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Bean(org.springframework.context.annotation.Bean)

Example 33 with StackEvent

use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.

the class FreeIpaUpscaleActions method updateClusterProxyRegistrationPreBootstrapAction.

@Bean(name = "UPSCALE_UPDATE_CLUSTERPROXY_REGISTRATION_PRE_BOOTSTRAP_STATE")
public Action<?, ?> updateClusterProxyRegistrationPreBootstrapAction() {
    return new AbstractUpscaleAction<>(StackEvent.class) {

        @Override
        protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Update cluster proxy registration before bootstrap");
            List<String> instanceIds = getInstanceIds(variables);
            Set<InstanceMetaData> newInstances = instanceMetaDataService.getByInstanceIds(stack.getId(), instanceIds);
            boolean allNewInstanceHasFqdn = newInstances.stream().allMatch(im -> StringUtils.isNotBlank(im.getDiscoveryFQDN()));
            Selectable event = allNewInstanceHasFqdn ? new ClusterProxyRegistrationRequest(stack.getId()) : new ClusterProxyRegistrationSuccess(stack.getId());
            sendEvent(context, event.selector(), event);
        }
    };
}
Also used : ClusterProxyRegistrationRequest(com.sequenceiq.freeipa.flow.stack.provision.event.clusterproxy.ClusterProxyRegistrationRequest) Stack(com.sequenceiq.freeipa.entity.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) ClusterProxyRegistrationSuccess(com.sequenceiq.freeipa.flow.stack.provision.event.clusterproxy.ClusterProxyRegistrationSuccess) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 34 with StackEvent

use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.

the class FreeIpaUpscaleActions method startingAction.

@Bean(name = "UPSCALE_STARTING_STATE")
public Action<?, ?> startingAction() {
    return new AbstractUpscaleAction<>(UpscaleEvent.class) {

        @Override
        protected void doExecute(StackContext context, UpscaleEvent payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            String operationId = payload.getOperationId();
            setOperationId(variables, operationId);
            setInstanceCountByGroup(variables, payload.getInstanceCountByGroup());
            setRepair(variables, payload.isRepair());
            setChainedAction(variables, payload.isChained());
            setFinalChain(variables, payload.isFinalChain());
            LOGGER.info("Starting upscale {}", payload);
            stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Starting upscale");
            sendEvent(context, UPSCALE_STARTING_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
        }
    };
}
Also used : StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) UpscaleEvent(com.sequenceiq.freeipa.flow.freeipa.upscale.event.UpscaleEvent) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) Map(java.util.Map) Stack(com.sequenceiq.freeipa.entity.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Bean(org.springframework.context.annotation.Bean)

Example 35 with StackEvent

use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.

the class ChangePrimaryGatewayActions method selectionAction.

@Bean(name = "CHANGE_PRIMARY_GATEWAY_SELECTION")
public Action<?, ?> selectionAction() {
    return new AbstractChangePrimaryGatewayAction<>(StackEvent.class) {

        @Override
        protected void doExecute(ChangePrimaryGatewayContext context, StackEvent payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.REPAIR_IN_PROGRESS, "Selecting the primary gateway");
            List<String> repairInstanceIds = getInstanceIds(variables);
            ChangePrimaryGatewaySelectionRequest request = new ChangePrimaryGatewaySelectionRequest(stack.getId(), repairInstanceIds);
            sendEvent(context, request);
        }
    };
}
Also used : StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) ChangePrimaryGatewayContext(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.ChangePrimaryGatewayContext) Map(java.util.Map) ChangePrimaryGatewaySelectionRequest(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.event.selection.ChangePrimaryGatewaySelectionRequest) Stack(com.sequenceiq.freeipa.entity.Stack) Bean(org.springframework.context.annotation.Bean)

Aggregations

StackEvent (com.sequenceiq.freeipa.flow.stack.StackEvent)54 Map (java.util.Map)40 Bean (org.springframework.context.annotation.Bean)40 Stack (com.sequenceiq.freeipa.entity.Stack)38 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)28 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)17 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)12 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)11 OperationService (com.sequenceiq.freeipa.service.operation.OperationService)11 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)10 ClientErrorException (javax.ws.rs.ClientErrorException)10 EnvironmentEndpoint (com.sequenceiq.environment.api.v1.environment.endpoint.EnvironmentEndpoint)9 Flow (com.sequenceiq.flow.core.Flow)9 FlowParameters (com.sequenceiq.flow.core.FlowParameters)8 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 Inject (javax.inject.Inject)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 Configuration (org.springframework.context.annotation.Configuration)8