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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations