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;
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations