Search in sources :

Example 26 with CapabilityType

use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.

the class DefaultNodeMatcher method typeSpecificMatching.

@Override
protected boolean typeSpecificMatching(NodeTemplate abstractTemplate, LocationResourceTemplate candidate, NodeType candidateType, LocationResources locationResources, MatchingConfiguration matchingConfiguration) {
    for (Entry<String, Capability> candidateCapability : safe(candidate.getTemplate().getCapabilities()).entrySet()) {
        MatchingFilterDefinition configuredFilterDefinition = matchingConfiguration == null ? null : safe(matchingConfiguration.getCapabilities()).get(candidateCapability.getKey());
        Map<String, List<IMatchPropertyConstraint>> configuredFilters = configuredFilterDefinition == null ? null : configuredFilterDefinition.getProperties();
        CapabilityType capabilityType = locationResources.getCapabilityTypes().get(candidateCapability.getValue().getType());
        // Ignore scalable capabiltiy for matching.
        if (!ToscaTypeUtils.isOfType(capabilityType, NormativeCapabilityTypes.SCALABLE)) {
            Capability templateCapability = safe(abstractTemplate.getCapabilities()).get(candidateCapability.getKey());
            if (templateCapability != null && !isValidTemplatePropertiesMatch(templateCapability.getProperties(), candidateCapability.getValue().getProperties(), capabilityType.getProperties(), configuredFilters)) {
                return false;
            }
        }
    }
    return true;
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Capability(org.alien4cloud.tosca.model.templates.Capability) List(java.util.List) MatchingFilterDefinition(alien4cloud.model.deployment.matching.MatchingFilterDefinition)

Example 27 with CapabilityType

use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.

the class TopologyServiceCore method getIndexedCapabilityTypesFromTopology.

/**
 * Get all capability types used in a topology
 *
 * @param topology the topology to find all relationship types
 * @return The map that contains the capability types.
 */
public Map<String, CapabilityType> getIndexedCapabilityTypesFromTopology(Topology topology) {
    Map<String, CapabilityType> capabilityTypes = Maps.newHashMap();
    if (topology.getNodeTemplates() == null) {
        return capabilityTypes;
    }
    for (Map.Entry<String, NodeTemplate> templateEntry : topology.getNodeTemplates().entrySet()) {
        NodeTemplate template = templateEntry.getValue();
        if (template.getCapabilities() != null) {
            for (Map.Entry<String, Capability> capabilityEntry : template.getCapabilities().entrySet()) {
                Capability capability = capabilityEntry.getValue();
                if (!capabilityTypes.containsKey(capability.getType())) {
                    CapabilityType capabilityType = getFromContextIfDefined(CapabilityType.class, capability.getType(), topology.getDependencies(), true);
                    capabilityTypes.put(capability.getType(), capabilityType);
                }
            }
        }
    }
    return capabilityTypes;
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Capability(org.alien4cloud.tosca.model.templates.Capability) Map(java.util.Map)

Example 28 with CapabilityType

use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.

the class NodeFilterValidationService method validateRequirementFilters.

/**
 * Performs validation of the node filters to check that relationships targets the filter requirements.
 */
private List<NodeFiltersTask> validateRequirementFilters(Topology topology, boolean skipInputs) {
    List<NodeFiltersTask> toReturnTaskList = Lists.newArrayList();
    Map<String, NodeTemplate> nodeTemplates = topology.getNodeTemplates();
    Map<String, NodeType> nodeTypes = topologyServiceCore.getIndexedNodeTypesFromTopology(topology, false, true, true);
    Map<String, CapabilityType> capabilityTypes = topologyServiceCore.getIndexedCapabilityTypesFromTopology(topology);
    for (Map.Entry<String, NodeTemplate> nodeTempEntry : nodeTemplates.entrySet()) {
        Map<String, RelationshipTemplate> relationshipsMap = nodeTempEntry.getValue().getRelationships();
        if (relationshipsMap == null || relationshipsMap.isEmpty()) {
            continue;
        }
        NodeType sourceNodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTempEntry.getValue().getType(), topology.getDependencies());
        if (sourceNodeType.isAbstract()) {
            continue;
        }
        NodeFiltersTask task = new NodeFiltersTask();
        task.setNodeTemplateName(nodeTempEntry.getKey());
        task.setCode(TaskCode.NODE_FILTER_INVALID);
        task.setComponent(sourceNodeType);
        task.setNodeFiltersToSatisfy(Lists.<NodeFilterToSatisfy>newArrayList());
        validateFiltersForNode(sourceNodeType, relationshipsMap, topology, nodeTypes, capabilityTypes, task, skipInputs);
        if (!task.getNodeFiltersToSatisfy().isEmpty()) {
            toReturnTaskList.add(task);
        }
    }
    return toReturnTaskList.isEmpty() ? null : toReturnTaskList;
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) NodeFiltersTask(alien4cloud.topology.task.NodeFiltersTask) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) Map(java.util.Map)

