Search in sources :

Example 41 with StackEvent

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

the class FreeIpaDownscaleActions method startingDownscaleAction.

@Bean(name = "STARTING_DOWNSCALE_STATE")
public Action<?, ?> startingDownscaleAction() {
    return new AbstractDownscaleAction<>(DownscaleEvent.class) {

        @Override
        protected void doExecute(StackContext context, DownscaleEvent payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            List<String> instanceIds = payload.getInstanceIds();
            setInstanceIds(variables, instanceIds);
            String operationId = payload.getOperationId();
            setOperationId(variables, operationId);
            List<String> fqdns = getInstanceMetadataFromStack(stack, instanceIds).stream().map(InstanceMetaData::getDiscoveryFQDN).filter(Objects::nonNull).collect(Collectors.toList());
            setDownscaleHosts(variables, fqdns);
            setRepair(variables, payload.isRepair());
            setChainedAction(variables, payload.isChained());
            setFinalChain(variables, payload.isFinalChain());
            setInstanceCountByGroup(variables, payload.getInstanceCountByGroup());
            LOGGER.info("Starting downscale {}", payload);
            stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Starting downscale");
            sendEvent(context, STARTING_DOWNSCALE_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
        }
    };
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) DownscaleEvent(com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleEvent) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) Map(java.util.Map) Stack(com.sequenceiq.freeipa.entity.Stack) Bean(org.springframework.context.annotation.Bean)

Example 42 with StackEvent

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

the class FreeIpaDownscaleActions method downscaleFinsihedAction.

@Bean(name = "DOWNSCALE_FINISHED_STATE")
public Action<?, ?> downscaleFinsihedAction() {
    return new AbstractDownscaleAction<>(StackEvent.class) {

        @Inject
        private OperationService operationService;

        @Override
        protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), getDownscaleCompleteStatus(variables), "Downscale complete");
            if (shouldCompleteOperation(variables)) {
                SuccessDetails successDetails = new SuccessDetails(stack.getEnvironmentCrn());
                successDetails.getAdditionalDetails().put("Hosts", getDownscaleHosts(variables));
                operationService.completeOperation(stack.getAccountId(), getOperationId(variables), List.of(successDetails), Collections.emptyList());
            }
            sendEvent(context, DOWNSCALE_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
        }
    };
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) Map(java.util.Map) Stack(com.sequenceiq.freeipa.entity.Stack) Bean(org.springframework.context.annotation.Bean)

Example 43 with StackEvent

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

the class FreeIpaDownscaleActions method downscaleClusterProxyRegistrationAction.

