use of com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.CreateExternalDatabaseResult in project cloudbreak by hortonworks.
the class CreateExternalDatabaseHandlerTest method acceptDbNone.
@Test
void acceptDbNone() {
when(stackService.getById(anyLong())).thenReturn(buildStack(DatabaseAvailabilityType.NONE));
CreateExternalDatabaseRequest request = new CreateExternalDatabaseRequest(STACK_ID, "selector", "resourceName", "crn");
Event<CreateExternalDatabaseRequest> event = new Event<>(EVENT_HEADERS, request);
underTest.accept(event);
verifyNoMoreInteractions(provisionService);
verifyNoMoreInteractions(stackUpdaterService);
verifyNoMoreInteractions(environmentValidator);
ArgumentCaptor<Event<CreateExternalDatabaseResult>> eventCaptor = ArgumentCaptor.forClass(Event.class);
verify(eventBus).notify(eq("CreateExternalDatabaseResult"), eventCaptor.capture());
Event<CreateExternalDatabaseResult> value = eventCaptor.getValue();
assertThat(value.getHeaders()).isEqualTo(EVENT_HEADERS);
assertThat(value.getData().getResourceCrn()).isNull();
}
use of com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.CreateExternalDatabaseResult in project cloudbreak by hortonworks.
the class CreateExternalDatabaseHandler method accept.
@Override
public void accept(Event<CreateExternalDatabaseRequest> createExternalDatabaseRequest) {
LOGGER.debug("In CreateExternalDatabaseHandler.accept");
CreateExternalDatabaseRequest request = createExternalDatabaseRequest.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 {
String resourceCrn = null;
if (externalDatabase.isEmbedded()) {
LOGGER.info("External database for stack {} is not requested.", stack.getName());
} else {
LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.EXTERNAL_DATABASE_CREATION_IN_PROGRESS.name());
stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.EXTERNAL_DATABASE_CREATION_IN_PROGRESS, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_CREATION_STARTED, "External database creation in progress");
LOGGER.debug("Getting environment CRN for stack {}", stack.getName());
DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn());
environmentValidator.checkValidEnvironment(stack.getName(), externalDatabase, environment);
provisionService.provisionDatabase(stack.getCluster(), externalDatabase, environment);
LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.PROVISION_REQUESTED.name());
stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.PROVISION_REQUESTED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_CREATION_FINISHED, "External database creation finished");
resourceCrn = stack.getCluster().getDatabaseServerCrn();
}
result = new CreateExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_WAIT_SUCCESS_EVENT.event(), stack.getName(), resourceCrn);
} catch (UserBreakException e) {
LOGGER.info("Database polling exited before timeout. Cause: ", e);
result = createFailedEvent(stack, e);
} catch (PollerStoppedException e) {
LOGGER.info(String.format("Database poller stopped for stack: %s", stack.getName()), e);
result = createFailedEvent(stack, e);
} catch (PollerException e) {
LOGGER.info(String.format("Database polling failed for stack: %s", stack.getName()), e);
result = createFailedEvent(stack, e);
} catch (Exception e) {
LOGGER.error(String.format("Exception during DB creation for stack/cluster: %s", stack.getName()), e);
result = createFailedEvent(stack, e);
}
LOGGER.debug("Sending reactor notification for selector {}", result.selector());
eventBus.notify(result.selector(), new Event<>(createExternalDatabaseRequest.getHeaders(), result));
}
use of com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.CreateExternalDatabaseResult in project cloudbreak by hortonworks.
the class ExternalDatabaseCreationActionsTest method externalDatabaseCreationFinishedAction.
@Test
void externalDatabaseCreationFinishedAction() {
CreateExternalDatabaseResult createExternalDatabaseResultPayload = new CreateExternalDatabaseResult(STACK_ID, EXTERNAL_DATABASE_WAIT_SUCCESS_EVENT.event(), STACK_NAME, STACK_CRN);
when(stateContext.getMessageHeader(MessageFactory.HEADERS.DATA.name())).thenReturn(createExternalDatabaseResultPayload);
Action<?, ?> action = configureAction(underTest::externalDatabaseCreationFinishedAction);
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_CREATION_SUCCESSFUL, STACK);
assertThat(selectorArgumentCaptor.getValue()).isEqualTo("EXTERNAL_DATABASE_CREATION_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.CreateExternalDatabaseResult in project cloudbreak by hortonworks.
the class CreateExternalDatabaseHandlerTest method accept.
@Test
void accept() {
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(provisionService).provisionDatabase(any(), any(), any());
when(stackService.getById(anyLong())).thenReturn(buildStack(DatabaseAvailabilityType.HA));
CreateExternalDatabaseRequest request = new CreateExternalDatabaseRequest(STACK_ID, "selector", "resourceName", "crn");
Event<CreateExternalDatabaseRequest> event = new Event<>(EVENT_HEADERS, request);
underTest.accept(event);
verify(provisionService).provisionDatabase(any(), eq(DatabaseAvailabilityType.HA), eq(environment));
verify(environmentValidator).checkValidEnvironment(eq(STACK_NAME), eq(DatabaseAvailabilityType.HA), eq(environment));
verify(stackUpdaterService).updateStatus(eq(STACK_ID), eq(DetailedStackStatus.EXTERNAL_DATABASE_CREATION_IN_PROGRESS), eq(ResourceEvent.CLUSTER_EXTERNAL_DATABASE_CREATION_STARTED), eq("External database creation in progress"));
verify(stackUpdaterService).updateStatus(eq(STACK_ID), eq(DetailedStackStatus.PROVISION_REQUESTED), eq(ResourceEvent.CLUSTER_EXTERNAL_DATABASE_CREATION_FINISHED), eq("External database creation finished"));
ArgumentCaptor<Event<CreateExternalDatabaseResult>> eventCaptor = ArgumentCaptor.forClass(Event.class);
verify(eventBus).notify(eq("CreateExternalDatabaseResult"), eventCaptor.capture());
Event<CreateExternalDatabaseResult> value = eventCaptor.getValue();
assertThat(value.getHeaders()).isEqualTo(EVENT_HEADERS);
assertThat(value.getData().getResourceCrn()).isEqualTo(DATABASE_CRN);
}
Aggregations