Search in sources :

Example 21 with TopologyWrapper

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

the class MinHostsTest method testNoTargetLabelsPresent.

@Test
public void testNoTargetLabelsPresent() throws Exception {
    ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "TargetAllocationMinHostsTest4", false);
    TopologyWrapper topology = new TopologyWrapper(repository.getElement(id).getTopologyTemplate());
    Criteria minHosts = new MinHosts(null, Integer.MAX_VALUE);
    List<String> ntIdsWithoutTargetLabel = topology.getTopLevelNTs().stream().filter(nt -> !ModelUtilities.getTargetLabel(nt).isPresent()).map(HasId::getId).collect(Collectors.toList());
    List<TopologyWrapper> topologies = minHosts.allocate(topology);
    assertEquals(2, topologies.size());
    TTopologyTemplate topology1 = topologies.get(0).getTopology();
    TTopologyTemplate topology2 = topologies.get(1).getTopology();
    assertEquals(17, topology1.getNodeTemplateOrRelationshipTemplate().size());
    assertEquals(17, topology2.getNodeTemplateOrRelationshipTemplate().size());
    List<String> types1 = new ArrayList<>();
    for (TNodeTemplate nodeTemplate : topology1.getNodeTemplates()) {
        types1.add(nodeTemplate.getType().getLocalPart());
    }
    assertEquals(10, types1.size());
    assertEquals(7, types1.stream().filter(type -> type.equalsIgnoreCase("shetland_pony")).count());
    assertEquals(2, types1.stream().filter(type -> type.equalsIgnoreCase("pasture")).count());
    for (TNodeTemplate nodeTemplate : topologies.get(0).getTopLevelNTs()) {
        if (ntIdsWithoutTargetLabel.contains(nodeTemplate.getId())) {
            assertEquals("pasture", topologies.get(0).getHostedOnSuccessor(nodeTemplate).getType().getLocalPart());
        }
    }
    List<String> types2 = new ArrayList<>();
    for (TNodeTemplate nodeTemplate : topology2.getNodeTemplates()) {
        types2.add(nodeTemplate.getType().getLocalPart());
    }
    assertEquals(10, types2.size());
    assertEquals(7, types2.stream().filter(type -> type.equalsIgnoreCase("shetland_pony")).count());
    assertEquals(2, types2.stream().filter(type -> type.equalsIgnoreCase("field_-w1-wip1")).count());
    for (TNodeTemplate nodeTemplate : topologies.get(1).getTopLevelNTs()) {
        if (ntIdsWithoutTargetLabel.contains(nodeTemplate.getId())) {
            assertEquals("field_-w1-wip1", topologies.get(1).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 22 with TopologyWrapper

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

the class FulfillPoliciesTest method testFilter.

@Test
public void testFilter() throws Exception {
    Criteria minConnections = new MinExternalConnections(null, Integer.MAX_VALUE);
    List<TopologyWrapper> topologies = minConnections.allocate(topology);
    if (topologies.size() != 4) {
        LOGGER.debug("Min cut algorithm didn't find all results");
        return;
    }
    boolean rightResultPresent = false;
    for (TopologyWrapper topology : topologies) {
        TTopologyTemplate topologyTemplate = topology.getTopology();
        TNodeTemplate pony3 = topologyTemplate.getNodeTemplate("shetland_pony_3");
        TNodeTemplate pony4 = topologyTemplate.getNodeTemplate("shetland_pony_4");
        if (ModelUtilities.getTargetLabel(pony3).get().equals("PastureProvider") && ModelUtilities.getTargetLabel(pony4).get().equals("FieldProvider")) {
            LOGGER.debug("Right result present");
            rightResultPresent = true;
            break;
        }
    }
    if (!rightResultPresent) {
        LOGGER.debug("Min cut algorithm didn't find needed result");
        return;
    }
    JsonNode params = JacksonProvider.mapper.readTree("{\"policySelection\":[" + "{\"policy\":\"floorwarmth10\",\"property\":\"warmth\",\"operator\":\"min\"}," + "{\"policy\":\"floorwarmth30\",\"property\":\"warmth\",\"operator\":\"max\"}]}");
    Criteria fulfillPolicies = new FulfillPolicies(params, Integer.MAX_VALUE);
    topologies = fulfillPolicies.filter(topologies);
    assertEquals(1, topologies.size());
    TTopologyTemplate allocated = topologies.get(0).getTopology();
    assertEquals(6, allocated.getNodeTemplates().size());
    // set by criteria
    assertEquals("PastureProvider", ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony_3")).get());
    assertEquals("FieldProvider", ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony_4")).get());
    // set by user
    assertEquals("PastureProvider", ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony")).get());
    assertEquals("FieldProvider", ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony_2")).get());
}
Also used : FulfillPolicies(org.eclipse.winery.repository.targetallocation.criteria.fulfillpolicies.FulfillPolicies) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) MinExternalConnections(org.eclipse.winery.repository.targetallocation.criteria.minexternalconnections.MinExternalConnections) JsonNode(com.fasterxml.jackson.databind.JsonNode) Criteria(org.eclipse.winery.repository.targetallocation.Criteria) TopologyWrapper(org.eclipse.winery.repository.targetallocation.util.TopologyWrapper) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Test(org.junit.jupiter.api.Test)

Example 23 with TopologyWrapper

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

the class ConnectsToGraphTest method testCreation.

@Test
public void testCreation() throws GitAPIException {
    setRevisionTo("bb9ff7e08f7b72d30a2fae326740ef8051701671");
    ServiceTemplateId id = new ServiceTemplateId("http://winery.opentosca.org/test/servicetemplates/ponyuniverse/daspecifier", "DASpecificationTest", false);
    TopologyWrapper topology = new TopologyWrapper(repository.getElement(id).getTopologyTemplate());
    assertEquals(5, topology.getNodeTemplates().size());
    assertEquals(4, topology.getRelationshipTemplates().size());
    ConnectsToGraph connectsToGraph = new ConnectsToGraph(topology);
    assertEquals(3, connectsToGraph.getNodes().size());
    assertEquals(2, connectsToGraph.getEdges().size());
}
Also used : TopologyWrapper(org.eclipse.winery.repository.targetallocation.util.TopologyWrapper) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) Test(org.junit.jupiter.api.Test)

Example 24 with TopologyWrapper

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

the class MinExternalConnectionsTest method twoTargetLabelsOnePossibleResult.

@Test
public void twoTargetLabelsOnePossibleResult() throws Exception {
    ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "MinExternalConnectionsTest1", false);
    TopologyWrapper topology = new TopologyWrapper(repository.getElement(id).getTopologyTemplate());
    Criteria minExternalConnections = new MinExternalConnections(null, Integer.MAX_VALUE);
    List<TopologyWrapper> topologies = minExternalConnections.allocate(topology);
    if (topologies.size() != 1) {
        LOGGER.debug("Randomized algorithm didn't find correct results");
        return;
    }
    assertEquals(6, topologies.get(0).getNodeTemplates().size());
}
Also used : 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)

Example 25 with TopologyWrapper

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

the class MinExternalConnectionsTest method performanceTest.

@Test
public void performanceTest() throws Exception {
    ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "MinExternalConnectionsTest2", false);
    TopologyWrapper topology = new TopologyWrapper(repository.getElement(id).getTopologyTemplate());
    Criteria minExternalConnections = new MinExternalConnections(null, Integer.MAX_VALUE);
    List<TopologyWrapper> topologies = minExternalConnections.allocate(topology);
    for (TopologyWrapper allocated : topologies) {
        assertEquals(22, allocated.getNodeTemplates().size());
    }
}
Also used : 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