org.apache.hadoop.util.Shell Java Examples

The following examples show how to use org.apache.hadoop.util.Shell. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FileUtil.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Given a Tar File as input it will untar the file in a the untar directory
 * passed as the second parameter
 * 
 * This utility will untar ".tar" files and ".tar.gz","tgz" files.
 *  
 * @param inFile The tar file as input. 
 * @param untarDir The untar directory where to untar the tar file.
 * @throws IOException
 */
public static void unTar(File inFile, File untarDir) throws IOException {
  if (!untarDir.mkdirs()) {
    if (!untarDir.isDirectory()) {
      throw new IOException("Mkdirs failed to create " + untarDir);
    }
  }

  boolean gzipped = inFile.toString().endsWith("gz");
  if(Shell.WINDOWS) {
    // Tar is not native to Windows. Use simple Java based implementation for 
    // tests and simple tar archives
    unTarUsingJava(inFile, untarDir, gzipped);
  }
  else {
    // spawn tar utility to untar archive for full fledged unix behavior such 
    // as resolving symlinks in tar archives
    unTarUsingTar(inFile, untarDir, gzipped);
  }
}
 
Example #2
Source File: HttpServer.java    From big-c with Apache License 2.0 6 votes vote down vote up
@InterfaceAudience.Private
public static Connector createDefaultChannelConnector() {
  SelectChannelConnector ret = new SelectChannelConnectorWithSafeStartup();
  ret.setLowResourceMaxIdleTime(10000);
  ret.setAcceptQueueSize(128);
  ret.setResolveNames(false);
  ret.setUseDirectBuffers(false);
  if(Shell.WINDOWS) {
    // result of setting the SO_REUSEADDR flag is different on Windows
    // http://msdn.microsoft.com/en-us/library/ms740621(v=vs.85).aspx
    // without this 2 NN's can start on the same machine and listen on 
    // the same port with indeterminate routing of incoming requests to them
    ret.setReuseAddress(false);
  }
  ret.setHeaderBufferSize(1024*64);
  return ret;
}
 
Example #3
Source File: TestLocalDirAllocator.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Test getLocalPathToRead() returns correct filename and "file" schema.
 *
 * @throws IOException
 */
@Test (timeout = 30000)
public void testGetLocalPathToRead() throws IOException {
  assumeTrue(!isWindows);
  String dir = buildBufferDir(ROOT, 0);
  try {
    conf.set(CONTEXT, dir);
    assertTrue(localFs.mkdirs(new Path(dir)));
    File f1 = dirAllocator.createTmpFileForWrite(FILENAME, SMALL_FILE_SIZE,
        conf);
    Path p1 = dirAllocator.getLocalPathToRead(f1.getName(), conf);
    assertEquals(f1.getName(), p1.getName());
    assertEquals("file", p1.getFileSystem(conf).getUri().getScheme());
  } finally {
    Shell.execCommand(Shell.getSetPermissionCommand("u+w", false,
                                                    BUFFER_DIR_ROOT));
    rmBufferDirs();
  }
}
 
Example #4
Source File: TestNodeManagerShutdown.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a script to run a container that will run forever unless
 * stopped by external means.
 */
private static File createUnhaltingScriptFile(ContainerId cId,
    File scriptFileDir, File processStartFile) throws IOException {
  File scriptFile = Shell.appendScriptExtension(scriptFileDir, "scriptFile");
  PrintWriter fileWriter = new PrintWriter(scriptFile);
  if (Shell.WINDOWS) {
    fileWriter.println("@echo \"Running testscript for delayed kill\"");
    fileWriter.println("@echo \"Writing pid to start file\"");
    fileWriter.println("@echo " + cId + ">> " + processStartFile);
    fileWriter.println("@pause");
  } else {
    fileWriter.write("#!/bin/bash\n\n");
    fileWriter.write("echo \"Running testscript for delayed kill\"\n");
    fileWriter.write("hello=\"Got SIGTERM\"\n");
    fileWriter.write("umask 0\n");
    fileWriter.write("trap \"echo $hello >> " + processStartFile +
      "\" SIGTERM\n");
    fileWriter.write("echo \"Writing pid to start file\"\n");
    fileWriter.write("echo $$ >> " + processStartFile + "\n");
    fileWriter.write("while true; do\ndate >> /dev/null;\n done\n");
  }

  fileWriter.close();
  return scriptFile;
}
 
Example #5
Source File: FileUtil.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Given a Tar File as input it will untar the file in a the untar directory
 * passed as the second parameter
 * 
 * This utility will untar ".tar" files and ".tar.gz","tgz" files.
 *  
 * @param inFile The tar file as input. 
 * @param untarDir The untar directory where to untar the tar file.
 * @throws IOException
 */
public static void unTar(File inFile, File untarDir) throws IOException {
  if (!untarDir.mkdirs()) {
    if (!untarDir.isDirectory()) {
      throw new IOException("Mkdirs failed to create " + untarDir);
    }
  }

  boolean gzipped = inFile.toString().endsWith("gz");
  if(Shell.WINDOWS) {
    // Tar is not native to Windows. Use simple Java based implementation for 
    // tests and simple tar archives
    unTarUsingJava(inFile, untarDir, gzipped);
  }
  else {
    // spawn tar utility to untar archive for full fledged unix behavior such 
    // as resolving symlinks in tar archives
    unTarUsingTar(inFile, untarDir, gzipped);
  }
}
 
Example #6
Source File: FileUtil.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Change the permissions on a file / directory, recursively, if
 * needed.
 * @param filename name of the file whose permissions are to change
 * @param perm permission string
 * @param recursive true, if permissions should be changed recursively
 * @return the exit code from the command.
 * @throws IOException exception on chmod
 */
public static int chmod(String filename, String perm, boolean recursive)
    throws IOException {
  String [] cmd = Shell.getSetPermissionCommand(perm, recursive);
  String[] args = new String[cmd.length + 1];
  System.arraycopy(cmd, 0, args, 0, cmd.length);
  args[cmd.length] = new File(filename).getPath();
  ShellCommandExecutor shExec = new ShellCommandExecutor(args);
  try {
    shExec.execute();
  }catch(IOException e) {
    if(LOG.isDebugEnabled()) {
      LOG.debug("Error while changing permission : {} Exception: {}", filename, StringUtils.stringifyException(e));
    }
  }
  return shExec.getExitCode();
}
 
Example #7
Source File: RawLocalFileSystem.java    From big-c with Apache License 2.0 6 votes vote down vote up
protected boolean mkOneDirWithMode(Path p, File p2f, FsPermission permission)
    throws IOException {
  if (permission == null) {
    return p2f.mkdir();
  } else {
    if (Shell.WINDOWS && NativeIO.isAvailable()) {
      try {
        NativeIO.Windows.createDirectoryWithMode(p2f, permission.toShort());
        return true;
      } catch (IOException e) {
        if (LOG.isDebugEnabled()) {
          LOG.debug(String.format(
              "NativeIO.createDirectoryWithMode error, path = %s, mode = %o",
              p2f, permission.toShort()), e);
        }
        return false;
      }
    } else {
      boolean b = p2f.mkdir();
      if (b) {
        setPermission(p, permission);
      }
      return b;
    }
  }
}
 
Example #8
Source File: TestLocalDirAllocator.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Test getLocalPathToRead() returns correct filename and "file" schema.
 *
 * @throws IOException
 */
@Test (timeout = 30000)
public void testGetLocalPathToRead() throws IOException {
  assumeTrue(!isWindows);
  String dir = buildBufferDir(ROOT, 0);
  try {
    conf.set(CONTEXT, dir);
    assertTrue(localFs.mkdirs(new Path(dir)));
    File f1 = dirAllocator.createTmpFileForWrite(FILENAME, SMALL_FILE_SIZE,
        conf);
    Path p1 = dirAllocator.getLocalPathToRead(f1.getName(), conf);
    assertEquals(f1.getName(), p1.getName());
    assertEquals("file", p1.getFileSystem(conf).getUri().getScheme());
  } finally {
    Shell.execCommand(Shell.getSetPermissionCommand("u+w", false,
                                                    BUFFER_DIR_ROOT));
    rmBufferDirs();
  }
}
 
Example #9
Source File: ResourceCalculatorPlugin.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Create the ResourceCalculatorPlugin from the class name and configure it. If
 * class name is null, this method will try and return a memory calculator
 * plugin available for this system.
 *
 * @param clazz ResourceCalculator plugin class-name
 * @param conf configure the plugin with this.
 * @return ResourceCalculatorPlugin or null if ResourceCalculatorPlugin is not
 * 		 available for current system
 */
public static ResourceCalculatorPlugin getResourceCalculatorPlugin(
    Class<? extends ResourceCalculatorPlugin> clazz, Configuration conf) {

  if (clazz != null) {
    return ReflectionUtils.newInstance(clazz, conf);
  }

  // No class given, try a os specific class
  try {
    if (Shell.LINUX) {
      return new LinuxResourceCalculatorPlugin();
    }
    if (Shell.WINDOWS) {
      return new WindowsResourceCalculatorPlugin();
    }
  } catch (SecurityException se) {
    // Failed to get Operating System name.
    return null;
  }

  // Not supported on this system.
  return null;
}
 
Example #10
Source File: NativeIO.java    From big-c with Apache License 2.0 6 votes vote down vote up
public static void chmod(String path, int mode) throws IOException {
  if (!Shell.WINDOWS) {
    chmodImpl(path, mode);
  } else {
    try {
      chmodImpl(path, mode);
    } catch (NativeIOException nioe) {
      if (nioe.getErrorCode() == 3) {
        throw new NativeIOException("No such file or directory",
            Errno.ENOENT);
      } else {
        LOG.warn(String.format("NativeIO.chmod error (%d): %s",
            nioe.getErrorCode(), nioe.getMessage()));
        throw new NativeIOException("Unknown error", Errno.UNKNOWN);
      }
    }
  }
}
 
Example #11
Source File: NativeIO.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public static String getOwner(FileDescriptor fd) throws IOException {
  ensureInitialized();
  if (Shell.WINDOWS) {
    String owner = Windows.getOwner(fd);
    owner = stripDomain(owner);
    return owner;
  } else {
    long uid = POSIX.getUIDforFDOwnerforOwner(fd);
    CachedUid cUid = uidCache.get(uid);
    long now = System.currentTimeMillis();
    if (cUid != null && (cUid.timestamp + cacheTimeout) > now) {
      return cUid.username;
    }
    String user = POSIX.getUserName(uid);
    LOG.info("Got UserName " + user + " for UID " + uid
        + " from the native implementation");
    cUid = new CachedUid(user, now);
    uidCache.put(uid, cUid);
    return user;
  }
}
 
Example #12
Source File: MiniYARNCluster.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
protected synchronized void serviceStop() throws Exception {
  if (resourceManagers[index] != null) {
    waitForAppMastersToFinish(5000);
    resourceManagers[index].stop();
  }

  if (Shell.WINDOWS) {
    // On Windows, clean up the short temporary symlink that was created to
    // work around path length limitation.
    String testWorkDirPath = testWorkDir.getAbsolutePath();
    try {
      FileContext.getLocalFSFileContext().delete(new Path(testWorkDirPath),
        true);
    } catch (IOException e) {
      LOG.warn("could not cleanup symlink: " +
        testWorkDir.getAbsolutePath());
    }
  }
  super.serviceStop();
}
 
Example #13
Source File: TestContainerLaunch.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test (timeout = 10000)
public void testWindowsShellScriptBuilderEnv() throws IOException {
  // Test is only relevant on Windows
  Assume.assumeTrue(Shell.WINDOWS);

  // The tests are built on assuming 8191 max command line length
  assertEquals(8191, Shell.WINDOWS_MAX_SHELL_LENGHT);

  ShellScriptBuilder builder = ShellScriptBuilder.create();

  // test env
  builder.env("somekey", org.apache.commons.lang.StringUtils.repeat("A", 1024));
  builder.env("somekey", org.apache.commons.lang.StringUtils.repeat(
      "A", Shell.WINDOWS_MAX_SHELL_LENGHT - ("@set somekey=").length()));
  try {
    builder.env("somekey", org.apache.commons.lang.StringUtils.repeat(
        "A", Shell.WINDOWS_MAX_SHELL_LENGHT - ("@set somekey=").length()) + 1);
    fail("long env was expected to throw");
  } catch(IOException e) {
    assertThat(e.getMessage(), CoreMatchers.containsString(expectedMessage));
  }
}
 
