Search in sources :

Example 1 with PermutationHelper

use of org.eclipse.winery.repository.targetallocation.util.PermutationHelper in project winery by eclipse.

the class CriteriaCached method getPermutations.

@Override
protected List<List<PermutationHelper>> getPermutations(List<List<PermutationHelper>> possibilities) {
    int generated = amountAllocated;
    // first permutation: determine where to inject nts
    List<List<PermutationHelper>> permutationsWithDuplicates = AllocationUtils.getPermutations(possibilities, outputCap - generated);
    List<List<PermutationHelper>> permutations = new ArrayList<>();
    for (List<PermutationHelper> permutation : permutationsWithDuplicates) {
        // duplicates can be present because topology was traversed from top level nts independently
        Set<PermutationHelper> removeDuplicates = new HashSet<>(permutation);
        List<List<PermutationHelper>> newPossibilities = new ArrayList<>();
        for (PermutationHelper permutationHelper : removeDuplicates) {
            List<PermutationHelper> possibility = new ArrayList<>();
            for (TTopologyTemplate replacement : permutationHelper.getReplacements()) {
                possibility.add(new PermutationHelper(permutationHelper.getCorrespondingNT(), replacement));
            }
            newPossibilities.add(possibility);
        }
        // second permutation: get actual injections
        List<List<PermutationHelper>> generatedPermutations = AllocationUtils.getPermutations(newPossibilities, outputCap - generated);
        generated += generatedPermutations.size();
        permutations.addAll(generatedPermutations);
    }
    return permutations;
}
Also used : PermutationHelper(org.eclipse.winery.repository.targetallocation.util.PermutationHelper) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Example 2 with PermutationHelper

use of org.eclipse.winery.repository.targetallocation.util.PermutationHelper in project winery by eclipse.

the class CriteriaCached method toInjectParameter.

@Override
protected Map<String, TTopologyTemplate> toInjectParameter(TopologyWrapper topology, List<PermutationHelper> permutation) {
    Map<String, TTopologyTemplate> injectParameter = new HashMap<>();
    Map<PermutationHelper, TNodeTemplate> successors = new HashMap<>();
    List<PermutationHelper> done = new ArrayList<>();
    // check predecessors of successors of nts to replace to see which nts should be hosted together
    for (PermutationHelper possibility : permutation) {
        TNodeTemplate successor = topology.getHostedOnSuccessor(possibility.getCorrespondingNT());
        if (successor == null) {
            // no successor -> no check needed
            injectParameter.put(possibility.getCorrespondingNT().getId(), possibility.getReplacement());
        } else {
            successors.put(possibility, successor);
        }
    }
    // group nts that should be hosted together
    for (Map.Entry<PermutationHelper, TNodeTemplate> entry : successors.entrySet()) {
        List<PermutationHelper> hostTogether = new ArrayList<>();
        for (Map.Entry<PermutationHelper, TNodeTemplate> entry2 : successors.entrySet()) {
            if (entry.getKey().getReplacement().equals(entry2.getKey().getReplacement()) && entry.getValue().equals(entry2.getValue()) && !done.contains(entry2.getKey())) {
                hostTogether.add(entry2.getKey());
            }
        }
        // the same matching nt is injected for all nts that should be hosted together
        TTopologyTemplate replacement = AllocationUtils.deepCopy(entry.getKey().getReplacement());
        for (PermutationHelper permutationHelper : hostTogether) {
            injectParameter.put(permutationHelper.getCorrespondingNT().getId(), replacement);
            done.add(permutationHelper);
        }
    }
    return injectParameter;
}
Also used : PermutationHelper(org.eclipse.winery.repository.targetallocation.util.PermutationHelper) HashMap(java.util.HashMap) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with PermutationHelper

use of org.eclipse.winery.repository.targetallocation.util.PermutationHelper in project winery by eclipse.

the class CriteriaCommon method generateTopologies.

/**
 * Creates possible topologies with injected matching PaaS fragments.
 */
