@Test void externalDatabaseCreationFailureAction() { RuntimeException expectedException = new RuntimeException(MESSAGE); CreateExternalDatabaseFailed createExternalDatabaseFailedPayload = new CreateExternalDatabaseFailed(STACK_ID, EXTERNAL_DATABASE_CREATION_FAILED_EVENT.event(), STACK_NAME, null, expectedException); when(stackService.getByIdWithClusterInTransaction(any())).thenReturn(STACK); when(runningFlows.get(anyString())).thenReturn(flow); when(stateContext.getMessageHeader(MessageFactory.HEADERS.DATA.name())).thenReturn(createExternalDatabaseFailedPayload); Action<?, ?> action = configureAction(underTest::externalDatabaseCreationFailureAction); action.execute(stateContext); verify(stackUpdaterService).updateStatus(STACK_ID, DetailedStackStatus.EXTERNAL_DATABASE_CREATION_FAILED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_CREATION_FAILED, MESSAGE); verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture()); verify(reactorEventFactory).createEvent(headersArgumentCaptor.capture(), payloadArgumentCaptor.capture()); verify(metricService).incrementMetricCounter(MetricType.EXTERNAL_DATABASE_CREATION_FAILED, STACK); verify(flow).setFlowFailed(exceptionCaptor.capture()); assertThat(selectorArgumentCaptor.getValue()).isEqualTo("STACK_CREATION_FAILHANDLED"); Object capturedPayload = payloadArgumentCaptor.getValue(); assertThat(capturedPayload).isInstanceOf(StackEvent.class); StackEvent stackEvent = (StackEvent) capturedPayload; assertThat(stackEvent.getResourceId()).isEqualTo(STACK_ID); Exception exception = exceptionCaptor.getValue(); assertThat(exception).isEqualTo(expectedException); }
@Bean(name = "EXTERNAL_DATABASE_CREATION_FAILED_STATE") public Action<?, ?> externalDatabaseCreationFailureAction() { return new AbstractExternalDatabaseCreationAction<>(CreateExternalDatabaseFailed.class) { @Override protected void doExecute(ExternalDatabaseContext context, CreateExternalDatabaseFailed payload, Map<Object, Object> variables) { stackUpdaterService.updateStatus(context.getStack().getId(), DetailedStackStatus.EXTERNAL_DATABASE_CREATION_FAILED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_CREATION_FAILED, payload.getException().getMessage()); getMetricService().incrementMetricCounter(MetricType.EXTERNAL_DATABASE_CREATION_FAILED, context.getStack()); sendEvent(context); } @Override protected Selectable createRequest(ExternalDatabaseContext context) { return new StackEvent(StackCreationEvent.STACKCREATION_FAILURE_HANDLED_EVENT.event(), context.getStack().getId()); } @Override protected void beforeReturnFlowContext(FlowParameters flowParameters, StateContext<ExternalDatabaseCreationState, ExternalDatabaseCreationEvent> stateContext, CreateExternalDatabaseFailed payload) { Flow flow = getFlow(flowParameters.getFlowId()); flow.setFlowFailed(payload.getException()); super.beforeReturnFlowContext(flowParameters, stateContext, payload); } }; }
ExternalDatabaseCreationActions { @Bean(name = "EXTERNAL_DATABASE_CREATION_FAILED_STATE") public Action<?, ?> externalDatabaseCreationFailureAction() { return new AbstractExternalDatabaseCreationAction<>(CreateExternalDatabaseFailed.class) { @Override protected void doExecute(ExternalDatabaseContext context, CreateExternalDatabaseFailed payload, Map<Object, Object> variables) { stackUpdaterService.updateStatus(context.getStack().getId(), DetailedStackStatus.EXTERNAL_DATABASE_CREATION_FAILED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_CREATION_FAILED, payload.getException().getMessage()); getMetricService().incrementMetricCounter(MetricType.EXTERNAL_DATABASE_CREATION_FAILED, context.getStack()); sendEvent(context); } @Override protected Selectable createRequest(ExternalDatabaseContext context) { return new StackEvent(StackCreationEvent.STACKCREATION_FAILURE_HANDLED_EVENT.event(), context.getStack().getId()); } @Override protected void beforeReturnFlowContext(FlowParameters flowParameters, StateContext<ExternalDatabaseCreationState, ExternalDatabaseCreationEvent> stateContext, CreateExternalDatabaseFailed payload) { Flow flow = getFlow(flowParameters.getFlowId()); flow.setFlowFailed(payload.getException()); super.beforeReturnFlowContext(flowParameters, stateContext, payload); } }; } }
ExternalDatabaseCreationActions { @Bean(name = "EXTERNAL_DATABASE_CREATION_FAILED_STATE") public Action<?, ?> externalDatabaseCreationFailureAction() { return new AbstractExternalDatabaseCreationAction<>(CreateExternalDatabaseFailed.class) { @Override protected void doExecute(ExternalDatabaseContext context, CreateExternalDatabaseFailed payload, Map<Object, Object> variables) { stackUpdaterService.updateStatus(context.getStack().getId(), DetailedStackStatus.EXTERNAL_DATABASE_CREATION_FAILED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_CREATION_FAILED, payload.getException().getMessage()); getMetricService().incrementMetricCounter(MetricType.EXTERNAL_DATABASE_CREATION_FAILED, context.getStack()); sendEvent(context); } @Override protected Selectable createRequest(ExternalDatabaseContext context) { return new StackEvent(StackCreationEvent.STACKCREATION_FAILURE_HANDLED_EVENT.event(), context.getStack().getId()); } @Override protected void beforeReturnFlowContext(FlowParameters flowParameters, StateContext<ExternalDatabaseCreationState, ExternalDatabaseCreationEvent> stateContext, CreateExternalDatabaseFailed payload) { Flow flow = getFlow(flowParameters.getFlowId()); flow.setFlowFailed(payload.getException()); super.beforeReturnFlowContext(flowParameters, stateContext, payload); } }; }  }
ExternalDatabaseCreationActions { @Bean(name = "EXTERNAL_DATABASE_CREATION_FAILED_STATE") public Action<?, ?> externalDatabaseCreationFailureAction() { return new AbstractExternalDatabaseCreationAction<>(CreateExternalDatabaseFailed.class) { @Override protected void doExecute(ExternalDatabaseContext context, CreateExternalDatabaseFailed payload, Map<Object, Object> variables) { stackUpdaterService.updateStatus(context.getStack().getId(), DetailedStackStatus.EXTERNAL_DATABASE_CREATION_FAILED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_CREATION_FAILED, payload.getException().getMessage()); getMetricService().incrementMetricCounter(MetricType.EXTERNAL_DATABASE_CREATION_FAILED, context.getStack()); sendEvent(context); } @Override protected Selectable createRequest(ExternalDatabaseContext context) { return new StackEvent(StackCreationEvent.STACKCREATION_FAILURE_HANDLED_EVENT.event(), context.getStack().getId()); } @Override protected void beforeReturnFlowContext(FlowParameters flowParameters, StateContext<ExternalDatabaseCreationState, ExternalDatabaseCreationEvent> stateContext, CreateExternalDatabaseFailed payload) { Flow flow = getFlow(flowParameters.getFlowId()); flow.setFlowFailed(payload.getException()); super.beforeReturnFlowContext(flowParameters, stateContext, payload); } }; }  @Bean(name = "WAIT_FOR_EXTERNAL_DATABASE_STATE") Action<?, ?> externalDatabaseCreation(); @Bean(name = "EXTERNAL_DATABASE_CREATION_FINISHED_STATE") Action<?, ?> externalDatabaseCreationFinishedAction(); @Bean(name = "EXTERNAL_DATABASE_CREATION_FAILED_STATE") Action<?, ?> externalDatabaseCreationFailureAction(); }
ExternalDatabaseCreationActions { @Bean(name = "EXTERNAL_DATABASE_CREATION_FAILED_STATE") public Action<?, ?> externalDatabaseCreationFailureAction() { return new AbstractExternalDatabaseCreationAction<>(CreateExternalDatabaseFailed.class) { @Override protected void doExecute(ExternalDatabaseContext context, CreateExternalDatabaseFailed payload, Map<Object, Object> variables) { stackUpdaterService.updateStatus(context.getStack().getId(), DetailedStackStatus.EXTERNAL_DATABASE_CREATION_FAILED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_CREATION_FAILED, payload.getException().getMessage()); getMetricService().incrementMetricCounter(MetricType.EXTERNAL_DATABASE_CREATION_FAILED, context.getStack()); sendEvent(context); } @Override protected Selectable createRequest(ExternalDatabaseContext context) { return new StackEvent(StackCreationEvent.STACKCREATION_FAILURE_HANDLED_EVENT.event(), context.getStack().getId()); } @Override protected void beforeReturnFlowContext(FlowParameters flowParameters, StateContext<ExternalDatabaseCreationState, ExternalDatabaseCreationEvent> stateContext, CreateExternalDatabaseFailed payload) { Flow flow = getFlow(flowParameters.getFlowId()); flow.setFlowFailed(payload.getException()); super.beforeReturnFlowContext(flowParameters, stateContext, payload); } }; }  @Bean(name = "WAIT_FOR_EXTERNAL_DATABASE_STATE") Action<?, ?> externalDatabaseCreation(); @Bean(name = "EXTERNAL_DATABASE_CREATION_FINISHED_STATE") Action<?, ?> externalDatabaseCreationFinishedAction(); @Bean(name = "EXTERNAL_DATABASE_CREATION_FAILED_STATE") Action<?, ?> externalDatabaseCreationFailureAction();  }