NumaResourceAllocator { public synchronized void recoverNumaResource(ContainerId containerId) { Container container = context.getContainers().get(containerId); ResourceMappings resourceMappings = container.getResourceMappings(); List<Serializable> assignedResources = resourceMappings .getAssignedResources(NUMA_RESOURCE_TYPE); if (assignedResources.size() == 1) { NumaResourceAllocation numaResourceAllocation = (NumaResourceAllocation) assignedResources.get(0); for (Entry<String, Long> nodeAndMemory : numaResourceAllocation .getNodeVsMemory().entrySet()) { numaNodeIdVsResource.get(nodeAndMemory.getKey()) .recoverMemory(containerId, nodeAndMemory.getValue()); } for (Entry<String, Integer> nodeAndCpus : numaResourceAllocation .getNodeVsCpus().entrySet()) { numaNodeIdVsResource.get(nodeAndCpus.getKey()).recoverCpus(containerId, nodeAndCpus.getValue()); } } else { LOG.error("Unexpected number:" + assignedResources.size() + " of assigned numa resources for " + containerId + " while recovering."); } } 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 testRecoverNumaResource() throws Exception { @SuppressWarnings("unchecked") ConcurrentHashMap<ContainerId, Container> mockContainers = mock( ConcurrentHashMap.class); Context mockContext = mock(Context.class); Container mockContainer = mock(Container.class); ResourceMappings value = new ResourceMappings(); AssignedResources assignedResources = new AssignedResources(); assignedResources.updateAssignedResources( Arrays.asList(new NumaResourceAllocation("0", 70000, "0", 4))); value.addAssignedResources("numa", assignedResources); when(mockContainer.getResourceMappings()).thenReturn(value); when(mockContainers.get(Matchers.any())).thenReturn(mockContainer); when(mockContext.getContainers()).thenReturn(mockContainers); NMStateStoreService mock = mock(NMStateStoreService.class); when(mockContext.getNMStateStore()).thenReturn(mock); numaResourceAllocator = new NumaResourceAllocator(mockContext); numaResourceAllocator.init(conf); numaResourceAllocator.recoverNumaResource( ContainerId.fromString("container_1481156246874_0001_01_000001")); NumaResourceAllocation numaNode = numaResourceAllocator .allocateNumaNodes(getContainer( ContainerId.fromString("container_1481156246874_0001_01_000005"), Resource.newInstance(2048, 1))); assertEquals("1", String.join(",", numaNode.getMemNodes())); assertEquals("1", String.join(",", numaNode.getCpuNodes())); numaNode = numaResourceAllocator.allocateNumaNodes(getContainer( ContainerId.fromString("container_1481156246874_0001_01_000006"), Resource.newInstance(2048, 4))); assertNull(numaNode); }