use of org.eclipse.winery.repository.targetallocation.Criteria 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);
}
}
}
use of org.eclipse.winery.repository.targetallocation.Criteria 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());
}
use of org.eclipse.winery.repository.targetallocation.Criteria 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.Criteria 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.Criteria 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());
}
Aggregations