Search in sources :

Example 1 with BlueprintParameterJson

use of com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson in project cloudbreak by hortonworks.

the class AmbariClusterService method prepareResults.

private void prepareResults(Iterable<BlueprintParameterJson> requests, Cluster cluster, Map<String, String> bpI, Map<String, String> results) {
    if (cluster.getBlueprintInputs().getValue() != null) {
        if (bpI != null) {
            for (Entry<String, String> stringStringEntry : bpI.entrySet()) {
                if (!results.keySet().contains(stringStringEntry.getKey())) {
                    results.put(stringStringEntry.getKey(), stringStringEntry.getValue());
                }
            }
        }
    }
    for (BlueprintParameterJson request : requests) {
        if (results.keySet().contains(request.getReferenceConfiguration())) {
            results.put(request.getName(), results.get(request.getReferenceConfiguration()));
            results.remove(request.getReferenceConfiguration());
        }
    }
}
Also used : BlueprintParameterJson(com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson)

Example 2 with BlueprintParameterJson

use of com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson 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 3 with BlueprintParameterJson

use of com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson in project cloudbreak by hortonworks.

the class BlueprintToBlueprintResponseConverter method convertInputParameters.

private Set<BlueprintParameterJson> convertInputParameters(Json inputParameters) throws IOException {
    Set<BlueprintParameterJson> result = new HashSet<>();
    if (inputParameters != null && StringUtils.isNoneEmpty(inputParameters.getValue())) {
        BlueprintInputParameters inputParametersObj = inputParameters.get(BlueprintInputParameters.class);
        List<BlueprintParameter> parameters = inputParametersObj.getParameters();
        for (BlueprintParameter record : parameters) {
            BlueprintParameterJson json = new BlueprintParameterJson();
            json.setDescription(record.getDescription());
            json.setName(record.getName());
            json.setReferenceConfiguration(record.getReferenceConfiguration());
            result.add(json);
        }
    }
    return result;
}
Also used : BlueprintParameter(com.sequenceiq.cloudbreak.domain.BlueprintParameter) BlueprintInputParameters(com.sequenceiq.cloudbreak.domain.BlueprintInputParameters) BlueprintParameterJson(com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson) HashSet(java.util.HashSet)

Example 4 with BlueprintParameterJson

use of com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson 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 5 with BlueprintParameterJson

use of com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson in project cloudbreak by hortonworks.

the class AmbariClusterService method retrieveOutputs.

@Override
public ConfigsResponse retrieveOutputs(Long stackId, Set<BlueprintParameterJson> requests) throws IOException {
    Stack stack = stackService.get(stackId);
    AmbariClient ambariClient = getAmbariClient(stack);
    Cluster cluster = stack.getCluster();
    List<String> targets = new ArrayList<>();
    Map<String, String> bpI = new HashMap<>();
    if (cluster.getBlueprintInputs().getValue() != null) {
        bpI = cluster.getBlueprintInputs().get(Map.class);
    }
    prepareTargets(requests, targets, bpI);
    Map<String, String> results = new HashMap<>();
    if (cluster.getAmbariIp() != null) {
        results = ambariClient.getConfigValuesByConfigIds(targets);
    }
    prepareResults(requests, cluster, bpI, results);
    prepareAdditionalInputParameters(results, cluster);
    Set<BlueprintInputJson> blueprintInputJsons = new HashSet<>();
    for (Entry<String, String> stringStringEntry : results.entrySet()) {
        for (BlueprintParameterJson blueprintParameter : requests) {
            if (stringStringEntry.getKey().equals(blueprintParameter.getName())) {
                BlueprintInputJson blueprintInputJson = new BlueprintInputJson();
                blueprintInputJson.setName(blueprintParameter.getName());
                blueprintInputJson.setPropertyValue(stringStringEntry.getValue());
                blueprintInputJsons.add(blueprintInputJson);
                break;
            }
        }
    }
    ConfigsResponse configsResponse = new ConfigsResponse();
    configsResponse.setInputs(blueprintInputJsons);
    return configsResponse;
}
Also used : HashMap(java.util.HashMap) ConfigsResponse(com.sequenceiq.cloudbreak.api.model.ConfigsResponse) ArrayList(java.util.ArrayList) BlueprintInputJson(com.sequenceiq.cloudbreak.api.model.BlueprintInputJson) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Stack(com.sequenceiq.cloudbreak.domain.Stack) Map(java.util.Map) HashMap(java.util.HashMap) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) HashSet(java.util.HashSet) BlueprintParameterJson(com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson)

Aggregations

BlueprintParameterJson (com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson)5 BlueprintInputParameters (com.sequenceiq.cloudbreak.domain.BlueprintInputParameters)3 BlueprintParameter (com.sequenceiq.cloudbreak.domain.BlueprintParameter)3 HashSet (java.util.HashSet)3 BlueprintInputJson (com.sequenceiq.cloudbreak.api.model.BlueprintInputJson)2 ConfigsResponse (com.sequenceiq.cloudbreak.api.model.ConfigsResponse)2 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)2 Stack (com.sequenceiq.cloudbreak.domain.Stack)2 Json (com.sequenceiq.cloudbreak.domain.json.Json)2 ArrayList (java.util.ArrayList)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)1 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)1 RDSConfig (com.sequenceiq.cloudbreak.domain.RDSConfig)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1