Search in sources :

Example 16 with TopologyWrapper

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

the class KargerMinCutVariationTest method twoTargetLabelsOnePossibleResult.

@Test
public void twoTargetLabelsOnePossibleResult() {
    ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "MinExternalConnectionsTest1", false);
    TopologyWrapper topology = new TopologyWrapper(repository.getElement(id).getTopologyTemplate());
    ConnectsToGraph connectsToGraph = new ConnectsToGraph(topology);
    KargerMinCutVariation kargerMinCutVariation = new KargerMinCutVariation(connectsToGraph);
    List<ConnectsToGraph> results = new ArrayList<>(kargerMinCutVariation.computeTargetLabelPartitions());
    // testing a monte carlo algorithm doesn't always work
    if (results.size() != 1 || results.get(0).getEdges().size() != 1) {
        LOGGER.debug("Monte Carlo Algorithm produced wrong result");
        return;
    }
    assertEquals(results.size(), 1);
    ConnectsToGraph result = results.get(0);
    assertEquals(result.getEdges().size(), 1);
    assertEquals(result.getNodes().size(), 2);
    Set<String> pastureProvider = new HashSet<>(Collections.singletonList("shetland_pony"));
    Set<String> fieldProvider = new HashSet<>(Arrays.asList("shetland_pony_2", "shetland_pony_3", "shetland_pony_4"));
    ConnectsToGraph.Node pastureNode = result.getNodes().stream().filter(node -> node.getTargetLabel().equalsIgnoreCase("PastureProvider")).collect(Collectors.toList()).get(0);
    ConnectsToGraph.Node fieldNode = result.getNodes().stream().filter(node -> node.getTargetLabel().equalsIgnoreCase("FieldProvider")).collect(Collectors.toList()).get(0);
    assertEquals(pastureNode.getNodeTemplateIds(), pastureProvider);
    assertEquals(fieldNode.getNodeTemplateIds(), fieldProvider);
}
Also used : ArrayList(java.util.ArrayList) TopologyWrapper(org.eclipse.winery.repository.targetallocation.util.TopologyWrapper) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 17 with TopologyWrapper

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

the class KargerMinCutVariationTest method performanceTest.

@Test
public void performanceTest() {
    ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "MinExternalConnectionsTest2", false);
    TopologyWrapper topology = new TopologyWrapper(repository.getElement(id).getTopologyTemplate());
    ConnectsToGraph connectsToGraph = new ConnectsToGraph(topology);
    KargerMinCutVariation kargerMinCutVariation = new KargerMinCutVariation(connectsToGraph);
    List<ConnectsToGraph> results = new ArrayList<>(kargerMinCutVariation.computeTargetLabelPartitions());
    // testing a monte carlo algorithm doesn't always work
    if (results.size() != 4 || results.get(0).getEdges().size() != 4) {
        LOGGER.debug("Monte Carlo Algorithm produced wrong result");
        return;
    }
    assertEquals(results.size(), 4);
    assertEquals(results.get(0).getEdges().size(), 4);
    assertEquals(results.get(1).getEdges().size(), 4);
    assertEquals(results.get(2).getEdges().size(), 4);
    assertEquals(results.get(3).getEdges().size(), 4);
}
Also used : ArrayList(java.util.ArrayList) TopologyWrapper(org.eclipse.winery.repository.targetallocation.util.TopologyWrapper) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) Test(org.junit.jupiter.api.Test)

Example 18 with TopologyWrapper

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

the class MinHostsTest method testOneTargetLabelPresent.

@Test
public void testOneTargetLabelPresent() throws Exception {
    ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "TargetAllocationMinHostsTest2", false);
    TopologyWrapper topology = new TopologyWrapper(repository.getElement(id).getTopologyTemplate());
    Criteria minHosts = new MinHosts(null, Integer.MAX_VALUE);
    List<TopologyWrapper> topologies = minHosts.allocate(topology);
    assertEquals(1, topologies.size());
    TTopologyTemplate topology1 = topologies.get(0).getTopology();
    assertEquals(7, topology1.getNodeTemplateOrRelationshipTemplate().size());
    List<String> types1 = new ArrayList<>();
    for (TNodeTemplate nodeTemplate : topology1.getNodeTemplates()) {
        types1.add(nodeTemplate.getType().getLocalPart());
    }
    assertEquals(4, types1.size());
    assertEquals(3, types1.stream().filter(type -> type.equalsIgnoreCase("shetland_pony")).count());
    assertEquals(1, types1.stream().filter(type -> type.equalsIgnoreCase("pasture")).count());
    for (TNodeTemplate nodeTemplate : topologies.get(0).getTopLevelNTs()) {
        assertEquals("pasture", topologies.get(0).getHostedOnSuccessor(nodeTemplate).getType().getLocalPart());
    }
}
Also used : TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) 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 19 with TopologyWrapper

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

