use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.
the class RedbeamsStopService method stopDatabaseServer.
public void stopDatabaseServer(String crn) {
DBStack dbStack = dbStackService.getByCrn(crn);
MDCBuilder.addEnvironmentCrn(dbStack.getEnvironmentId());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Stop called for: {}", dbStack);
}
if (dbStack.getStatus().isStopInProgressOrCompleted()) {
LOGGER.debug("DatabaseServer with crn {} is already being stopped", dbStack.getResourceCrn());
return;
}
dbStackStatusUpdater.updateStatus(dbStack.getId(), DetailedDBStackStatus.STOP_REQUESTED);
flowManager.notify(RedbeamsStopEvent.REDBEAMS_STOP_EVENT.selector(), new RedbeamsEvent(RedbeamsStopEvent.REDBEAMS_STOP_EVENT.selector(), dbStack.getId()));
}
use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.
the class DatabaseServerConfigTest method testUnsetRelationsToEntitiesToBeDeleted.
@Test
public void testUnsetRelationsToEntitiesToBeDeleted() {
config.setDbStack(new DBStack());
Set<DatabaseConfig> databases = new HashSet<>();
databases.add(new DatabaseConfig());
config.setDatabases(databases);
config.unsetRelationsToEntitiesToBeDeleted();
assertFalse(config.getDbStack().isPresent());
assertTrue(config.getDatabases().isEmpty());
}
use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.
the class AbstractRedbeamsProvisionActionTest method setUp.
@BeforeEach
public void setUp() throws Exception {
dbStack = new DBStack();
dbStack.setId(101L);
dbStack.setResourceCrn(CrnTestUtil.getDatabaseServerCrnBuilder().setAccountId("acc").setResource("resource").build().toString());
dbStack.setName("mystack");
dbStack.setRegion("us-east-1");
dbStack.setAvailabilityZone("us-east-1b");
dbStack.setCloudPlatform("AWS");
dbStack.setPlatformVariant("GovCloud");
dbStack.setEnvironmentId(ENVIRONMENT_CRN);
dbStack.setOwnerCrn(Crn.safeFromString("crn:cdp:iam:us-west-1:cloudera:user:bob@cloudera.com"));
credential = new Credential("userId", null, "userCrn", "account");
cloudCredential = new CloudCredential("userId", "userName", "account");
}
use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.
the class AllocateDatabaseServerV4RequestToDBStackConverter method convert.
public DBStack convert(AllocateDatabaseServerV4Request source, String ownerCrnString) {
Crn ownerCrn = Crn.safeFromString(ownerCrnString);
CrnUser user = crnUserDetailsService.loadUserByUsername(ownerCrnString);
DetailedEnvironmentResponse environment = environmentService.getByCrn(source.getEnvironmentCrn());
DBStack dbStack = new DBStack();
dbStack.setOwnerCrn(ownerCrn);
dbStack.setUserName(user.getEmail());
CloudPlatform cloudPlatform = updateCloudPlatformAndRelatedFields(source, dbStack, environment.getCloudPlatform());
dbStack.setName(source.getName() != null ? source.getName() : generateDatabaseServerStackName(environment.getName()));
dbStack.setEnvironmentId(source.getEnvironmentCrn());
setRegion(dbStack, environment);
if (source.getDatabaseServer() != null) {
dbStack.setDatabaseServer(buildDatabaseServer(source.getDatabaseServer(), cloudPlatform, ownerCrn, environment.getSecurityAccess()));
}
Map<String, Object> asMap = providerParameterCalculator.get(source).asMap();
if (asMap != null) {
Map<String, String> parameter = new HashMap<>();
asMap.forEach((key, value) -> parameter.put(key, value.toString()));
dbStack.setParameters(parameter);
}
dbStack.setNetwork(buildNetwork(source.getNetwork(), environment, cloudPlatform, dbStack));
Instant now = clock.getCurrentInstant();
dbStack.setDBStackStatus(new DBStackStatus(dbStack, DetailedDBStackStatus.PROVISION_REQUESTED, now.toEpochMilli()));
dbStack.setResourceCrn(crnService.createCrn(dbStack).toString());
dbStack.setTags(getTags(dbStack, source, environment));
dbStack.setSslConfig(getSslConfig(source, dbStack));
return dbStack;
}
use of com.sequenceiq.redbeams.domain.stack.DBStack in project cloudbreak by hortonworks.
the class UpdateDatabaseServerRegistrationHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<UpdateDatabaseServerRegistrationRequest> handlerEvent) {
Event<UpdateDatabaseServerRegistrationRequest> event = handlerEvent.getEvent();
LOGGER.debug("Received event: {}", event);
UpdateDatabaseServerRegistrationRequest request = event.getData();
DBStack dbStack = dbStackService.getById(request.getResourceId());
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