use of com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StopExternalDatabaseFailed in project cloudbreak by hortonworks.
the class ExternalDatabaseStopActions method externalDatabaseStopFailureAction.
@Bean(name = "EXTERNAL_DATABASE_STOP_FAILED_STATE")
public Action<?, ?> externalDatabaseStopFailureAction() {
return new AbstractExternalDatabaseStopAction<>(StopExternalDatabaseFailed.class) {
@Override
protected void doExecute(ExternalDatabaseContext context, StopExternalDatabaseFailed payload, Map<Object, Object> variables) {
stackUpdaterService.updateStatus(context.getStack().getId(), DetailedStackStatus.EXTERNAL_DATABASE_STOP_FAILED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_STOP_FAILED, payload.getException().getMessage());
getMetricService().incrementMetricCounter(MetricType.EXTERNAL_DATABASE_STOP_FAILED, context.getStack());
sendEvent(context);
}
@Override
protected Selectable createRequest(ExternalDatabaseContext context) {
return new StackEvent(ExternalDatabaseStopEvent.EXTERNAL_DATABASE_STOP_FAILURE_HANDLED_EVENT.event(), context.getStack().getId());
}
@Override
protected void beforeReturnFlowContext(FlowParameters flowParameters, StateContext<ExternalDatabaseStopState, ExternalDatabaseStopEvent> stateContext, StopExternalDatabaseFailed payload) {
Flow flow = getFlow(flowParameters.getFlowId());
flow.setFlowFailed(payload.getException());
super.beforeReturnFlowContext(flowParameters, stateContext, payload);
}
};
}
use of com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StopExternalDatabaseFailed in project cloudbreak by hortonworks.
the class ExternalDatabaseStopActionsTest method externalDatabaseCreationFailureAction.
@Test
void externalDatabaseCreationFailureAction() {
RuntimeException expectedException = new RuntimeException(MESSAGE);
StopExternalDatabaseFailed stopExternalDatabaseFailedPayload = new StopExternalDatabaseFailed(STACK_ID, EXTERNAL_DATABASE_STOP_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(stopExternalDatabaseFailedPayload);
Action<?, ?> action = configureAction(underTest::externalDatabaseStopFailureAction);
action.execute(stateContext);
verify(stackUpdaterService).updateStatus(STACK_ID, DetailedStackStatus.EXTERNAL_DATABASE_STOP_FAILED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_STOP_FAILED, MESSAGE);
verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture());
verify(reactorEventFactory).createEvent(headersArgumentCaptor.capture(), payloadArgumentCaptor.capture());
verify(metricService).incrementMetricCounter(MetricType.EXTERNAL_DATABASE_STOP_FAILED, STACK);
verify(flow).setFlowFailed(exceptionCaptor.capture());
assertThat(selectorArgumentCaptor.getValue()).isEqualTo("EXTERNAL_DATABASE_STOP_FAILURE_HANDLED_EVENT");
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);
}
use of com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StopExternalDatabaseFailed in project cloudbreak by hortonworks.
the class StopExternalDatabaseHandlerTest method acceptCatchErrors.
@ParameterizedTest
@ValueSource(classes = { UserBreakException.class, PollerStoppedException.class, PollerException.class, Exception.class })
@MockitoSettings(strictness = Strictness.LENIENT)
void acceptCatchErrors(Class<? extends Exception> exceptionClass) {
doAnswer(a -> {
throw exceptionClass.getDeclaredConstructor().newInstance();
}).when(stopService).stopDatabase(any(), any(DatabaseAvailabilityType.class), any());
DetailedEnvironmentResponse environment = new DetailedEnvironmentResponse();
environment.setCloudPlatform("AWS");
when(environmentClientService.getByCrn(anyString())).thenReturn(environment);
when(externalDatabaseConfig.isExternalDatabasePauseSupportedFor(any())).thenReturn(true);
Stack stack = buildStack(DatabaseAvailabilityType.HA);
stack.setType(StackType.WORKLOAD);
stack.getCluster().setDatabaseServerCrn(DATABASE_CRN);
when(stackService.getById(anyLong())).thenReturn(stack);
StopExternalDatabaseRequest request = new StopExternalDatabaseRequest(STACK_ID, "selector", "resourceName", "crn");
Event<StopExternalDatabaseRequest> event = new Event<>(EVENT_HEADERS, request);
underTest.accept(event);
verify(stopService).stopDatabase(eq(stack.getCluster()), eq(DatabaseAvailabilityType.HA), eq(environment));
verify(stackUpdaterService).updateStatus(eq(STACK_ID), eq(DetailedStackStatus.EXTERNAL_DATABASE_STOP_IN_PROGRESS), eq(ResourceEvent.CLUSTER_EXTERNAL_DATABASE_STOP_COMMANCED), eq("External database stop in progress"));
verify(stackUpdaterService, never()).updateStatus(eq(STACK_ID), eq(DetailedStackStatus.EXTERNAL_DATABASE_STOP_FINISHED), eq(ResourceEvent.CLUSTER_EXTERNAL_DATABASE_CREATION_FINISHED), anyString());
ArgumentCaptor<Event<StopExternalDatabaseFailed>> eventCaptor = ArgumentCaptor.forClass(Event.class);
verify(eventBus).notify(eq("StopExternalDatabaseFailed"), eventCaptor.capture());
Event<StopExternalDatabaseFailed> value = eventCaptor.getValue();
assertThat(value.getHeaders()).isEqualTo(EVENT_HEADERS);
assertThat(value.getData().getResourceCrn()).isEqualTo(DATABASE_CRN);
}
Aggregations