@Bean(name = "DOWNSCALE_CLUSTERPROXY_REGISTRATION_STATE")
public Action<?, ?> downscaleClusterProxyRegistrationAction() {
    return new AbstractDownscaleAction<>(StackEvent.class) {

        @Override
        protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) throws Exception {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Updating cluster proxy registration.");
            List<String> repairInstanceIds = getInstanceIds(variables);
            List<String> instanceIdsToRegister = stack.getNotDeletedInstanceMetaDataList().stream().map(InstanceMetaData::getInstanceId).filter(instanceId -> !repairInstanceIds.contains(instanceId)).collect(Collectors.toList());
            ClusterProxyUpdateRegistrationRequest request = new ClusterProxyUpdateRegistrationRequest(stack.getId(), instanceIdsToRegister);
            sendEvent(context, request.selector(), request);
        }
    };
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) DOWNSCALE_FINISHED_EVENT(com.sequenceiq.freeipa.flow.freeipa.downscale.DownscaleFlowEvent.DOWNSCALE_FINISHED_EVENT) Action(org.springframework.statemachine.action.Action) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) DOWNSCALE_ADD_ADDITIONAL_HOSTNAMES_FINISHED_EVENT(com.sequenceiq.freeipa.flow.freeipa.downscale.DownscaleFlowEvent.DOWNSCALE_ADD_ADDITIONAL_HOSTNAMES_FINISHED_EVENT) LoggerFactory(org.slf4j.LoggerFactory) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) ClientErrorException(javax.ws.rs.ClientErrorException) CollectAdditionalHostnamesRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.collecthostnames.CollectAdditionalHostnamesRequest) RemoveHostsFromOrchestrationSuccess(com.sequenceiq.freeipa.flow.freeipa.downscale.event.removehosts.RemoveHostsFromOrchestrationSuccess) DOWNSCALE_UPDATE_KERBEROS_NAMESERVERS_CONFIG_FINISHED_EVENT(com.sequenceiq.freeipa.flow.freeipa.downscale.DownscaleFlowEvent.DOWNSCALE_UPDATE_KERBEROS_NAMESERVERS_CONFIG_FINISHED_EVENT) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) Map(java.util.Map) ClusterProxyUpdateRegistrationFailedToDownscaleFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.downscale.failure.ClusterProxyUpdateRegistrationFailedToDownscaleFailureEventConverter) ClusterProxyUpdateRegistrationRequest(com.sequenceiq.freeipa.flow.freeipa.provision.event.clusterproxy.ClusterProxyUpdateRegistrationRequest) DownscaleStackCollectResourcesRequest(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackCollectResourcesRequest) EnvironmentEndpoint(com.sequenceiq.environment.api.v1.environment.endpoint.EnvironmentEndpoint) PayloadConverter(com.sequenceiq.flow.core.PayloadConverter) RemoveReplicationAgreementsRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.removereplication.RemoveReplicationAgreementsRequest) RevokeCertsResponse(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.cert.RevokeCertsResponse) UPDATE_METADATA_FOR_DELETION_REQUEST_FINISHED_EVENT(com.sequenceiq.freeipa.flow.freeipa.downscale.DownscaleFlowEvent.UPDATE_METADATA_FOR_DELETION_REQUEST_FINISHED_EVENT) FailureDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails) Set(java.util.Set) WebApplicationExceptionMessageExtractor(com.sequenceiq.cloudbreak.common.exception.WebApplicationExceptionMessageExtractor) FlowParameters(com.sequenceiq.flow.core.FlowParameters) DOWNSCALE_UPDATE_ENVIRONMENT_STACK_CONFIG_FAILED_EVENT(com.sequenceiq.freeipa.flow.freeipa.downscale.DownscaleFlowEvent.DOWNSCALE_UPDATE_ENVIRONMENT_STACK_CONFIG_FAILED_EVENT) Collectors(java.util.stream.Collectors) RevokeCertsRequest(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.cert.RevokeCertsRequest) STARTING_DOWNSCALE_FINISHED_EVENT(com.sequenceiq.freeipa.flow.freeipa.downscale.DownscaleFlowEvent.STARTING_DOWNSCALE_FINISHED_EVENT) RegionAwareInternalCrnGeneratorFactory(com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory) UpdateDnsSoaRecordsRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.dnssoarecords.UpdateDnsSoaRecordsRequest) RemoveDnsResponseToDownscaleFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.downscale.failure.RemoveDnsResponseToDownscaleFailureEventConverter) Objects(java.util.Objects) Configuration(org.springframework.context.annotation.Configuration) DownscaleStackCollectResourcesResultToDownscaleFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.downscale.failure.DownscaleStackCollectResourcesResultToDownscaleFailureEventConverter) DOWNSCALE_UPDATE_ENVIRONMENT_STACK_CONFIG_FINISHED_EVENT(com.sequenceiq.freeipa.flow.freeipa.downscale.DownscaleFlowEvent.DOWNSCALE_UPDATE_ENVIRONMENT_STACK_CONFIG_FINISHED_EVENT) List(java.util.List) DownscaleStackCollectResourcesResult(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackCollectResourcesResult) StackUpdater(com.sequenceiq.freeipa.service.stack.StackUpdater) Flow(com.sequenceiq.flow.core.Flow) CollectAdditionalHostnamesResponse(com.sequenceiq.freeipa.flow.freeipa.downscale.event.collecthostnames.CollectAdditionalHostnamesResponse) KerberosConfigUpdateService(com.sequenceiq.freeipa.service.config.KerberosConfigUpdateService) InstanceGroupService(com.sequenceiq.freeipa.service.stack.instance.InstanceGroupService) RevokeCertsResponseToDownscaleFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.downscale.failure.RevokeCertsResponseToDownscaleFailureEventConverter) DownscaleStackResultToDownscaleFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.downscale.failure.DownscaleStackResultToDownscaleFailureEventConverter) RemoveServersResponseToDownscaleFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.downscale.failure.RemoveServersResponseToDownscaleFailureEventConverter) StopTelemetryRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.stoptelemetry.StopTelemetryRequest) DOWNSCALE_UPDATE_KERBEROS_NAMESERVERS_CONFIG_FAILED_EVENT(com.sequenceiq.freeipa.flow.freeipa.downscale.DownscaleFlowEvent.DOWNSCALE_UPDATE_KERBEROS_NAMESERVERS_CONFIG_FAILED_EVENT) FAIL_HANDLED_EVENT(com.sequenceiq.freeipa.flow.freeipa.downscale.DownscaleFlowEvent.FAIL_HANDLED_EVENT) UPDATE_METADATA_FINISHED_EVENT(com.sequenceiq.freeipa.flow.freeipa.downscale.DownscaleFlowEvent.UPDATE_METADATA_FINISHED_EVENT) StopTelemetryResponse(com.sequenceiq.freeipa.flow.freeipa.downscale.event.stoptelemetry.StopTelemetryResponse) DownscaleStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackResult) RemoveServersResponse(com.sequenceiq.freeipa.flow.freeipa.downscale.event.removeserver.RemoveServersResponse) UpdateDnsSoaRecordsResponse(com.sequenceiq.freeipa.flow.freeipa.downscale.event.dnssoarecords.UpdateDnsSoaRecordsResponse) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) StateContext(org.springframework.statemachine.StateContext) DownscaleFlowEvent(com.sequenceiq.freeipa.flow.freeipa.downscale.DownscaleFlowEvent) CleanupEvent(com.sequenceiq.freeipa.flow.freeipa.cleanup.CleanupEvent) LinkedList(java.util.LinkedList) RemoveServersRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.removeserver.RemoveServersRequest) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Stack(com.sequenceiq.freeipa.entity.Stack) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) RemoveHostsFromOrchestrationRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.removehosts.RemoveHostsFromOrchestrationRequest) Logger(org.slf4j.Logger) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ClusterProxyUpdateRegistrationSuccess(com.sequenceiq.freeipa.flow.freeipa.provision.event.clusterproxy.ClusterProxyUpdateRegistrationSuccess) DownscaleState(com.sequenceiq.freeipa.flow.freeipa.downscale.DownscaleState) RemoveDnsResponse(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.dns.RemoveDnsResponse) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) DownscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleFailureEvent) TerminationService(com.sequenceiq.freeipa.flow.stack.termination.action.TerminationService) DownscaleEvent(com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleEvent) SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) RemoveHostsResponseToDownscaleFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.downscale.failure.RemoveHostsResponseToDownscaleFailureEventConverter) Bean(org.springframework.context.annotation.Bean) RemoveDnsRequest(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.dns.RemoveDnsRequest) Collections(java.util.Collections) DownscaleStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackRequest) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) ClusterProxyUpdateRegistrationRequest(com.sequenceiq.freeipa.flow.freeipa.provision.event.clusterproxy.ClusterProxyUpdateRegistrationRequest) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) Map(java.util.Map) Stack(com.sequenceiq.freeipa.entity.Stack) Bean(org.springframework.context.annotation.Bean)

