From dc3f4fc2f44c22300cd0b4832469b8cd59a1f228 Mon Sep 17 00:00:00 2001 From: Abhishek Modi Date: Tue, 19 Nov 2019 08:08:40 +0530 Subject: [PATCH] YARN-9965. Fix NodeManager failing to start on subsequent times when Hdfs Auxillary Jar is set (addendum). Contributed by Prabhu Joseph. --- .../containermanager/AuxServices.java | 3 +- .../containermanager/TestAuxServices.java | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) 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/AuxServices.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/AuxServices.java index dacf79b0b43..95d701c1524 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/AuxServices.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/AuxServices.java @@ -311,7 +311,8 @@ public class AuxServices extends AbstractService * @return path of the downloaded file * @throws IOException */ - private Path maybeDownloadJars(String sName, String className, String + @VisibleForTesting + protected Path maybeDownloadJars(String sName, String className, String remoteFile, AuxServiceFile.TypeEnum type, Configuration conf) throws IOException { // load AuxiliaryService from remote classpath 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/TestAuxServices.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/TestAuxServices.java index 925289a1a4c..da0b9cd1f8c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/TestAuxServices.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/TestAuxServices.java @@ -22,6 +22,7 @@ import static org.apache.hadoop.service.Service.STATE.INITED; import static org.apache.hadoop.service.Service.STATE.STARTED; import static org.apache.hadoop.service.Service.STATE.STOPPED; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -95,6 +96,7 @@ import org.apache.hadoop.yarn.server.nodemanager.LocalDirsHandlerService; import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container; import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerImpl; import org.apache.hadoop.yarn.server.nodemanager.containermanager.deletion.task.FileDeletionTask; +import org.apache.hadoop.yarn.server.nodemanager.containermanager.records.AuxServiceFile; import org.junit.Assert; import org.junit.Test; @@ -487,6 +489,45 @@ public class TestAuxServices { } } + @Test (timeout = 15000) + public void testReuseLocalizedAuxiliaryJar() throws Exception { + File testJar = null; + AuxServices aux = null; + Configuration conf = new YarnConfiguration(); + FileSystem fs = FileSystem.get(conf); + String root = "target/LocalDir"; + try { + testJar = JarFinder.makeClassLoaderTestJar(this.getClass(), rootDir, + "test-runjar.jar", 2048, ServiceB.class.getName(), LightService + .class.getName()); + Context mockContext = mock(Context.class); + LocalDirsHandlerService mockDirsHandler = mock( + LocalDirsHandlerService.class); + Path rootAuxServiceDirPath = new Path(root, "nmAuxService"); + when(mockDirsHandler.getLocalPathForWrite(anyString())).thenReturn( + rootAuxServiceDirPath); + when(mockContext.getLocalDirsHandler()).thenReturn(mockDirsHandler); + aux = new AuxServices(MOCK_AUX_PATH_HANDLER, mockContext, + MOCK_DEL_SERVICE); + // First Time the jar gets localized + Path path = aux.maybeDownloadJars("ServiceB", ServiceB.class.getName(), + testJar.getAbsolutePath(), AuxServiceFile.TypeEnum.STATIC, conf); + + // Validate the path on reuse of localized jar + path = aux.maybeDownloadJars("ServiceB", ServiceB.class.getName(), + testJar.getAbsolutePath(), AuxServiceFile.TypeEnum.STATIC, conf); + assertFalse("Failed to reuse the localized jar", + path.toString().endsWith("/*")); + } finally { + if (testJar != null) { + testJar.delete(); + } + if (fs.exists(new Path(root))) { + fs.delete(new Path(root), true); + } + } + } + @Test public void testAuxEventDispatch() throws IOException { Configuration conf = new Configuration();