Example #14
Source File: TestJournalNode.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test(timeout=100000)
public void testFailToStartWithBadConfig() throws Exception {
  Configuration conf = new Configuration();
  conf.set(DFSConfigKeys.DFS_JOURNALNODE_EDITS_DIR_KEY, "non-absolute-path");
  conf.set(DFSConfigKeys.DFS_JOURNALNODE_HTTP_ADDRESS_KEY, "0.0.0.0:0");
  assertJNFailsToStart(conf, "should be an absolute path");
  
  // Existing file which is not a directory 
  File existingFile = new File(TEST_BUILD_DATA, "testjournalnodefile");
  assertTrue(existingFile.createNewFile());
  try {
    conf.set(DFSConfigKeys.DFS_JOURNALNODE_EDITS_DIR_KEY,
        existingFile.getAbsolutePath());
    assertJNFailsToStart(conf, "Not a directory");
  } finally {
    existingFile.delete();
  }
  
  // Directory which cannot be created
  conf.set(DFSConfigKeys.DFS_JOURNALNODE_EDITS_DIR_KEY,
      Shell.WINDOWS ? "\\\\cannotBeCreated" : "/proc/does-not-exist");
  assertJNFailsToStart(conf, "Cannot create directory");
}
 
Example #15
Source File: RawLocalFileSystem.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private LocalFSFileOutputStream(Path f, boolean append,
    FsPermission permission) throws IOException {
  File file = pathToFile(f);
  if (permission == null) {
    this.fos = new FileOutputStream(file, append);
  } else {
    if (Shell.WINDOWS && NativeIO.isAvailable()) {
      this.fos = NativeIO.Windows.createFileOutputStreamWithMode(file,
          append, permission.toShort());
    } else {
      this.fos = new FileOutputStream(file, append);
      boolean success = false;
      try {
        setPermission(f, permission);
        success = true;
      } finally {
        if (!success) {
          IOUtils.cleanup(LOG, this.fos);
        }
      }
    }
  }
}
 
Example #16
Source File: NativeIO.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the file stat for a file descriptor.
 *
 * @param fd file descriptor.
 * @return the file descriptor file stat.
 * @throws IOException thrown if there was an IO error while obtaining the file stat.
 */
public static Stat getFstat(FileDescriptor fd) throws IOException {
  Stat stat = null;
  if (!Shell.WINDOWS) {
    stat = fstat(fd); 
    stat.owner = getName(IdCache.USER, stat.ownerId);
    stat.group = getName(IdCache.GROUP, stat.groupId);
  } else {
    try {
      stat = fstat(fd);
    } catch (NativeIOException nioe) {
      if (nioe.getErrorCode() == 6) {
        throw new NativeIOException("The handle is invalid.",
            Errno.EBADF);
      } else {
        LOG.warn(String.format("NativeIO.getFstat error (%d): %s",
            nioe.getErrorCode(), nioe.getMessage()));
        throw new NativeIOException("Unknown error", Errno.UNKNOWN);
      }
    }
  }
  return stat;
}
 
Example #17
Source File: ContainerLaunch.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
protected void link(Path src, Path dst) throws IOException {
  File srcFile = new File(src.toUri().getPath());
  String srcFileStr = srcFile.getPath();
  String dstFileStr = new File(dst.toString()).getPath();
  // If not on Java7+ on Windows, then copy file instead of symlinking.
  // See also FileUtil#symLink for full explanation.
  if (!Shell.isJava7OrAbove() && srcFile.isFile()) {
    lineWithLenCheck(String.format("@copy \"%s\" \"%s\"", srcFileStr, dstFileStr));
    errorCheck();
  } else {
    lineWithLenCheck(String.format("@%s symlink \"%s\" \"%s\"", Shell.WINUTILS,
      dstFileStr, srcFileStr));
    errorCheck();
  }
}
 
