Search in sources :

Example 1 with ExtendedResourceProfile

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

the class Main method initProfiles.

private void initProfiles(Injector injector) {
    LOGGER.info("Initializing Profiles");
    ServiceProfileManager profileManager = injector.getInstance(ServiceProfileManager.class);
    Map<String, Map<String, String>> profiles = injector.getInstance(MyriadConfiguration.class).getProfiles();
    TaskUtils taskUtils = injector.getInstance(TaskUtils.class);
    if (MapUtils.isNotEmpty(profiles)) {
        for (Map.Entry<String, Map<String, String>> profile : profiles.entrySet()) {
            Map<String, String> profileResourceMap = profile.getValue();
            if (MapUtils.isNotEmpty(profiles) && profileResourceMap.containsKey("cpu") && profileResourceMap.containsKey("mem")) {
                Long cpu = Long.parseLong(profileResourceMap.get("cpu"));
                Long mem = Long.parseLong(profileResourceMap.get("mem"));
                ServiceResourceProfile serviceProfile = new ExtendedResourceProfile(new NMProfile(profile.getKey(), cpu, mem), taskUtils.getNodeManagerCpus(), taskUtils.getNodeManagerMemory(), taskUtils.getNodeManagerPorts());
                profileManager.add(serviceProfile);
            } else {
                LOGGER.error("Invalid definition for profile: " + profile.getKey());
            }
        }
    }
}
Also used : ServiceProfileManager(org.apache.myriad.scheduler.ServiceProfileManager) ExtendedResourceProfile(org.apache.myriad.scheduler.ExtendedResourceProfile) TaskUtils(org.apache.myriad.scheduler.TaskUtils) NMProfile(org.apache.myriad.scheduler.NMProfile) MyriadConfiguration(org.apache.myriad.configuration.MyriadConfiguration) ServiceResourceProfile(org.apache.myriad.scheduler.ServiceResourceProfile) Map(java.util.Map)

Example 2 with ExtendedResourceProfile

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

the class TestResourceOfferContainer method testResouceOfferContainerForNMWithOutRole.

@Test
public void testResouceOfferContainerForNMWithOutRole() {
    Protos.Offer offer = new OfferBuilder("test.com").addScalarResource("cpus", 4.0).addScalarResource("mem", 8000).addRangeResource("ports", 3500, 3600).build();
    Map<String, Long> ports = new HashMap<>(4);
    ports.put("test1.address", 0L);
    ports.put("test2.address", 0L);
    ports.put("test3.address", 0L);
    ports.put("test4.port", 3501L);
    ServiceResourceProfile profile1 = new ExtendedResourceProfile(new NMProfile("small", 2L, 6000L), .2, 1024.0, ports);
    ResourceOfferContainer roc = new ResourceOfferContainer(offer, profile1, "");
    System.out.print(roc.getCpus());
    System.out.print(roc.getMem());
    System.out.print(roc.getPorts());
    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, "");
    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, "");
    assertFalse("Should be unsatisfied if too much memory requested", roc.satisfies(profile3));
    ports.put("test.bad.address", 1500L);
    ServiceResourceProfile profile4 = new ExtendedResourceProfile(new NMProfile("portOutOfRange", 3L, 50000L), .2, 1024.0, ports);
    roc = new ResourceOfferContainer(offer, profile4, "");
    assertFalse("Should be unsatisfied if port not in range", roc.satisfies(profile4));
    List<Protos.Resource> resourcesCpu = roc.consumeCpus(3.0);
    assertTrue("Should get a list of resources of size 1", resourcesCpu.size() == 1.0);
    assertTrue("Cpus should be decreased", roc.getCpus() == 1.0);
    List<Protos.Resource> resourcesMem = roc.consumeMem(7000.0);
    assertTrue("Should get a list of resources of size 1", resourcesMem.size() == 1);
    assertTrue("Mem should be decreased", roc.getMem() == 1000.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)

Example 3 with ExtendedResourceProfile

use of org.apache.myriad.scheduler.ExtendedResourceProfile 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

ExtendedResourceProfile (org.apache.myriad.scheduler.ExtendedResourceProfile)3 NMProfile (org.apache.myriad.scheduler.NMProfile)3 ServiceResourceProfile (org.apache.myriad.scheduler.ServiceResourceProfile)3 HashMap (java.util.HashMap)2 Protos (org.apache.mesos.Protos)2 OfferBuilder (org.apache.myriad.scheduler.offer.OfferBuilder)2 Test (org.junit.Test)2 Map (java.util.Map)1 MyriadConfiguration (org.apache.myriad.configuration.MyriadConfiguration)1 ServiceProfileManager (org.apache.myriad.scheduler.ServiceProfileManager)1 TaskUtils (org.apache.myriad.scheduler.TaskUtils)1