Search in sources :

Example 6 with BlueprintFile

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;
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) BlueprintFile(com.sequenceiq.cloudbreak.domain.BlueprintFile) HashSet(java.util.HashSet)

Example 7 with BlueprintFile

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;
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) BlueprintFile(com.sequenceiq.cloudbreak.domain.BlueprintFile) HashSet(java.util.HashSet)

Example 8 with BlueprintFile

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);
        }
    }
}
Also used : Set(java.util.Set) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) JsonNode(com.fasterxml.jackson.databind.JsonNode) Json(com.sequenceiq.cloudbreak.common.json.Json) IOException(java.io.IOException) BlueprintV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request) BlueprintFile(com.sequenceiq.cloudbreak.domain.BlueprintFile) HashMap(java.util.HashMap) Map(java.util.Map) PostConstruct(javax.annotation.PostConstruct)

Aggregations

Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)8 BlueprintFile (com.sequenceiq.cloudbreak.domain.BlueprintFile)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 BlueprintV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request)3 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Json (com.sequenceiq.cloudbreak.common.json.Json)1 ClusterTemplate (com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterTemplate)1 IOException (java.io.IOException)1 Map (java.util.Map)1 Set (java.util.Set)1 PostConstruct (javax.annotation.PostConstruct)1