Search in sources :

Example 6 with BadRequestException

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

the class CmTemplateValidator method validateRole.

private void validateRole(String accountId, EntitledForServiceScale role, Versioned blueprintVersion, CmTemplateProcessor templateProcessor) {
    boolean versionEnablesScaling = isVersionEnablesScaling(blueprintVersion, role);
    boolean entitledFor = entitlementService.isEntitledFor(accountId, role.getEntitledFor());
    if (role.getBlockedUntilCDPVersion().isPresent() && !versionEnablesScaling && !entitledFor) {
        throw new BadRequestException(String.format("'%s' service is not enabled to scale until CDP %s", role.name(), role.getBlockedUntilCDPVersion().get()));
    } else if (role.getBlockedUntilCDPVersion().isEmpty() && !entitledFor) {
        throw new BadRequestException(String.format("'%s' service is not enabled to scale", role.name()));
    } else if (role.getRequiredService().isPresent() && !isRequiredServicePresent(role.getRequiredService(), templateProcessor) && versionEnablesScaling) {
        throw new BadRequestException(String.format("'%s' service is not presented on the cluster, and that is required", role.getRequiredService().get()));
    } else {
        LOGGER.info("Account is entitled for {} so scaling is enabled.", role.getEntitledFor());
    }
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException)

Example 7 with BadRequestException

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

the class NetworkV4RequestToNetworkConverter method convert.

public Network convert(NetworkV4Request source) {
    Network network = new Network();
    network.setName(missingResourceNameGenerator.generateName(APIResourceType.NETWORK));
    network.setSubnetCIDR(source.getSubnetCIDR());
    network.setOutboundInternetTraffic(OutboundInternetTraffic.ENABLED);
    Map<String, Object> parameters = providerParameterCalculator.get(source).asMap();
    if (parameters != null) {
        try {
            network.setAttributes(new Json(parameters));
        } catch (IllegalArgumentException ignored) {
            throw new BadRequestException("Invalid parameters");
        }
    }
    return network;
}
Also used : Network(com.sequenceiq.cloudbreak.domain.Network) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Json(com.sequenceiq.cloudbreak.common.json.Json)

Example 8 with BadRequestException

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

the class GatewayTopologyV4RequestToGatewayTopologyConverter method convertExposedServices.

private void convertExposedServices(GatewayTopology gatewayTopology, GatewayTopologyV4Request source) {
    try {
        if (!CollectionUtils.isEmpty(source.getExposedServices())) {
            ExposedServices exposedServices = gatewayTopologyV4RequestToExposedServicesConverter.convert(source);
            gatewayTopology.setExposedServices(new Json(exposedServices));
        }
    } catch (IllegalArgumentException e) {
        throw new BadRequestException("Invalid exposedServices in request. Could not be parsed to JSON.", e);
    }
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ExposedServices(com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.ExposedServices) Json(com.sequenceiq.cloudbreak.common.json.Json)

Example 9 with BadRequestException

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

the class StopStartDownscaleFlowEventChainFactory method createFlowTriggerEventQueue.

@Override
public FlowTriggerEventQueue createFlowTriggerEventQueue(ClusterAndStackDownscaleTriggerEvent event) {
    StackView stackView = stackService.getViewByIdWithoutAuth(event.getResourceId());
    Map<String, Set<Long>> hostGroupsWithPrivateIds = event.getHostGroupsWithPrivateIds();
    Queue<Selectable> flowEventChain = new ConcurrentLinkedQueue<>();
    // TODO CB-14929: Is a stack sync really required here. What does it do ? (As of now it also serves to accept the event)
    addStackSyncTriggerEvent(event, flowEventChain);
    if (hostGroupsWithPrivateIds.keySet().size() > 1) {
        throw new BadRequestException("Start stop downscale flow was intended to handle only 1 hostgroup.");
    }
    for (Map.Entry<String, Set<Long>> hostGroupWithPrivateIds : hostGroupsWithPrivateIds.entrySet()) {
        StopStartDownscaleTriggerEvent te = new StopStartDownscaleTriggerEvent(StopStartDownscaleEvent.STOPSTART_DOWNSCALE_TRIGGER_EVENT.event(), stackView.getId(), hostGroupWithPrivateIds.getKey(), hostGroupWithPrivateIds.getValue());
        flowEventChain.add(te);
    }
    return new FlowTriggerEventQueue(getName(), event, flowEventChain);
}
Also used : Set(java.util.Set) StopStartDownscaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StopStartDownscaleTriggerEvent) FlowTriggerEventQueue(com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Map(java.util.Map)

Example 10 with BadRequestException

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

the class ClouderaManagerClusterCreationSetupService method determineCmRepoConfig.

private ClusterComponent determineCmRepoConfig(Optional<Component> stackClouderaManagerRepoConfig, String osType, Cluster cluster, String cdhStackVersion) throws CloudbreakImageCatalogException {
    Json json;
    if (Objects.isNull(stackClouderaManagerRepoConfig) || stackClouderaManagerRepoConfig.isEmpty()) {
        ImageCatalogPlatform platform = platformStringTransformer.getPlatformStringForImageCatalog(cluster.getStack().getCloudPlatform(), cluster.getStack().getPlatformVariant());
        ClouderaManagerRepo clouderaManagerRepo = defaultClouderaManagerRepoService.getDefault(osType, StackType.CDH.name(), cdhStackVersion, platform);
        if (clouderaManagerRepo == null) {
            throw new BadRequestException(String.format("Couldn't determine Cloudera Manager repo for the stack: %s", cluster.getStack().getName()));
        }
        json = new Json(clouderaManagerRepo);
    } else {
        json = stackClouderaManagerRepoConfig.get().getAttributes();
    }
    return new ClusterComponent(ComponentType.CM_REPO_DETAILS, json, cluster);
}
Also used : ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) ImageCatalogPlatform(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Json(com.sequenceiq.cloudbreak.common.json.Json)

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