use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class UpdateNodeCountValidatorTest method validateClusterStatusDownscaleNodeFailureTargetedUpscaleSupported.
@Test
void validateClusterStatusDownscaleNodeFailureTargetedUpscaleSupported() {
when(targetedUpscaleSupportService.targetedUpscaleEntitlementsEnabled(any())).thenReturn(Boolean.TRUE);
Stack stack = new Stack();
stack.setName("stack");
Cluster cluster = mock(Cluster.class);
stack.setCluster(cluster);
stack.setStackStatus(new StackStatus(stack, DetailedStackStatus.NODE_FAILURE));
BadRequestException e = Assertions.assertThrows(BadRequestException.class, () -> underTest.validateClusterStatus(stack, false));
assertEquals("Data Hub 'stack' is currently in 'NODE_FAILURE' state. Node count can only be updated if it's running.", e.getMessage());
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class ClusterTemplateViewServiceTest method testPrepareCreation.
@Test
public void testPrepareCreation() {
BadRequestException expectedException = assertThrows(BadRequestException.class, () -> underTest.prepareCreation(new ClusterTemplateView()));
assertEquals("Cluster template creation is not supported from ClusterTemplateViewService", expectedException.getMessage());
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class DatabaseConfigService method register.
public DatabaseConfig register(DatabaseConfig configToSave, boolean test) {
if (repository.findByName(configToSave.getName()).isPresent()) {
throw new BadRequestException(String.format("database config already exists with name '%s'", configToSave.getName()));
}
if (configToSave.getConnectionDriver() == null) {
configToSave.setConnectionDriver(configToSave.getDatabaseVendor().connectionDriver());
LOGGER.info("Database configuration lacked a connection driver; defaulting to {}", configToSave.getConnectionDriver());
}
if (test) {
String testResults = testConnection(configToSave);
if (!testResults.equals(DATABASE_TEST_RESULT_SUCCESS)) {
throw new IllegalArgumentException(testResults);
}
}
try {
MDCBuilder.buildMdcContext(configToSave);
// prepareCreation(configToSave);
configToSave.setCreationDate(clock.getCurrentTimeMillis());
Crn crn = crnService.createCrn(configToSave);
configToSave.setResourceCrn(crn);
configToSave.setAccountId(crn.getAccountId());
return transactionService.required(() -> {
DatabaseConfig saved = repository.save(configToSave);
ownerAssignmentService.assignResourceOwnerRoleIfEntitled(ThreadBasedUserCrnProvider.getUserCrn(), saved.getResourceCrn().toString(), ThreadBasedUserCrnProvider.getAccountId());
return saved;
});
} catch (TransactionService.TransactionExecutionException e) {
LOGGER.error("Error happened during database config registration: ", e);
throw new InternalServerErrorException(e);
}
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class DatabaseServerConfigService method create.
public DatabaseServerConfig create(DatabaseServerConfig resource, Long workspaceId, boolean test) {
if (repository.findByName(resource.getName()).isPresent()) {
throw new BadRequestException(String.format("%s already exists with name '%s' in workspace %d", DatabaseServerConfig.class.getSimpleName(), resource.getName(), resource.getWorkspaceId()));
}
if (resource.getConnectionDriver() == null) {
resource.setConnectionDriver(resource.getDatabaseVendor().connectionDriver());
LOGGER.info("Database server configuration lacked a connection driver; defaulting to {}", resource.getConnectionDriver());
}
if (test) {
// FIXME? Currently no checks if logged-in user has access to workspace
// Compare with AbstractWorkspaceAwareResourceService
String testResults = testConnection(resource);
if (!testResults.equals(DATABASE_TEST_RESULT_SUCCESS)) {
throw new IllegalArgumentException(testResults);
}
}
try {
MDCBuilder.buildMdcContext(resource);
// prepareCreation(resource);
resource.setCreationDate(clock.getCurrentTimeMillis());
if (resource.getResourceCrn() == null) {
Crn crn = crnService.createCrn(resource);
resource.setResourceCrn(crn);
resource.setAccountId(crn.getAccountId());
}
resource.setWorkspaceId(workspaceId);
return transactionService.required(() -> {
DatabaseServerConfig saved = repository.save(resource);
ownerAssignmentService.assignResourceOwnerRoleIfEntitled(ThreadBasedUserCrnProvider.getUserCrn(), saved.getResourceCrn().toString(), ThreadBasedUserCrnProvider.getAccountId());
return saved;
});
} catch (TransactionService.TransactionExecutionException e) {
LOGGER.error("Error happened during database server creation: ", e);
throw new InternalServerErrorException(e);
}
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class RedbeamsCreationService method launchDatabaseServer.
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.findByEnvironmentCrnAndClusterCrn(dbStack.getEnvironmentId(), 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;
}
Aggregations