Example 29 with CapabilityType

use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.

the class NodeMatchingReplaceModifier method processSpecificReplacement.

@Override
protected void processSpecificReplacement(NodeTemplate replacingNode, NodeTemplate replacedTopologyNode, Set<String> topologyNotMergedProps) {
    // Also merge relationships
    replacingNode.setRelationships(replacedTopologyNode.getRelationships());
    // not miss any capability
    for (Map.Entry<String, Capability> locationCapabilityEntry : safe(replacingNode.getCapabilities()).entrySet()) {
        // Merge capabilities properties from the topology into the substituted node un-set properties
        CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, locationCapabilityEntry.getValue().getType());
        Capability locationCapability = locationCapabilityEntry.getValue();
        Capability abstractCapability = safe(replacedTopologyNode.getCapabilities()).get(locationCapabilityEntry.getKey());
        // Ignore injection of location values for scalable capability
        if (abstractCapability != null && MapUtils.isNotEmpty(abstractCapability.getProperties())) {
            if (capabilityType != null && !ToscaTypeUtils.isOfType(capabilityType, NormativeCapabilityTypes.SCALABLE)) {
                locationCapability.setProperties(CollectionUtils.merge(abstractCapability.getProperties(), locationCapability.getProperties(), true, topologyNotMergedProps));
            } else {
                locationCapability.setProperties(abstractCapability.getProperties());
            }
        }
    }
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Capability(org.alien4cloud.tosca.model.templates.Capability) Map(java.util.Map)

Example 30 with CapabilityType

use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.

the class ServiceResourceService method validateRelationshipTypes.

private void validateRelationshipTypes(ServiceResource serviceResource, final NodeType nodeType) {
    safe(serviceResource.getCapabilitiesRelationshipTypes()).forEach((capabilityName, relationshipTypeId) -> {
        RelationshipType relationshipType = toscaTypeSearchService.findByIdOrFail(RelationshipType.class, relationshipTypeId);
        String[] validTargets = relationshipType.getValidTargets();
        if (ArrayUtils.isNotEmpty(validTargets)) {
            CapabilityDefinition capabilityDefinition = nodeType.getCapabilities().stream().filter(c -> c.getId().equals(capabilityName)).findFirst().get();
            Csar csar = toscaTypeSearchService.getArchive(nodeType.getArchiveName(), nodeType.getArchiveVersion());
            Set<CSARDependency> allDependencies = new HashSet<>(safe(csar.getDependencies()));
            allDependencies.add(new CSARDependency(csar.getName(), csar.getVersion(), csar.getHash()));
            CapabilityType capabilityType = toscaTypeSearchService.getElementInDependencies(CapabilityType.class, capabilityDefinition.getType(), allDependencies);
            Set<String> allAcceptedTypes = new HashSet<>();
            allAcceptedTypes.addAll(capabilityType.getDerivedFrom());
            allAcceptedTypes.add(capabilityType.getElementId());
            boolean isValid = false;
            for (String validTarget : validTargets) {
                if (allAcceptedTypes.contains(validTarget)) {
                    isValid = true;
                    break;
                }
            }
            if (!isValid) {
                throw new IncompatibleHalfRelationshipException("[" + relationshipType.getId() + "] is not compatible with [" + capabilityType.getId() + "]");
            }
        }
    });
    safe(serviceResource.getRequirementsRelationshipTypes()).forEach((k, v) -> {
        toscaTypeSearchService.findByIdOrFail(RelationshipType.class, v);
    });
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) IncompatibleHalfRelationshipException(org.alien4cloud.alm.service.exceptions.IncompatibleHalfRelationshipException) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) HashSet(java.util.HashSet)

Aggregations

CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)48 Capability (org.alien4cloud.tosca.model.templates.Capability)25 NodeType (org.alien4cloud.tosca.model.types.NodeType)21 Set (java.util.Set)20 Test (org.junit.Test)18 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)14 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)13 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)13 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)10 Map (java.util.Map)9 Csar (org.alien4cloud.tosca.model.Csar)8 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)8 NotFoundException (alien4cloud.exception.NotFoundException)7 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)5 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)5 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)5 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)4 List (java.util.List)3 FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)3 MatchingFilterDefinition (alien4cloud.model.deployment.matching.MatchingFilterDefinition)2