Example #18
Source File: HttpServer2.java    From big-c with Apache License 2.0 6 votes vote down vote up
@InterfaceAudience.Private
public static Connector createDefaultChannelConnector() {
  SelectChannelConnector ret = new SelectChannelConnectorWithSafeStartup();
  ret.setLowResourceMaxIdleTime(10000);
  ret.setAcceptQueueSize(128);
  ret.setResolveNames(false);
  ret.setUseDirectBuffers(false);
  if(Shell.WINDOWS) {
    // result of setting the SO_REUSEADDR flag is different on Windows
    // http://msdn.microsoft.com/en-us/library/ms740621(v=vs.85).aspx
    // without this 2 NN's can start on the same machine and listen on
    // the same port with indeterminate routing of incoming requests to them
    ret.setReuseAddress(false);
  }
  ret.setHeaderBufferSize(1024*64);
  return ret;
}
 
Example #19
Source File: TestLocalDirAllocator.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/** Two buffer dirs. The first dir exists & is on a read-only disk;
 * The second dir exists & is RW
 * @throws Exception
 */
@Test (timeout = 30000)
public void testROBufferDirAndRWBufferDir() throws Exception {
  if (isWindows) return;
  String dir1 = buildBufferDir(ROOT, 1);
  String dir2 = buildBufferDir(ROOT, 2);
  try {
    conf.set(CONTEXT, dir1 + "," + dir2);
    assertTrue(localFs.mkdirs(new Path(dir2)));
    BUFFER_ROOT.setReadOnly();
    validateTempDirCreation(dir2);
    validateTempDirCreation(dir2);
  } finally {
    Shell.execCommand(Shell.getSetPermissionCommand("u+w", false,
                                                    BUFFER_DIR_ROOT));
    rmBufferDirs();
  }
}
 
Example #20
Source File: TestAtomicFileOutputStream.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testFailToRename() throws IOException {
  assumeTrue(Shell.WINDOWS);
  OutputStream fos = null;
  try {
    fos = new AtomicFileOutputStream(DST_FILE);
    fos.write(TEST_STRING.getBytes());
    FileUtil.setWritable(TEST_DIR, false);
    exception.expect(IOException.class);
    exception.expectMessage("failure in native rename");
    try {
      fos.close();
    } finally {
      fos = null;
    }
  } finally {
    IOUtils.cleanup(null, fos);
    FileUtil.setWritable(TEST_DIR, true);
  }
}
 
Example #21
Source File: TestContainerExecutor.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test (timeout = 5000)
public void testRunCommandWithCpuAndMemoryResources() {
  // Windows only test
  assumeTrue(Shell.WINDOWS);
  Configuration conf = new Configuration();
  conf.set(YarnConfiguration.NM_WINDOWS_CONTAINER_CPU_LIMIT_ENABLED, "true");
  conf.set(YarnConfiguration.NM_WINDOWS_CONTAINER_MEMORY_LIMIT_ENABLED, "true");
  String[] command = containerExecutor.getRunCommand("echo", "group1", null, null,
      conf, Resource.newInstance(1024, 1));
  float yarnProcessors = NodeManagerHardwareUtils.getContainersCores(
      ResourceCalculatorPlugin.getResourceCalculatorPlugin(null, conf),
      conf);
  int cpuRate = Math.min(10000, (int) ((1 * 10000) / yarnProcessors));
  // Assert the cpu and memory limits are set correctly in the command
  String[] expected = { Shell.WINUTILS, "task", "create", "-m", "1024", "-c",
      String.valueOf(cpuRate), "group1", "cmd /c " + "echo" };
  Assert.assertTrue(Arrays.equals(expected, command));
}
 
Example #22
Source File: FileUtil.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Change the permissions on a file / directory, recursively, if
 * needed.
 * @param filename name of the file whose permissions are to change
 * @param perm permission string
 * @param recursive true, if permissions should be changed recursively
 * @return the exit code from the command.
 * @throws IOException
 */
