YARN-8989. [YARN-8851] Move DockerCommandPlugin volume related APIs' invocation from DockerLinuxContainerRuntime#prepareContainer to #launchContainer. (Zhankun Tang via wangda)
Change-Id: Ia6d532c687168448416dfdf46f0ac34bff20e6ca
This commit is contained in:
parent
897643928c
commit
fe7dab8ef5
@ -456,32 +456,6 @@ private String runDockerVolumeCommand(DockerVolumeCommand dockerVolumeCommand,
|
|||||||
@Override
|
@Override
|
||||||
public void prepareContainer(ContainerRuntimeContext ctx)
|
public void prepareContainer(ContainerRuntimeContext ctx)
|
||||||
throws ContainerExecutionException {
|
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(
|
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
|
if (nmContext != null
|
||||||
&& nmContext.getResourcePluginManager().getNameToPlugins() != null) {
|
&& nmContext.getResourcePluginManager().getNameToPlugins() != null) {
|
||||||
for (ResourcePlugin plugin : nmContext.getResourcePluginManager()
|
for (ResourcePlugin plugin : nmContext.getResourcePluginManager()
|
||||||
.getNameToPlugins().values()) {
|
.getNameToPlugins().values()) {
|
||||||
DockerCommandPlugin dockerCommandPlugin =
|
DockerCommandPlugin dockerCommandPlugin =
|
||||||
plugin.getDockerCommandPluginInstance();
|
plugin.getDockerCommandPluginInstance();
|
||||||
|
|
||||||
if (dockerCommandPlugin != null) {
|
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);
|
dockerCommandPlugin.updateDockerRunCommand(runCommand, container);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1958,16 +1958,16 @@ private void checkVolumeCreateCommand()
|
|||||||
ArgumentCaptor<PrivilegedOperation> opCaptor = ArgumentCaptor.forClass(
|
ArgumentCaptor<PrivilegedOperation> opCaptor = ArgumentCaptor.forClass(
|
||||||
PrivilegedOperation.class);
|
PrivilegedOperation.class);
|
||||||
|
|
||||||
//single invocation expected
|
//Three invocations expected (volume creation, volume check, run container)
|
||||||
//due to type erasure + mocking, this verification requires a suppress
|
//due to type erasure + mocking, this verification requires a suppress
|
||||||
// warning annotation on the entire method
|
// warning annotation on the entire method
|
||||||
verify(mockExecutor, times(2))
|
verify(mockExecutor, times(3))
|
||||||
.executePrivilegedOperation(anyList(), opCaptor.capture(), any(
|
.executePrivilegedOperation(anyList(), opCaptor.capture(), any(
|
||||||
File.class), anyMap(), anyBoolean(), anyBoolean());
|
File.class), anyMap(), anyBoolean(), anyBoolean());
|
||||||
|
|
||||||
//verification completed. we need to isolate specific invications.
|
//verification completed. we need to isolate specific invications.
|
||||||
// hence, reset mock here
|
// hence, reset mock here
|
||||||
Mockito.reset(mockExecutor);
|
//Mockito.reset(mockExecutor);
|
||||||
|
|
||||||
List<PrivilegedOperation> allCaptures = opCaptor.getAllValues();
|
List<PrivilegedOperation> allCaptures = opCaptor.getAllValues();
|
||||||
|
|
||||||
@ -2070,10 +2070,8 @@ private void testDockerCommandPluginWithVolumesOutput(
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
runtime.prepareContainer(containerRuntimeContext);
|
runtime.prepareContainer(containerRuntimeContext);
|
||||||
|
|
||||||
checkVolumeCreateCommand();
|
|
||||||
|
|
||||||
runtime.launchContainer(containerRuntimeContext);
|
runtime.launchContainer(containerRuntimeContext);
|
||||||
|
checkVolumeCreateCommand();
|
||||||
} catch (ContainerExecutionException e) {
|
} catch (ContainerExecutionException e) {
|
||||||
if (expectFail) {
|
if (expectFail) {
|
||||||
// Expected
|
// Expected
|
||||||
@ -2166,10 +2164,11 @@ public void testDockerCommandPlugin() throws Exception {
|
|||||||
ContainerRuntimeContext containerRuntimeContext = builder.build();
|
ContainerRuntimeContext containerRuntimeContext = builder.build();
|
||||||
|
|
||||||
runtime.prepareContainer(containerRuntimeContext);
|
runtime.prepareContainer(containerRuntimeContext);
|
||||||
checkVolumeCreateCommand();
|
|
||||||
|
|
||||||
runtime.launchContainer(containerRuntimeContext);
|
runtime.launchContainer(containerRuntimeContext);
|
||||||
List<String> dockerCommands = readDockerCommands();
|
checkVolumeCreateCommand();
|
||||||
|
|
||||||
|
List<String> dockerCommands = readDockerCommands(3);
|
||||||
|
|
||||||
int expected = 14;
|
int expected = 14;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user