Search in sources :

Example 26 with BadRequestException

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;
}
Also used : CredentialVerificationRequest(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationRequest) CredentialVerificationResult(com.sequenceiq.cloudbreak.cloud.event.credential.CredentialVerificationResult) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) OperationException(com.sequenceiq.cloudbreak.service.stack.connector.OperationException)

Example 27 with BadRequestException

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());
        }
    }
}
Also used : RDSConfig(com.sequenceiq.cloudbreak.domain.RDSConfig) ConfigsResponse(com.sequenceiq.cloudbreak.api.model.ConfigsResponse) BlueprintInputJson(com.sequenceiq.cloudbreak.api.model.BlueprintInputJson) BlueprintParameter(com.sequenceiq.cloudbreak.domain.BlueprintParameter) Json(com.sequenceiq.cloudbreak.domain.json.Json) BlueprintParameterJson(com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson) BlueprintInputJson(com.sequenceiq.cloudbreak.api.model.BlueprintInputJson) IOException(java.io.IOException) BlueprintInputParameters(com.sequenceiq.cloudbreak.domain.BlueprintInputParameters) Stack(com.sequenceiq.cloudbreak.domain.Stack) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) BlueprintParameterJson(com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson) HashSet(java.util.HashSet)

Example 28 with BadRequestException

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));
    }
}
Also used : RecipeService(com.sequenceiq.cloudbreak.service.recipe.RecipeService) IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) LoggerFactory(org.slf4j.LoggerFactory) RecipeRequest(com.sequenceiq.cloudbreak.api.model.RecipeRequest) HostGroupService(com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService) ClusterService(com.sequenceiq.cloudbreak.service.cluster.ClusterService) ConstraintTemplateRepository(com.sequenceiq.cloudbreak.repository.ConstraintTemplateRepository) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Inject(javax.inject.Inject) ConstraintTemplate(com.sequenceiq.cloudbreak.domain.ConstraintTemplate) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) ConstraintJson(com.sequenceiq.cloudbreak.api.model.ConstraintJson) Stack(com.sequenceiq.cloudbreak.domain.Stack) ConversionService(org.springframework.core.convert.ConversionService) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) Constraint(com.sequenceiq.cloudbreak.domain.Constraint) Logger(org.slf4j.Logger) Collection(java.util.Collection) InstanceGroupRepository(com.sequenceiq.cloudbreak.repository.InstanceGroupRepository) Set(java.util.Set) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Recipe(com.sequenceiq.cloudbreak.domain.Recipe) Component(org.springframework.stereotype.Component) HostGroupRequest(com.sequenceiq.cloudbreak.api.model.HostGroupRequest) ConstraintRepository(com.sequenceiq.cloudbreak.repository.ConstraintRepository) StringUtils.isEmpty(org.springframework.util.StringUtils.isEmpty) Optional(java.util.Optional) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException)

Example 29 with BadRequestException

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;
}
Also used : HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 30 with BadRequestException

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;
}
Also used : PlatformParameters(com.sequenceiq.cloudbreak.cloud.PlatformParameters) 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