use of com.sequenceiq.cloudbreak.domain.BlueprintFile in project cloudbreak by hortonworks.
the class BlueprintLoaderService method updateDefaultBlueprints.
private Set<Blueprint> updateDefaultBlueprints(Iterable<Blueprint> blueprintsInDatabase, Workspace workspace) {
Set<Blueprint> resultList = new HashSet<>();
LOGGER.debug("Updating default blueprints which are contains text modifications.");
for (Blueprint blueprintInDatabase : blueprintsInDatabase) {
BlueprintFile defaultBlueprint = defaultBlueprintCache.defaultBlueprints().get(blueprintInDatabase.getName());
if (isActiveBlueprintMustBeUpdatedAndNotUserManaged(blueprintInDatabase, defaultBlueprint) || isNotActiveAndMustComeBack(blueprintInDatabase, defaultBlueprint)) {
LOGGER.debug("Default blueprint '{}' needs to modify for the '{}' workspace because the validation text changed.", blueprintInDatabase.getName(), workspace.getId());
resultList.add(prepareBlueprint(blueprintInDatabase, defaultBlueprint, workspace));
}
}
LOGGER.debug("Finished to Update default blueprints which are contains text modifications.");
return resultList;
}
use of com.sequenceiq.cloudbreak.domain.BlueprintFile in project cloudbreak by hortonworks.
the class BlueprintLoaderService method addMissingBlueprints.
private Set<Blueprint> addMissingBlueprints(Collection<Blueprint> blueprintsInDatabase, Workspace workspace) {
Set<Blueprint> resultList = new HashSet<>();
LOGGER.debug("Adding default blueprints which are missing for the user.");
for (Entry<String, BlueprintFile> diffBlueprint : collectDeviationOfExistingAndDefaultBlueprints(blueprintsInDatabase).entrySet()) {
LOGGER.debug("Default blueprint '{}' needs to be added for the '{}' workspace because the default validation missing.", diffBlueprint.getKey(), workspace.getId());
Blueprint bp = new Blueprint();
prepareBlueprint(bp, diffBlueprint.getValue(), workspace);
bp.setName(diffBlueprint.getValue().getName());
bp = setupBlueprint(bp, workspace);
String accountId = ThreadBasedUserCrnProvider.getAccountId();
String creator = ThreadBasedUserCrnProvider.getUserCrn();
blueprintService.decorateWithCrn(bp, accountId, creator);
resultList.add(bp);
}
LOGGER.debug("Finished to add default blueprints which are missing for the user.");
return resultList;
}
use of com.sequenceiq.cloudbreak.domain.BlueprintFile in project cloudbreak by hortonworks.
the class DefaultBlueprintCache method loadBlueprintsFromFile.
@PostConstruct
public void loadBlueprintsFromFile() {
Map<String, Set<String>> blueprints = blueprints();
for (Map.Entry<String, Set<String>> blueprintEntry : blueprints.entrySet()) {
try {
for (String blueprintText : blueprintEntry.getValue()) {
String[] split = blueprintText.trim().split("=");
if (blueprintUtils.isBlueprintNamePreConfigured(blueprintText, split)) {
LOGGER.debug("Load default validation '{}'.", AnonymizerUtil.anonymize(blueprintText));
BlueprintV4Request blueprintJson = new BlueprintV4Request();
blueprintJson.setName(split[0].trim());
JsonNode jsonNode = blueprintUtils.convertStringToJsonNode(blueprintUtils.readDefaultBlueprintFromFile(blueprintEntry.getKey(), split));
JsonNode blueprintNode = jsonNode.get("blueprint");
blueprintJson.setBlueprint(blueprintNode.toString());
Blueprint bp = converter.convert(blueprintJson);
JsonNode tags = jsonNode.get("tags");
Map<String, Object> tagParameters = blueprintUtils.prepareTags(tags);
bp.setTags(new Json(tagParameters));
JsonNode description = jsonNode.get("description");
bp.setDescription(description == null ? split[0] : description.asText(split[0]));
JsonNode blueprintUpgradeOption = blueprintNode.isMissingNode() ? null : blueprintNode.get("blueprintUpgradeOption");
bp.setBlueprintUpgradeOption(getBlueprintUpgradeOption(blueprintUpgradeOption));
BlueprintFile bpf = new BlueprintFile.Builder().name(bp.getName()).blueprintText(bp.getBlueprintText()).stackName(bp.getStackName()).stackVersion(bp.getStackVersion()).stackType(bp.getStackType()).blueprintUpgradeOption(bp.getBlueprintUpgradeOption()).hostGroupCount(bp.getHostGroupCount()).description(bp.getDescription()).build();
defaultBlueprints.put(bp.getName(), bpf);
}
}
} catch (IOException e) {
LOGGER.error("Can not read default validation from file: ", e);
}
}
}
Aggregations