Search in sources :

Example 96 with NodeType

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

the class TopologyService method searchForNodeTypes.

/**
 * Search for nodeTypes given some filters. Apply AND filter strategy when multiple values for a filter key.
 */
public List<SuggestionsTask> searchForNodeTypes(String workspace, Map<String, Map<String, Set<String>>> nodeTemplatesToFilters, Map<String, NodeType> toExcludeIndexedNodeTypes, boolean excludeAbstract) throws IOException {
    if (nodeTemplatesToFilters == null || nodeTemplatesToFilters.isEmpty()) {
        return null;
    }
    List<SuggestionsTask> toReturnTasks = Lists.newArrayList();
    for (Map.Entry<String, Map<String, Set<String>>> nodeTemplatesToFiltersEntry : nodeTemplatesToFilters.entrySet()) {
        Map<String, String[]> formattedFilters = Maps.newHashMap();
        Map<String, FilterValuesStrategy> filterValueStrategy = Maps.newHashMap();
        NodeType[] data = null;
        if (nodeTemplatesToFiltersEntry.getValue() != null) {
            for (Map.Entry<String, Set<String>> filterEntry : nodeTemplatesToFiltersEntry.getValue().entrySet()) {
                formattedFilters.put(filterEntry.getKey(), filterEntry.getValue().toArray(new String[filterEntry.getValue().size()]));
                // AND strategy if multiple values
                filterValueStrategy.put(filterEntry.getKey(), FilterValuesStrategy.AND);
            }
            // retrieve only non abstract components
            if (excludeAbstract) {
                formattedFilters.put("abstract", ArrayUtils.toArray(String.valueOf("false")));
            }
            // use topology workspace + global workspace
            formattedFilters.put("workspace", ArrayUtils.toArray(workspace, "ALIEN_GLOBAL_WORKSPACE"));
            GetMultipleDataResult<NodeType> searchResult = alienDAO.search(NodeType.class, null, formattedFilters, filterValueStrategy, 20);
            data = getIndexedNodeTypesFromSearchResponse(searchResult, toExcludeIndexedNodeTypes.get(nodeTemplatesToFiltersEntry.getKey()));
        }
        TaskCode taskCode = ArrayUtils.isEmpty(data) ? TaskCode.IMPLEMENT : TaskCode.REPLACE;
        SuggestionsTask task = new SuggestionsTask();
        task.setNodeTemplateName(nodeTemplatesToFiltersEntry.getKey());
        task.setComponent(toExcludeIndexedNodeTypes.get(nodeTemplatesToFiltersEntry.getKey()));
        task.setCode(taskCode);
        task.setSuggestedNodeTypes(data);
        toReturnTasks.add(task);
    }
    return toReturnTasks;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) FilterValuesStrategy(org.elasticsearch.mapping.FilterValuesStrategy) TaskCode(alien4cloud.topology.task.TaskCode) NodeType(org.alien4cloud.tosca.model.types.NodeType) SuggestionsTask(alien4cloud.topology.task.SuggestionsTask) Map(java.util.Map)

Example 97 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType 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 98 with NodeType

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

the class TopologyCapabilityBoundsValidationServices method isCapabilityUpperBoundReachedForTarget.

// 
public boolean isCapabilityUpperBoundReachedForTarget(String nodeTemplateName, Map<String, NodeTemplate> nodeTemplates, String capabilityName, Set<CSARDependency> dependencies) {
    NodeTemplate nodeTemplate = nodeTemplates.get(nodeTemplateName);
    NodeType relatedIndexedNodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTemplate.getType(), dependencies);
    chekCapability(nodeTemplateName, capabilityName, nodeTemplate);
    CapabilityDefinition capabilityDefinition = getCapabilityDefinition(relatedIndexedNodeType.getCapabilities(), capabilityName);
    if (capabilityDefinition.getUpperBound() == Integer.MAX_VALUE) {
        return false;
    }
    List<RelationshipEntry> targetRelatedRelationships = TopologyUtils.getTargetRelationships(nodeTemplateName, nodeTemplates);
    if (targetRelatedRelationships == null || targetRelatedRelationships.isEmpty()) {
        return false;
    }
    int count = 0;
    for (RelationshipEntry relationshipEntry : targetRelatedRelationships) {
        if (relationshipEntry.getRelationship().getTargetedCapabilityName().equals(capabilityName)) {
            count++;
        }
    }
    return count >= capabilityDefinition.getUpperBound();
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipEntry(org.alien4cloud.tosca.utils.TopologyUtils.RelationshipEntry) NodeType(org.alien4cloud.tosca.model.types.NodeType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition)

