Search in sources :

Example 16 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.

the class ClusterOperationService method create.

@Measure(ClusterOperationService.class)
public Cluster create(Stack stack, Cluster cluster, List<ClusterComponent> components, User user) throws TransactionService.TransactionExecutionException {
    LOGGER.debug("Cluster requested [BlueprintId: {}]", cluster.getBlueprint().getId());
    String stackName = stack.getName();
    if (stack.getCluster() != null) {
        throw new BadRequestException(String.format("A cluster is already created on this stack! [cluster: '%s']", stack.getCluster().getName()));
    }
    long start = System.currentTimeMillis();
    return transactionService.required(() -> {
        setWorkspace(cluster, stack.getWorkspace());
        cluster.setEnvironmentCrn(stack.getEnvironmentCrn());
        if (Status.CREATE_FAILED.equals(stack.getStatus())) {
            throw new BadRequestException("Stack creation failed, cannot create cluster.");
        }
        if (cluster.getFileSystem() != null) {
            cluster.setFileSystem(fileSystemConfigService.createWithMdcContextRestore(cluster.getFileSystem(), cluster.getWorkspace(), user));
        }
        removeGatewayIfNotSupported(cluster, components);
        cluster.setStack(stack);
        stack.setCluster(cluster);
        Cluster savedCluster = measure(() -> clusterService.saveClusterAndComponent(cluster, components, stackName), LOGGER, "saveClusterAndComponent {} ms");
        measure(() -> usageLoggingUtil.logClusterRequestedUsageEvent(cluster), LOGGER, "logClusterRequestedUsageEvent {} ms");
        LOGGER.info("cluster saved {} ms", System.currentTimeMillis() - start);
        return savedCluster;
    });
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Measure(com.sequenceiq.cloudbreak.aspect.Measure)

Example 17 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.

the class ClusterOperationService method updateUserNamePassword.

public FlowIdentifier updateUserNamePassword(Long stackId, UserNamePasswordV4Request userNamePasswordJson) {
    Stack stack = stackService.getById(stackId);
    Cluster cluster = stack.getCluster();
    String oldUserName = cluster.getUserName();
    String oldPassword = cluster.getPassword();
    String newUserName = userNamePasswordJson.getUserName();
    String newPassword = userNamePasswordJson.getPassword();
    if (!newUserName.equals(oldUserName)) {
        return flowManager.triggerClusterCredentialReplace(stack.getId(), userNamePasswordJson.getUserName(), userNamePasswordJson.getPassword());
    } else if (!newPassword.equals(oldPassword)) {
        return flowManager.triggerClusterCredentialUpdate(stack.getId(), userNamePasswordJson.getPassword());
    } else {
        throw new BadRequestException("The request may not change credential");
    }
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 18 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.

the class UpdateHostsValidator method validateRequest.

public boolean validateRequest(Stack stack, HostGroupAdjustmentV4Request hostGroupAdjustment) {
    HostGroup hostGroup = getHostGroup(stack, hostGroupAdjustment);
    int scalingAdjustment = hostGroupAdjustment.getScalingAdjustment();
    boolean downScale = scalingAdjustment < 0;
    if (scalingAdjustment == 0) {
        throw new BadRequestException("No scaling adjustments specified. Nothing to do.");
    }
    if (!downScale && hostGroup.getInstanceGroup() != null) {
        validateUnusedHosts(hostGroup.getInstanceGroup(), scalingAdjustment);
    } else {
        validateRegisteredHosts(stack, hostGroupAdjustment);
        if (hostGroupAdjustment.getWithStackUpdate() && hostGroupAdjustment.getScalingAdjustment() > 0) {
            throw new BadRequestException("ScalingAdjustment has to be decommission if you define withStackUpdate = 'true'.");
        }
    }
    return downScale;
}
Also used : HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint)

Example 19 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.

the class UpdateHostsValidator method validateRegisteredHosts.

private void validateRegisteredHosts(Stack stack, HostGroupAdjustmentV4Request hostGroupAdjustment) {
    String hostGroupName = hostGroupAdjustment.getHostGroup();
    hostGroupService.getByClusterIdAndName(stack.getCluster().getId(), hostGroupName).ifPresentOrElse(hostGroup -> {
        if (hostGroup.getInstanceGroup() == null) {
            throw new BadRequestException(String.format("Can't find instancegroup for hostgroup: %s", hostGroupName));
        } else {
            InstanceGroup instanceGroup = hostGroup.getInstanceGroup();
            int hostsCount = instanceGroup.getNotDeletedAndNotZombieInstanceMetaDataSet().size();
            int adjustment = Math.abs(hostGroupAdjustment.getScalingAdjustment());
            Boolean validateNodeCount = hostGroupAdjustment.getValidateNodeCount();
            if (validateNodeCount == null || validateNodeCount) {
                if (hostsCount <= adjustment) {
                    String errorMessage = String.format("[hostGroup: '%s', current hosts: %s, decommissions requested: %s]", hostGroupName, hostsCount, adjustment);
                    throw new BadRequestException(String.format("The host group must contain at least 1 host after the decommission: %s", errorMessage));
                }
            } else if (hostsCount - adjustment < 0) {
                throw new BadRequestException(String.format("There are not enough hosts in host group: %s to remove", hostGroupName));
            }
        }
    }, () -> {
        throw new BadRequestException(String.format("Can't find hostgroup: %s", hostGroupName));
    });
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)

Example 20 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.

the class BlueprintConfigValidator method validate.

public void validate(Blueprint blueprint) {
    CmTemplateProcessor cmTemplateProcessor = new CmTemplateProcessor(blueprint.getBlueprintText());
    if (cmTemplateProcessor.isInstantiatorPresent()) {
        throw new BadRequestException("Instantiator is present in your Cloudera Manager template which is probably incorrect.");
    }
    if (cmTemplateProcessor.isRepositoriesPresent()) {
        throw new BadRequestException("Repositories are present in your Cloudera Manager template, this must be removed.");
    }
    Pattern passwordPattern = Pattern.compile("\\*\\*\\*");
    Matcher passwordMatch = passwordPattern.matcher(blueprint.getBlueprintText());
    if (passwordMatch.find()) {
        throw new BadRequestException("Password placeholder with **** is present in your Cloudera Manager template which is probably incorrect.");
    }
    Pattern volumePattern = Pattern.compile("/hadoopfs/fs(.*?)");
    Matcher volumeMatch = volumePattern.matcher(blueprint.getBlueprintText());
    if (volumeMatch.find()) {
        throw new BadRequestException("Volume configuration should not be part of your Cloudera Manager template.");
    }
    if (!cmTemplateProcessor.everyHostTemplateHasRoleConfigGroupsRefNames()) {
        throw new BadRequestException("RoleConfigGroupsRefNames is probably missing or misspelled in your Cloudera Manager template.");
    }
    if (!cmTemplateProcessor.everyServiceHasRoleConfigGroups()) {
        throw new BadRequestException("RoleConfigGroups is probably missing or misspelled in your Cloudera Manager template.");
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) CmTemplateProcessor(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor)

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