the class MinHostsTest method testTwoTargetLabelsPresent.

@Test
public void testTwoTargetLabelsPresent() throws Exception {
    ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "TargetAllocationMinHostsTest3", false);
    TopologyWrapper topology = new TopologyWrapper(repository.getElement(id).getTopologyTemplate());
    Criteria minHosts = new MinHosts(null, Integer.MAX_VALUE);
    List<TopologyWrapper> topologies = minHosts.allocate(topology);
    assertEquals(2, topologies.size());
    TTopologyTemplate topology1 = topologies.get(0).getTopology();
    TTopologyTemplate topology2 = topologies.get(1).getTopology();
    assertEquals(8, topology1.getNodeTemplateOrRelationshipTemplate().size());
    assertEquals(8, topology2.getNodeTemplateOrRelationshipTemplate().size());
    List<String> types1 = new ArrayList<>();
    for (TNodeTemplate nodeTemplate : topology1.getNodeTemplates()) {
        types1.add(nodeTemplate.getType().getLocalPart());
    }
    assertEquals(5, types1.size());
    assertEquals(3, types1.stream().filter(type -> type.equalsIgnoreCase("shetland_pony")).count());
    assertEquals(1, types1.stream().filter(type -> type.equalsIgnoreCase("pasture")).count());
    assertEquals(1, types1.stream().filter(type -> type.equalsIgnoreCase("field_-w1-wip1")).count());
    for (TNodeTemplate nodeTemplate : topologies.get(0).getTopLevelHosts()) {
        List<TNodeTemplate> predecessors = topologies.get(0).getHostedOnPredecessors(nodeTemplate);
        if (nodeTemplate.getType().getLocalPart().equalsIgnoreCase("pasture")) {
            assertEquals(predecessors.size(), 2);
        } else if (nodeTemplate.getType().getLocalPart().equalsIgnoreCase("field")) {
            assertEquals(predecessors.size(), 1);
        }
    }
    List<String> types2 = new ArrayList<>();
    for (TNodeTemplate nodeTemplate : topology2.getNodeTemplates()) {
        types2.add(nodeTemplate.getType().getLocalPart());
    }
    assertEquals(5, types2.size());
    assertEquals(3, types2.stream().filter(type -> type.equalsIgnoreCase("shetland_pony")).count());
    assertEquals(1, types2.stream().filter(type -> type.equalsIgnoreCase("pasture")).count());
    assertEquals(1, types2.stream().filter(type -> type.equalsIgnoreCase("field_-w1-wip1")).count());
    for (TNodeTemplate nodeTemplate : topologies.get(1).getTopLevelHosts()) {
        List<TNodeTemplate> predecessors = topologies.get(1).getHostedOnPredecessors(nodeTemplate);
        if (nodeTemplate.getType().getLocalPart().equalsIgnoreCase("pasture")) {
            assertEquals(predecessors.size(), 1);
        } else if (nodeTemplate.getType().getLocalPart().equalsIgnoreCase("field")) {
            assertEquals(predecessors.size(), 2);
        }
    }
}
Also used : TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) 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 20 with TopologyWrapper

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

the class MinHostsTest method testFilter.

@Test
public void testFilter() throws Exception {
    List<TopologyWrapper> topologies = new ArrayList<>();
    for (int i = 1; i < 5; i++) {
        ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "TargetAllocationMinHostsTest" + i, false);
        topologies.add(new TopologyWrapper(repository.getElement(id).getTopologyTemplate()));
    }
    assertEquals(4, topologies.size());
    Criteria minHosts = new MinHosts(null, Integer.MAX_VALUE);
    List<TopologyWrapper> filtered = minHosts.filter(topologies);
    assertEquals(2, filtered.size());
    assertEquals(5, filtered.get(0).getNodeTemplates().size());
}
Also used : ArrayList(java.util.ArrayList) TopologyWrapper(org.eclipse.winery.repository.targetallocation.util.TopologyWrapper) Criteria(org.eclipse.winery.repository.targetallocation.Criteria) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) Test(org.junit.jupiter.api.Test)

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