List of usage examples for org.apache.hadoop.util Shell WINDOWS
boolean WINDOWS
To view the source code for org.apache.hadoop.util Shell WINDOWS.
Click Source Link
From source file:org.apache.falcon.hive.util.HiveDRUtils.java
License:Apache License
public static String getFilePathFromEnv(String env) { String path = System.getenv(env); if (path != null && Shell.WINDOWS) { // In Windows, file paths are enclosed in \" so remove them here // to avoid path errors if (path.charAt(0) == '"') { path = path.substring(1);//from www .j a v a 2s.co m } if (path.charAt(path.length() - 1) == '"') { path = path.substring(0, path.length() - 1); } } return path; }
From source file:org.apache.falcon.security.HostnameFilterTest.java
License:Apache License
@Test public void testHostname() throws Exception { ServletRequest request = Mockito.mock(ServletRequest.class); Mockito.when(request.getRemoteAddr()).thenReturn("localhost"); ServletResponse response = Mockito.mock(ServletResponse.class); final AtomicBoolean invoked = new AtomicBoolean(); FilterChain chain = new FilterChain() { @Override/*from w w w . j av a 2 s . c om*/ public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException { Assert.assertTrue(HostnameFilter.get().contains(Shell.WINDOWS ? "127.0.0.1" : "localhost")); invoked.set(true); } }; Filter filter = new HostnameFilter(); filter.init(null); Assert.assertNull(HostnameFilter.get()); filter.doFilter(request, response, chain); Assert.assertTrue(invoked.get()); Assert.assertNull(HostnameFilter.get()); filter.destroy(); }
From source file:org.apache.falcon.workflow.util.OozieActionConfigurationHelper.java
License:Apache License
public static Configuration createActionConf() throws IOException { Configuration conf = new Configuration(); Path confPath = new Path("file:///" + System.getProperty("oozie.action.conf.xml")); final boolean actionConfExists = confPath.getFileSystem(conf).exists(confPath); LOG.info("Oozie Action conf {} found ? {}", confPath, actionConfExists); if (actionConfExists) { LOG.info("Oozie Action conf found, adding path={}, conf={}", confPath, conf.toString()); conf.addResource(confPath);//from w w w .j av a 2 s . c om dumpConf(conf, "oozie action conf "); } String tokenFile = System.getenv("HADOOP_TOKEN_FILE_LOCATION"); if (tokenFile != null) { if (Shell.WINDOWS) { if (tokenFile.charAt(0) == '"') { tokenFile = tokenFile.substring(1); } if (tokenFile.charAt(tokenFile.length() - 1) == '"') { tokenFile = tokenFile.substring(0, tokenFile.length() - 1); } } conf.set("mapreduce.job.credentials.binary", tokenFile); System.setProperty("mapreduce.job.credentials.binary", tokenFile); conf.set("tez.credentials.path", tokenFile); System.setProperty("tez.credentials.path", tokenFile); } conf.set("datanucleus.plugin.pluginRegistryBundleCheck", "LOG"); conf.setBoolean("hive.exec.mode.local.auto", false); return conf; }
From source file:org.apache.hcatalog.templeton.StreamOutputWriter.java
License:Apache License
private ExecBean auxRun(String program, List<String> args, Map<String, String> env) throws NotAuthorizedException, ExecuteException, IOException { DefaultExecutor executor = new DefaultExecutor(); executor.setExitValues(null);/*from w w w. j a v a 2 s. c o m*/ // Setup stdout and stderr int nbytes = appConf.getInt(AppConfig.EXEC_MAX_BYTES_NAME, -1); ByteArrayOutputStream outStream = new MaxByteArrayOutputStream(nbytes); ByteArrayOutputStream errStream = new MaxByteArrayOutputStream(nbytes); executor.setStreamHandler(new PumpStreamHandler(outStream, errStream)); // Only run for N milliseconds int timeout = appConf.getInt(AppConfig.EXEC_TIMEOUT_NAME, 0); ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout); executor.setWatchdog(watchdog); CommandLine cmd = makeCommandLine(program, args); LOG.info("Running: " + cmd); ExecBean res = new ExecBean(); if (Shell.WINDOWS) { //The default executor is sometimes causing failure on windows. hcat // command sometimes returns non zero exit status with it. It seems // to hit some race conditions on windows. env = execEnv(env); String[] envVals = new String[env.size()]; int i = 0; for (Entry<String, String> kv : env.entrySet()) { envVals[i++] = kv.getKey() + "=" + kv.getValue(); System.out.println("Setting " + kv.getKey() + "=" + kv.getValue()); } Process proc = Runtime.getRuntime().exec(cmd.toStrings(), envVals); //consume stderr StreamOutputWriter errorGobbler = new StreamOutputWriter(proc.getErrorStream(), "ERROR", errStream); //consume stdout StreamOutputWriter outputGobbler = new StreamOutputWriter(proc.getInputStream(), "OUTPUT", outStream); //start collecting input streams errorGobbler.start(); outputGobbler.start(); //execute try { res.exitcode = proc.waitFor(); } catch (InterruptedException e) { throw new IOException(e); } //flush errorGobbler.out.flush(); outputGobbler.out.flush(); } else { res.exitcode = executor.execute(cmd, execEnv(env)); } String enc = appConf.get(AppConfig.EXEC_ENCODING_NAME); res.stdout = outStream.toString(enc); res.stderr = errStream.toString(enc); return res; }
From source file:org.apache.hive.beeline.qfile.QFile.java
License:Apache License
private boolean executeDiff() throws IOException, InterruptedException { List<String> diffCommandArgs = new ArrayList<String>(); diffCommandArgs.add("diff"); // Text file comparison diffCommandArgs.add("-a"); if (Shell.WINDOWS) { // Ignore changes in the amount of white space diffCommandArgs.add("-b"); // Files created on Windows machines have different line endings // than files created on Unix/Linux. Windows uses carriage return and line feed // ("\r\n") as a line ending, whereas Unix uses just line feed ("\n"). // Also StringBuilder.toString(), Stream to String conversions adds extra // spaces at the end of the line. diffCommandArgs.add("--strip-trailing-cr"); // Strip trailing carriage return on input diffCommandArgs.add("-B"); // Ignore changes whose lines are all blank }// ww w . j a v a 2s .co m // Add files to compare to the arguments list diffCommandArgs.add(getQuotedString(expcetedOutputFile)); diffCommandArgs.add(getQuotedString(outputFile)); System.out.println("Running: " + org.apache.commons.lang.StringUtils.join(diffCommandArgs, ' ')); Process executor = Runtime.getRuntime().exec(diffCommandArgs.toArray(new String[diffCommandArgs.size()])); StreamPrinter errPrinter = new StreamPrinter(executor.getErrorStream(), null, System.err); StreamPrinter outPrinter = new StreamPrinter(executor.getInputStream(), null, System.out); outPrinter.start(); errPrinter.start(); int result = executor.waitFor(); outPrinter.join(); errPrinter.join(); executor.waitFor(); return (result == 0); }
From source file:org.apache.hive.beeline.qfile.QFile.java
License:Apache License
private static String getQuotedString(File file) { return Shell.WINDOWS ? String.format("\"%s\"", file.getAbsolutePath()) : file.getAbsolutePath(); }
From source file:org.apache.hive.beeline.QFile.java
License:Apache License
private QTestProcessExecResult executeDiff() throws IOException, InterruptedException { List<String> diffCommandArgs = new ArrayList<String>(); diffCommandArgs.add("diff"); // Text file comparison diffCommandArgs.add("-a"); if (Shell.WINDOWS) { // Ignore changes in the amount of white space diffCommandArgs.add("-b"); // Files created on Windows machines have different line endings // than files created on Unix/Linux. Windows uses carriage return and line feed // ("\r\n") as a line ending, whereas Unix uses just line feed ("\n"). // Also StringBuilder.toString(), Stream to String conversions adds extra // spaces at the end of the line. diffCommandArgs.add("--strip-trailing-cr"); // Strip trailing carriage return on input diffCommandArgs.add("-B"); // Ignore changes whose lines are all blank }/*w w w. j ava2 s . com*/ // Add files to compare to the arguments list diffCommandArgs.add(getQuotedString(expectedOutputFile)); diffCommandArgs.add(getQuotedString(outputFile)); System.out.println("Running: " + org.apache.commons.lang.StringUtils.join(diffCommandArgs, ' ')); Process executor = Runtime.getRuntime().exec(diffCommandArgs.toArray(new String[diffCommandArgs.size()])); ByteArrayOutputStream bos = new ByteArrayOutputStream(); PrintStream out = new PrintStream(bos, true, "UTF-8"); StreamPrinter errPrinter = new StreamPrinter(executor.getErrorStream(), null, System.err); StreamPrinter outPrinter = new StreamPrinter(executor.getInputStream(), null, System.out, out); outPrinter.start(); errPrinter.start(); int result = executor.waitFor(); outPrinter.join(); errPrinter.join(); executor.waitFor(); return QTestProcessExecResult.create(result, new String(bos.toByteArray(), StandardCharsets.UTF_8)); }
From source file:org.apache.hive.hcatalog.api.TestHCatClient.java
License:Apache License
@BeforeClass public static void startMetaStoreServer() throws Exception { hcatConf = new HiveConf(TestHCatClient.class); String metastoreUri = System.getProperty("test." + HiveConf.ConfVars.METASTOREURIS.varname); if (metastoreUri != null) { hcatConf.setVar(HiveConf.ConfVars.METASTOREURIS, metastoreUri); useExternalMS = true;//from w w w . ja va 2 s .c o m return; } if (Shell.WINDOWS) { WindowsPathUtil.convertPathsFromWindowsToHdfs(hcatConf); } System.setProperty(HiveConf.ConfVars.METASTORE_EVENT_LISTENERS.varname, DbNotificationListener.class.getName()); // turn on db notification listener on metastore msPort = MetaStoreUtils.startMetaStore(); securityManager = System.getSecurityManager(); System.setSecurityManager(new NoExitSecurityManager()); hcatConf.setVar(HiveConf.ConfVars.METASTOREURIS, "thrift://localhost:" + msPort); hcatConf.setIntVar(HiveConf.ConfVars.METASTORETHRIFTCONNECTIONRETRIES, 3); hcatConf.set(HiveConf.ConfVars.SEMANTIC_ANALYZER_HOOK.varname, HCatSemanticAnalyzer.class.getName()); hcatConf.set(HiveConf.ConfVars.PREEXECHOOKS.varname, ""); hcatConf.set(HiveConf.ConfVars.POSTEXECHOOKS.varname, ""); hcatConf.set(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY.varname, "false"); System.setProperty(HiveConf.ConfVars.PREEXECHOOKS.varname, " "); System.setProperty(HiveConf.ConfVars.POSTEXECHOOKS.varname, " "); }
From source file:org.apache.hive.hcatalog.api.TestHCatClient.java
License:Apache License
public static String fixPath(String path) { if (!Shell.WINDOWS) { return path; }//from w w w.jav a2 s .c o m String expectedDir = path.replaceAll("\\\\", "/"); if (!expectedDir.startsWith("/")) { expectedDir = "/" + expectedDir; } return expectedDir; }
From source file:org.apache.hive.hcatalog.mapreduce.HCatBaseTest.java
License:Apache License
/** * Create a new HiveConf and set properties necessary for unit tests. *//* w w w .jav a 2 s . c o m*/ protected void setUpHiveConf() { hiveConf = new HiveConf(this.getClass()); hiveConf.setVar(HiveConf.ConfVars.PREEXECHOOKS, ""); hiveConf.setVar(HiveConf.ConfVars.POSTEXECHOOKS, ""); hiveConf.setBoolVar(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY, false); hiveConf.setVar(HiveConf.ConfVars.METASTOREWAREHOUSE, TEST_WAREHOUSE_DIR); hiveConf.setVar(HiveConf.ConfVars.HIVEMAPREDMODE, "nonstrict"); hiveConf.setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER, "org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory"); if (Shell.WINDOWS) { WindowsPathUtil.convertPathsFromWindowsToHdfs(hiveConf); } }