Search in sources :

Example 1 with SuggestionsTask

use of alien4cloud.topology.task.SuggestionsTask in project alien4cloud by alien4cloud.

the class TopologyService method findReplacementForNode.

/**
 * Find replacements nodes for a node template
 *
 * @param nodeTemplateName the node to search for replacements
 * @param topology the topology
 * @return all possible replacement types for this node
 */
@SneakyThrows(IOException.class)
public NodeType[] findReplacementForNode(String nodeTemplateName, Topology topology) {
    NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeTemplateName);
    Map<String, Map<String, Set<String>>> nodeTemplatesToFilters = Maps.newHashMap();
    Entry<String, NodeTemplate> nodeTempEntry = Maps.immutableEntry(nodeTemplateName, nodeTemplate);
    NodeType indexedNodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTemplate.getType(), topology.getDependencies());
    processNodeTemplate(topology, nodeTempEntry, nodeTemplatesToFilters);
    List<SuggestionsTask> topoTasks = searchForNodeTypes(topology.getWorkspace(), nodeTemplatesToFilters, MapUtil.newHashMap(new String[] { nodeTemplateName }, new NodeType[] { indexedNodeType }), false);
    if (CollectionUtils.isEmpty(topoTasks)) {
        return null;
    }
    return removeDuplicatedNodeTypeForReplacement(indexedNodeType.getElementId(), topoTasks.get(0).getSuggestedNodeTypes());
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) SuggestionsTask(alien4cloud.topology.task.SuggestionsTask) Map(java.util.Map) SneakyThrows(lombok.SneakyThrows)

Example 2 with SuggestionsTask

use of alien4cloud.topology.task.SuggestionsTask 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)

Aggregations

SuggestionsTask (alien4cloud.topology.task.SuggestionsTask)2 Map (java.util.Map)2 NodeType (org.alien4cloud.tosca.model.types.NodeType)2 TaskCode (alien4cloud.topology.task.TaskCode)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 SneakyThrows (lombok.SneakyThrows)1 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)1 FilterValuesStrategy (org.elasticsearch.mapping.FilterValuesStrategy)1