use of com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent in project cloudbreak by hortonworks.
the class StartDatabaseServerFailedActionTest method shouldCreateRequest.
@Test
public void shouldCreateRequest() {
RedbeamsEvent request = (RedbeamsEvent) victim.createRequest(null);
assertEquals(RedbeamsStartEvent.REDBEAMS_START_FAILURE_HANDLED_EVENT.event(), request.selector());
}
use of com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent in project cloudbreak by hortonworks.
the class StopDatabaseServerActionTest method shouldUpdateStatusOnPrepare.
@Test
public void shouldUpdateStatusOnPrepare() {
RedbeamsEvent event = new RedbeamsEvent(RESOURCE_ID);
victim.prepareExecution(event, null);
verify(dbStackStatusUpdater).updateStatus(RESOURCE_ID, DetailedDBStackStatus.STOP_IN_PROGRESS);
}
use of com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent in project cloudbreak by hortonworks.
the class RedbeamsCreationServiceTest method testLaunchDatabaseServer.
@Test
public void testLaunchDatabaseServer() throws Exception {
when(cloudPlatformConnectors.get(any(CloudPlatformVariant.class))).thenReturn(connector);
when(connector.resources().getDBStackTemplate()).thenReturn(TEMPLATE);
Crn crn = Crn.fromString("crn:cdp:iam:us-west-1:1234:database:2312312");
when(dbStackService.findByNameAndEnvironmentCrn(DB_STACK_NAME, ENVIRONMENT_CRN)).thenReturn(Optional.empty());
when(dbStackService.save(dbStack)).thenReturn(dbStack);
when(databaseServerConfigService.findByEnvironmentCrnAndClusterCrn(ENVIRONMENT_CRN, CLUSTER_CRN)).thenReturn(Optional.empty());
DBStack launchedStack = underTest.launchDatabaseServer(dbStack, CLUSTER_CRN);
assertThat(launchedStack).isEqualTo(dbStack);
verify(dbStackService).save(dbStack);
assertThat(dbStack.getResourceCrn()).isEqualTo(crn.toString());
assertThat(dbStack.getTemplate()).isEqualTo(TEMPLATE);
ArgumentCaptor<DatabaseServerConfig> databaseServerConfigCaptor = ArgumentCaptor.forClass(DatabaseServerConfig.class);
verify(databaseServerConfigService).create(databaseServerConfigCaptor.capture(), eq(RedbeamsCreationService.DEFAULT_WORKSPACE), eq(false));
DatabaseServerConfig databaseServerConfig = databaseServerConfigCaptor.getValue();
assertThat(databaseServerConfig.getResourceStatus()).isEqualTo(ResourceStatus.SERVICE_MANAGED);
assertThat(databaseServerConfig.getAccountId()).isEqualTo(ACCOUNT_ID);
assertThat(databaseServerConfig.getName()).isEqualTo(DB_STACK_NAME);
assertThat(databaseServerConfig.getDescription()).isEqualTo(DB_STACK_DESCRIPTION);
assertThat(databaseServerConfig.getEnvironmentId()).isEqualTo(ENVIRONMENT_CRN);
assertThat(databaseServerConfig.getConnectionDriver()).isEqualTo(CONNECTION_DRIVER);
assertThat(databaseServerConfig.getConnectionUserName()).isEqualTo(ROOT_USER_NAME);
assertThat(databaseServerConfig.getConnectionPassword()).isEqualTo(ROOT_PASSWORD);
assertThat(databaseServerConfig.getDatabaseVendor()).isEqualTo(DatabaseVendor.POSTGRES);
assertThat(databaseServerConfig.getHost()).isNull();
assertThat(databaseServerConfig.getPort()).isNull();
assertThat(databaseServerConfig.getResourceCrn()).isEqualTo(crn);
assertThat(databaseServerConfig.getDbStack().isPresent()).isTrue();
assertThat(databaseServerConfig.getDbStack().get()).isEqualTo(dbStack);
ArgumentCaptor<RedbeamsEvent> eventCaptor = ArgumentCaptor.forClass(RedbeamsEvent.class);
verify(flowManager).notify(eq(RedbeamsProvisionEvent.REDBEAMS_PROVISION_EVENT.selector()), eventCaptor.capture());
RedbeamsEvent provisionEvent = eventCaptor.getValue();
assertThat(provisionEvent.selector()).isEqualTo(RedbeamsProvisionEvent.REDBEAMS_PROVISION_EVENT.selector());
assertThat(provisionEvent.getResourceId()).isEqualTo(dbStack.getId());
}
use of com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent in project cloudbreak by hortonworks.
the class RedbeamsTerminationServiceTest method verifyTermination.
private void verifyTermination(long id) {
verify(dbStackStatusUpdater).updateStatus(id, DetailedDBStackStatus.DELETE_REQUESTED);
ArgumentCaptor<RedbeamsEvent> eventCaptor = ArgumentCaptor.forClass(RedbeamsEvent.class);
InOrder inOrder = Mockito.inOrder(cancelService, flowManager);
inOrder.verify(cancelService).cancelRunningFlows(id);
inOrder.verify(flowManager).notify(eq(RedbeamsTerminationEvent.REDBEAMS_TERMINATION_EVENT.selector()), eventCaptor.capture());
RedbeamsEvent event = eventCaptor.getValue();
assertEquals(id, event.getResourceId().longValue());
assertTrue(event.isForced());
}
use of com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent in project cloudbreak by hortonworks.
the class RedbeamsCreationService method launchDatabaseServer.
public DBStack launchDatabaseServer(DBStack dbStack, String clusterCrn) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Create called with: {}", dbStack);
}
if (dbStackService.findByNameAndEnvironmentCrn(dbStack.getName(), dbStack.getEnvironmentId()).isPresent()) {
throw new BadRequestException("A stack for this database server already exists in the environment");
}
Optional<DatabaseServerConfig> optionalDBServerConfig = databaseServerConfigService.findByEnvironmentCrnAndClusterCrn(dbStack.getEnvironmentId(), clusterCrn);
DBStack savedDbStack;
boolean startFlow = false;
if (optionalDBServerConfig.isEmpty()) {
LOGGER.debug("DataBaseServerConfig is not available by cluster crn '{}'", clusterCrn);
savedDbStack = saveDbStackAndRegisterDatabaseServerConfig(dbStack, clusterCrn);
startFlow = true;
} else {
DatabaseServerConfig dbServerConfig = optionalDBServerConfig.get();
if (dbServerConfig.getDbStack().isEmpty()) {
LOGGER.debug("DBStack is not available in DatabaseServerConfig '{}'", dbServerConfig.getResourceCrn());
savedDbStack = saveDbStackInDatabaseServerConfig(dbServerConfig, dbStack);
startFlow = true;
} else {
savedDbStack = dbServerConfig.getDbStack().get();
}
}
if (startFlow) {
flowManager.notify(RedbeamsProvisionEvent.REDBEAMS_PROVISION_EVENT.selector(), new RedbeamsEvent(RedbeamsProvisionEvent.REDBEAMS_PROVISION_EVENT.selector(), savedDbStack.getId()));
}
return savedDbStack;
}
Aggregations