@Test public void testShouldNotLaunchDatabaseServerWhenDatabaseServerConfigIsAvailable() { when(dbStackService.findByNameAndEnvironmentCrn(DB_STACK_NAME, ENVIRONMENT_CRN)).thenReturn(Optional.empty()); when(databaseServerConfigService.getByClusterCrn(CLUSTER_CRN)).thenReturn(Optional.of(databaseServerConfig)); when(databaseServerConfig.getDbStack()).thenReturn(Optional.of(dbStack)); DBStack launchedStack = underTest.launchDatabaseServer(dbStack, CLUSTER_CRN); assertEquals(dbStack, launchedStack); verifyZeroInteractions(flowManager); verifyNoMoreInteractions(databaseServerConfigService); }
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);  }