use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class ServiceProviderCredentialAdapter method init.
public Credential init(Credential credential) {
CloudContext cloudContext = new CloudContext(credential.getId(), credential.getName(), credential.cloudPlatform(), credential.getOwner());
CloudCredential cloudCredential = credentialConverter.convert(credential);
CredentialVerificationRequest request = new CredentialVerificationRequest(cloudContext, cloudCredential);
LOGGER.info("Triggering event: {}", request);
eventBus.notify(request.selector(), eventFactory.createEvent(request));
try {
CredentialVerificationResult res = request.await();
String message = "Failed to verify the credential: ";
LOGGER.info("Result: {}", res);
if (res.getStatus() != EventStatus.OK) {
LOGGER.error(message, res.getErrorDetails());
throw new BadRequestException(message + res.getErrorDetails(), res.getErrorDetails());
}
if (CredentialStatus.FAILED.equals(res.getCloudCredentialStatus().getStatus())) {
throw new BadRequestException(message + res.getCloudCredentialStatus().getStatusReason(), res.getCloudCredentialStatus().getException());
}
CloudCredential cloudCredentialResponse = res.getCloudCredentialStatus().getCloudCredential();
mergeSmartSenseAttributeIfExists(credential, cloudCredentialResponse);
} catch (InterruptedException e) {
LOGGER.error("Error while executing credential verification", e);
throw new OperationException(e);
}
return credential;
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class ClusterDecorator method prepareConnectedClusterParameters.
private void prepareConnectedClusterParameters(Cluster requestedCluster, IdentityUser user, ConnectedClusterRequest connectedClusterRequest) {
if (connectedClusterRequest != null) {
Long stackId;
Stack publicStack;
if (!Strings.isNullOrEmpty(connectedClusterRequest.getSourceClusterName())) {
publicStack = stackService.getPublicStack(connectedClusterRequest.getSourceClusterName(), user);
stackId = publicStack.getId();
} else {
stackId = connectedClusterRequest.getSourceClusterId();
publicStack = stackService.get(connectedClusterRequest.getSourceClusterId());
}
// We should set the ldap to the source cluster ldap
requestedCluster.setLdapConfig(publicStack.getCluster().getLdapConfig());
// We should set the ranger metastore to the source cluster ranger metastore if exist!
RDSConfig rangerRds = rdsConfigService.findByClusterIdAndType(publicStack.getOwner(), publicStack.getAccount(), publicStack.getCluster().getId(), RdsType.RANGER);
if (rangerRds != null) {
requestedCluster.getRdsConfigs().add(rangerRds);
}
try {
Set<BlueprintParameterJson> requests = new HashSet<>();
Json blueprintAttributes = requestedCluster.getBlueprint().getInputParameters();
if (blueprintAttributes != null && StringUtils.isNoneEmpty(blueprintAttributes.getValue())) {
BlueprintInputParameters inputParametersObj = blueprintAttributes.get(BlueprintInputParameters.class);
for (BlueprintParameter blueprintParameter : inputParametersObj.getParameters()) {
BlueprintParameterJson blueprintParameterJson = new BlueprintParameterJson();
blueprintParameterJson.setName(blueprintParameter.getName());
blueprintParameterJson.setReferenceConfiguration(blueprintParameter.getReferenceConfiguration());
blueprintParameterJson.setDescription(blueprintParameter.getDescription());
requests.add(blueprintParameterJson);
}
}
ConfigsResponse configsResponse = clusterService.retrieveOutputs(stackId, requests);
Map<String, String> newInputs = requestedCluster.getBlueprintInputs().get(Map.class);
for (BlueprintInputJson blueprintInputJson : configsResponse.getInputs()) {
newInputs.put(blueprintInputJson.getName(), blueprintInputJson.getPropertyValue());
}
requestedCluster.setBlueprintInputs(new Json(newInputs));
} catch (IOException e) {
LOGGER.error("Could not propagate cluster input parameters", e);
throw new BadRequestException("Could not propagate cluster input parameters: " + e.getMessage());
}
}
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class HostGroupDecorator method getDetailsFromExistingHostGroup.
private HostGroup getDetailsFromExistingHostGroup(Constraint constraint, HostGroup subject, String instanceGroupName, Collection<HostGroup> hostGroups) {
Optional<HostGroup> hostGroupOptional = hostGroups.stream().filter(input -> input.getConstraint().getInstanceGroup().getGroupName().equals(instanceGroupName)).findFirst();
if (hostGroupOptional.isPresent()) {
HostGroup hostGroup = hostGroupOptional.get();
Integer instanceGroupNodeCount = hostGroup.getConstraint().getInstanceGroup().getNodeCount();
if (constraint.getHostCount() > instanceGroupNodeCount) {
throw new BadRequestException(String.format("The 'hostCount' of host group '%s' constraint could not be more than '%s'!", subject.getName(), instanceGroupNodeCount));
}
hostGroup.getConstraint().setHostCount(constraint.getHostCount());
hostGroup.setName(subject.getName());
return hostGroup;
} else {
throw new BadRequestException(String.format("Invalid 'instanceGroupName'! Could not find instance group with name: '%s'", instanceGroupName));
}
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class HostGroupDecorator method getHostGroupByInstanceGroupName.
private HostGroup getHostGroupByInstanceGroupName(Constraint constraint, HostGroup subject, Cluster cluster, String instanceGroupName) {
HostGroup result = subject;
Set<HostGroup> hostGroups = hostGroupService.getByCluster(cluster.getId());
if (hostGroups.isEmpty()) {
Stack stack = cluster.getStack();
if (stack == null) {
String msg = String.format("There is no stack associated to cluster (id:'%s', name: '%s')!", cluster.getId(), cluster.getName());
throw new BadRequestException(msg);
} else {
subject.setConstraint(constraint);
}
} else {
result = getDetailsFromExistingHostGroup(constraint, subject, instanceGroupName, hostGroups);
}
return result;
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class StackDecorator method decorate.
public Stack decorate(Stack subject, StackRequest request, IdentityUser user) {
prepareCredential(subject, request, user);
prepareDomainIfDefined(subject, request, user);
Long credentialId = request.getCredentialId();
String credentialName = request.getCredentialName();
if (credentialId != null || subject.getCredential() != null || credentialName != null) {
subject.setCloudPlatform(subject.getCredential().cloudPlatform());
if (subject.getInstanceGroups() == null) {
throw new BadRequestException("Instance groups must be specified!");
}
PlatformParameters pps = cloudParameterCache.getPlatformParameters().get(Platform.platform(subject.cloudPlatform()));
Boolean mandatoryNetwork = pps.specialParameters().getSpecialParameters().get(PlatformParametersConsts.NETWORK_IS_MANDATORY);
if (BooleanUtils.isTrue(mandatoryNetwork) && request.getNetworkId() == null && subject.getNetwork() == null) {
throw new BadRequestException("Network must be specified!");
}
prepareNetwork(subject, request.getNetworkId());
prepareOrchestratorIfNotExist(subject, subject.getCredential());
if (subject.getFailurePolicy() != null) {
validatFailurePolicy(subject, subject.getFailurePolicy());
}
prepareInstanceGroups(subject, request, subject.getCredential(), user);
prepareFlexSubscription(subject, request.getFlexId());
validate(subject);
}
return subject;
}
Aggregations