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