public static int chmod(String filename, String perm, boolean recursive)
                          throws IOException {
  String [] cmd = Shell.getSetPermissionCommand(perm, recursive);
  String[] args = new String[cmd.length + 1];
  System.arraycopy(cmd, 0, args, 0, cmd.length);
  args[cmd.length] = new File(filename).getPath();
  ShellCommandExecutor shExec = new ShellCommandExecutor(args);
  try {
    shExec.execute();
  }catch(IOException e) {
    if(LOG.isDebugEnabled()) {
      LOG.debug("Error while changing permission : " + filename 
                +" Exception: " + StringUtils.stringifyException(e));
    }
  }
  return shExec.getExitCode();
}
 
Example #23
Source File: TestScriptUDF.java    From spork with Apache License 2.0 5 votes vote down vote up
@Test
public void testPythonBuiltinModuleImport1() throws Exception {
    String[] script = {
            "#!/usr/bin/python",
            "import os",
            "@outputSchema(\"env:chararray\")",
            "def getEnv(envkey):" ,
            " return os.getenv(envkey);"
    };
    String userenv = Shell.WINDOWS?"USERNAME":"USER";
    String[] input = {
            userenv,
            "JAVA_HOME"
    };

    Util.createInputFile(cluster, "testPythonBuiltinModuleImport1", input);
    File scriptFile = Util.createLocalInputFile("importos.py", script);

    pigServer.registerCode(scriptFile.getAbsolutePath(), "jython", "pig");
    pigServer.registerQuery("A = LOAD 'testPythonBuiltinModuleImport1' as (a0:chararray);");
    pigServer.registerQuery("B = foreach A generate pig.getEnv(a0);");

    Iterator<Tuple> iter = pigServer.openIterator("B");
    Assert.assertTrue(iter.hasNext());
    Tuple t = iter.next();
    Assert.assertTrue(t.get(0).toString().equals(System.getenv(input[0])));
    Assert.assertTrue(iter.hasNext());
    t = iter.next();
    Assert.assertTrue(t.get(0).toString().equals(System.getenv(input[1])));
    Assert.assertFalse(iter.hasNext());
}
 
Example #24
Source File: ShortCircuitShm.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Create the ShortCircuitShm.
 * 
 * @param shmId       The ID to use.
 * @param stream      The stream that we're going to use to create this 
 *                    shared memory segment.
 *                    
 *                    Although this is a FileInputStream, we are going to
 *                    assume that the underlying file descriptor is writable
 *                    as well as readable. It would be more appropriate to use
 *                    a RandomAccessFile here, but that class does not have
 *                    any public accessor which returns a FileDescriptor,
 *                    unlike FileInputStream.
 */
public ShortCircuitShm(ShmId shmId, FileInputStream stream)
      throws IOException {
  if (!NativeIO.isAvailable()) {
    throw new UnsupportedOperationException("NativeIO is not available.");
  }
  if (Shell.WINDOWS) {
    throw new UnsupportedOperationException(
        "DfsClientShm is not yet implemented for Windows.");
  }
  if (unsafe == null) {
    throw new UnsupportedOperationException(
        "can't use DfsClientShm because we failed to " +
        "load misc.Unsafe.");
  }
  this.shmId = shmId;
  this.mmappedLength = getUsableLength(stream);
  this.baseAddress = POSIX.mmap(stream.getFD(), 
      POSIX.MMAP_PROT_READ | POSIX.MMAP_PROT_WRITE, true, mmappedLength);
  this.slots = new Slot[mmappedLength / BYTES_PER_SLOT];
  this.allocatedSlots = new BitSet(slots.length);
  if (LOG.isTraceEnabled()) {
    LOG.trace("creating " + this.getClass().getSimpleName() +
        "(shmId=" + shmId +
        ", mmappedLength=" + mmappedLength +
        ", baseAddress=" + String.format("%x", baseAddress) +
        ", slots.length=" + slots.length + ")");
  }
}
 
