Search in sources :

Example 6 with OfferBuilder

use of org.apache.myriad.scheduler.offer.OfferBuilder in project incubator-myriad by apache.

the class TestResourceOfferContainer method testResouceOfferContainerForNMWithRole.

@Test
public void testResouceOfferContainerForNMWithRole() {
    Protos.Offer offer = new OfferBuilder("test.com").addScalarResource("cpus", 2.0).addScalarResource("mem", 8000).addScalarResource("cpus", "test", 4.0).addScalarResource("mem", "test", 32000.0).addRangeResource("ports", 3500, 3600).addRangeResource("ports", "test", 1500, 1600).build();
    Map<String, Long> ports = new HashMap<>(4);
    ports.put("test1.address", 0L);
    ports.put("test2.address", 0L);
    ports.put("test3.address", 1500L);
    ports.put("test4.port", 3502L);
    ServiceResourceProfile profile1 = new ExtendedResourceProfile(new NMProfile("small", 2L, 8000L), .2, 1024.0, ports);
    ResourceOfferContainer roc = new ResourceOfferContainer(offer, profile1, "test");
    assertTrue(roc.getHostName().equals("test.com"));
    assertTrue("Should be satisfied if offer contains request", roc.satisfies(profile1));
    ServiceResourceProfile profile2 = new ExtendedResourceProfile(new NMProfile("tooMuchCpu", 7L, 8000L), .2, 1024.0, ports);
    roc = new ResourceOfferContainer(offer, profile2, "test");
    assertFalse("Should be unsatisfied if too much cpu requested", roc.satisfies(profile2));
    ServiceResourceProfile profile3 = new ExtendedResourceProfile(new NMProfile("tooMuchMem", 3L, 50000L), .2, 1024.0, ports);
    roc = new ResourceOfferContainer(offer, profile3, "test");
    assertFalse("Should be unsatisfied if too much memory requested", roc.satisfies(profile3));
    ports.put("test.bad.address", 32000L);
    ServiceResourceProfile profile4 = new ExtendedResourceProfile(new NMProfile("portOutOfRange", 3L, 50000L), .2, 1024.0, ports);
    roc = new ResourceOfferContainer(offer, profile4, "test");
    assertFalse("Should be unsatisfied if port not in range", roc.satisfies(profile4));
    List<Protos.Resource> resources = roc.consumeCpus(4.5);
    assertTrue("Resource List should be of size to when requesting 4.1 cpus", (resources.size() == 2));
    assertTrue("Cpus should be decreased", roc.getCpus() <= 1.5);
    List<Protos.Resource> resources1 = roc.consumeCpus(1.5);
    assertTrue("Resource List should be of size 1", resources1.size() == 1);
    assertTrue("All cpu resources should be consumed", roc.getCpus() <= 0.0);
}
Also used : ExtendedResourceProfile(org.apache.myriad.scheduler.ExtendedResourceProfile) HashMap(java.util.HashMap) OfferBuilder(org.apache.myriad.scheduler.offer.OfferBuilder) NMProfile(org.apache.myriad.scheduler.NMProfile) Protos(org.apache.mesos.Protos) ServiceResourceProfile(org.apache.myriad.scheduler.ServiceResourceProfile) Test(org.junit.Test)

Aggregations

Protos (org.apache.mesos.Protos)6 OfferBuilder (org.apache.myriad.scheduler.offer.OfferBuilder)6 Test (org.junit.Test)6 HashMap (java.util.HashMap)4 ServiceResourceProfile (org.apache.myriad.scheduler.ServiceResourceProfile)4 BaseConfigurableTest (org.apache.myriad.BaseConfigurableTest)2 ExtendedResourceProfile (org.apache.myriad.scheduler.ExtendedResourceProfile)2 NMProfile (org.apache.myriad.scheduler.NMProfile)2 ResourceOfferContainer (org.apache.myriad.scheduler.resource.ResourceOfferContainer)2 NodeTask (org.apache.myriad.state.NodeTask)2 ServiceConfiguration (org.apache.myriad.configuration.ServiceConfiguration)1