Search in sources :

Example 6 with CapabilityDefinition

use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition in project alien4cloud by alien4cloud.

the class TemplateBuilder method fillCapabilitiesMap.

private static void fillCapabilitiesMap(Map<String, Capability> map, List<CapabilityDefinition> elements, Map<String, Capability> mapToMerge, boolean adaptToType) {
    if (elements == null) {
        return;
    }
    for (CapabilityDefinition capa : elements) {
        Capability toAddCapa = MapUtils.getObject(mapToMerge, capa.getId());
        Map<String, AbstractPropertyValue> capaProperties = null;
        CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capa.getType());
        if (capabilityType != null && capabilityType.getProperties() != null) {
            // Inject all default values from the type.
            capaProperties = PropertyUtil.getDefaultPropertyValuesFromPropertyDefinitions(capabilityType.getProperties());
            // Override them with values as defined in the actual Capability Definition of the node type.
            if (capa.getProperties() != null) {
                capaProperties.putAll(capa.getProperties());
            }
        }
        // only merge if the types are equals
        if (toAddCapa == null || (StringUtils.isNotBlank(toAddCapa.getType()) && !Objects.equals(toAddCapa.getType(), capa.getType()))) {
            toAddCapa = new Capability();
            toAddCapa.setType(capa.getType());
            toAddCapa.setProperties(capaProperties);
        } else {
            if (StringUtils.isBlank(toAddCapa.getType())) {
                toAddCapa.setType(capa.getType());
            }
            if (MapUtils.isNotEmpty(capaProperties)) {
                Map<String, AbstractPropertyValue> nodeCapaProperties = safe(toAddCapa.getProperties());
                capaProperties.putAll(nodeCapaProperties);
                toAddCapa.setProperties(capaProperties);
            }
        }
        Map<String, AbstractPropertyValue> properties = Maps.newLinkedHashMap();
        fillProperties(properties, capabilityType != null ? capabilityType.getProperties() : null, toAddCapa.getProperties(), adaptToType);
        toAddCapa.setProperties(properties);
        map.put(capa.getId(), toAddCapa);
    }
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Capability(org.alien4cloud.tosca.model.templates.Capability) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Example 7 with CapabilityDefinition

use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition in project alien4cloud by alien4cloud.

the class DanglingRequirementService method addDanglingNodes.

