SLIDER-622 move test-side native lib checks into SliderUtils for AM to use too
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 1a9b8fb..247c25d 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
@@ -34,6 +34,7 @@
import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.io.IOUtils;
+import org.apache.hadoop.io.nativeio.NativeIO;
import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.security.SecurityUtil;
import org.apache.hadoop.security.UserGroupInformation;
@@ -1720,6 +1721,36 @@
return is;
}
+ /**
+ * Check for any needed libraries being present. On Unix none are needed;
+ * on windows they must be present
+ * @return true if all is well
+ */
+ public static String checkForRequiredNativeLibraries() {
+
+ if (!Shell.WINDOWS) {
+ return "";
+ }
+ StringBuilder errorText = new StringBuilder("");
+ if (!NativeIO.isAvailable()) {
+ errorText.append("No native IO library. ");
+ }
+ try {
+ String path = Shell.getQualifiedBinPath("winutils.exe");
+ log.debug("winutils is at {}", path);
+ } catch (IOException e) {
+ errorText.append("No WINUTILS.EXE. ");
+ log.warn("No winutils: {}", e, e);
+ }
+ try {
+ File target = new File("target");
+ FileUtil.canRead(target);
+ } catch (UnsatisfiedLinkError e) {
+ log.warn("Failing to link to native IO methods: {}", e, e);
+ errorText.append("No native IO methods");
+ }
+ return errorText.toString();
+ }
/**
* Strictly verify that windows utils is present.
@@ -1727,25 +1758,14 @@
* the headers.
* @throws IOException on any problem reading the file
* @throws FileNotFoundException if the file is not considered valid
- * @param logger
*/
- public static void maybeVerifyWinUtilsValid(Logger logger) throws
+ public static void maybeVerifyWinUtilsValid() throws
IOException,
SliderException {
- if (!Shell.WINDOWS) {
- return;
+ String errorText = SliderUtils.checkForRequiredNativeLibraries();
+ if (!errorText.isEmpty()) {
+ throw new BadClusterStateException(errorText);
}
- String exePath = Shell.getWinUtilsPath();
- String program = WINUTILS;
- if (exePath == null) {
- throw new FileNotFoundException(program + " not found on Path : " +
- System.getenv("Path"));
- }
- File exe = new File(exePath);
-
- verifyWindowsExe(program, exe);
- execCommand(WINUTILS, 0, 5000, log, null, exePath, "systeminfo");
-
}
public static void verifyIsFile(String program, File exe) throws
@@ -1947,7 +1967,7 @@
public static void validateSliderClientEnvironment(Logger logger) throws
IOException,
SliderException {
- maybeVerifyWinUtilsValid(logger);
+ maybeVerifyWinUtilsValid();
}
/**
diff --git a/slider-core/src/test/groovy/org/apache/slider/common/tools/TestExecutionEnvironment.groovy b/slider-core/src/test/groovy/org/apache/slider/common/tools/TestExecutionEnvironment.groovy
index ad78c0e..97b72d1 100644
--- a/slider-core/src/test/groovy/org/apache/slider/common/tools/TestExecutionEnvironment.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/common/tools/TestExecutionEnvironment.groovy
@@ -34,7 +34,7 @@
@Test
public void testWinutils() throws Throwable {
- SliderUtils.maybeVerifyWinUtilsValid(log);
+ SliderUtils.maybeVerifyWinUtilsValid();
}
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 61960e6..6351c14 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
@@ -134,7 +134,7 @@
@Test
public void testHasWinutils() throws Throwable {
assume(Shell.WINDOWS, "not windows")
- SliderUtils.maybeVerifyWinUtilsValid(log)
+ SliderUtils.maybeVerifyWinUtilsValid()
}
@Test
diff --git a/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy b/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
index 6e63da9..87621a1 100644
--- a/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
+++ b/slider-core/src/test/groovy/org/apache/slider/test/SliderTestUtils.groovy
@@ -27,9 +27,7 @@
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.fs.FileStatus
import org.apache.hadoop.fs.FileSystem as HadoopFS
-import org.apache.hadoop.fs.FileUtil
import org.apache.hadoop.fs.Path
-import org.apache.hadoop.io.nativeio.NativeIO
import org.apache.hadoop.util.Shell
import org.apache.hadoop.yarn.api.records.ApplicationReport
import org.apache.hadoop.yarn.conf.YarnConfiguration
@@ -191,45 +189,15 @@
fail("Not implemented")
}
- /**
- * Check for any needed libraries being present. On Unix none are needed;
- * on windows they must be present
- * @return true if all is well
- */
- public static String checkForRequiredLibraries() {
-
- if (!Shell.WINDOWS) {
- return "";
- }
- StringBuilder errorText = new StringBuilder("")
- boolean available = true;
- if (!NativeIO.available) {
- errorText.append("No native IO library. ")
- }
- try {
- def path = Shell.getQualifiedBinPath("winutils.exe");
- log.debug("winutils is at $path")
- } catch (IOException e) {
- errorText.append("No WINUTILS.EXE. ")
- log.warn("No winutils: $e", e)
- }
- try {
- File target = new File("target")
- FileUtil.canRead(target)
- } catch (UnsatisfiedLinkError e) {
- log.warn("Failing to link to native IO methods: $e", e)
- errorText.append("No native IO methods")
- }
- return errorText.toString();
- }
+
/**
* Assert that any needed libraries being present. On Unix none are needed;
* on windows they must be present
*/
public static void assertNativeLibrariesPresent() {
- String errorText = checkForRequiredLibraries()
- if (errorText != null) {
+ String errorText = SliderUtils.checkForRequiredNativeLibraries()
+ if (errorText != "") {
fail(errorText)
}
}