@Test public void testLaunchDatabaseServer() throws Exception { connector = mock(CloudConnector.class, RETURNS_DEEP_STUBS); 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.getByClusterCrn(CLUSTER_CRN)).thenReturn(Optional.empty()); DBStack launchedStack = underTest.launchDatabaseServer(dbStack, CLUSTER_CRN); assertEquals(dbStack, launchedStack); verify(dbStackService).save(dbStack); assertEquals(crn, dbStack.getResourceCrn()); assertEquals(TEMPLATE, dbStack.getTemplate()); ArgumentCaptor<DatabaseServerConfig> databaseServerConfigCaptor = ArgumentCaptor.forClass(DatabaseServerConfig.class); verify(databaseServerConfigService).create(databaseServerConfigCaptor.capture(), eq(RedbeamsCreationService.DEFAULT_WORKSPACE), eq(false)); DatabaseServerConfig databaseServerConfig = databaseServerConfigCaptor.getValue(); assertEquals(ResourceStatus.SERVICE_MANAGED, databaseServerConfig.getResourceStatus()); assertEquals(ACCOUNT_ID, databaseServerConfig.getAccountId()); assertEquals(DB_STACK_NAME, databaseServerConfig.getName()); assertEquals(DB_STACK_DESCRIPTION, databaseServerConfig.getDescription()); assertEquals(ENVIRONMENT_CRN, databaseServerConfig.getEnvironmentId()); assertEquals(CONNECTION_DRIVER, databaseServerConfig.getConnectionDriver()); assertEquals(ROOT_USER_NAME, databaseServerConfig.getConnectionUserName()); assertEquals(ROOT_PASSWORD, databaseServerConfig.getConnectionPassword()); assertEquals(DatabaseVendor.POSTGRES, databaseServerConfig.getDatabaseVendor()); assertNull(databaseServerConfig.getHost()); assertNull(databaseServerConfig.getPort()); assertEquals(crn, databaseServerConfig.getResourceCrn()); assertEquals(dbStack, databaseServerConfig.getDbStack().get()); ArgumentCaptor<RedbeamsEvent> eventCaptor = ArgumentCaptor.forClass(RedbeamsEvent.class); verify(flowManager).notify(eq(RedbeamsProvisionEvent.REDBEAMS_PROVISION_EVENT.selector()), eventCaptor.capture()); RedbeamsEvent provisionEvent = eventCaptor.getValue(); assertEquals(RedbeamsProvisionEvent.REDBEAMS_PROVISION_EVENT.selector(), provisionEvent.selector()); assertEquals(dbStack.getId(), provisionEvent.getResourceId()); }
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.getByClusterCrn(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; }
RedbeamsCreationService { 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.getByClusterCrn(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; } }
RedbeamsCreationService { 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.getByClusterCrn(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; }  }
RedbeamsCreationService { 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.getByClusterCrn(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; }  DBStack launchDatabaseServer(DBStack dbStack, String clusterCrn); }
RedbeamsCreationService { 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.getByClusterCrn(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; }  DBStack launchDatabaseServer(DBStack dbStack, String clusterCrn);  }