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