use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.
the class RedbeamsTerminationServiceTest method setup.
@BeforeEach
void setup() {
dbStack = new DBStack();
dbStack.setId(1L);
DBStackStatus dbStackStatus = new DBStackStatus();
dbStack.setDBStackStatus(dbStackStatus);
dbStack.getDbStackStatus().setStatus(Status.AVAILABLE);
dbStack2 = new DBStack();
dbStack2.setId(2L);
dbStackStatus = new DBStackStatus();
dbStack2.setDBStackStatus(dbStackStatus);
dbStack2.getDbStackStatus().setStatus(Status.AVAILABLE);
server = new DatabaseServerConfig();
server.setId(1L);
server.setResourceCrn(SERVER_CRN);
server.setResourceStatus(ResourceStatus.SERVICE_MANAGED);
server2 = new DatabaseServerConfig();
server2.setId(2L);
server2.setResourceCrn(SERVER_2_CRN);
server2.setResourceStatus(ResourceStatus.SERVICE_MANAGED);
}
use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.
the class DeregisterDatabaseServerHandlerTest method testDeleteDatabaseServerConfigIfExists.
@Test
public void testDeleteDatabaseServerConfigIfExists() {
mockDeregisterEvent();
DBStack dbStack = new DBStack();
dbStack.setResourceCrn(RESOURCE_CRN);
when(dbStackService.getById(RESOURCE_ID)).thenReturn(dbStack);
DatabaseServerConfig databaseServerConfig = new DatabaseServerConfig();
when(databaseServerConfigService.getByCrn(any(Crn.class))).thenReturn(Optional.of(databaseServerConfig));
underTest.accept(event);
verify(databaseServerConfigService).delete(databaseServerConfig);
verify(eventBus).notify(any(Object.class), any(Event.class));
}
use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.
the class UpdateDatabaseServerRegistrationHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent handlerEvent) {
Event<UpdateDatabaseServerRegistrationRequest> event = handlerEvent.getEvent();
LOGGER.debug("Received event: {}", event);
UpdateDatabaseServerRegistrationRequest request = event.getData();
DBStack dbStack = request.getDBStack();
List<CloudResource> dbResources = request.getDbResources();
Selectable response;
try {
DatabaseServerConfig dbServerConfig = databaseServerConfigService.getByCrn(Crn.safeFromString(dbStack.getResourceCrn())).orElseThrow(() -> new IllegalStateException("Cannot find database server " + dbStack.getResourceCrn()));
CloudResource dbHostname = cloudResourceHelper.getResourceTypeFromList(ResourceType.RDS_HOSTNAME, dbResources).orElseThrow(() -> new IllegalStateException("DB hostname not found for allocated database."));
CloudResource dbPort = cloudResourceHelper.getResourceTypeFromList(ResourceType.RDS_PORT, dbResources).orElseThrow(() -> new IllegalStateException("DB port not found for allocated database."));
CloudPlatform cloudPlatform = CloudPlatform.valueOf(dbStack.getCloudPlatform());
String dbHostnameString = dbHostname.getName();
dbServerConfig.setHost(dbHostnameString);
dbServerConfig.setPort(Integer.parseInt(dbPort.getName()));
String updatedUserName = userGeneratorService.updateUserName(dbServerConfig.getConnectionUserName(), Optional.of(cloudPlatform), dbHostnameString);
dbServerConfig.setConnectionUserName(updatedUserName);
databaseServerConfigService.update(dbServerConfig);
CloudContext cloudContext = request.getCloudContext();
databaseServerSslCertificateSyncService.syncSslCertificateIfNeeded(cloudContext, request.getCloudCredential(), dbStack, request.getDatabaseStack());
response = new UpdateDatabaseServerRegistrationSuccess(request.getResourceId());
LOGGER.debug("Database server registration update successfully finished for {}", cloudContext);
} catch (Exception e) {
response = new UpdateDatabaseServerRegistrationFailed(request.getResourceId(), e);
LOGGER.warn("Error updating the database server registration:", e);
}
return response;
}
Aggregations