use of org.apache.myriad.scheduler.NMProfile 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());
}
}
}
}
use of org.apache.myriad.scheduler.NMProfile 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);
}
use of org.apache.myriad.scheduler.NMProfile 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);
}
Aggregations