NumaResourceAllocator { public synchronized NumaResourceAllocation allocateNumaNodes( Container container) throws ResourceHandlerException { NumaResourceAllocation allocation = allocate(container.getContainerId(), container.getResource()); if (allocation != null) { try { context.getNMStateStore().storeAssignedResources(container, NUMA_RESOURCE_TYPE, Arrays.asList(allocation)); } catch (IOException e) { releaseNumaResource(container.getContainerId()); throw new ResourceHandlerException(e); } } return allocation; } NumaResourceAllocator(Context context); void init(Configuration conf); synchronized NumaResourceAllocation allocateNumaNodes(
      Container container); synchronized void releaseNumaResource(ContainerId containerId); synchronized void recoverNumaResource(ContainerId containerId);  }
@Test public void testAllocateNumaNode() throws Exception { NumaResourceAllocation nodeInfo = numaResourceAllocator .allocateNumaNodes(getContainer( ContainerId.fromString("container_1481156246874_0001_01_000001"), Resource.newInstance(2048, 2))); Assert.assertEquals("0", String.join(",", nodeInfo.getMemNodes())); Assert.assertEquals("0", String.join(",", nodeInfo.getCpuNodes())); }
@Test public void testAllocateNumaNodeWithRoundRobinFashionAssignment() throws Exception { NumaResourceAllocation nodeInfo1 = numaResourceAllocator .allocateNumaNodes(getContainer( ContainerId.fromString("container_1481156246874_0001_01_000001"), Resource.newInstance(2048, 2))); Assert.assertEquals("0", String.join(",", nodeInfo1.getMemNodes())); Assert.assertEquals("0", String.join(",", nodeInfo1.getCpuNodes())); NumaResourceAllocation nodeInfo2 = numaResourceAllocator .allocateNumaNodes(getContainer( ContainerId.fromString("container_1481156246874_0001_01_000002"), Resource.newInstance(2048, 2))); Assert.assertEquals("1", String.join(",", nodeInfo2.getMemNodes())); Assert.assertEquals("1", String.join(",", nodeInfo2.getCpuNodes())); NumaResourceAllocation nodeInfo3 = numaResourceAllocator .allocateNumaNodes(getContainer( ContainerId.fromString("container_1481156246874_0001_01_000003"), Resource.newInstance(2048, 2))); Assert.assertEquals("0", String.join(",", nodeInfo3.getMemNodes())); Assert.assertEquals("0", String.join(",", nodeInfo3.getCpuNodes())); NumaResourceAllocation nodeInfo4 = numaResourceAllocator .allocateNumaNodes(getContainer( ContainerId.fromString("container_1481156246874_0001_01_000003"), Resource.newInstance(2048, 2))); Assert.assertEquals("1", String.join(",", nodeInfo4.getMemNodes())); Assert.assertEquals("1", String.join(",", nodeInfo4.getCpuNodes())); }
@Test public void testAllocateNumaNodeWithMultipleNodesForMemory() throws Exception { NumaResourceAllocation nodeInfo = numaResourceAllocator .allocateNumaNodes(getContainer( ContainerId.fromString("container_1481156246874_0001_01_000001"), Resource.newInstance(102400, 2))); Assert.assertEquals("0,1", String.join(",", nodeInfo.getMemNodes())); Assert.assertEquals("0", String.join(",", nodeInfo.getCpuNodes())); }
@Test public void testAllocateNumaNodeWithMultipleNodesForCpus() throws Exception { NumaResourceAllocation nodeInfo = numaResourceAllocator .allocateNumaNodes(getContainer( ContainerId.fromString("container_1481156246874_0001_01_000001"), Resource.newInstance(2048, 6))); Assert.assertEquals("0", String.join(",", nodeInfo.getMemNodes())); Assert.assertEquals("0,1", String.join(",", nodeInfo.getCpuNodes())); }
@Test public void testAllocateNumaNodeWhenNoNumaMemResourcesAvailable() throws Exception { NumaResourceAllocation nodeInfo = numaResourceAllocator .allocateNumaNodes(getContainer( ContainerId.fromString("container_1481156246874_0001_01_000001"), Resource.newInstance(2048000, 6))); Assert.assertNull("Should not assign numa nodes when there" + " are no sufficient memory resources available.", nodeInfo); }
@Test public void testAllocateNumaNodeWhenNoNumaCpuResourcesAvailable() throws Exception { NumaResourceAllocation nodeInfo = numaResourceAllocator .allocateNumaNodes(getContainer( ContainerId.fromString("container_1481156246874_0001_01_000001"), Resource.newInstance(2048, 600))); Assert.assertNull("Should not assign numa nodes when there" + " are no sufficient cpu resources available.", nodeInfo); }