FpgaResourceHandlerImpl implements ResourceHandler { @Override public List<PrivilegedOperation> reacquireContainer(ContainerId containerId) throws ResourceHandlerException { allocator.recoverAssignedFpgas(containerId); return null; } @VisibleForTesting  FpgaResourceHandlerImpl(Context nmContext,
      CGroupsHandler cGroupsHandler,
      PrivilegedOperationExecutor privilegedOperationExecutor,
      AbstractFpgaVendorPlugin plugin,
      FpgaDiscoverer fpgaDiscoverer); String getRequestedIPID(Container container); @Override List<PrivilegedOperation> bootstrap(Configuration configuration); @Override List<PrivilegedOperation> preStart(Container container); @Override List<PrivilegedOperation> reacquireContainer(ContainerId containerId); @Override List<PrivilegedOperation> updateContainer(Container container); @Override List<PrivilegedOperation> postComplete(ContainerId containerId); @Override List<PrivilegedOperation> teardown(); @Override String toString(); static final String EXCLUDED_FPGAS_CLI_OPTION; static final String CONTAINER_ID_CLI_OPTION; }
@Test public void testReacquireContainer() throws ResourceHandlerException { Container c0 = mockContainer(0, 2, "GEMM"); List<FpgaDevice> assigned = new ArrayList<>(); assigned.add(new FpgaDevice( vendorType, 247, 0, "acl0")); assigned.add(new FpgaDevice( vendorType, 247, 1, "acl1")); mockStateStoreForContainer(c0, assigned); configuration.set(YarnConfiguration.NM_FPGA_ALLOWED_DEVICES, "0,1,2"); fpgaResourceHandler.bootstrap(configuration); Assert.assertEquals(0, fpgaResourceHandler.getFpgaAllocator().getUsedFpgaCount()); Assert.assertEquals(3, fpgaResourceHandler.getFpgaAllocator().getAvailableFpgaCount()); fpgaResourceHandler.reacquireContainer(getContainerId(0)); List<FpgaDevice> used = fpgaResourceHandler.getFpgaAllocator(). getUsedFpga().get(getContainerId(0).toString()); int count = 0; for (FpgaDevice device : used) { if (device.getMinor() == 0){ count++; } if (device.getMinor() == 1) { count++; } } Assert.assertEquals("Unexpected used minor number in allocator",2, count); List<FpgaDevice> available = fpgaResourceHandler .getFpgaAllocator() .getAvailableFpga() .get(vendorType); count = 0; for (FpgaDevice device : available) { if (device.getMinor() == 2) { count++; } } Assert.assertEquals("Unexpected available minor number in allocator", 1, count); Container c1 = mockContainer(1, 1, "GEMM"); assigned = new ArrayList<>(); assigned.add(new FpgaDevice( vendorType, 247, 5, "acl0")); mockStateStoreForContainer(c1, assigned); boolean flag = false; try { fpgaResourceHandler.reacquireContainer(getContainerId(1)); } catch (ResourceHandlerException e) { flag = true; } Assert.assertTrue(flag); Assert.assertEquals(2, fpgaResourceHandler.getFpgaAllocator().getUsedFpgaCount()); Assert.assertEquals(1, fpgaResourceHandler.getFpgaAllocator().getAvailableFpgaCount()); Container c2 = mockContainer(2, 1, "GEMM"); assigned = new ArrayList<>(); assigned.add(new FpgaDevice( vendorType, 247, 1, "acl0")); mockStateStoreForContainer(c2, assigned); flag = false; try { fpgaResourceHandler.reacquireContainer(getContainerId(2)); } catch (ResourceHandlerException e) { flag = true; } Assert.assertTrue(flag); Assert.assertEquals(2, fpgaResourceHandler.getFpgaAllocator().getUsedFpgaCount()); Assert.assertEquals(1, fpgaResourceHandler.getFpgaAllocator().getAvailableFpgaCount()); Container c3 = mockContainer(3, 1, "GEMM"); assigned = new ArrayList<>(); assigned.add(new FpgaDevice( vendorType, 247, 2, "acl2")); mockStateStoreForContainer(c3, assigned); fpgaResourceHandler.reacquireContainer(getContainerId(3)); Assert.assertEquals(3, fpgaResourceHandler.getFpgaAllocator().getUsedFpgaCount()); Assert.assertEquals(0, fpgaResourceHandler.getFpgaAllocator().getAvailableFpgaCount()); }