Search in sources :

Example 6 with TopologyWrapper

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

the class FulfillPoliciesTest method setUp.

@BeforeEach
public void setUp() throws GitAPIException {
    setRevisionTo("bb9ff7e08f7b72d30a2fae326740ef8051701671");
    ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "TargetAllocationFulfillPoliciesTest1", false);
    topology = new TopologyWrapper(repository.getElement(id).getTopologyTemplate());
}
Also used : TopologyWrapper(org.eclipse.winery.repository.targetallocation.util.TopologyWrapper) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with TopologyWrapper

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

the class FulfillPoliciesTest method testSimpleOperators.

@Test
public void testSimpleOperators() throws Exception {
    JsonNode params = JacksonProvider.mapper.readTree("{\"policySelection\":[" + "{\"policy\":\"floorwarmth10\",\"property\":\"warmth\",\"operator\":\">\"}," + "{\"policy\":\"floorwarmth30\",\"property\":\"warmth\",\"operator\":\"<\"}]}");
    Criteria fulfillPolicies = new FulfillPolicies(params, Integer.MAX_VALUE);
    List<TopologyWrapper> allocatedTopologies = fulfillPolicies.allocate(topology);
    assertEquals(4, allocatedTopologies.size());
    TopologyWrapper allocated1 = allocatedTopologies.get(0);
    TopologyWrapper allocated2 = allocatedTopologies.get(1);
    TopologyWrapper allocated3 = allocatedTopologies.get(2);
    TopologyWrapper allocated4 = allocatedTopologies.get(3);
    assertEquals(8, allocated1.getNodeTemplates().size());
    assertEquals(8, allocated2.getNodeTemplates().size());
    assertEquals(8, allocated3.getNodeTemplates().size());
    assertEquals(8, allocated4.getNodeTemplates().size());
    List<String> targetLabels1 = getTargetLabels(allocated1);
    List<String> targetLabels2 = getTargetLabels(allocated2);
    List<String> targetLabels3 = getTargetLabels(allocated3);
    List<String> targetLabels4 = getTargetLabels(allocated4);
    assertEquals(3, targetLabels1.stream().filter("PastureProvider"::equalsIgnoreCase).count());
    assertEquals(1, targetLabels1.stream().filter("FieldProvider"::equalsIgnoreCase).count());
    assertEquals(2, targetLabels2.stream().filter("PastureProvider"::equalsIgnoreCase).count());
    assertEquals(2, targetLabels2.stream().filter("FieldProvider"::equalsIgnoreCase).count());
    assertEquals(2, targetLabels3.stream().filter("PastureProvider"::equalsIgnoreCase).count());
    assertEquals(2, targetLabels3.stream().filter("FieldProvider"::equalsIgnoreCase).count());
    assertEquals(1, targetLabels4.stream().filter("PastureProvider"::equalsIgnoreCase).count());
    assertEquals(3, targetLabels4.stream().filter("FieldProvider"::equalsIgnoreCase).count());
}
Also used : FulfillPolicies(org.eclipse.winery.repository.targetallocation.criteria.fulfillpolicies.FulfillPolicies) JsonNode(com.fasterxml.jackson.databind.JsonNode) Criteria(org.eclipse.winery.repository.targetallocation.Criteria) TopologyWrapper(org.eclipse.winery.repository.targetallocation.util.TopologyWrapper) Test(org.junit.jupiter.api.Test)

Example 8 with TopologyWrapper

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

the class MinHostsTest method test5Pony3FieldProvider.

@Test
public void test5Pony3FieldProvider() 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_3"), "FieldProvider");
    Criteria minHosts = new MinHosts(null, Integer.MAX_VALUE);
    List<TopologyWrapper> topologies = minHosts.allocate(topology);
    assertEquals(1, topologies.size());
    TTopologyTemplate allocated = topologies.get(0).getTopology();
    assertEquals(6, allocated.getNodeTemplates().size());
    assertEquals(4, allocated.getRelationshipTemplates().size());
    assertEquals("LargeStallProvider".toLowerCase(), ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony")).get());
    assertEquals("LargeStallProvider".toLowerCase(), ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony_2")).get());
    assertEquals("FieldProvider".toLowerCase(), ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony_3")).get());
    assertEquals(2, allocated.getNodeTemplates().stream().map(ModelUtilities::getTargetLabel).collect(Collectors.toSet()).size());
}
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) Test(org.junit.jupiter.api.Test)

Example 9 with TopologyWrapper

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

the class MinHostsTest method test5Original.

@Test
public void test5Original() 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());
    Criteria minHosts = new MinHosts(null, Integer.MAX_VALUE);
    List<TopologyWrapper> topologies = minHosts.allocate(topology);
    assertEquals(1, topologies.size());
    TTopologyTemplate allocated = topologies.get(0).getTopology();
    assertEquals(6, allocated.getNodeTemplates().size());
    assertEquals(5, allocated.getRelationshipTemplates().size());
    assertEquals("LargeStallProvider".toLowerCase(), ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony")).get());
    assertEquals("LargeStallProvider".toLowerCase(), ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony_2")).get());
    assertEquals("LargeStallProvider".toLowerCase(), ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony_3")).get());
    assertEquals(1, allocated.getNodeTemplates().stream().map(ModelUtilities::getTargetLabel).collect(Collectors.toSet()).size());
}
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) Test(org.junit.jupiter.api.Test)

Example 10 with TopologyWrapper

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

the class MinHostsTest method testOneTopLevelTwoPossibilitiesNoTargetLabel.

@Test
public void testOneTopLevelTwoPossibilitiesNoTargetLabel() throws Exception {
    ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "TargetAllocationMinHostsTest1", 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(9, topology1.getNodeTemplateOrRelationshipTemplate().size());
    assertEquals(9, topology2.getNodeTemplateOrRelationshipTemplate().size());
    List<String> types1 = new ArrayList<>();
    for (TNodeTemplate nodeTemplate : topology1.getNodeTemplates()) {
        types1.add(nodeTemplate.getType().getLocalPart());
    }
    assertEquals(6, types1.size());
    assertTrue(types1.contains("shetland_pony"));
    assertTrue(types1.contains("pasture"));
    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(6, types2.size());
    assertTrue(types2.contains("shetland_pony"));
    assertTrue(types2.contains("field_-w1-wip1"));
    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)

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