Search in sources :

Example 6 with FulfillPolicies

use of org.eclipse.winery.repository.targetallocation.criteria.fulfillpolicies.FulfillPolicies 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)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)6 FulfillPolicies (org.eclipse.winery.repository.targetallocation.criteria.fulfillpolicies.FulfillPolicies)6 Criteria (org.eclipse.winery.repository.targetallocation.Criteria)5 Test (org.junit.jupiter.api.Test)5 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)3 MinExternalConnections (org.eclipse.winery.repository.targetallocation.criteria.minexternalconnections.MinExternalConnections)2 TopologyWrapper (org.eclipse.winery.repository.targetallocation.util.TopologyWrapper)2 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)1 AllocationException (org.eclipse.winery.repository.exceptions.AllocationException)1 MinHosts (org.eclipse.winery.repository.targetallocation.criteria.minhosts.MinHosts)1 Executable (org.junit.jupiter.api.function.Executable)1