private void addDanglingNodes(Topology topology, TopologyContext topologyContext, NodeTemplate nodeTemplate, RequirementDefinition requirementDefinition, int count) {
    // TODO If the TOSCA context does not has the TOSCA normative types then add it automatically
    String danglingTemplateType = requirementDefinition.getNodeType() == null ? NormativeTypesConstant.ROOT_NODE_TYPE : requirementDefinition.getNodeType();
    NodeType danglingNodeType = ToscaContext.get(NodeType.class, danglingTemplateType);
    List<CapabilityDefinition> compatibleCapabilityByType = capabilityMatcherService.getCompatibleCapabilityByType(danglingNodeType, requirementDefinition.getType());
    CapabilityDefinition targetCapabilityDefinition = compatibleCapabilityByType.size() == 0 ? null : compatibleCapabilityByType.get(0);
    RelationshipType danglingRelationshipType = fetchValidRelationshipType(requirementDefinition, targetCapabilityDefinition);
    // check if the type is scalable (then count is used as a scalability parameter) or if we should add multiple instances
    CapabilityDefinition scalable = NodeTypeUtils.getCapabilityByType(danglingNodeType, NormativeCapabilityTypes.SCALABLE);
    if (scalable == null) {
        scalable = NodeTypeUtils.getCapabilityByType(danglingNodeType, AlienCapabilityTypes.CLUSTER_CONTROLLER);
    }
    List<NodeTemplate> addedNodes = Lists.newArrayList();
    if (scalable == null) {
        for (int i = 0; i < count; i++) {
            NodeTemplate addedNode = addDanglingNode(topology, topologyContext, nodeTemplate, requirementDefinition, danglingNodeType, danglingRelationshipType, targetCapabilityDefinition);
            addedNodes.add(addedNode);
        }
    } else {
        NodeTemplate danglingTemplate = addDanglingNode(topology, topologyContext, nodeTemplate, requirementDefinition, danglingNodeType, danglingRelationshipType, targetCapabilityDefinition);
        Capability scalableCapability = danglingTemplate.getCapabilities().get(scalable.getId());
        TopologyUtils.setScalingProperty(NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES, count, scalableCapability);
        TopologyUtils.setScalingProperty(NormativeComputeConstants.SCALABLE_MAX_INSTANCES, requirementDefinition.getUpperBound(), scalableCapability);
        addedNodes.add(danglingTemplate);
    }
    // Recursively add dangling nodes.
    for (NodeTemplate addedNode : addedNodes) {
        addDanglingRequirements(topology, topologyContext, addedNode, null);
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Capability(org.alien4cloud.tosca.model.templates.Capability) NodeType(org.alien4cloud.tosca.model.types.NodeType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) PropertyConstraint(org.alien4cloud.tosca.model.definitions.PropertyConstraint) EqualConstraint(org.alien4cloud.tosca.model.definitions.constraints.EqualConstraint)

Example 8 with CapabilityDefinition

use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition in project alien4cloud by alien4cloud.

the class SearchTest method prepareToscaElement.

private void prepareToscaElement() {
    List<CapabilityDefinition> capa = Lists.newArrayList(new CapabilityDefinition("container", "container", 1), new CapabilityDefinition("container1", "container1", 1), new CapabilityDefinition("container2", "container2", 1), new CapabilityDefinition("container3", "container3", 1), new CapabilityDefinition("war", "war", 1));
    List<RequirementDefinition> req = Lists.newArrayList(new RequirementDefinition("Runtime", "Runtime"), new RequirementDefinition("server", "server"), new RequirementDefinition("blob", "blob"));
    List<String> der = Lists.newArrayList("Parent1", "Parent2");
    indexedNodeTypeTest = createIndexedNodeType("1", "positive", "1.0", "", capa, req, der, new ArrayList<String>());
    indexedNodeTypeTest.setId("1");
    dataTest.add(indexedNodeTypeTest);
    capa = Lists.newArrayList(new CapabilityDefinition("banana", "banana", 1), new CapabilityDefinition("banana1", "banana1", 1), new CapabilityDefinition("container", "container", 1), new CapabilityDefinition("banana3", "banana3", 1), new CapabilityDefinition("zar", "zar", 1));
    req = Lists.newArrayList(new RequirementDefinition("Pant", "Pant"), new RequirementDefinition("DBZ", "DBZ"), new RequirementDefinition("Animes", "Animes"));
    der = Lists.newArrayList("Songoku", "Kami");
    indexedNodeTypeTest2 = createIndexedNodeType("2", "pokerFace", "1.0", "", capa, req, der, new ArrayList<String>());
    dataTest.add(indexedNodeTypeTest2);
    capa = Lists.newArrayList(new CapabilityDefinition("potatoe", "potatoe", 1), new CapabilityDefinition("potatoe2", "potatoe2", 1), new CapabilityDefinition("potatoe3", "potatoe3", 1), new CapabilityDefinition("potatoe4", "potatoe4", 1), new CapabilityDefinition("zor", "zor", 1));
    req = Lists.newArrayList(new RequirementDefinition("OnePiece", "OnePiece"), new RequirementDefinition("beelzebub", "beelzebub"), new RequirementDefinition("DBGT", "DBGT"));
    der = Lists.newArrayList("Jerome", "Sandrini");
    indexedNodeTypeTest3 = createIndexedNodeType("3", "nagative", "1.5", "", capa, req, der, new ArrayList<String>());
    dataTest.add(indexedNodeTypeTest3);
    capa = Lists.newArrayList(new CapabilityDefinition("yams", "yams", 1), new CapabilityDefinition("yams1", "yams1", 1), new CapabilityDefinition("positiveYes", "positiveYes", 1), new CapabilityDefinition("yams3", "yams3", 1), new CapabilityDefinition("war world", "war world", 1));
    req = Lists.newArrayList(new RequirementDefinition("Naruto", "Naruto"), new RequirementDefinition("FT", "FT"), new RequirementDefinition("Bleach", "Bleach"));
    der = Lists.newArrayList("Luc", "Boutier");
    indexedNodeTypeTest4 = createIndexedNodeType("4", "pokerFace", "2.0", "", capa, req, der, new ArrayList<String>());
    dataTest.add(indexedNodeTypeTest4);
}
Also used : ArrayList(java.util.ArrayList) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition)

Example 9 with CapabilityDefinition

use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition in project alien4cloud by alien4cloud.

the class NodeFilterValidationService method validateNodeFilterCapabilities.

private void validateNodeFilterCapabilities(NodeFilter nodeFilter, NodeTemplate target, NodeType targetType, Map<String, CapabilityType> capabilityTypes, NodeFilterToSatisfy nodeFilterToSatisfy, boolean skipInputs) {
    if (nodeFilter.getCapabilities() == null || nodeFilter.getCapabilities().isEmpty()) {
        return;
    }
    Map<String, FilterDefinition> capabilities = nodeFilter.getCapabilities();
    for (Map.Entry<String, FilterDefinition> filterDefinitionEntry : capabilities.entrySet()) {
        String capabilityName = filterDefinitionEntry.getKey();
        CapabilityDefinition definition = getCapabilityDefinition(targetType, capabilityName);
        if (definition == null) {
            nodeFilterToSatisfy.getMissingCapabilities().add(capabilityName);
            continue;
        }
        CapabilityType capabilityType = capabilityTypes.get(definition.getType());
        List<Violations> violations = validatePropertyFilters(filterDefinitionEntry.getValue().getProperties(), target.getCapabilities().get(definition.getId()).getProperties(), capabilityType.getProperties(), skipInputs);
        violations.forEach(violation -> violation.capabilityName = capabilityName);
        if (nodeFilterToSatisfy.getViolations() == null) {
            nodeFilterToSatisfy.setViolations(violations);
        } else {
            nodeFilterToSatisfy.getViolations().addAll(violations);
        }
    }
}
Also used : FilterDefinition(org.alien4cloud.tosca.model.definitions.FilterDefinition) CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Violations(alien4cloud.topology.task.NodeFilterToSatisfy.Violations) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) Map(java.util.Map)

Example 10 with CapabilityDefinition

use of org.alien4cloud.tosca.model.definitions.CapabilityDefinition in project alien4cloud by alien4cloud.

the class DefineAsDefaultForCapabilityDefinitionsSteps method I_have_a_node_type_with_id_and_an_archive_version_with_capability.

@Given("^I have a node type with id \"([^\"]*)\" and an archive version \"([^\"]*)\" with capability \"([^\"]*)\"$")
public void I_have_a_node_type_with_id_and_an_archive_version_with_capability(String elementId, String archiveVersion, String capability) throws Throwable {
    List<CapabilityDefinition> capabilities = Lists.newArrayList(new CapabilityDefinition(capability, capability, 1));
    createOneIndexNodeType(elementId, archiveVersion, capabilities, true);
}
Also used : CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) Given(cucumber.api.java.en.Given)

Aggregations

CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)24 NodeType (org.alien4cloud.tosca.model.types.NodeType)16 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)11 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)9 Capability (org.alien4cloud.tosca.model.templates.Capability)5 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)5 ArrayList (java.util.ArrayList)4 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)4 Date (java.util.Date)3 Map (java.util.Map)3 Csar (org.alien4cloud.tosca.model.Csar)3 FacetedSearchResult (alien4cloud.dao.model.FacetedSearchResult)2 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)2 HashMap (java.util.HashMap)2 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)2 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)2 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)2 EqualConstraint (org.alien4cloud.tosca.model.definitions.constraints.EqualConstraint)2 RelationshipEntry (org.alien4cloud.tosca.utils.TopologyUtils.RelationshipEntry)2 Test (org.junit.Test)2