Search in sources :

Example 1 with GeneratedCmTemplate

use of com.sequenceiq.cloudbreak.cmtemplate.generator.template.domain.GeneratedCmTemplate in project cloudbreak by hortonworks.

the class GeneratedClusterTemplateServiceTest method testTemplateGeneration.

@Test
public void testTemplateGeneration() throws IOException, JSONException {
    TestFile outputFile = getTestFile(getFileName(TEMPLATE_GENERATOR_TEST_OUTPUTS, outputPath));
    GeneratedCmTemplate generatedCmTemplate = generatedClusterTemplateService().prepareClouderaManagerTemplate(inputs, stackType, version, UUID);
    JSONObject expected = toJSON(outputFile.getFileContent());
    JSONObject result = toJSON(generatedCmTemplate.getTemplate());
    assertJsonEquals(expected.toString(), result.toString(), when(IGNORING_ARRAY_ORDER));
}
Also used : JSONObject(org.json.JSONObject) GeneratedCmTemplate(com.sequenceiq.cloudbreak.cmtemplate.generator.template.domain.GeneratedCmTemplate) Test(org.junit.Test)

Example 2 with GeneratedCmTemplate

use of com.sequenceiq.cloudbreak.cmtemplate.generator.template.domain.GeneratedCmTemplate in project cloudbreak by hortonworks.

the class GeneratedCmTemplateService method prepareClouderaManagerTemplate.

public GeneratedCmTemplate prepareClouderaManagerTemplate(Set<String> services, String stackType, String version, String uuid) {
    CmTemplateProcessor processor = initiateTemplate();
    Set<ServiceConfig> serviceConfigs = collectServiceConfigs(services);
    Map<String, Set<String>> hostServiceMap = new HashMap<>();
    prepareCdhVersion(stackType, version, processor);
    processor.setDisplayName(prepareDisplayName(uuid));
    processor.setServices(prepareApiClusterTemplateServices(serviceConfigs, hostServiceMap));
    processor.setHostTemplates(prepareApiClusterTemplateHostTemplates(hostServiceMap));
    return new GeneratedCmTemplate(prepareTemplate(processor));
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ServiceConfig(com.sequenceiq.cloudbreak.cmtemplate.generator.configuration.domain.dependencies.ServiceConfig) HashMap(java.util.HashMap) GeneratedCmTemplate(com.sequenceiq.cloudbreak.cmtemplate.generator.template.domain.GeneratedCmTemplate) CmTemplateProcessor(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor)

Example 3 with GeneratedCmTemplate

use of com.sequenceiq.cloudbreak.cmtemplate.generator.template.domain.GeneratedCmTemplate in project cloudbreak by hortonworks.

the class BlueprintV4RequestToBlueprintConverter method convert.

public Blueprint convert(BlueprintV4Request json) {
    Blueprint blueprint = new Blueprint();
    if (StringUtils.isNotEmpty(json.getUrl())) {
        String sourceUrl = json.getUrl().trim();
        try {
            String urlText = URLUtils.readUrl(sourceUrl);
            jsonHelper.createJsonFromString(urlText);
            blueprint.setBlueprintText(urlText);
        } catch (IOException | CloudbreakApiException e) {
            throw new BadRequestException(String.format("Cannot download cluster template from: %s", sourceUrl), e);
        }
    } else if (!CollectionUtils.isEmpty(json.getServices()) && !Strings.isNullOrEmpty(json.getPlatform())) {
        GeneratedCmTemplate generatedCmTemplate = clusterTemplateGeneratorService.generateTemplateByServices(json.getServices(), json.getPlatform());
        blueprint.setBlueprintText(generatedCmTemplate.getTemplate());
    } else {
        blueprint.setBlueprintText(json.getBlueprint());
    }
    try {
        JsonNode blueprintJson = JsonUtil.readTree(blueprint.getBlueprintText());
        if (blueprintUtils.isBuiltinBlueprint(blueprintJson)) {
            LOGGER.info("Built-in blueprint format detected, applying embedded \"blueprint\" content");
            blueprintJson = blueprintUtils.getBuiltinBlueprintContent(blueprintJson);
            blueprint.setBlueprintText(JsonUtil.writeValueAsString(blueprintJson));
        }
        if (blueprintUtils.isClouderaManagerClusterTemplate(blueprintJson)) {
            blueprint.setStackName(blueprintUtils.getCDHDisplayName(blueprintJson));
            blueprint.setHostGroupCount(blueprintUtils.countHostTemplates(blueprintJson));
            blueprint.setStackVersion(blueprintUtils.getCDHStackVersion(blueprintJson));
            blueprint.setStackType("CDH");
        } else {
            throw new BadRequestException("Failed to determine cluster template format");
        }
    } catch (IOException e) {
        throw new BadRequestException(JSON_PARSE_EXCEPTION_MESSAGE, e);
    }
    blueprint.setName(getNameByItsAvailability(json.getName()));
    blueprint.setDescription(json.getDescription());
    blueprint.setStatus(ResourceStatus.USER_MANAGED);
    blueprint.setTags(createJsonFromTagsMap(json.getTags()));
    return blueprint;
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) GeneratedCmTemplate(com.sequenceiq.cloudbreak.cmtemplate.generator.template.domain.GeneratedCmTemplate) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) CloudbreakApiException(com.sequenceiq.cloudbreak.json.CloudbreakApiException)

Aggregations

GeneratedCmTemplate (com.sequenceiq.cloudbreak.cmtemplate.generator.template.domain.GeneratedCmTemplate)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 CmTemplateProcessor (com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor)1 ServiceConfig (com.sequenceiq.cloudbreak.cmtemplate.generator.configuration.domain.dependencies.ServiceConfig)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)1 CloudbreakApiException (com.sequenceiq.cloudbreak.json.CloudbreakApiException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 JSONObject (org.json.JSONObject)1 Test (org.junit.Test)1