|
@@ -28,6 +28,7 @@ import java.io.File;
|
|
import java.io.FileOutputStream;
|
|
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.io.PrintWriter;
|
|
import java.io.PrintWriter;
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
@@ -36,11 +37,16 @@ import java.util.concurrent.ConcurrentMap;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
|
|
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
|
|
|
|
+import org.apache.hadoop.fs.Path;
|
|
import org.apache.hadoop.io.nativeio.NativeIO;
|
|
import org.apache.hadoop.io.nativeio.NativeIO;
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
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;
|
|
|
|
+import org.apache.hadoop.yarn.api.records.impl.pb.ContainerIdPBImpl;
|
|
|
|
+import org.apache.hadoop.yarn.api.records.impl.pb.ApplicationAttemptIdPBImpl;
|
|
|
|
+import org.apache.hadoop.yarn.api.records.impl.pb.ApplicationIdPBImpl;
|
|
|
|
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerImpl;
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
import org.apache.hadoop.yarn.event.AsyncDispatcher;
|
|
import org.apache.hadoop.yarn.event.AsyncDispatcher;
|
|
import org.apache.hadoop.yarn.exceptions.YarnException;
|
|
import org.apache.hadoop.yarn.exceptions.YarnException;
|
|
@@ -210,4 +216,80 @@ public class TestContainerLogsPage {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testLogDirWithDriveLetter() throws Exception {
|
|
|
|
+ //To verify that logs paths which include drive letters (Windows)
|
|
|
|
+ //do not lose their drive letter specification
|
|
|
|
+ LocalDirsHandlerService localDirs = mock(LocalDirsHandlerService.class);
|
|
|
|
+ List<String> logDirs = new ArrayList<String>();
|
|
|
|
+ logDirs.add("F:/nmlogs");
|
|
|
|
+ when(localDirs.getLogDirs()).thenReturn(logDirs);
|
|
|
|
+
|
|
|
|
+ ApplicationIdPBImpl appId = mock(ApplicationIdPBImpl.class);
|
|
|
|
+ when(appId.toString()).thenReturn("app_id_1");
|
|
|
|
+
|
|
|
|
+ ApplicationAttemptIdPBImpl appAttemptId =
|
|
|
|
+ mock(ApplicationAttemptIdPBImpl.class);
|
|
|
|
+ when(appAttemptId.getApplicationId()).thenReturn(appId);
|
|
|
|
+
|
|
|
|
+ ContainerId containerId = mock(ContainerIdPBImpl.class);
|
|
|
|
+ when(containerId.getApplicationAttemptId()).thenReturn(appAttemptId);
|
|
|
|
+
|
|
|
|
+ List<File> logDirFiles = ContainerLogsUtils.getContainerLogDirs(
|
|
|
|
+ containerId, localDirs);
|
|
|
|
+
|
|
|
|
+ Assert.assertTrue("logDir lost drive letter " +
|
|
|
|
+ logDirFiles.get(0),
|
|
|
|
+ logDirFiles.get(0).toString().indexOf("F:" + File.separator +
|
|
|
|
+ "nmlogs") > -1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testLogFileWithDriveLetter() throws Exception {
|
|
|
|
+
|
|
|
|
+ ContainerImpl container = mock(ContainerImpl.class);
|
|
|
|
+
|
|
|
|
+ ApplicationIdPBImpl appId = mock(ApplicationIdPBImpl.class);
|
|
|
|
+ when(appId.toString()).thenReturn("appId");
|
|
|
|
+
|
|
|
|
+ Application app = mock(Application.class);
|
|
|
|
+ when(app.getAppId()).thenReturn(appId);
|
|
|
|
+
|
|
|
|
+ ApplicationAttemptIdPBImpl appAttemptId =
|
|
|
|
+ mock(ApplicationAttemptIdPBImpl.class);
|
|
|
|
+ when(appAttemptId.getApplicationId()).thenReturn(appId);
|
|
|
|
+
|
|
|
|
+ ConcurrentMap<ApplicationId, Application> applications =
|
|
|
|
+ new ConcurrentHashMap<ApplicationId, Application>();
|
|
|
|
+ applications.put(appId, app);
|
|
|
|
+
|
|
|
|
+ ContainerId containerId = mock(ContainerIdPBImpl.class);
|
|
|
|
+ when(containerId.toString()).thenReturn("containerId");
|
|
|
|
+ when(containerId.getApplicationAttemptId()).thenReturn(appAttemptId);
|
|
|
|
+
|
|
|
|
+ ConcurrentMap<ContainerId, Container> containers =
|
|
|
|
+ new ConcurrentHashMap<ContainerId, Container>();
|
|
|
|
+
|
|
|
|
+ containers.put(containerId, container);
|
|
|
|
+
|
|
|
|
+ LocalDirsHandlerService localDirs = mock(LocalDirsHandlerService.class);
|
|
|
|
+ when(localDirs.getLogPathToRead("appId" + Path.SEPARATOR + "containerId" +
|
|
|
|
+ Path.SEPARATOR + "fileName"))
|
|
|
|
+ .thenReturn(new Path("F:/nmlogs/appId/containerId/fileName"));
|
|
|
|
+
|
|
|
|
+ NMContext context = mock(NMContext.class);
|
|
|
|
+ when(context.getLocalDirsHandler()).thenReturn(localDirs);
|
|
|
|
+ when(context.getApplications()).thenReturn(applications);
|
|
|
|
+ when(context.getContainers()).thenReturn(containers);
|
|
|
|
+
|
|
|
|
+ File logFile = ContainerLogsUtils.getContainerLogFile(containerId,
|
|
|
|
+ "fileName", null, context);
|
|
|
|
+
|
|
|
|
+ Assert.assertTrue("logFile lost drive letter " +
|
|
|
|
+ logFile,
|
|
|
|
+ logFile.toString().indexOf("F:" + File.separator + "nmlogs") > -1);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|