Example 44 with StackEvent

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

the class StackProvisionActions method stackCreationFailureAction.

@Bean(name = "STACK_CREATION_FAILED_STATE")
public Action<?, ?> stackCreationFailureAction() {
    return new AbstractStackFailureAction<StackProvisionState, StackProvisionEvent>() {

        @Override
        protected StackFailureContext createFlowContext(FlowParameters flowParameters, StateContext<StackProvisionState, StackProvisionEvent> stateContext, StackFailureEvent payload) {
            Flow flow = getFlow(flowParameters.getFlowId());
            Stack stack = stackService.getStackById(payload.getResourceId());
            MDCBuilder.buildMdcContext(stack);
            flow.setFlowFailed(payload.getException());
            return new StackFailureContext(flowParameters, stack);
        }

        @Override
        protected void doExecute(StackFailureContext context, StackFailureEvent payload, Map<Object, Object> variables) {
            stackProvisionService.handleStackCreationFailure(context.getStack(), payload.getException());
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(StackFailureContext context) {
            return new StackEvent(StackProvisionEvent.STACKCREATION_FAILURE_HANDLED_EVENT.event(), context.getStack().getId());
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractStackFailureAction(com.sequenceiq.freeipa.flow.stack.AbstractStackFailureAction) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) StackFailureEvent(com.sequenceiq.freeipa.flow.stack.StackFailureEvent) StateContext(org.springframework.statemachine.StateContext) StackFailureContext(com.sequenceiq.freeipa.flow.stack.StackFailureContext) Map(java.util.Map) Flow(com.sequenceiq.flow.core.Flow) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.freeipa.entity.Stack) Bean(org.springframework.context.annotation.Bean)

Example 45 with StackEvent

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

the class StackProvisionActions method getTlsInfoAction.

@Bean(name = "GET_TLS_INFO_STATE")
public Action<?, ?> getTlsInfoAction() {
    return new AbstractStackProvisionAction<>(GetTlsInfoResult.class) {

        @Override
        protected void doExecute(StackContext context, GetTlsInfoResult payload, Map<Object, Object> variables) {
            stackProvisionService.saveTlsInfo(context, payload.getTlsInfo());
            sendEvent(context, new StackEvent(StackProvisionEvent.SETUP_TLS_EVENT.event(), context.getStack().getId()));
        }
    };
}
Also used : StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) GetTlsInfoResult(com.sequenceiq.cloudbreak.cloud.event.instance.GetTlsInfoResult) Map(java.util.Map) 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