Search in sources :

Example 66 with FlowParameters

use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.

the class CheckImageActionTest method testWhenCreateFinishedThenSendEvent.

@Test
void testWhenCreateFinishedThenSendEvent() {
    Stack stack = mock(Stack.class);
    when(stack.getId()).thenReturn(STACK_ID);
    FlowParameters flowParameters = new FlowParameters("flowId", "flowTriggerUserCrn", mock(SpanContext.class));
    when(stackContext.getStack()).thenReturn(stack);
    when(stackContext.getFlowParameters()).thenReturn(flowParameters);
    when(reactorEventFactory.createEvent(any(Map.class), any())).thenReturn(mock(Event.class));
    CheckImageResult checkImageResult = new CheckImageResult(1L, ImageStatus.CREATE_FINISHED, ANY_STATUS_PROGRESS_VALUE);
    when(stackCreationService.checkImage(stackContext)).thenReturn(checkImageResult);
    underTest.doExecute(stackContext, stackEvent, variables);
    verify(eventBus).notify((Object) any(), any(Event.class));
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) SpanContext(io.opentracing.SpanContext) CheckImageResult(com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageResult) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) Event(reactor.bus.Event) HashMap(java.util.HashMap) Map(java.util.Map) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 67 with FlowParameters

use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.

the class ExternalDatabaseStopActionsTest method setup.

