@Test public void testRelease() { server.setResourceStatus(ResourceStatus.SERVICE_MANAGED); DBStack dbStack = new DBStack(); server.setDbStack(dbStack); when(repository.findByResourceCrn(any())).thenReturn(Optional.of(server)); when(repository.save(server)).thenReturn(server); DatabaseServerConfig releasedServer = underTest.release(SERVER_CRN.toString()); assertEquals(ResourceStatus.USER_MANAGED, releasedServer.getResourceStatus()); assertFalse(releasedServer.getDbStack().isPresent()); verify(dbStackService).delete(dbStack); verify(repository).save(server); }
public DatabaseServerConfig release(String resourceCrn) { try { return transactionService.required(() -> { DatabaseServerConfig resource = getByCrn(resourceCrn); if (!resource.getResourceStatus().isReleasable()) { throw new ConflictException(String.format("Database server configuration has unreleasable resource " + "status %s: releasable statuses are %s", resource.getResourceStatus(), ResourceStatus.getReleasableValues())); } Optional<DBStack> dbStack = resource.getDbStack(); if (dbStack.isPresent()) { dbStackService.delete(dbStack.get()); resource.setDbStack(null); } else { LOGGER.info("Database stack missing for crn: '{}', continuing anyway", resourceCrn); } resource.setResourceStatus(ResourceStatus.USER_MANAGED); return repository.save(resource); }); } catch (TransactionService.TransactionExecutionException e) { throw e.getCause() != null ? e.getCause() : new RedbeamsException("Failed to release management of " + resourceCrn); } }
DatabaseServerConfigService extends AbstractArchivistService<DatabaseServerConfig> implements ResourceBasedCrnProvider { public DatabaseServerConfig release(String resourceCrn) { try { return transactionService.required(() -> { DatabaseServerConfig resource = getByCrn(resourceCrn); if (!resource.getResourceStatus().isReleasable()) { throw new ConflictException(String.format("Database server configuration has unreleasable resource " + "status %s: releasable statuses are %s", resource.getResourceStatus(), ResourceStatus.getReleasableValues())); } Optional<DBStack> dbStack = resource.getDbStack(); if (dbStack.isPresent()) { dbStackService.delete(dbStack.get()); resource.setDbStack(null); } else { LOGGER.info("Database stack missing for crn: '{}', continuing anyway", resourceCrn); } resource.setResourceStatus(ResourceStatus.USER_MANAGED); return repository.save(resource); }); } catch (TransactionService.TransactionExecutionException e) { throw e.getCause() != null ? e.getCause() : new RedbeamsException("Failed to release management of " + resourceCrn); } } }
DatabaseServerConfigService extends AbstractArchivistService<DatabaseServerConfig> implements ResourceBasedCrnProvider { public DatabaseServerConfig release(String resourceCrn) { try { return transactionService.required(() -> { DatabaseServerConfig resource = getByCrn(resourceCrn); if (!resource.getResourceStatus().isReleasable()) { throw new ConflictException(String.format("Database server configuration has unreleasable resource " + "status %s: releasable statuses are %s", resource.getResourceStatus(), ResourceStatus.getReleasableValues())); } Optional<DBStack> dbStack = resource.getDbStack(); if (dbStack.isPresent()) { dbStackService.delete(dbStack.get()); resource.setDbStack(null); } else { LOGGER.info("Database stack missing for crn: '{}', continuing anyway", resourceCrn); } resource.setResourceStatus(ResourceStatus.USER_MANAGED); return repository.save(resource); }); } catch (TransactionService.TransactionExecutionException e) { throw e.getCause() != null ? e.getCause() : new RedbeamsException("Failed to release management of " + resourceCrn); } }  }
DatabaseServerConfigService extends AbstractArchivistService<DatabaseServerConfig> implements ResourceBasedCrnProvider { public DatabaseServerConfig release(String resourceCrn) { try { return transactionService.required(() -> { DatabaseServerConfig resource = getByCrn(resourceCrn); if (!resource.getResourceStatus().isReleasable()) { throw new ConflictException(String.format("Database server configuration has unreleasable resource " + "status %s: releasable statuses are %s", resource.getResourceStatus(), ResourceStatus.getReleasableValues())); } Optional<DBStack> dbStack = resource.getDbStack(); if (dbStack.isPresent()) { dbStackService.delete(dbStack.get()); resource.setDbStack(null); } else { LOGGER.info("Database stack missing for crn: '{}', continuing anyway", resourceCrn); } resource.setResourceStatus(ResourceStatus.USER_MANAGED); return repository.save(resource); }); } catch (TransactionService.TransactionExecutionException e) { throw e.getCause() != null ? e.getCause() : new RedbeamsException("Failed to release management of " + resourceCrn); } }  Set<DatabaseServerConfig> findAll(Long workspaceId, String environmentCrn); DatabaseServerConfig create(DatabaseServerConfig resource, Long workspaceId, boolean test); DatabaseServerConfig update(DatabaseServerConfig resource); DatabaseServerConfig release(String resourceCrn); @Override DatabaseServerConfig delete(DatabaseServerConfig resource); DatabaseServerConfig getByName(Long workspaceId, String environmentCrn, String name); DatabaseServerConfig getByCrn(String resourceCrn); Optional<DatabaseServerConfig> getByCrn(Crn resourceCrn); Optional<DatabaseServerConfig> getByClusterCrn(String clusterCrn); DatabaseServerConfig deleteByCrn(String crn); @Override JpaRepository repository(); Set<DatabaseServerConfig> getByCrns(Set<String> crns); String testConnection(String crn); String testConnection(DatabaseServerConfig resource); String createDatabaseOnServer(String serverCrn, String databaseName, String databaseType, Optional<String> databaseDescription); @Override AuthorizationResourceType getResourceType(); @Override String getResourceCrnByResourceName(String resourceName); @Override List<String> getResourceCrnListByResourceNameList(List<String> resourceNames); @Override List<String> getResourceCrnsInAccount(); }
DatabaseServerConfigService extends AbstractArchivistService<DatabaseServerConfig> implements ResourceBasedCrnProvider { public DatabaseServerConfig release(String resourceCrn) { try { return transactionService.required(() -> { DatabaseServerConfig resource = getByCrn(resourceCrn); if (!resource.getResourceStatus().isReleasable()) { throw new ConflictException(String.format("Database server configuration has unreleasable resource " + "status %s: releasable statuses are %s", resource.getResourceStatus(), ResourceStatus.getReleasableValues())); } Optional<DBStack> dbStack = resource.getDbStack(); if (dbStack.isPresent()) { dbStackService.delete(dbStack.get()); resource.setDbStack(null); } else { LOGGER.info("Database stack missing for crn: '{}', continuing anyway", resourceCrn); } resource.setResourceStatus(ResourceStatus.USER_MANAGED); return repository.save(resource); }); } catch (TransactionService.TransactionExecutionException e) { throw e.getCause() != null ? e.getCause() : new RedbeamsException("Failed to release management of " + resourceCrn); } }  Set<DatabaseServerConfig> findAll(Long workspaceId, String environmentCrn); DatabaseServerConfig create(DatabaseServerConfig resource, Long workspaceId, boolean test); DatabaseServerConfig update(DatabaseServerConfig resource); DatabaseServerConfig release(String resourceCrn); @Override DatabaseServerConfig delete(DatabaseServerConfig resource); DatabaseServerConfig getByName(Long workspaceId, String environmentCrn, String name); DatabaseServerConfig getByCrn(String resourceCrn); Optional<DatabaseServerConfig> getByCrn(Crn resourceCrn); Optional<DatabaseServerConfig> getByClusterCrn(String clusterCrn); DatabaseServerConfig deleteByCrn(String crn); @Override JpaRepository repository(); Set<DatabaseServerConfig> getByCrns(Set<String> crns); String testConnection(String crn); String testConnection(DatabaseServerConfig resource); String createDatabaseOnServer(String serverCrn, String databaseName, String databaseType, Optional<String> databaseDescription); @Override AuthorizationResourceType getResourceType(); @Override String getResourceCrnByResourceName(String resourceName); @Override List<String> getResourceCrnListByResourceNameList(List<String> resourceNames); @Override List<String> getResourceCrnsInAccount();  }