Search in sources :

Example 1 with HealthCheckSuccess

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

the class ChangePrimaryGatewayActions method healthCheckAction.

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

        @Override
        protected void doExecute(ChangePrimaryGatewayContext context, StackEvent payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            Selectable request;
            if (isFinalChain(variables)) {
                stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.REPAIR_IN_PROGRESS, "Checking the health");
                request = new HealthCheckRequest(stack.getId(), false);
            } else {
                LOGGER.debug("Repair in progress, skipping the health check");
                request = new HealthCheckSuccess(stack.getId(), null);
            }
            sendEvent(context, request.selector(), request);
        }
    };
}
Also used : StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) HealthCheckSuccess(com.sequenceiq.freeipa.flow.stack.HealthCheckSuccess) ChangePrimaryGatewayContext(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.ChangePrimaryGatewayContext) HealthCheckRequest(com.sequenceiq.freeipa.flow.stack.HealthCheckRequest) Map(java.util.Map) Stack(com.sequenceiq.freeipa.entity.Stack) Bean(org.springframework.context.annotation.Bean)

Example 2 with HealthCheckSuccess

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

the class RebootActions method rebootFinishedAction.

@Bean(name = "REBOOT_FINISHED_STATE")
public Action<?, ?> rebootFinishedAction() {
    return new AbstractRebootAction<>(HealthCheckSuccess.class) {

        @Inject
        private OperationService operationService;

        @Override
        protected void doExecute(RebootContext context, HealthCheckSuccess payload, Map<Object, Object> variables) {
            addMdcOperationId(variables);
            rebootService.finishInstanceReboot(context);
            LOGGER.info("Finished rebooting {}.", context.getInstanceIds());
            Stack stack = context.getStack();
            SuccessDetails successDetails = new SuccessDetails(stack.getEnvironmentCrn());
            successDetails.getAdditionalDetails().put("InstanceIds", context.getInstanceIdList());
            operationService.completeOperation(stack.getAccountId(), getOperationId(variables), List.of(successDetails), Collections.emptyList());
            sendEvent(context);
        }

        @Override
        protected Object getFailurePayload(HealthCheckSuccess payload, Optional<RebootContext> flowContext, Exception ex) {
            return new InstanceFailureEvent(payload.getResourceId(), ex, payload.getInstanceIds());
        }

        @Override
        protected Selectable createRequest(RebootContext context) {
            return new InstanceEvent(RebootEvent.REBOOT_FINALIZED_EVENT.event(), context.getStack().getId(), context.getInstanceIdList());
        }

        @Override
        protected RebootContext createFlowContext(FlowParameters flowParameters, StateContext<RebootState, RebootEvent> stateContext, HealthCheckSuccess payload) {
            Long stackId = payload.getResourceId();
            Stack stack = stackService.getByIdWithListsInTransaction(stackId);
            MDCBuilder.buildMdcContext(stack);
            List<InstanceMetaData> instances = instanceMetaDataService.findNotTerminatedForStack(stackId).stream().filter(instanceMetaData -> payload.getInstanceIds().contains(instanceMetaData.getInstanceId())).collect(Collectors.toList());
            return new RebootContext(flowParameters, stack, instances, null, null);
        }
    };
}
Also used : Action(org.springframework.statemachine.action.Action) InstanceMetaDataToCloudInstanceConverter(com.sequenceiq.freeipa.converter.cloud.InstanceMetaDataToCloudInstanceConverter) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) RebootInstancesRequest(com.sequenceiq.cloudbreak.cloud.event.instance.RebootInstancesRequest) LoggerFactory(org.slf4j.LoggerFactory) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) RebootInstanceEvent(com.sequenceiq.freeipa.flow.instance.reboot.RebootInstanceEvent) ResourceToCloudResourceConverter(com.sequenceiq.freeipa.converter.cloud.ResourceToCloudResourceConverter) InstanceEvent(com.sequenceiq.freeipa.flow.instance.InstanceEvent) Inject(javax.inject.Inject) HealthCheckRequest(com.sequenceiq.freeipa.flow.stack.HealthCheckRequest) StateContext(org.springframework.statemachine.StateContext) Credential(com.sequenceiq.freeipa.dto.Credential) ResourceService(com.sequenceiq.freeipa.service.resource.ResourceService) InstanceFailureEvent(com.sequenceiq.freeipa.flow.instance.InstanceFailureEvent) Map(java.util.Map) Resource(com.sequenceiq.freeipa.entity.Resource) StackService(com.sequenceiq.freeipa.service.stack.StackService) RebootEvent(com.sequenceiq.freeipa.flow.instance.reboot.RebootEvent) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Stack(com.sequenceiq.freeipa.entity.Stack) RebootInstancesResultToCleanupFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.failure.RebootInstancesResultToCleanupFailureEventConverter) RebootState(com.sequenceiq.freeipa.flow.instance.reboot.RebootState) PayloadConverter(com.sequenceiq.flow.core.PayloadConverter) InstanceMetaDataService(com.sequenceiq.freeipa.service.stack.instance.InstanceMetaDataService) Logger(org.slf4j.Logger) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) FailureDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails) FlowParameters(com.sequenceiq.flow.core.FlowParameters) CredentialToCloudCredentialConverter(com.sequenceiq.freeipa.converter.cloud.CredentialToCloudCredentialConverter) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Collectors(java.util.stream.Collectors) HealthCheckSuccess(com.sequenceiq.freeipa.flow.stack.HealthCheckSuccess) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) RebootContext(com.sequenceiq.freeipa.flow.instance.reboot.RebootContext) RebootService(com.sequenceiq.freeipa.flow.instance.reboot.RebootService) RebootInstancesResult(com.sequenceiq.cloudbreak.cloud.event.instance.RebootInstancesResult) WaitUntilAvailableFailedToInstanceFailureEventConverter(com.sequenceiq.freeipa.flow.instance.reboot.failure.WaitUntilAvailableFailedToInstanceFailureEventConverter) Optional(java.util.Optional) SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) Bean(org.springframework.context.annotation.Bean) Collections(java.util.Collections) CredentialService(com.sequenceiq.freeipa.service.CredentialService) SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) InstanceFailureEvent(com.sequenceiq.freeipa.flow.instance.InstanceFailureEvent) Optional(java.util.Optional) HealthCheckSuccess(com.sequenceiq.freeipa.flow.stack.HealthCheckSuccess) StateContext(org.springframework.statemachine.StateContext) Stack(com.sequenceiq.freeipa.entity.Stack) RebootInstanceEvent(com.sequenceiq.freeipa.flow.instance.reboot.RebootInstanceEvent) InstanceEvent(com.sequenceiq.freeipa.flow.instance.InstanceEvent) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) FlowParameters(com.sequenceiq.flow.core.FlowParameters) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) RebootContext(com.sequenceiq.freeipa.flow.instance.reboot.RebootContext) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Aggregations

Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)2 Stack (com.sequenceiq.freeipa.entity.Stack)2 HealthCheckRequest (com.sequenceiq.freeipa.flow.stack.HealthCheckRequest)2 HealthCheckSuccess (com.sequenceiq.freeipa.flow.stack.HealthCheckSuccess)2 Map (java.util.Map)2 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 RebootInstancesRequest (com.sequenceiq.cloudbreak.cloud.event.instance.RebootInstancesRequest)1 RebootInstancesResult (com.sequenceiq.cloudbreak.cloud.event.instance.RebootInstancesResult)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 MDCBuilder (com.sequenceiq.cloudbreak.logger.MDCBuilder)1 FlowParameters (com.sequenceiq.flow.core.FlowParameters)1 PayloadConverter (com.sequenceiq.flow.core.PayloadConverter)1 FailureDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails)1 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)1 CredentialToCloudCredentialConverter (com.sequenceiq.freeipa.converter.cloud.CredentialToCloudCredentialConverter)1 InstanceMetaDataToCloudInstanceConverter (com.sequenceiq.freeipa.converter.cloud.InstanceMetaDataToCloudInstanceConverter)1 ResourceToCloudResourceConverter (com.sequenceiq.freeipa.converter.cloud.ResourceToCloudResourceConverter)1 Credential (com.sequenceiq.freeipa.dto.Credential)1