Search in sources :

Example 51 with BadRequestException

use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.

the class StackRequestToStackConverter method getRegion.

private String getRegion(StackRequest source) {
    boolean containerOrchestrator;
    try {
        containerOrchestrator = orchestratorTypeResolver.resolveType(source.getOrchestrator().getType()).containerOrchestrator();
    } catch (CloudbreakException ignored) {
        throw new BadRequestException("Orchestrator not supported.");
    }
    if (OrchestratorConstants.YARN.equals(source.getOrchestrator().getType())) {
        return OrchestratorConstants.YARN;
    }
    if (isEmpty(source.getRegion()) && !containerOrchestrator) {
        Map<Platform, Region> regions = Maps.newHashMap();
        if (isNoneEmpty(defaultRegions)) {
            for (String entry : defaultRegions.split(",")) {
                String[] keyValue = entry.split(":");
                regions.put(platform(keyValue[0]), Region.region(keyValue[1]));
            }
            Region platformRegion = regions.get(platform(source.getCloudPlatform()));
            if (platformRegion == null || isEmpty(platformRegion.value())) {
                throw new BadRequestException(String.format("No default region specified for: %s. Region cannot be empty.", source.getCloudPlatform()));
            }
            return platformRegion.value();
        } else {
            throw new BadRequestException("No default region is specified. Region cannot be empty.");
        }
    }
    return source.getRegion();
}
Also used : Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Region(com.sequenceiq.cloudbreak.cloud.model.Region)

Example 52 with BadRequestException

use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.

the class StackRequestToStackConverter method convertInstanceGroups.

private Set<InstanceGroup> convertInstanceGroups(StackRequest source, Stack stack) {
    List<InstanceGroupRequest> instanceGroupRequests = source.getInstanceGroups();
    Set<InstanceGroup> convertedSet = new HashSet<>();
    for (InstanceGroupRequest instanceGroupRequest : instanceGroupRequests) {
        InstanceGroup instanceGroup = getConversionService().convert(instanceGroupRequest, InstanceGroup.class);
        if (instanceGroup != null) {
            convertedSet.add(getConversionService().convert(instanceGroupRequest, InstanceGroup.class));
        }
    }
    boolean gatewaySpecified = false;
    for (InstanceGroup instanceGroup : convertedSet) {
        instanceGroup.setStack(stack);
        if (!gatewaySpecified) {
            if (InstanceGroupType.GATEWAY.equals(instanceGroup.getInstanceGroupType())) {
                gatewaySpecified = true;
            }
        }
    }
    boolean containerOrchestrator;
    try {
        containerOrchestrator = orchestratorTypeResolver.resolveType(source.getOrchestrator().getType()).containerOrchestrator();
    } catch (CloudbreakException ignored) {
        throw new BadRequestException("Orchestrator not supported.");
    }
    if (!gatewaySpecified && !containerOrchestrator) {
        throw new BadRequestException("Ambari server must be specified");
    }
    return convertedSet;
}
Also used : InstanceGroupRequest(com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) HashSet(java.util.HashSet)

Example 53 with BadRequestException

use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.

the class StackValidationRequestToStackValidationConverter method validateCredential.

private void validateCredential(StackValidationRequest stackValidationRequest, StackValidation stackValidation) {
    if (stackValidationRequest.getCredentialId() != null) {
        Credential credential = credentialService.get(stackValidationRequest.getCredentialId());
        stackValidation.setCredential(credential);
    } else if (stackValidationRequest.getCredentialName() != null) {
        Credential credential = credentialService.get(stackValidationRequest.getCredentialName(), stackValidationRequest.getAccount());
        stackValidation.setCredential(credential);
    } else if (stackValidationRequest.getCredential() != null) {
        Credential credential = conversionService.convert(stackValidationRequest.getCredential(), Credential.class);
        stackValidation.setCredential(credential);
    } else {
        throw new BadRequestException("Credential is not configured for the validation request!");
    }
}
Also used : Credential(com.sequenceiq.cloudbreak.domain.Credential) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException)

Example 54 with BadRequestException

use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.

the class StackValidationRequestToStackValidationConverter method validateNetwork.

private void validateNetwork(Long networkId, NetworkRequest networkRequest, StackValidation stackValidation) {
    SpecialParameters specialParameters = cloudParameterCache.getPlatformParameters().get(Platform.platform(stackValidation.getCredential().cloudPlatform())).specialParameters();
    if (networkId != null) {
        Network network = networkService.get(networkId);
        stackValidation.setNetwork(network);
    } else if (networkRequest != null) {
        Network network = conversionService.convert(networkRequest, Network.class);
        stackValidation.setNetwork(network);
    } else if (specialParameters.getSpecialParameters().get(PlatformParametersConsts.NETWORK_IS_MANDATORY)) {
        throw new BadRequestException("Network is not configured for the validation request!");
    }
}
Also used : Network(com.sequenceiq.cloudbreak.domain.Network) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) SpecialParameters(com.sequenceiq.cloudbreak.api.model.SpecialParameters)

Example 55 with BadRequestException

use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.

the class StackValidationRequestToStackValidationConverter method validateBlueprint.

private void validateBlueprint(StackValidationRequest stackValidationRequest, StackValidation stackValidation) {
    if (stackValidationRequest.getBlueprintId() != null) {
        Blueprint blueprint = blueprintService.get(stackValidationRequest.getBlueprintId());
        stackValidation.setBlueprint(blueprint);
    } else if (stackValidationRequest.getBlueprintName() != null) {
        Blueprint blueprint = blueprintService.get(stackValidationRequest.getBlueprintName(), stackValidationRequest.getAccount());
        stackValidation.setBlueprint(blueprint);
    } else if (stackValidationRequest.getBlueprint() != null) {
        Blueprint blueprint = conversionService.convert(stackValidationRequest.getBlueprint(), Blueprint.class);
        stackValidation.setBlueprint(blueprint);
    } else {
        throw new BadRequestException("Blueprint is not configured for the validation request!");
    }
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException)

Aggregations

BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)87 Stack (com.sequenceiq.cloudbreak.domain.Stack)16 Transactional (javax.transaction.Transactional)13 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)12 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)12 Json (com.sequenceiq.cloudbreak.domain.json.Json)12 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)12 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)11 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)9 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)9 IOException (java.io.IOException)7 Credential (com.sequenceiq.cloudbreak.domain.Credential)6 HashMap (java.util.HashMap)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 Constraint (com.sequenceiq.cloudbreak.domain.Constraint)5 BlueprintParameterJson (com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson)4 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)4 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)4 HashSet (java.util.HashSet)4 BlueprintInputJson (com.sequenceiq.cloudbreak.api.model.BlueprintInputJson)3