private List<TopologyWrapper> generateTopologies(List<TopologyWrapper> topologies) throws Exception {
    List<TopologyWrapper> allGenerated = new ArrayList<>();
    for (TopologyWrapper topology : topologies) {
        List<List<PermutationHelper>> possibilities = getPossibleMatches(topology);
        if (possibilities.isEmpty()) {
            logger.debug("No matching fragments found for this target label topology, trying next one...");
            continue;
        }
        List<List<PermutationHelper>> permutations = getPermutations(possibilities);
        List<TopologyWrapper> generated = new ArrayList<>();
        for (List<PermutationHelper> permutation : permutations) {
            TTopologyTemplate newTopologyTemplate = AllocationUtils.deepCopy(topology.getTopology());
            Map<String, TTopologyTemplate> injectParameter = toInjectParameter(topology, permutation);
            newTopologyTemplate = splitting.injectNodeTemplates(newTopologyTemplate, injectParameter, injectRemoval);
            TopologyWrapper newTopology = new TopologyWrapper(newTopologyTemplate);
            generated.add(newTopology);
        }
        allGenerated.addAll(generated);
        amountAllocated += generated.size();
    }
    return allGenerated;
}
Also used : PermutationHelper(org.eclipse.winery.repository.targetallocation.util.PermutationHelper) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TopologyWrapper(org.eclipse.winery.repository.targetallocation.util.TopologyWrapper)

Example 4 with PermutationHelper

use of org.eclipse.winery.repository.targetallocation.util.PermutationHelper in project winery by eclipse.

the class FulfillPolicies method generateTargetLabelTopologies.

@Override
public List<TopologyWrapper> generateTargetLabelTopologies(TopologyWrapper topology) throws AllocationException {
    if (fragmentsCache == null) {
        fragmentsCache = new FragmentsCache(topology.getPresentTargetLabels());
    }
    Map<TNodeTemplate, Set<String>> possibleTargetLabels = assignTargetLabels(topology);
    List<List<PermutationHelper>> possibilities = new ArrayList<>();
    for (Map.Entry<TNodeTemplate, Set<String>> entry : possibleTargetLabels.entrySet()) {
        List<PermutationHelper> possibility = new ArrayList<>();
        for (String targetLabel : entry.getValue()) {
            possibility.add(new PermutationHelper(entry.getKey(), targetLabel));
        }
        possibilities.add(possibility);
    }
    List<List<PermutationHelper>> permutations = AllocationUtils.getPermutations(possibilities, outputCap);
    return AllocationUtils.generateTargetLabelTopologies(topology, permutations);
}
Also used : PermutationHelper(org.eclipse.winery.repository.targetallocation.util.PermutationHelper) Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) FragmentsCache(org.eclipse.winery.repository.targetallocation.util.FragmentsCache) ArrayList(java.util.ArrayList) List(java.util.List) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with PermutationHelper

use of org.eclipse.winery.repository.targetallocation.util.PermutationHelper in project winery by eclipse.

the class FulfillPolicies method getPossibleMatches.

@Override
protected List<List<PermutationHelper>> getPossibleMatches(TopologyWrapper topology) throws Exception {
    List<List<PermutationHelper>> possibilities = new ArrayList<>();
    Map<TNodeTemplate, List<PolicyWrapper>> policiesForNTs = getPoliciesForNTs(topology, params);
    for (TNodeTemplate topLevelNT : topology.getTopLevelNTs()) {
        // get matching fragments
        Map<TNodeTemplate, List<TTopologyTemplate>> fragments = fragmentsCache.getAllMatchingFragments(topology, topLevelNT);
        // remove matching fragments that don't fulfill the policies
        List<TTopologyTemplate> allFragments = fragments.values().stream().flatMap(List::stream).collect(Collectors.toList());
        List<TTopologyTemplate> fragmentsFulfilling = new PolicyComparison(policiesForNTs.get(topLevelNT), allFragments).getFragmentsFulfillingPolicies();
        Map<TNodeTemplate, List<TTopologyTemplate>> fragmentsFulfillingPoliciesWithNTs = mapFragmentsByNTs(fragments, fragmentsFulfilling);
        List<PermutationHelper> possibility = new ArrayList<>();
        for (Map.Entry<TNodeTemplate, List<TTopologyTemplate>> entry : fragmentsFulfillingPoliciesWithNTs.entrySet()) {
            possibility.add(new PermutationHelper(entry.getKey(), entry.getValue()));
        }
        possibilities.add(possibility);
    }
    return possibilities;
}
Also used : PermutationHelper(org.eclipse.winery.repository.targetallocation.util.PermutationHelper) ArrayList(java.util.ArrayList) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) List(java.util.List) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ArrayList (java.util.ArrayList)8 PermutationHelper (org.eclipse.winery.repository.targetallocation.util.PermutationHelper)8 List (java.util.List)7 Map (java.util.Map)6 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)6 HashMap (java.util.HashMap)5 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)5 HashSet (java.util.HashSet)3 Set (java.util.Set)2 AllocationException (org.eclipse.winery.repository.exceptions.AllocationException)1 FragmentsCache (org.eclipse.winery.repository.targetallocation.util.FragmentsCache)1 TopologyWrapper (org.eclipse.winery.repository.targetallocation.util.TopologyWrapper)1