Search in sources :

Example 1 with FulfillPolicies

use of org.eclipse.winery.repository.targetallocation.criteria.fulfillpolicies.FulfillPolicies in project winery by eclipse.

the class Allocation method getCriteria.

private Criteria getCriteria(AllocationRequest.CriteriaRequest criteriaRequest, int outputCap) throws AllocationException {
    String criteriaType = criteriaRequest.getCriteria();
    JsonNode params = criteriaRequest.getCriteriaParams();
    switch(criteriaType) {
        case "FulfillPolicies":
            return new FulfillPolicies(params, outputCap);
        case "MinHosts":
            return new MinHosts(params, outputCap);
        case "MinExternalConnections":
            return new MinExternalConnections(params, outputCap);
        default:
            throw new AllocationException("Couldn't find criteria: " + criteriaType);
    }
}
Also used : MinHosts(org.eclipse.winery.repository.targetallocation.criteria.minhosts.MinHosts) FulfillPolicies(org.eclipse.winery.repository.targetallocation.criteria.fulfillpolicies.FulfillPolicies) MinExternalConnections(org.eclipse.winery.repository.targetallocation.criteria.minexternalconnections.MinExternalConnections) JsonNode(com.fasterxml.jackson.databind.JsonNode) AllocationException(org.eclipse.winery.repository.exceptions.AllocationException)

Example 2 with FulfillPolicies

use of org.eclipse.winery.repository.targetallocation.criteria.fulfillpolicies.FulfillPolicies in project winery by eclipse.

the class FulfillPoliciesTest method testApprox.

@Test
public void testApprox() throws Exception {
    JsonNode params = JacksonProvider.mapper.readTree("{\"policySelection\":[" + "{\"policy\":\"floorwarmth10\",\"property\":\"warmth\",\"operator\":\"approx\"}," + "{\"policy\":\"floorwarmth30\",\"property\":\"warmth\",\"operator\":\"approx\"}]}");
    Criteria fulfillPolicies = new FulfillPolicies(params, Integer.MAX_VALUE);
    List<TTopologyTemplate> allocatedTopologies = fulfillPolicies.allocate(topology).stream().map(TopologyWrapper::getTopology).collect(Collectors.toList());
    assertEquals(1, allocatedTopologies.size());
    TTopologyTemplate allocated = allocatedTopologies.get(0);
    assertEquals(8, allocated.getNodeTemplates().size());
    // set by criteria
    assertEquals("PastureProvider".toLowerCase(), ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony_3")).get());
    assertEquals("FieldProvider".toLowerCase(), ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony_4")).get());
    // set by user
    assertEquals("PastureProvider".toLowerCase(), ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony")).get());
    assertEquals("FieldProvider".toLowerCase(), 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) JsonNode(com.fasterxml.jackson.databind.JsonNode) Criteria(org.eclipse.winery.repository.targetallocation.Criteria) Test(org.junit.jupiter.api.Test)

Example 3 with FulfillPolicies

use of org.eclipse.winery.repository.targetallocation.criteria.fulfillpolicies.FulfillPolicies in project winery by eclipse.

the class FulfillPoliciesTest method testNotPossible.

@Test
public void testNotPossible() 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);
    Executable executable = () -> fulfillPolicies.allocate(topology);
    assertThrows(AllocationException.class, executable, "");
}
Also used : FulfillPolicies(org.eclipse.winery.repository.targetallocation.criteria.fulfillpolicies.FulfillPolicies) JsonNode(com.fasterxml.jackson.databind.JsonNode) Criteria(org.eclipse.winery.repository.targetallocation.Criteria) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 4 with FulfillPolicies

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

use of org.eclipse.winery.repository.targetallocation.criteria.fulfillpolicies.FulfillPolicies in project winery by eclipse.

the class FulfillPoliciesTest method testMinMax.

@Test
public void testMinMax() throws Exception {
    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);
    List<TTopologyTemplate> allocatedTopologies = fulfillPolicies.allocate(topology).stream().map(TopologyWrapper::getTopology).collect(Collectors.toList());
    assertEquals(1, allocatedTopologies.size());
    TTopologyTemplate allocated = allocatedTopologies.get(0);
    assertEquals(8, allocated.getNodeTemplates().size());
    // set by criteria
    assertEquals("PastureProvider".toLowerCase(), ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony_3")).get());
    assertEquals("FieldProvider".toLowerCase(), ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony_4")).get());
    // set by user
    assertEquals("PastureProvider".toLowerCase(), ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony")).get());
    assertEquals("FieldProvider".toLowerCase(), 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) JsonNode(com.fasterxml.jackson.databind.JsonNode) Criteria(org.eclipse.winery.repository.targetallocation.Criteria) 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