return blueprintJson;
}
@Override
public Blueprint convert(BlueprintJson json) {
Blueprint blueprint = new Blueprint();
if (json.getUrl() != null && !json.getUrl().isEmpty()) {
String sourceUrl = json.getUrl().trim();
try {
String urlText = readUrl(sourceUrl);
jsonHelper.createJsonFromString(urlText);
blueprint.setBlueprintText(urlText);
} catch (Exception e) {
throw new BadRequestException("Cannot download ambari blueprint from: " + sourceUrl, e);
}
} else {
blueprint.setBlueprintText(json.getAmbariBlueprint());
}
validateBlueprint(blueprint.getBlueprintText());
blueprint.setName(json.getName());
blueprint.setDescription(json.getDescription());
ObjectMapper mapper = new ObjectMapper();
try {
JsonNode root = mapper.readTree(blueprint.getBlueprintText());
int hostGroupCount = 0;
blueprint.setBlueprintName(root.get("Blueprints").get("blueprint_name").asText());
Iterator<JsonNode> hostGroups = root.get("host_groups").elements();
while (hostGroups.hasNext()) {
hostGroups.next();
hostGroupCount++;
}
blueprint.setHostGroupCount(hostGroupCount);
} catch (IOException e) {
throw new BadRequestException("Invalid Blueprint: Failed to parse JSON.", e);
}
return blueprint;