Example 99 with NodeType

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

the class TopologyRequirementBoundsValidationServices method isRequirementUpperBoundReachedForSource.

/**
 * Check if the upperBound of a requirement is reached on a node template
 *
 * @param nodeTemplate the node to check for requirement bound
 * @param requirementName the name of the requirement
 * @param dependencies the dependencies of the topology
 * @return true if requirement upper bound is reached, false otherwise
 */
public boolean isRequirementUpperBoundReachedForSource(NodeTemplate nodeTemplate, String requirementName, Set<CSARDependency> dependencies) {
    NodeType relatedIndexedNodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTemplate.getType(), dependencies);
    Requirement requirement = nodeTemplate.getRequirements().get(requirementName);
    if (nodeTemplate.getRelationships() == null || nodeTemplate.getRelationships().isEmpty()) {
        return false;
    }
    RequirementDefinition requirementDefinition = getRequirementDefinition(relatedIndexedNodeType.getRequirements(), requirementName, requirement.getType());
    if (requirementDefinition.getUpperBound() == Integer.MAX_VALUE) {
        return false;
    }
    int count = countRelationshipsForRequirement(nodeTemplate, requirementDefinition);
    return count >= requirementDefinition.getUpperBound();
}
Also used : Requirement(org.alien4cloud.tosca.model.templates.Requirement) NodeTemplateUtils.countRelationshipsForRequirement(org.alien4cloud.tosca.utils.NodeTemplateUtils.countRelationshipsForRequirement) NodeType(org.alien4cloud.tosca.model.types.NodeType) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition)

Example 100 with NodeType

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

the class TopologyTreeBuilderService method getNonNativesNodes.

/**
 * Get the non-natives node of a topology.
 *
 * @param topology
 * @return a Map of non-natives nodes.
 */
@ToscaContextual
public Map<String, NodeTemplate> getNonNativesNodes(Topology topology) {
    Map<String, NodeTemplate> nonNativesNode = new HashMap<>();
    if (topology.getNodeTemplates() != null) {
        for (Entry<String, NodeTemplate> templateEntry : topology.getNodeTemplates().entrySet()) {
            NodeTemplate template = templateEntry.getValue();
            NodeType indexedToscaElement = ToscaContext.getOrFail(NodeType.class, template.getType());
            boolean isCompute = ToscaTypeUtils.isOfType(indexedToscaElement, NormativeComputeConstants.COMPUTE_TYPE);
            boolean isNetwork = ToscaTypeUtils.isOfType(indexedToscaElement, NormativeNetworkConstants.NETWORK_TYPE);
            boolean isVolume = ToscaTypeUtils.isOfType(indexedToscaElement, NormativeBlockStorageConstants.BLOCKSTORAGE_TYPE);
            if (!isCompute && !isNetwork && !isVolume) {
                nonNativesNode.put(templateEntry.getKey(), template);
            }
        }
    }
    return nonNativesNode;
}
Also used : PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) HashMap(java.util.HashMap) NodeType(org.alien4cloud.tosca.model.types.NodeType) ToscaContextual(alien4cloud.tosca.context.ToscaContextual)

Aggregations

NodeType (org.alien4cloud.tosca.model.types.NodeType)156 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)50 Test (org.junit.Test)44 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)26 Set (java.util.Set)26 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)23 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)22 Map (java.util.Map)19 Csar (org.alien4cloud.tosca.model.Csar)19 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)16 HashMap (java.util.HashMap)15 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)15 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)14 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)14 Topology (org.alien4cloud.tosca.model.templates.Topology)9 NotFoundException (alien4cloud.exception.NotFoundException)8 Capability (org.alien4cloud.tosca.model.templates.Capability)8 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)8 MatchingConfiguration (alien4cloud.model.deployment.matching.MatchingConfiguration)7 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)7