@BeforeEach
void setup() {
    STACK.setId(STACK_ID);
    FlowParameters flowParameters = new FlowParameters(FLOW_ID, FLOW_TRIGGER_USER_CRN, null);
    when(stateContext.getMessageHeader(MessageFactory.HEADERS.FLOW_PARAMETERS.name())).thenReturn(flowParameters);
    when(stateContext.getExtendedState()).thenReturn(extendedState);
    when(extendedState.getVariables()).thenReturn(new HashMap<>());
    when(stateContext.getStateMachine()).thenReturn(stateMachine);
    when(stateMachine.getState()).thenReturn(state);
    when(reactorEventFactory.createEvent(anyMap(), isNotNull())).thenReturn(event);
    when(stackService.getByIdWithClusterInTransaction(any())).thenReturn(STACK);
    when(stateContext.getEvent()).thenReturn(flowEvent);
    when(tracer.buildSpan(anyString())).thenReturn(spanBuilder);
    when(spanBuilder.addReference(anyString(), any())).thenReturn(spanBuilder);
    when(spanBuilder.ignoreActiveSpan()).thenReturn(spanBuilder);
    when(spanBuilder.start()).thenReturn(span);
    when(tracer.activateSpan(span)).thenReturn(scope);
    when(span.context()).thenReturn(spanContext);
    when(flowEvent.name()).thenReturn("eventName");
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 68 with FlowParameters

use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.

the class ExternalDatabaseTerminationActionsTest method setup.

@BeforeEach
void setup() {
    STACK.setId(STACK_ID);
    FlowParameters flowParameters = new FlowParameters(FLOW_ID, FLOW_TRIGGER_USER_CRN, null);
    when(stateContext.getMessageHeader(MessageFactory.HEADERS.FLOW_PARAMETERS.name())).thenReturn(flowParameters);
    when(stateContext.getExtendedState()).thenReturn(extendedState);
    when(extendedState.getVariables()).thenReturn(new HashMap<>());
    when(stateContext.getStateMachine()).thenReturn(stateMachine);
    when(stateMachine.getState()).thenReturn(state);
    when(reactorEventFactory.createEvent(anyMap(), isNotNull())).thenReturn(event);
    when(stackService.getByIdWithClusterInTransaction(any())).thenReturn(STACK);
    when(stateContext.getEvent()).thenReturn(flowEvent);
    when(tracer.buildSpan(anyString())).thenReturn(spanBuilder);
    when(spanBuilder.addReference(anyString(), any())).thenReturn(spanBuilder);
    when(spanBuilder.ignoreActiveSpan()).thenReturn(spanBuilder);
    when(spanBuilder.start()).thenReturn(span);
    when(tracer.activateSpan(span)).thenReturn(scope);
    when(span.context()).thenReturn(spanContext);
    when(flowEvent.name()).thenReturn("eventName");
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 69 with FlowParameters

use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.

the class DatalakeRestoreActions method datalakeRestoreInProgress.

@Bean(name = "DATALAKE_DATABASE_RESTORE_IN_PROGRESS_STATE")
public Action<?, ?> datalakeRestoreInProgress() {
    return new AbstractSdxAction<>(SdxEvent.class) {

        @Override
        protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SdxEvent payload) {
            return SdxContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(SdxContext context, SdxEvent payload, Map<Object, Object> variables) {
            LOGGER.info("Datalake database restore is in progress for {} ", payload.getResourceId());
            String operationId = (String) variables.get(OPERATION_ID);
            sdxBackupRestoreService.updateDatabaseStatusEntry(operationId, SdxOperationStatus.INPROGRESS, null);
            SdxCluster sdxCluster = sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.DATALAKE_RESTORE_INPROGRESS, ResourceEvent.DATALAKE_RESTORE_IN_PROGRESS, "Datalake restore in progress", payload.getResourceId());
            eventSenderService.sendEventAndNotification(sdxCluster, context.getFlowTriggerUserCrn(), ResourceEvent.DATALAKE_RESTORE_IN_PROGRESS);
            metricService.incrementMetricCounter(MetricType.SDX_RESTORE_REQUESTED, sdxCluster);
            sendEvent(context, DatalakeDatabaseRestoreWaitRequest.from(context, operationId));
        }

        @Override
        protected Object getFailurePayload(SdxEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return DatalakeDatabaseRestoreFailedEvent.from(payload, ex);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) SdxEvent(com.sequenceiq.datalake.flow.SdxEvent) Map(java.util.Map) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 70 with FlowParameters

use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.

the class DatalakeRestoreActions method restoreFailed.

@Bean(name = "DATALAKE_RESTORE_FAILED_STATE")
public Action<?, ?> restoreFailed() {
    return new AbstractSdxAction<>(DatalakeRestoreFailedEvent.class) {

        @Override
        protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, DatalakeRestoreFailedEvent payload) {
            return SdxContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(SdxContext context, DatalakeRestoreFailedEvent payload, Map<Object, Object> variables) {
            Exception exception = payload.getException();
            LOGGER.error("Datalake database restore could not be started for datalake with id: {}", payload.getResourceId(), exception);
            SdxCluster sdxCluster = sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.RUNNING, ResourceEvent.DATALAKE_RESTORE_FINISHED, "Datalake is running, Datalake restore failed", payload.getResourceId());
            eventSenderService.sendEventAndNotification(sdxCluster, context.getFlowTriggerUserCrn(), ResourceEvent.DATALAKE_RESTORE_FAILED, List.of(exception.getMessage()));
            Flow flow = getFlow(context.getFlowParameters().getFlowId());
            flow.setFlowFailed(payload.getException());
            metricService.incrementMetricCounter(MetricType.SDX_RESTORE_FAILED, sdxCluster);
            sendEvent(context, DATALAKE_RESTORE_FAILURE_HANDLED_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(DatalakeRestoreFailedEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return null;
        }
    };
}
Also used : DatalakeRestoreFailedEvent(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeRestoreFailedEvent) FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Map(java.util.Map) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Flow(com.sequenceiq.flow.core.Flow) Bean(org.springframework.context.annotation.Bean)

Aggregations

FlowParameters (com.sequenceiq.flow.core.FlowParameters)103 Map (java.util.Map)84 StateContext (org.springframework.statemachine.StateContext)84 Bean (org.springframework.context.annotation.Bean)81 Optional (java.util.Optional)67 SdxContext (com.sequenceiq.datalake.flow.SdxContext)56 AbstractSdxAction (com.sequenceiq.datalake.service.AbstractSdxAction)52 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)31 Flow (com.sequenceiq.flow.core.Flow)28 SdxEvent (com.sequenceiq.datalake.flow.SdxEvent)16 Stack (com.sequenceiq.freeipa.entity.Stack)12 List (java.util.List)11 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)10 BeforeEach (org.junit.jupiter.api.BeforeEach)9 Test (org.junit.jupiter.api.Test)9 HashMap (java.util.HashMap)8 PollerStoppedException (com.dyngr.exception.PollerStoppedException)7 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)7 FailureDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails)7 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)7