use of org.eclipse.winery.repository.targetallocation.util.TopologyWrapper in project winery by eclipse.
the class MinHostsTest method test5PonyPastureProviderPony2FieldProvider.
@Test
public void test5PonyPastureProviderPony2FieldProvider() throws Exception {
ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "TargetAllocationMinHostsTest5_-w1-wip1", false);
TopologyWrapper topology = new TopologyWrapper(repository.getElement(id).getTopologyTemplate());
ModelUtilities.setTargetLabel(topology.getTopology().getNodeTemplate("shetland_pony"), "PastureProvider");
ModelUtilities.setTargetLabel(topology.getTopology().getNodeTemplate("shetland_pony_2"), "FieldProvider");
Criteria minHosts = new MinHosts(null, Integer.MAX_VALUE);
List<TopologyWrapper> topologies = minHosts.allocate(topology);
assertEquals(2, topologies.size());
TTopologyTemplate allocated1 = topologies.get(0).getTopology();
assertEquals(6, allocated1.getNodeTemplates().size());
assertEquals(3, allocated1.getRelationshipTemplates().size());
TTopologyTemplate allocated2 = topologies.get(1).getTopology();
assertEquals(6, allocated2.getNodeTemplates().size());
assertEquals(3, allocated2.getRelationshipTemplates().size());
assertEquals("PastureProvider".toLowerCase(), ModelUtilities.getTargetLabel(allocated1.getNodeTemplate("shetland_pony")).get());
assertEquals("FieldProvider".toLowerCase(), ModelUtilities.getTargetLabel(allocated1.getNodeTemplate("shetland_pony_2")).get());
assertEquals(2, allocated1.getNodeTemplates().stream().map(ModelUtilities::getTargetLabel).collect(Collectors.toSet()).size());
assertEquals("PastureProvider".toLowerCase(), ModelUtilities.getTargetLabel(allocated2.getNodeTemplate("shetland_pony")).get());
assertEquals("FieldProvider".toLowerCase(), ModelUtilities.getTargetLabel(allocated2.getNodeTemplate("shetland_pony_2")).get());
assertEquals(2, allocated2.getNodeTemplates().stream().map(ModelUtilities::getTargetLabel).collect(Collectors.toSet()).size());
// one topology has shetland_pony_3 on pastureprovider, one on fieldprovider
TNodeTemplate pony3Allocated1 = allocated1.getNodeTemplate("shetland_pony_3");
TNodeTemplate pony3Allocated2 = allocated2.getNodeTemplate("shetland_pony_3");
boolean pony3Provider = (ModelUtilities.getTargetLabel(pony3Allocated1).get().equalsIgnoreCase("PastureProvider") && ModelUtilities.getTargetLabel(pony3Allocated2).get().equalsIgnoreCase("FieldProvider")) || (ModelUtilities.getTargetLabel(pony3Allocated1).get().equalsIgnoreCase("FieldProvider") && ModelUtilities.getTargetLabel(pony3Allocated2).get().equalsIgnoreCase("PastureProvider"));
assertTrue(pony3Provider);
}
use of org.eclipse.winery.repository.targetallocation.util.TopologyWrapper in project winery by eclipse.
the class Allocation method allocate.
public List<ServiceTemplateId> allocate(ServiceTemplateId serviceTemplateId) throws Exception {
AllocationUtils.idCounter = 0;
TopologyWrapper topology = getTopology(serviceTemplateId);
Iterator<Criteria> iterator = criteria.iterator();
Criteria next = iterator.next();
// assign target labels only
if (assignOnly) {
return save(serviceTemplateId, assignOnly(topology, next), "assigned");
}
// allocate
long start = System.currentTimeMillis();
LOGGER.debug("Allocating using " + criteria.getClass().getSimpleName() + " criteria");
List<TopologyWrapper> allocatedTopologies = next.allocate(topology);
LOGGER.debug("Execution time: " + ((System.currentTimeMillis() - start) / 1000d) + "s");
// filter
while (iterator.hasNext()) {
next = iterator.next();
LOGGER.debug("Filtering using " + next.getClass().getSimpleName() + " criteria");
allocatedTopologies = next.filter(allocatedTopologies);
LOGGER.debug("Remaining possible topologies: " + allocatedTopologies.size());
}
return save(serviceTemplateId, allocatedTopologies, "allocated");
}
use of org.eclipse.winery.repository.targetallocation.util.TopologyWrapper in project winery by eclipse.
the class CriteriaCached method allocate.
@Override
public List<TopologyWrapper> allocate(TopologyWrapper topology) throws Exception {
Set<String> originalTopLevelNTIds = topology.getTopLevelNTs().stream().map(HasId::getId).collect(Collectors.toSet());
fragmentsCache = new FragmentsCache(topology.getPresentTargetLabels());
List<TopologyWrapper> generatedTopologies = super.allocate(topology);
// remove NTs that were no top level nts originally but are now because of injection
generatedTopologies.forEach(t -> t.removeNotNeededNTs(originalTopLevelNTIds));
return generatedTopologies;
}
use of org.eclipse.winery.repository.targetallocation.util.TopologyWrapper 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.TopologyWrapper in project winery by eclipse.
the class MinExternalConnections method generateTargetLabelTopologies.
@Override
public List<TopologyWrapper> generateTargetLabelTopologies(TopologyWrapper topology) {
ConnectsToGraph connectsToGraph = new ConnectsToGraph(topology);
KargerMinCutVariation minCut = new KargerMinCutVariation(connectsToGraph);
Set<ConnectsToGraph> minCutGraphs = minCut.computeTargetLabelPartitions();
List<TopologyWrapper> generatedTopologies = new ArrayList<>();
for (ConnectsToGraph minCutGraph : minCutGraphs) {
if (generatedTopologies.size() >= outputCap) {
break;
}
TopologyWrapper clone = new TopologyWrapper(AllocationUtils.deepCopy(topology.getTopology()));
Map<String, TNodeTemplate> topLevelNtsByIds = clone.getTopLevelNtsByIds();
// map merged ConnectsToGraph to topology
for (ConnectsToGraph.Node node : minCutGraph.getNodes()) {
for (String nodeTemplateId : node.getNodeTemplateIds()) {
ModelUtilities.setTargetLabel(topLevelNtsByIds.get(nodeTemplateId), node.getTargetLabel());
}
}
generatedTopologies.add(clone);
}
return generatedTopologies;
}
Aggregations