Search in sources :

Example 61 with BadRequestException

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());
}
Also used : StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 62 with BadRequestException

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());
}
Also used : ClusterTemplateView(com.sequenceiq.cloudbreak.domain.view.ClusterTemplateView) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 63 with BadRequestException

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);
    }
}
Also used : TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) DatabaseConfig(com.sequenceiq.redbeams.domain.DatabaseConfig)

Example 64 with BadRequestException

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);
    }
}
Also used : TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) DatabaseServerConfig(com.sequenceiq.redbeams.domain.DatabaseServerConfig) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn)

Example 65 with BadRequestException

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;
}
Also used : DatabaseServerConfig(com.sequenceiq.redbeams.domain.DatabaseServerConfig) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) RedbeamsEvent(com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsEvent)

Aggregations

BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)298 Test (org.junit.jupiter.api.Test)134 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)45 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)34 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)26 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)23 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)22 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)21 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)21 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)19 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)19 Stack (com.sequenceiq.freeipa.entity.Stack)18 BaseDiagnosticsCollectionRequest (com.sequenceiq.common.api.diagnostics.BaseDiagnosticsCollectionRequest)14 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)14 SdxClusterRequest (com.sequenceiq.sdx.api.model.SdxClusterRequest)14 Set (java.util.Set)14 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)13 NameOrCrn (com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn)12 Json (com.sequenceiq.cloudbreak.common.json.Json)12 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)12