Search in sources :

Example 6 with BadRequestException

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

the class SimpleAccountPreferencesService method getOneById.

@Override
public AccountPreferences getOneById(Long id, IdentityUser user) {
    AccountPreferences accountPreferences = repository.findOne(id);
    if (!user.getRoles().contains(IdentityUserRole.ADMIN)) {
        throw new BadRequestException("AccountPreferences are only available for admin users!");
    } else if (accountPreferences == null) {
        throw new BadRequestException(String.format("AccountPreferences could not find with id: %s", id));
    } else if (!accountPreferences.getAccount().equals(user.getAccount())) {
        throw new BadRequestException("AccountPreferences are only available for the owner admin user!");
    }
    authorizationService.hasReadPermission(accountPreferences);
    return accountPreferences;
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) AccountPreferences(com.sequenceiq.cloudbreak.domain.AccountPreferences)

Example 7 with BadRequestException

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

the class PlatformResourceRequestJsonToPlatformResourceRequest method convert.

@Override
public PlatformResourceRequest convert(PlatformResourceRequestJson source) {
    PlatformResourceRequest platformResourceRequest = new PlatformResourceRequest();
    if (!Strings.isNullOrEmpty(source.getCredentialName())) {
        platformResourceRequest.setCredential(credentialService.get(source.getCredentialName(), source.getAccount()));
    } else if (source.getCredentialId() != null) {
        platformResourceRequest.setCredential(credentialService.get(source.getCredentialId()));
    } else {
        throw new BadRequestException("The credentialId or the credentialName must be specified in the request");
    }
    if (!Strings.isNullOrEmpty(source.getPlatformVariant())) {
        platformResourceRequest.setCloudPlatform(platformResourceRequest.getCredential().cloudPlatform());
    } else {
        platformResourceRequest.setPlatformVariant(Strings.isNullOrEmpty(source.getPlatformVariant()) ? platformResourceRequest.getCredential().cloudPlatform() : source.getPlatformVariant());
    }
    platformResourceRequest.setFilters(source.getFilters());
    platformResourceRequest.setRegion(source.getRegion());
    platformResourceRequest.setCloudPlatform(platformResourceRequest.getCredential().cloudPlatform());
    if (!Strings.isNullOrEmpty(source.getAvailabilityZone())) {
        platformResourceRequest.setAvailabilityZone(source.getAvailabilityZone());
    }
    return platformResourceRequest;
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) PlatformResourceRequest(com.sequenceiq.cloudbreak.domain.PlatformResourceRequest)

Example 8 with BadRequestException

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

the class AmbariStackDetailsJsonToStackRepoDetailsConverter method convert.

