Search in sources :

Example 51 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId 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 52 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId 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 53 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId 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)

Example 54 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId 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 55 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class TopologyMappingsWrapperTest method removeNotNeededSuccessors.

@Test
public void removeNotNeededSuccessors() {
    ServiceTemplateId policiesIO = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates", "TargetAllocationMinHostsTest1", false);
    TopologyWrapper topology = new TopologyWrapper(repository.getElement(policiesIO).getTopologyTemplate());
    assertEquals(9, topology.getNodeTemplates().size());
    topology.removeNotNeededSuccessors(topology.getTopology().getNodeTemplate("shetland_pony"));
    assertEquals(7, topology.getNodeTemplates().size());
    assertEquals(4, topology.getRelationshipTemplates().size());
}
Also used : ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) Test(org.junit.jupiter.api.Test)

Aggregations

ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)126 Test (org.junit.jupiter.api.Test)73 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)44 ArrayList (java.util.ArrayList)41 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)40 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)35 QName (javax.xml.namespace.QName)25 IOException (java.io.IOException)24 IRepository (org.eclipse.winery.repository.backend.IRepository)19 List (java.util.List)17 POST (javax.ws.rs.POST)17 Path (javax.ws.rs.Path)16 Produces (javax.ws.rs.Produces)16 HashMap (java.util.HashMap)15 TopologyWrapper (org.eclipse.winery.repository.targetallocation.util.TopologyWrapper)15 Map (java.util.Map)14 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)14 URI (java.net.URI)13 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)13 TNodeType (org.eclipse.winery.model.tosca.TNodeType)13