Search in sources :

Example 11 with TopologyWrapper

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);
}
Also used : TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) TopologyWrapper(org.eclipse.winery.repository.targetallocation.util.TopologyWrapper) Criteria(org.eclipse.winery.repository.targetallocation.Criteria) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Test(org.junit.jupiter.api.Test)

Example 12 with TopologyWrapper

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");
}
Also used : TopologyWrapper(org.eclipse.winery.repository.targetallocation.util.TopologyWrapper)

Example 13 with TopologyWrapper

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;
}
Also used : FragmentsCache(org.eclipse.winery.repository.targetallocation.util.FragmentsCache) TopologyWrapper(org.eclipse.winery.repository.targetallocation.util.TopologyWrapper)

Example 14 with TopologyWrapper

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;
}
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 15 with TopologyWrapper

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;
}
Also used : ArrayList(java.util.ArrayList) TopologyWrapper(org.eclipse.winery.repository.targetallocation.util.TopologyWrapper) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate)

Aggregations

TopologyWrapper (org.eclipse.winery.repository.targetallocation.util.TopologyWrapper)25 Test (org.junit.jupiter.api.Test)16 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)15 ArrayList (java.util.ArrayList)13 Criteria (org.eclipse.winery.repository.targetallocation.Criteria)13 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)11 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)9 List (java.util.List)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 FulfillPolicies (org.eclipse.winery.repository.targetallocation.criteria.fulfillpolicies.FulfillPolicies)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)1 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)1 MinExternalConnections (org.eclipse.winery.repository.targetallocation.criteria.minexternalconnections.MinExternalConnections)1 FragmentsCache (org.eclipse.winery.repository.targetallocation.util.FragmentsCache)1 PermutationHelper (org.eclipse.winery.repository.targetallocation.util.PermutationHelper)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1