Repository: incubator-slider Updated Branches: refs/heads/feature/SLIDER-350-windows bfdec5897 -> 2e3c4c81b
SLIDER-350 add strict test for windows utils being valid Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/2e3c4c81 Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/2e3c4c81 Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/2e3c4c81 Branch: refs/heads/feature/SLIDER-350-windows Commit: 2e3c4c81b799cbf6d06e394c2b17f8f161f68734 Parents: bfdec58 Author: Steve Loughran <ste...@apache.org> Authored: Thu Sep 4 13:46:59 2014 +0100 Committer: Steve Loughran <ste...@apache.org> Committed: Thu Sep 4 13:46:59 2014 +0100 ---------------------------------------------------------------------- .../apache/slider/common/tools/SliderUtils.java | 50 +++++++++++++++++++- .../common/tools/TestWindowsSupport.groovy | 30 ++++++++++-- 2 files changed, 76 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/2e3c4c81/slider-core/src/main/java/org/apache/slider/common/tools/SliderUtils.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/common/tools/SliderUtils.java b/slider-core/src/main/java/org/apache/slider/common/tools/SliderUtils.java index a864878..eb214db 100644 --- a/slider-core/src/main/java/org/apache/slider/common/tools/SliderUtils.java +++ b/slider-core/src/main/java/org/apache/slider/common/tools/SliderUtils.java @@ -37,6 +37,7 @@ import org.apache.hadoop.net.NetUtils; import org.apache.hadoop.security.SecurityUtil; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.util.ExitUtil; +import org.apache.hadoop.util.Shell; import org.apache.hadoop.util.VersionInfo; import org.apache.hadoop.yarn.api.records.ApplicationReport; import org.apache.hadoop.yarn.api.records.Container; @@ -63,6 +64,7 @@ import org.slf4j.LoggerFactory; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileNotFoundException; +import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; @@ -104,8 +106,9 @@ public final class SliderUtils { public static final String JAVA_SECURITY_KRB5_REALM = "java.security.krb5.realm"; public static final String JAVA_SECURITY_KRB5_KDC = "java.security.krb5.kdc"; + public static final String WINUTILS = "WINUTILS.EXE"; + - private SliderUtils() { } @@ -1499,4 +1502,49 @@ public final class SliderUtils { return is; } + + /** + * Strictly verify that windows utils is present. + * Checks go as far as opening the file and looking for + * the headers. + * @throws IOException on any problem reading the file + * @throws FileNotFoundException if the file is not considered valid + */ + public static void verifyWinUtilsValid() throws IOException { + if (!Shell.WINDOWS) { + return; + } + String winUtilsPath = Shell.getWinUtilsPath(); + if (winUtilsPath == null) { + throw new FileNotFoundException(WINUTILS + " not found on Path : " + + System.getenv("Path")); + } + File winUtils = new File(winUtilsPath); + if (!winUtils.isFile()) { + throw new FileNotFoundException(WINUTILS + + " at " + winUtilsPath + + " is not a file"); + + } + if (winUtils.length() < 0x100) { + throw new FileNotFoundException(WINUTILS + + " at " + winUtilsPath + + " is too short to be an executable"); + } + // now read two bytes and verify the header. + FileReader reader = null; + try { + int[] header = new int[2]; + reader = new FileReader(winUtilsPath); + header[0] = reader.read(); + header[1] = reader.read(); + if (header[0] != 'M' || header[1] != 'Z') { + throw new FileNotFoundException(WINUTILS + + " at " + winUtilsPath + + " is not a windows executable file"); + } + } finally { + IOUtils.closeStream(reader); + } + } } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/2e3c4c81/slider-core/src/test/groovy/org/apache/slider/common/tools/TestWindowsSupport.groovy ---------------------------------------------------------------------- diff --git a/slider-core/src/test/groovy/org/apache/slider/common/tools/TestWindowsSupport.groovy b/slider-core/src/test/groovy/org/apache/slider/common/tools/TestWindowsSupport.groovy index 7f5edf3..84356ea 100644 --- a/slider-core/src/test/groovy/org/apache/slider/common/tools/TestWindowsSupport.groovy +++ b/slider-core/src/test/groovy/org/apache/slider/common/tools/TestWindowsSupport.groovy @@ -27,14 +27,16 @@ import org.apache.hadoop.fs.Path import org.apache.hadoop.fs.FileSystem as HadoopFS import org.apache.hadoop.util.Shell import org.apache.slider.providers.agent.AgentUtils -import org.apache.slider.test.SliderTestUtils +import org.apache.slider.server.services.workflow.EndOfServiceWaiter +import org.apache.slider.server.services.workflow.ForkedProcessService +import org.apache.slider.test.SliderTestBase import org.junit.Test import java.util.regex.Pattern @CompileStatic @Slf4j -class TestWindowsSupport extends SliderTestUtils { +class TestWindowsSupport extends SliderTestBase { private static final Pattern hasDriveLetterSpecifier = Pattern.compile("^/?[a-zA-Z]:"); @@ -94,7 +96,6 @@ class TestWindowsSupport extends SliderTestUtils { @Test public void testSliderFS() throws Throwable { assume(Shell.WINDOWS, "not windows") - SliderFileSystem sfs = new SliderFileSystem(new Configuration()) try { def metainfo = AgentUtils.getApplicationMetainfo(sfs, windowsFile) @@ -107,6 +108,29 @@ class TestWindowsSupport extends SliderTestUtils { @Test public void testEmitKillCommand() throws Throwable { killJavaProcesses("regionserver", 9) + } + + @Test + public void testHasWinutils() throws Throwable { + assume(Shell.WINDOWS, "not windows") + SliderUtils.verifyWinUtilsValid() + } + @Test + public void testExecWinutils() throws Throwable { + assume(Shell.WINDOWS, "not windows") + def winUtilsPath = Shell.winUtilsPath + assert winUtilsPath + File winUtils = new File(winUtilsPath) + log.debug("Winutils is at $winUtils)") + ForkedProcessService process; + process = new ForkedProcessService( + methodName.methodName, + [:], + [winUtilsPath, "systeminfo"]); + process.init(new Configuration()); + EndOfServiceWaiter waiter = new EndOfServiceWaiter(process); + process.start(); + waiter.waitForServiceToStop(5000); } }