use of com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.TerminateExternalDatabaseResult in project cloudbreak by hortonworks.
the class ExternalDatabaseTerminationActionsTest method externalDatabaseCreationFinishedAction.
@Test
void externalDatabaseCreationFinishedAction() {
TerminateExternalDatabaseResult terminateExternalDatabaseResultPayload = new TerminateExternalDatabaseResult(STACK_ID, EXTERNAL_DATABASE_WAIT_SUCCESS_EVENT.event(), STACK_NAME, STACK_CRN);
when(stateContext.getMessageHeader(MessageFactory.HEADERS.DATA.name())).thenReturn(terminateExternalDatabaseResultPayload);
Action<?, ?> action = configureAction(underTest::externalDatabaseTerminationFinishedAction);
action.execute(stateContext);
verifyNoMoreInteractions(stackUpdaterService);
verify(eventBus).notify(selectorArgumentCaptor.capture(), eventArgumentCaptor.capture());
verify(reactorEventFactory).createEvent(headersArgumentCaptor.capture(), payloadArgumentCaptor.capture());
verify(metricService).incrementMetricCounter(MetricType.EXTERNAL_DATABASE_TERMINATION_SUCCESSFUL, STACK);
assertThat(selectorArgumentCaptor.getValue()).isEqualTo("EXTERNAL_DATABASE_TERMINATION_FINISHED_EVENT");
Object capturedPayload = payloadArgumentCaptor.getValue();
assertThat(capturedPayload).isInstanceOf(StackEvent.class);
StackEvent stackEvent = (StackEvent) capturedPayload;
assertThat(stackEvent.getResourceId()).isEqualTo(STACK_ID);
}
use of com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.TerminateExternalDatabaseResult in project cloudbreak by hortonworks.
the class TerminateExternalDatabaseHandlerTest method accept.
@ParameterizedTest
@ValueSource(booleans = { false, true })
void accept(boolean needHA) {
DetailedEnvironmentResponse environment = new DetailedEnvironmentResponse();
environment.setCloudPlatform("cloudplatform");
when(environmentClientService.getByCrn(anyString())).thenReturn(environment);
doAnswer(a -> {
Cluster cluster = a.getArgument(0);
cluster.setDatabaseServerCrn(DATABASE_CRN);
return null;
}).when(terminationService).terminateDatabase(any(), any(), any(), anyBoolean());
when(stackService.getById(anyLong())).thenReturn(buildStack(DatabaseAvailabilityType.HA));
TerminateExternalDatabaseRequest request = new TerminateExternalDatabaseRequest(STACK_ID, "selector", "resourceName", "crn", needHA);
Event<TerminateExternalDatabaseRequest> event = new Event<>(EVENT_HEADERS, request);
underTest.accept(event);
verify(terminationService).terminateDatabase(any(), eq(DatabaseAvailabilityType.HA), eq(environment), eq(needHA));
verify(stackUpdaterService).updateStatus(eq(STACK_ID), eq(DetailedStackStatus.EXTERNAL_DATABASE_DELETION_IN_PROGRESS), eq(ResourceEvent.CLUSTER_EXTERNAL_DATABASE_DELETION_STARTED), eq("External database deletion in progress"));
verify(stackUpdaterService).updateStatus(eq(STACK_ID), eq(DetailedStackStatus.AVAILABLE), eq(ResourceEvent.CLUSTER_EXTERNAL_DATABASE_DELETION_FINISHED), eq("External database deletion finished"));
ArgumentCaptor<Event<TerminateExternalDatabaseResult>> eventCaptor = ArgumentCaptor.forClass(Event.class);
verify(eventBus).notify(eq("TerminateExternalDatabaseResult"), eventCaptor.capture());
Event<TerminateExternalDatabaseResult> value = eventCaptor.getValue();
assertThat(value.getHeaders()).isEqualTo(EVENT_HEADERS);
assertThat(value.getData().getResourceCrn()).isEqualTo(DATABASE_CRN);
}
use of com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.TerminateExternalDatabaseResult in project cloudbreak by hortonworks.
the class TerminateExternalDatabaseHandler method accept.
@Override
public void accept(Event<TerminateExternalDatabaseRequest> terminateExternalDatabaseRequest) {
LOGGER.debug("In TerminateExternalDatabaseHandler.accept");
TerminateExternalDatabaseRequest request = terminateExternalDatabaseRequest.getData();
Stack stack = stackService.getById(request.getResourceId());
DatabaseAvailabilityType externalDatabase = ObjectUtils.defaultIfNull(stack.getExternalDatabaseCreationType(), DatabaseAvailabilityType.NONE);
LOGGER.debug("External database: {} for stack {}", externalDatabase.name(), stack.getName());
Selectable result;
try {
if (externalDatabase.isEmbedded()) {
LOGGER.info("External database for stack {} is not requested. Termination is not necessary.", stack.getName());
result = new TerminateExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_WAIT_TERMINATION_SUCCESS_EVENT.event(), stack.getName(), null);
} else {
LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.EXTERNAL_DATABASE_DELETION_IN_PROGRESS.name());
stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.EXTERNAL_DATABASE_DELETION_IN_PROGRESS, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_DELETION_STARTED, "External database deletion in progress");
LOGGER.debug("Getting environment CRN for stack {}", stack.getName());
DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn());
terminationService.terminateDatabase(stack.getCluster(), externalDatabase, environment, request.isForced());
LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.AVAILABLE.name());
stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.AVAILABLE, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_DELETION_FINISHED, "External database deletion finished");
result = new TerminateExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_WAIT_TERMINATION_SUCCESS_EVENT.event(), stack.getName(), stack.getCluster().getDatabaseServerCrn());
}
} catch (UserBreakException e) {
LOGGER.info("Database termination polling exited before timeout. Cause: ", e);
result = terminateFailedEvent(stack, e);
} catch (PollerStoppedException e) {
LOGGER.info(String.format("Database termination poller stopped for stack: %s", stack.getName()), e);
result = terminateFailedEvent(stack, e);
} catch (PollerException e) {
LOGGER.info(String.format("Database termination polling failed for stack: %s", stack.getName()), e);
result = terminateFailedEvent(stack, e);
} catch (Exception e) {
LOGGER.error(String.format("Exception during DB termination for stack/cluster: %s", stack.getName()), e);
result = terminateFailedEvent(stack, e);
}
LOGGER.debug("Sending reactor notification for selector {}", result.selector());
eventBus.notify(result.selector(), new Event<>(terminateExternalDatabaseRequest.getHeaders(), result));
}
use of com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.TerminateExternalDatabaseResult in project cloudbreak by hortonworks.
the class TerminateExternalDatabaseHandlerTest method acceptDbNone.
@Test
void acceptDbNone() {
when(stackService.getById(anyLong())).thenReturn(buildStack(DatabaseAvailabilityType.NONE));
TerminateExternalDatabaseRequest request = new TerminateExternalDatabaseRequest(STACK_ID, "selector", "resourceName", "crn", false);
Event<TerminateExternalDatabaseRequest> event = new Event<>(EVENT_HEADERS, request);
underTest.accept(event);
verifyNoMoreInteractions(terminationService);
verifyNoMoreInteractions(stackUpdaterService);
ArgumentCaptor<Event<TerminateExternalDatabaseResult>> eventCaptor = ArgumentCaptor.forClass(Event.class);
verify(eventBus).notify(eq("TerminateExternalDatabaseResult"), eventCaptor.capture());
Event<TerminateExternalDatabaseResult> value = eventCaptor.getValue();
assertThat(value.getHeaders()).isEqualTo(EVENT_HEADERS);
assertThat(value.getData().getResourceCrn()).isNull();
}
Aggregations