Example #25
Source File: FileUtil.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Platform independent implementation for {@link File#setExecutable(boolean)}
 * File#setExecutable does not work as expected on Windows.
 * Note: revoking execute permission on folders does not have the same
 * behavior on Windows as on Unix platforms. Creating, deleting or renaming
 * a file within that folder will still succeed on Windows.
 * @param f input file
 * @param executable set to executable or not
 * @return true on success, false otherwise
 */
public static boolean setExecutable(File f, boolean executable) {
  if (Shell.WINDOWS) {
    try {
      String permission = executable ? "u+x" : "u-x";
      FileUtil.chmod(f.getCanonicalPath(), permission, false);
      return true;
    } catch (IOException ex) {
      return false;
    }
  } else {
    return f.setExecutable(executable);
  }
}
 
Example #26
Source File: FileUtil.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Platform independent implementation for {@link File#setReadable(boolean)}
 * File#setReadable does not work as expected on Windows.
 * @param f input file
 * @param readable
 * @return true on success, false otherwise
 */
public static boolean setReadable(File f, boolean readable) {
  if (Shell.WINDOWS) {
    try {
      String permission = readable ? "u+r" : "u-r";
      FileUtil.chmod(f.getCanonicalPath(), permission, false);
      return true;
    } catch (IOException ex) {
      return false;
    }
  } else {
    return f.setReadable(readable);
  }
}
 
Example #27
Source File: Stat.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Whether Stat is supported on the current platform
 * @return
 */
public static boolean isAvailable() {
  if (Shell.LINUX || Shell.FREEBSD || Shell.MAC) {
    return true;
  }
  return false;
}
 
Example #28
Source File: FileUtil.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Platform independent implementation for {@link File#canRead()}
 * @param f input file
 * @return On Unix, same as {@link File#canRead()}
 *         On Windows, true if process has read access on the path
 */
public static boolean canRead(File f) {
  if (Shell.WINDOWS) {
    try {
      return NativeIO.Windows.access(f.getCanonicalPath(),
          NativeIO.Windows.AccessRight.ACCESS_READ);
    } catch (IOException e) {
      return false;
    }
  } else {
    return f.canRead();
  }
}
 
Example #29
Source File: TestContainerExecutor.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test (timeout = 5000)
public void testRunCommandwithPriority() throws Exception {
  Configuration conf = new Configuration();
  conf.setInt(YarnConfiguration.NM_CONTAINER_EXECUTOR_SCHED_PRIORITY, 2);
  String[] command = containerExecutor.getRunCommand("echo", "group1", "user", null, conf);
  if (Shell.WINDOWS) {
    // windows doesn't currently support
    assertEquals("first command should be the run command for the platform", 
             Shell.WINUTILS, command[0]); 
  } else {
    assertEquals("first command should be nice", "nice", command[0]); 
    assertEquals("second command should be -n", "-n", command[1]); 
    assertEquals("third command should be the priority", Integer.toString(2),
                 command[2]); 
  }

  // test with negative number
  conf.setInt(YarnConfiguration.NM_CONTAINER_EXECUTOR_SCHED_PRIORITY, -5);
  command = containerExecutor.getRunCommand("echo", "group1", "user", null, conf);
  if (Shell.WINDOWS) {
    // windows doesn't currently support
    assertEquals("first command should be the run command for the platform", 
             Shell.WINUTILS, command[0]); 
  } else {
    assertEquals("first command should be nice", "nice", command[0]); 
    assertEquals("second command should be -n", "-n", command[1]); 
    assertEquals("third command should be the priority", Integer.toString(-5),
                  command[2]); 
  }
}
 
Example #30
Source File: TestPath.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test (timeout = 30000)
public void testIsWindowsAbsolutePath() {
  if (!Shell.WINDOWS) return;
  assertTrue(Path.isWindowsAbsolutePath("C:\\test", false));
  assertTrue(Path.isWindowsAbsolutePath("C:/test", false));
  assertTrue(Path.isWindowsAbsolutePath("/C:/test", true));
  assertFalse(Path.isWindowsAbsolutePath("/test", false));
  assertFalse(Path.isWindowsAbsolutePath("/test", true));
  assertFalse(Path.isWindowsAbsolutePath("C:test", false));
  assertFalse(Path.isWindowsAbsolutePath("/C:test", true));
}