diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/DockerLinuxContainerRuntime.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/DockerLinuxContainerRuntime.java index 15ff0ffb97..225bc19925 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/DockerLinuxContainerRuntime.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/DockerLinuxContainerRuntime.java @@ -456,32 +456,6 @@ private String runDockerVolumeCommand(DockerVolumeCommand dockerVolumeCommand, @Override public void prepareContainer(ContainerRuntimeContext ctx) throws ContainerExecutionException { - Container container = ctx.getContainer(); - - // Create volumes when needed. - if (nmContext != null - && nmContext.getResourcePluginManager().getNameToPlugins() != null) { - for (ResourcePlugin plugin : nmContext.getResourcePluginManager() - .getNameToPlugins().values()) { - DockerCommandPlugin dockerCommandPlugin = - plugin.getDockerCommandPluginInstance(); - if (dockerCommandPlugin != null) { - DockerVolumeCommand dockerVolumeCommand = - dockerCommandPlugin.getCreateDockerVolumeCommand( - ctx.getContainer()); - if (dockerVolumeCommand != null) { - runDockerVolumeCommand(dockerVolumeCommand, container); - - // After volume created, run inspect to make sure volume properly - // created. - if (dockerVolumeCommand.getSubCommand().equals( - DockerVolumeCommand.VOLUME_CREATE_SUB_COMMAND)) { - checkDockerVolumeCreated(dockerVolumeCommand, container); - } - } - } - } - } } private void checkDockerVolumeCreated( @@ -1034,14 +1008,30 @@ public void launchContainer(ContainerRuntimeContext ctx) } } - // use plugins to update docker run command. + // use plugins to create volume and update docker run command. if (nmContext != null && nmContext.getResourcePluginManager().getNameToPlugins() != null) { for (ResourcePlugin plugin : nmContext.getResourcePluginManager() .getNameToPlugins().values()) { DockerCommandPlugin dockerCommandPlugin = plugin.getDockerCommandPluginInstance(); + if (dockerCommandPlugin != null) { + // Create volumes when needed. + DockerVolumeCommand dockerVolumeCommand = + dockerCommandPlugin.getCreateDockerVolumeCommand( + ctx.getContainer()); + if (dockerVolumeCommand != null) { + runDockerVolumeCommand(dockerVolumeCommand, container); + + // After volume created, run inspect to make sure volume properly + // created. + if (dockerVolumeCommand.getSubCommand().equals( + DockerVolumeCommand.VOLUME_CREATE_SUB_COMMAND)) { + checkDockerVolumeCreated(dockerVolumeCommand, container); + } + } + // Update cmd dockerCommandPlugin.updateDockerRunCommand(runCommand, container); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/TestDockerContainerRuntime.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/TestDockerContainerRuntime.java index 40ac61851f..0b5ce3ac37 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/TestDockerContainerRuntime.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/TestDockerContainerRuntime.java @@ -1958,16 +1958,16 @@ private void checkVolumeCreateCommand() ArgumentCaptor opCaptor = ArgumentCaptor.forClass( PrivilegedOperation.class); - //single invocation expected + //Three invocations expected (volume creation, volume check, run container) //due to type erasure + mocking, this verification requires a suppress // warning annotation on the entire method - verify(mockExecutor, times(2)) + verify(mockExecutor, times(3)) .executePrivilegedOperation(anyList(), opCaptor.capture(), any( File.class), anyMap(), anyBoolean(), anyBoolean()); //verification completed. we need to isolate specific invications. // hence, reset mock here - Mockito.reset(mockExecutor); + //Mockito.reset(mockExecutor); List allCaptures = opCaptor.getAllValues(); @@ -2070,10 +2070,8 @@ private void testDockerCommandPluginWithVolumesOutput( try { runtime.prepareContainer(containerRuntimeContext); - - checkVolumeCreateCommand(); - runtime.launchContainer(containerRuntimeContext); + checkVolumeCreateCommand(); } catch (ContainerExecutionException e) { if (expectFail) { // Expected @@ -2166,10 +2164,11 @@ public void testDockerCommandPlugin() throws Exception { ContainerRuntimeContext containerRuntimeContext = builder.build(); runtime.prepareContainer(containerRuntimeContext); - checkVolumeCreateCommand(); runtime.launchContainer(containerRuntimeContext); - List dockerCommands = readDockerCommands(); + checkVolumeCreateCommand(); + + List dockerCommands = readDockerCommands(3); int expected = 14; int counter = 0;