|
@@ -20,7 +20,6 @@ package org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.resourc
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.util.StringUtils;
|
|
import org.apache.hadoop.util.StringUtils;
|
|
-import org.apache.hadoop.yarn.api.protocolrecords.ResourceTypes;
|
|
|
|
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
|
|
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
|
|
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
|
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
|
import org.apache.hadoop.yarn.api.records.ContainerId;
|
|
import org.apache.hadoop.yarn.api.records.ContainerId;
|
|
@@ -36,9 +35,10 @@ import org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileg
|
|
import org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperationExecutor;
|
|
import org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperationExecutor;
|
|
import org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.resources.CGroupsHandler;
|
|
import org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.resources.CGroupsHandler;
|
|
import org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.resources.ResourceHandlerException;
|
|
import org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.resources.ResourceHandlerException;
|
|
|
|
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.resourceplugin.gpu.GpuDevice;
|
|
import org.apache.hadoop.yarn.server.nodemanager.containermanager.resourceplugin.gpu.GpuDiscoverer;
|
|
import org.apache.hadoop.yarn.server.nodemanager.containermanager.resourceplugin.gpu.GpuDiscoverer;
|
|
|
|
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.runtime.ContainerRuntimeConstants;
|
|
import org.apache.hadoop.yarn.server.nodemanager.recovery.NMStateStoreService;
|
|
import org.apache.hadoop.yarn.server.nodemanager.recovery.NMStateStoreService;
|
|
-import org.apache.hadoop.yarn.util.resource.ResourceUtils;
|
|
|
|
import org.apache.hadoop.yarn.util.resource.TestResourceUtils;
|
|
import org.apache.hadoop.yarn.util.resource.TestResourceUtils;
|
|
import org.junit.Assert;
|
|
import org.junit.Assert;
|
|
import org.junit.Before;
|
|
import org.junit.Before;
|
|
@@ -46,6 +46,7 @@ import org.junit.Test;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.io.Serializable;
|
|
import java.io.Serializable;
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
@@ -92,7 +93,7 @@ public class TestGpuResourceHandler {
|
|
@Test
|
|
@Test
|
|
public void testBootStrap() throws Exception {
|
|
public void testBootStrap() throws Exception {
|
|
Configuration conf = new YarnConfiguration();
|
|
Configuration conf = new YarnConfiguration();
|
|
- conf.set(YarnConfiguration.NM_GPU_ALLOWED_DEVICES, "0");
|
|
|
|
|
|
+ conf.set(YarnConfiguration.NM_GPU_ALLOWED_DEVICES, "0:0");
|
|
|
|
|
|
GpuDiscoverer.getInstance().initialize(conf);
|
|
GpuDiscoverer.getInstance().initialize(conf);
|
|
|
|
|
|
@@ -106,8 +107,8 @@ public class TestGpuResourceHandler {
|
|
.newInstance(ApplicationId.newInstance(1234L, 1), 1), id);
|
|
.newInstance(ApplicationId.newInstance(1234L, 1), 1), id);
|
|
}
|
|
}
|
|
|
|
|
|
- private static Container mockContainerWithGpuRequest(int id,
|
|
|
|
- int numGpuRequest) {
|
|
|
|
|
|
+ private static Container mockContainerWithGpuRequest(int id, int numGpuRequest,
|
|
|
|
+ boolean dockerContainerEnabled) {
|
|
Container c = mock(Container.class);
|
|
Container c = mock(Container.class);
|
|
when(c.getContainerId()).thenReturn(getContainerId(id));
|
|
when(c.getContainerId()).thenReturn(getContainerId(id));
|
|
|
|
|
|
@@ -117,29 +118,46 @@ public class TestGpuResourceHandler {
|
|
res.setResourceValue(ResourceInformation.GPU_URI, numGpuRequest);
|
|
res.setResourceValue(ResourceInformation.GPU_URI, numGpuRequest);
|
|
when(c.getResource()).thenReturn(res);
|
|
when(c.getResource()).thenReturn(res);
|
|
when(c.getResourceMappings()).thenReturn(resMapping);
|
|
when(c.getResourceMappings()).thenReturn(resMapping);
|
|
|
|
+
|
|
|
|
+ ContainerLaunchContext clc = mock(ContainerLaunchContext.class);
|
|
|
|
+ Map<String, String> env = new HashMap<>();
|
|
|
|
+ if (dockerContainerEnabled) {
|
|
|
|
+ env.put(ContainerRuntimeConstants.ENV_CONTAINER_TYPE, "docker");
|
|
|
|
+ }
|
|
|
|
+ when(clc.getEnvironment()).thenReturn(env);
|
|
|
|
+ when(c.getLaunchContext()).thenReturn(clc);
|
|
return c;
|
|
return c;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private static Container mockContainerWithGpuRequest(int id,
|
|
|
|
+ int numGpuRequest) {
|
|
|
|
+ return mockContainerWithGpuRequest(id, numGpuRequest, false);
|
|
|
|
+ }
|
|
|
|
+
|
|
private void verifyDeniedDevices(ContainerId containerId,
|
|
private void verifyDeniedDevices(ContainerId containerId,
|
|
- List<Integer> deniedDevices)
|
|
|
|
|
|
+ List<GpuDevice> deniedDevices)
|
|
throws ResourceHandlerException, PrivilegedOperationException {
|
|
throws ResourceHandlerException, PrivilegedOperationException {
|
|
verify(mockCGroupsHandler, times(1)).createCGroup(
|
|
verify(mockCGroupsHandler, times(1)).createCGroup(
|
|
CGroupsHandler.CGroupController.DEVICES, containerId.toString());
|
|
CGroupsHandler.CGroupController.DEVICES, containerId.toString());
|
|
|
|
|
|
if (null != deniedDevices && !deniedDevices.isEmpty()) {
|
|
if (null != deniedDevices && !deniedDevices.isEmpty()) {
|
|
|
|
+ List<Integer> deniedDevicesMinorNumber = new ArrayList<>();
|
|
|
|
+ for (GpuDevice deniedDevice : deniedDevices) {
|
|
|
|
+ deniedDevicesMinorNumber.add(deniedDevice.getMinorNumber());
|
|
|
|
+ }
|
|
verify(mockPrivilegedExecutor, times(1)).executePrivilegedOperation(
|
|
verify(mockPrivilegedExecutor, times(1)).executePrivilegedOperation(
|
|
new PrivilegedOperation(PrivilegedOperation.OperationType.GPU, Arrays
|
|
new PrivilegedOperation(PrivilegedOperation.OperationType.GPU, Arrays
|
|
.asList(GpuResourceHandlerImpl.CONTAINER_ID_CLI_OPTION,
|
|
.asList(GpuResourceHandlerImpl.CONTAINER_ID_CLI_OPTION,
|
|
containerId.toString(),
|
|
containerId.toString(),
|
|
GpuResourceHandlerImpl.EXCLUDED_GPUS_CLI_OPTION,
|
|
GpuResourceHandlerImpl.EXCLUDED_GPUS_CLI_OPTION,
|
|
- StringUtils.join(",", deniedDevices))), true);
|
|
|
|
|
|
+ StringUtils.join(",", deniedDevicesMinorNumber))), true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
|
- public void testAllocation() throws Exception {
|
|
|
|
|
|
+ private void commonTestAllocation(boolean dockerContainerEnabled)
|
|
|
|
+ throws Exception {
|
|
Configuration conf = new YarnConfiguration();
|
|
Configuration conf = new YarnConfiguration();
|
|
- conf.set(YarnConfiguration.NM_GPU_ALLOWED_DEVICES, "0,1,3,4");
|
|
|
|
|
|
+ conf.set(YarnConfiguration.NM_GPU_ALLOWED_DEVICES, "0:0,1:1,2:3,3:4");
|
|
GpuDiscoverer.getInstance().initialize(conf);
|
|
GpuDiscoverer.getInstance().initialize(conf);
|
|
|
|
|
|
gpuResourceHandler.bootstrap(conf);
|
|
gpuResourceHandler.bootstrap(conf);
|
|
@@ -147,31 +165,55 @@ public class TestGpuResourceHandler {
|
|
gpuResourceHandler.getGpuAllocator().getAvailableGpus());
|
|
gpuResourceHandler.getGpuAllocator().getAvailableGpus());
|
|
|
|
|
|
/* Start container 1, asks 3 containers */
|
|
/* Start container 1, asks 3 containers */
|
|
- gpuResourceHandler.preStart(mockContainerWithGpuRequest(1, 3));
|
|
|
|
|
|
+ gpuResourceHandler.preStart(
|
|
|
|
+ mockContainerWithGpuRequest(1, 3, dockerContainerEnabled));
|
|
|
|
|
|
// Only device=4 will be blocked.
|
|
// Only device=4 will be blocked.
|
|
- verifyDeniedDevices(getContainerId(1), Arrays.asList(4));
|
|
|
|
|
|
+ if (dockerContainerEnabled) {
|
|
|
|
+ verifyDeniedDevices(getContainerId(1),
|
|
|
|
+ Collections.<GpuDevice>emptyList());
|
|
|
|
+ } else{
|
|
|
|
+ verifyDeniedDevices(getContainerId(1), Arrays.asList(new GpuDevice(3,4)));
|
|
|
|
+ }
|
|
|
|
|
|
/* Start container 2, asks 2 containers. Excepted to fail */
|
|
/* Start container 2, asks 2 containers. Excepted to fail */
|
|
boolean failedToAllocate = false;
|
|
boolean failedToAllocate = false;
|
|
try {
|
|
try {
|
|
- gpuResourceHandler.preStart(mockContainerWithGpuRequest(2, 2));
|
|
|
|
|
|
+ gpuResourceHandler.preStart(
|
|
|
|
+ mockContainerWithGpuRequest(2, 2, dockerContainerEnabled));
|
|
} catch (ResourceHandlerException e) {
|
|
} catch (ResourceHandlerException e) {
|
|
failedToAllocate = true;
|
|
failedToAllocate = true;
|
|
}
|
|
}
|
|
Assert.assertTrue(failedToAllocate);
|
|
Assert.assertTrue(failedToAllocate);
|
|
|
|
|
|
/* Start container 3, ask 1 container, succeeded */
|
|
/* Start container 3, ask 1 container, succeeded */
|
|
- gpuResourceHandler.preStart(mockContainerWithGpuRequest(3, 1));
|
|
|
|
|
|
+ gpuResourceHandler.preStart(
|
|
|
|
+ mockContainerWithGpuRequest(3, 1, dockerContainerEnabled));
|
|
|
|
|
|
// devices = 0/1/3 will be blocked
|
|
// devices = 0/1/3 will be blocked
|
|
- verifyDeniedDevices(getContainerId(3), Arrays.asList(0, 1, 3));
|
|
|
|
|
|
+ if (dockerContainerEnabled) {
|
|
|
|
+ verifyDeniedDevices(getContainerId(3),
|
|
|
|
+ Collections.<GpuDevice>emptyList());
|
|
|
|
+ } else {
|
|
|
|
+ verifyDeniedDevices(getContainerId(3), Arrays
|
|
|
|
+ .asList(new GpuDevice(0, 0), new GpuDevice(1, 1),
|
|
|
|
+ new GpuDevice(2, 3)));
|
|
|
|
+ }
|
|
|
|
|
|
- /* Start container 4, ask 0 container, succeeded */
|
|
|
|
- gpuResourceHandler.preStart(mockContainerWithGpuRequest(4, 0));
|
|
|
|
|
|
|
|
- // All devices will be blocked
|
|
|
|
- verifyDeniedDevices(getContainerId(4), Arrays.asList(0, 1, 3, 4));
|
|
|
|
|
|
+ /* Start container 4, ask 0 container, succeeded */
|
|
|
|
+ gpuResourceHandler.preStart(
|
|
|
|
+ mockContainerWithGpuRequest(4, 0, dockerContainerEnabled));
|
|
|
|
+
|
|
|
|
+ if (dockerContainerEnabled) {
|
|
|
|
+ verifyDeniedDevices(getContainerId(4),
|
|
|
|
+ Collections.<GpuDevice>emptyList());
|
|
|
|
+ } else{
|
|
|
|
+ // All devices will be blocked
|
|
|
|
+ verifyDeniedDevices(getContainerId(4), Arrays
|
|
|
|
+ .asList(new GpuDevice(0, 0), new GpuDevice(1, 1), new GpuDevice(2, 3),
|
|
|
|
+ new GpuDevice(3, 4)));
|
|
|
|
+ }
|
|
|
|
|
|
/* Release container-1, expect cgroups deleted */
|
|
/* Release container-1, expect cgroups deleted */
|
|
gpuResourceHandler.postComplete(getContainerId(1));
|
|
gpuResourceHandler.postComplete(getContainerId(1));
|
|
@@ -190,12 +232,24 @@ public class TestGpuResourceHandler {
|
|
gpuResourceHandler.getGpuAllocator().getAvailableGpus());
|
|
gpuResourceHandler.getGpuAllocator().getAvailableGpus());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Test
|
|
|
|
+ public void testAllocationWhenDockerContainerEnabled() throws Exception {
|
|
|
|
+ // When docker container is enabled, no devices should be written to
|
|
|
|
+ // devices.deny.
|
|
|
|
+ commonTestAllocation(true);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testAllocation() throws Exception {
|
|
|
|
+ commonTestAllocation(false);
|
|
|
|
+ }
|
|
|
|
+
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
@Test
|
|
@Test
|
|
public void testAssignedGpuWillBeCleanedupWhenStoreOpFails()
|
|
public void testAssignedGpuWillBeCleanedupWhenStoreOpFails()
|
|
throws Exception {
|
|
throws Exception {
|
|
Configuration conf = new YarnConfiguration();
|
|
Configuration conf = new YarnConfiguration();
|
|
- conf.set(YarnConfiguration.NM_GPU_ALLOWED_DEVICES, "0,1,3,4");
|
|
|
|
|
|
+ conf.set(YarnConfiguration.NM_GPU_ALLOWED_DEVICES, "0:0,1:1,2:3,3:4");
|
|
GpuDiscoverer.getInstance().initialize(conf);
|
|
GpuDiscoverer.getInstance().initialize(conf);
|
|
|
|
|
|
gpuResourceHandler.bootstrap(conf);
|
|
gpuResourceHandler.bootstrap(conf);
|
|
@@ -204,7 +258,7 @@ public class TestGpuResourceHandler {
|
|
|
|
|
|
doThrow(new IOException("Exception ...")).when(mockNMStateStore)
|
|
doThrow(new IOException("Exception ...")).when(mockNMStateStore)
|
|
.storeAssignedResources(
|
|
.storeAssignedResources(
|
|
- any(ContainerId.class), anyString(), anyList());
|
|
|
|
|
|
+ any(Container.class), anyString(), anyList());
|
|
|
|
|
|
boolean exception = false;
|
|
boolean exception = false;
|
|
/* Start container 1, asks 3 containers */
|
|
/* Start container 1, asks 3 containers */
|
|
@@ -227,13 +281,16 @@ public class TestGpuResourceHandler {
|
|
conf.set(YarnConfiguration.NM_GPU_ALLOWED_DEVICES, " ");
|
|
conf.set(YarnConfiguration.NM_GPU_ALLOWED_DEVICES, " ");
|
|
GpuDiscoverer.getInstance().initialize(conf);
|
|
GpuDiscoverer.getInstance().initialize(conf);
|
|
|
|
|
|
- gpuResourceHandler.bootstrap(conf);
|
|
|
|
- Assert.assertEquals(0,
|
|
|
|
- gpuResourceHandler.getGpuAllocator().getAvailableGpus());
|
|
|
|
|
|
+ try {
|
|
|
|
+ gpuResourceHandler.bootstrap(conf);
|
|
|
|
+ Assert.fail("Should fail because no GPU available");
|
|
|
|
+ } catch (ResourceHandlerException e) {
|
|
|
|
+ // Expected because of no resource available
|
|
|
|
+ }
|
|
|
|
|
|
/* Start container 1, asks 0 containers */
|
|
/* Start container 1, asks 0 containers */
|
|
gpuResourceHandler.preStart(mockContainerWithGpuRequest(1, 0));
|
|
gpuResourceHandler.preStart(mockContainerWithGpuRequest(1, 0));
|
|
- verifyDeniedDevices(getContainerId(1), Collections.<Integer>emptyList());
|
|
|
|
|
|
+ verifyDeniedDevices(getContainerId(1), Collections.<GpuDevice>emptyList());
|
|
|
|
|
|
/* Start container 2, asks 1 containers. Excepted to fail */
|
|
/* Start container 2, asks 1 containers. Excepted to fail */
|
|
boolean failedToAllocate = false;
|
|
boolean failedToAllocate = false;
|
|
@@ -256,7 +313,7 @@ public class TestGpuResourceHandler {
|
|
@Test
|
|
@Test
|
|
public void testAllocationStored() throws Exception {
|
|
public void testAllocationStored() throws Exception {
|
|
Configuration conf = new YarnConfiguration();
|
|
Configuration conf = new YarnConfiguration();
|
|
- conf.set(YarnConfiguration.NM_GPU_ALLOWED_DEVICES, "0,1,3,4");
|
|
|
|
|
|
+ conf.set(YarnConfiguration.NM_GPU_ALLOWED_DEVICES, "0:0,1:1,2:3,3:4");
|
|
GpuDiscoverer.getInstance().initialize(conf);
|
|
GpuDiscoverer.getInstance().initialize(conf);
|
|
|
|
|
|
gpuResourceHandler.bootstrap(conf);
|
|
gpuResourceHandler.bootstrap(conf);
|
|
@@ -267,34 +324,34 @@ public class TestGpuResourceHandler {
|
|
Container container = mockContainerWithGpuRequest(1, 3);
|
|
Container container = mockContainerWithGpuRequest(1, 3);
|
|
gpuResourceHandler.preStart(container);
|
|
gpuResourceHandler.preStart(container);
|
|
|
|
|
|
- verify(mockNMStateStore).storeAssignedResources(getContainerId(1),
|
|
|
|
- ResourceInformation.GPU_URI,
|
|
|
|
- Arrays.<Serializable>asList("0", "1", "3"));
|
|
|
|
-
|
|
|
|
- Assert.assertEquals(3, container.getResourceMappings()
|
|
|
|
- .getAssignedResources(ResourceInformation.GPU_URI).size());
|
|
|
|
|
|
+ verify(mockNMStateStore).storeAssignedResources(container,
|
|
|
|
+ ResourceInformation.GPU_URI, Arrays
|
|
|
|
+ .<Serializable>asList(new GpuDevice(0, 0), new GpuDevice(1, 1),
|
|
|
|
+ new GpuDevice(2, 3)));
|
|
|
|
|
|
// Only device=4 will be blocked.
|
|
// Only device=4 will be blocked.
|
|
- verifyDeniedDevices(getContainerId(1), Arrays.asList(4));
|
|
|
|
|
|
+ verifyDeniedDevices(getContainerId(1), Arrays.asList(new GpuDevice(3, 4)));
|
|
|
|
|
|
/* Start container 2, ask 0 container, succeeded */
|
|
/* Start container 2, ask 0 container, succeeded */
|
|
container = mockContainerWithGpuRequest(2, 0);
|
|
container = mockContainerWithGpuRequest(2, 0);
|
|
gpuResourceHandler.preStart(container);
|
|
gpuResourceHandler.preStart(container);
|
|
|
|
|
|
- verifyDeniedDevices(getContainerId(2), Arrays.asList(0, 1, 3, 4));
|
|
|
|
|
|
+ verifyDeniedDevices(getContainerId(2), Arrays
|
|
|
|
+ .asList(new GpuDevice(0, 0), new GpuDevice(1, 1), new GpuDevice(2, 3),
|
|
|
|
+ new GpuDevice(3, 4)));
|
|
Assert.assertEquals(0, container.getResourceMappings()
|
|
Assert.assertEquals(0, container.getResourceMappings()
|
|
.getAssignedResources(ResourceInformation.GPU_URI).size());
|
|
.getAssignedResources(ResourceInformation.GPU_URI).size());
|
|
|
|
|
|
// Store assigned resource will not be invoked.
|
|
// Store assigned resource will not be invoked.
|
|
verify(mockNMStateStore, never()).storeAssignedResources(
|
|
verify(mockNMStateStore, never()).storeAssignedResources(
|
|
- eq(getContainerId(2)), eq(ResourceInformation.GPU_URI),
|
|
|
|
|
|
+ eq(container), eq(ResourceInformation.GPU_URI),
|
|
anyListOf(Serializable.class));
|
|
anyListOf(Serializable.class));
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void testRecoverResourceAllocation() throws Exception {
|
|
public void testRecoverResourceAllocation() throws Exception {
|
|
Configuration conf = new YarnConfiguration();
|
|
Configuration conf = new YarnConfiguration();
|
|
- conf.set(YarnConfiguration.NM_GPU_ALLOWED_DEVICES, "0,1,3,4");
|
|
|
|
|
|
+ conf.set(YarnConfiguration.NM_GPU_ALLOWED_DEVICES, "0:0,1:1,2:3,3:4");
|
|
GpuDiscoverer.getInstance().initialize(conf);
|
|
GpuDiscoverer.getInstance().initialize(conf);
|
|
|
|
|
|
gpuResourceHandler.bootstrap(conf);
|
|
gpuResourceHandler.bootstrap(conf);
|
|
@@ -305,7 +362,8 @@ public class TestGpuResourceHandler {
|
|
ResourceMappings rmap = new ResourceMappings();
|
|
ResourceMappings rmap = new ResourceMappings();
|
|
ResourceMappings.AssignedResources ar =
|
|
ResourceMappings.AssignedResources ar =
|
|
new ResourceMappings.AssignedResources();
|
|
new ResourceMappings.AssignedResources();
|
|
- ar.updateAssignedResources(Arrays.<Serializable>asList("1", "3"));
|
|
|
|
|
|
+ ar.updateAssignedResources(
|
|
|
|
+ Arrays.<Serializable>asList(new GpuDevice(1, 1), new GpuDevice(2, 3)));
|
|
rmap.addAssignedResources(ResourceInformation.GPU_URI, ar);
|
|
rmap.addAssignedResources(ResourceInformation.GPU_URI, ar);
|
|
when(nmContainer.getResourceMappings()).thenReturn(rmap);
|
|
when(nmContainer.getResourceMappings()).thenReturn(rmap);
|
|
|
|
|
|
@@ -315,12 +373,15 @@ public class TestGpuResourceHandler {
|
|
// Reacquire container restore state of GPU Resource Allocator.
|
|
// Reacquire container restore state of GPU Resource Allocator.
|
|
gpuResourceHandler.reacquireContainer(getContainerId(1));
|
|
gpuResourceHandler.reacquireContainer(getContainerId(1));
|
|
|
|
|
|
- Map<Integer, ContainerId> deviceAllocationMapping =
|
|
|
|
|
|
+ Map<GpuDevice, ContainerId> deviceAllocationMapping =
|
|
gpuResourceHandler.getGpuAllocator().getDeviceAllocationMapping();
|
|
gpuResourceHandler.getGpuAllocator().getDeviceAllocationMapping();
|
|
Assert.assertEquals(2, deviceAllocationMapping.size());
|
|
Assert.assertEquals(2, deviceAllocationMapping.size());
|
|
Assert.assertTrue(
|
|
Assert.assertTrue(
|
|
- deviceAllocationMapping.keySet().containsAll(Arrays.asList(1, 3)));
|
|
|
|
- Assert.assertEquals(deviceAllocationMapping.get(1), getContainerId(1));
|
|
|
|
|
|
+ deviceAllocationMapping.keySet().contains(new GpuDevice(1, 1)));
|
|
|
|
+ Assert.assertTrue(
|
|
|
|
+ deviceAllocationMapping.keySet().contains(new GpuDevice(2, 3)));
|
|
|
|
+ Assert.assertEquals(deviceAllocationMapping.get(new GpuDevice(1, 1)),
|
|
|
|
+ getContainerId(1));
|
|
|
|
|
|
// TEST CASE
|
|
// TEST CASE
|
|
// Try to reacquire a container but requested device is not in allowed list.
|
|
// Try to reacquire a container but requested device is not in allowed list.
|
|
@@ -328,7 +389,8 @@ public class TestGpuResourceHandler {
|
|
rmap = new ResourceMappings();
|
|
rmap = new ResourceMappings();
|
|
ar = new ResourceMappings.AssignedResources();
|
|
ar = new ResourceMappings.AssignedResources();
|
|
// id=5 is not in allowed list.
|
|
// id=5 is not in allowed list.
|
|
- ar.updateAssignedResources(Arrays.<Serializable>asList("4", "5"));
|
|
|
|
|
|
+ ar.updateAssignedResources(
|
|
|
|
+ Arrays.<Serializable>asList(new GpuDevice(3, 4), new GpuDevice(4, 5)));
|
|
rmap.addAssignedResources(ResourceInformation.GPU_URI, ar);
|
|
rmap.addAssignedResources(ResourceInformation.GPU_URI, ar);
|
|
when(nmContainer.getResourceMappings()).thenReturn(rmap);
|
|
when(nmContainer.getResourceMappings()).thenReturn(rmap);
|
|
|
|
|
|
@@ -348,9 +410,10 @@ public class TestGpuResourceHandler {
|
|
deviceAllocationMapping =
|
|
deviceAllocationMapping =
|
|
gpuResourceHandler.getGpuAllocator().getDeviceAllocationMapping();
|
|
gpuResourceHandler.getGpuAllocator().getDeviceAllocationMapping();
|
|
Assert.assertEquals(2, deviceAllocationMapping.size());
|
|
Assert.assertEquals(2, deviceAllocationMapping.size());
|
|
- Assert.assertTrue(
|
|
|
|
- deviceAllocationMapping.keySet().containsAll(Arrays.asList(1, 3)));
|
|
|
|
- Assert.assertEquals(deviceAllocationMapping.get(1), getContainerId(1));
|
|
|
|
|
|
+ Assert.assertTrue(deviceAllocationMapping.keySet()
|
|
|
|
+ .containsAll(Arrays.asList(new GpuDevice(1, 1), new GpuDevice(2, 3))));
|
|
|
|
+ Assert.assertEquals(deviceAllocationMapping.get(new GpuDevice(1, 1)),
|
|
|
|
+ getContainerId(1));
|
|
|
|
|
|
// TEST CASE
|
|
// TEST CASE
|
|
// Try to reacquire a container but requested device is already assigned.
|
|
// Try to reacquire a container but requested device is already assigned.
|
|
@@ -358,7 +421,8 @@ public class TestGpuResourceHandler {
|
|
rmap = new ResourceMappings();
|
|
rmap = new ResourceMappings();
|
|
ar = new ResourceMappings.AssignedResources();
|
|
ar = new ResourceMappings.AssignedResources();
|
|
// id=3 is already assigned
|
|
// id=3 is already assigned
|
|
- ar.updateAssignedResources(Arrays.<Serializable>asList("4", "3"));
|
|
|
|
|
|
+ ar.updateAssignedResources(
|
|
|
|
+ Arrays.<Serializable>asList(new GpuDevice(3, 4), new GpuDevice(2, 3)));
|
|
rmap.addAssignedResources("gpu", ar);
|
|
rmap.addAssignedResources("gpu", ar);
|
|
when(nmContainer.getResourceMappings()).thenReturn(rmap);
|
|
when(nmContainer.getResourceMappings()).thenReturn(rmap);
|
|
|
|
|
|
@@ -378,8 +442,9 @@ public class TestGpuResourceHandler {
|
|
deviceAllocationMapping =
|
|
deviceAllocationMapping =
|
|
gpuResourceHandler.getGpuAllocator().getDeviceAllocationMapping();
|
|
gpuResourceHandler.getGpuAllocator().getDeviceAllocationMapping();
|
|
Assert.assertEquals(2, deviceAllocationMapping.size());
|
|
Assert.assertEquals(2, deviceAllocationMapping.size());
|
|
- Assert.assertTrue(
|
|
|
|
- deviceAllocationMapping.keySet().containsAll(Arrays.asList(1, 3)));
|
|
|
|
- Assert.assertEquals(deviceAllocationMapping.get(1), getContainerId(1));
|
|
|
|
|
|
+ Assert.assertTrue(deviceAllocationMapping.keySet()
|
|
|
|
+ .containsAll(Arrays.asList(new GpuDevice(1, 1), new GpuDevice(2, 3))));
|
|
|
|
+ Assert.assertEquals(deviceAllocationMapping.get(new GpuDevice(1, 1)),
|
|
|
|
+ getContainerId(1));
|
|
}
|
|
}
|
|
}
|
|
}
|