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());
}
}
}
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());
}
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());
}
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());
}
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());
}
}
Aggregations