@Override
public StackRepoDetails convert(AmbariStackDetailsJson source) {
    StackRepoDetails repo = new StackRepoDetails();
    Map<String, String> stack = new HashMap<>();
    Map<String, String> util = new HashMap<>();
    boolean baseRepoRequiredFieldsExists = Stream.of(source.getStackRepoId(), source.getStackBaseURL(), source.getUtilsRepoId(), source.getUtilsBaseURL()).noneMatch(StringUtils::isEmpty);
    if (!isVdfRequiredFieldsExists(source) && !baseRepoRequiredFieldsExists) {
        String msg = "The 'repositoryVersion', 'versionDefinitionFileUrl' or " + "'stackBaseURL', 'stackRepoId', 'utilsBaseUrl', 'utilsRepoId' fields must be specified!";
        throw new BadRequestException(msg);
    }
    stack.put("repoid", source.getStackRepoId());
    util.put("repoid", source.getUtilsRepoId());
    if (baseRepoRequiredFieldsExists) {
        String stackBaseURL = source.getStackBaseURL();
        String utilsBaseURL = source.getUtilsBaseURL();
        if (source.getOs() == null) {
            stack.put(REDHAT_6, stackBaseURL);
            stack.put(REDHAT_7, stackBaseURL);
            stack.put(DEBIAN_9, stackBaseURL);
            stack.put(UBUNTU_16, stackBaseURL);
            util.put(REDHAT_6, utilsBaseURL);
            util.put(REDHAT_7, utilsBaseURL);
            util.put(DEBIAN_9, utilsBaseURL);
            util.put(UBUNTU_16, utilsBaseURL);
        } else {
            stack.put(source.getOs(), stackBaseURL);
            util.put(source.getOs(), utilsBaseURL);
        }
    }
    if (!StringUtils.isEmpty(source.getRepositoryVersion())) {
        stack.put(StackRepoDetails.REPOSITORY_VERSION, source.getRepositoryVersion());
        stack.put("repoid", source.getStack());
    }
    if (!StringUtils.isEmpty(source.getVersionDefinitionFileUrl())) {
        stack.put(StackRepoDetails.CUSTOM_VDF_REPO_KEY, source.getVersionDefinitionFileUrl());
    }
    if (!StringUtils.isEmpty(source.getMpackUrl())) {
        stack.put(StackRepoDetails.MPACK_TAG, source.getMpackUrl());
    }
    repo.setStack(stack);
    repo.setUtil(util);
    repo.setEnableGplRepo(source.isEnableGplRepo());
    repo.setVerify(source.getVerify());
    repo.setHdpVersion(source.getVersion());
    return repo;
}
Also used : StackRepoDetails(com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException)

Example 9 with BadRequestException

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

the class BlueprintRequestToBlueprintConverter method prepareBlueprintInputs.

private void prepareBlueprintInputs(BlueprintRequest json, Blueprint blueprint) {
    List<BlueprintParameter> blueprintParameterList = new ArrayList<>();
    for (BlueprintParameterJson blueprintParameterJson : json.getInputs()) {
        BlueprintParameter blueprintParameter = new BlueprintParameter();
        blueprintParameter.setReferenceConfiguration(blueprintParameterJson.getReferenceConfiguration());
        blueprintParameter.setDescription(blueprintParameterJson.getDescription());
        blueprintParameter.setName(blueprintParameterJson.getName());
        blueprintParameterList.add(blueprintParameter);
    }
    BlueprintInputParameters inputParameters = new BlueprintInputParameters(blueprintParameterList);
    try {
        blueprint.setInputParameters(new Json(inputParameters));
    } catch (JsonProcessingException e) {
        throw new BadRequestException("Invalid Blueprint: Failed to parse inputs.", e);
    }
}
Also used : ArrayList(java.util.ArrayList) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) BlueprintParameter(com.sequenceiq.cloudbreak.domain.BlueprintParameter) Json(com.sequenceiq.cloudbreak.domain.json.Json) BlueprintParameterJson(com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) BlueprintInputParameters(com.sequenceiq.cloudbreak.domain.BlueprintInputParameters) BlueprintParameterJson(com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson)

Example 10 with BadRequestException

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

the class CredentialRequestToCredentialConverter method convert.

@Override
public Credential convert(CredentialRequest source) {
    Credential credential = new Credential();
    credential.setName(source.getName());
    credential.setDescription(source.getDescription());
    String cloudPlatform = source.getCloudPlatform();
    credential.setCloudPlatform(cloudPlatform);
    Map<String, Object> parameters = credentialDefinitionService.processProperties(platform(cloudPlatform), source.getParameters());
    if (parameters != null && !parameters.isEmpty()) {
        try {
            credential.setAttributes(new Json(parameters));
        } catch (JsonProcessingException ignored) {
            throw new BadRequestException("Invalid parameters");
        }
    }
    if (source.getTopologyId() != null) {
        credential.setTopology(topologyService.getById(source.getTopologyId()));
    }
    return credential;
}
Also used : Credential(com.sequenceiq.cloudbreak.domain.Credential) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Json(com.sequenceiq.cloudbreak.domain.json.Json) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

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