List of usage examples for org.apache.hadoop.util Shell execCommand
public static String execCommand(String... cmd) throws IOException
From source file:ParascaleFileStatus.java
License:Apache License
static String execCommand(final File f, final String... cmd) throws IOException { final String[] args = new String[cmd.length + 1]; System.arraycopy(cmd, 0, args, 0, cmd.length); args[cmd.length] = f.getCanonicalPath(); final String output = Shell.execCommand(args); return output; }
From source file:ChunkLocator.java
License:Apache License
protected String execCommand(File aFile, String[] command) throws IOException { final String[] args = new String[command.length + 1]; System.arraycopy(command, 0, args, 0, command.length); args[command.length] = aFile.getCanonicalPath(); return Shell.execCommand(args); }
From source file:com.cloudera.hadoop.hdfs.nfs.nfs4.FixedUserIDMapper.java
License:Apache License
public static String getCurrentGroup() { File script = null;/*from ww w . j a va2s . co m*/ try { script = File.createTempFile("group", ".sh"); String[] cmd = { "bash", script.getAbsolutePath() }; Files.write("groups | cut -d ' ' -f 1", script, Charsets.UTF_8); return Shell.execCommand(cmd).trim(); } catch (Exception e) { throw new RuntimeException(e); } finally { if (script != null) { script.delete(); } } }
From source file:com.cloudera.hadoop.hdfs.nfs.nfs4.FixedUserIDMapper.java
License:Apache License
@Override public int getGIDForGroup(String user, int defaultGID) throws Exception { return Integer.parseInt(Shell.execCommand("id -g").trim()); }
From source file:com.cloudera.hadoop.hdfs.nfs.nfs4.FixedUserIDMapper.java
License:Apache License
@Override public int getUIDForUser(String user, int defaultUID) throws Exception { return Integer.parseInt(Shell.execCommand("id -u").trim()); }
From source file:com.cloudera.hadoop.hdfs.nfs.nfs4.TestWithClient.java
License:Apache License
protected String getOwner(File file) throws IOException { String[] cmd = new String[] { "stat", "-c", "%U", file.getCanonicalPath() }; return Shell.execCommand(cmd).trim(); }
From source file:com.cloudera.hadoop.hdfs.nfs.nfs4.TestWithClient.java
License:Apache License
protected String getOwnerGroup(File file) throws IOException { String[] cmd = new String[] { "/usr/bin/stat", "-c", "%G", file.getAbsolutePath() }; return Shell.execCommand(cmd).trim(); }
From source file:com.cloudera.hadoop.hdfs.nfs.nfs4.UserIDMapper.java
License:Apache License
/** * @return String username associated with the current process *///from www. j ava 2 s.com public static String getCurrentUser() { String user = System.getenv("USER"); if (user != null) { try { user = Shell.execCommand("whoami").trim(); } catch (Exception e) { throw new RuntimeException(e); } } return user; }
From source file:com.cloudera.hadoop.hdfs.nfs.nfs4.UserIDMapperSystem.java
License:Apache License
protected synchronized int getCachedID(String[] cmd, String name, int defaultID, Map<String, Long> negativeCache, Map<String, IDCache<Integer>> postitveCache) throws Exception { Long timestamp = negativeCache.get(name); if (timestamp != null) { if (System.currentTimeMillis() - timestamp < mNegativeCacheTime) { return defaultID; } else {// www. j a v a 2 s. c o m negativeCache.remove(name); } } IDCache<Integer> cache = postitveCache.get(name); if (cache != null) { if (System.currentTimeMillis() - cache.timestamp < mPositiveCacheTime) { return cache.id; } else { postitveCache.remove(name); } } String result = null; try { result = Shell.execCommand(cmd); int id = Integer.parseInt(result.trim()); postitveCache.put(name, new IDCache<Integer>(id)); return id; } catch (Shell.ExitCodeException e) { LOGGER.warn("Error parsing '" + result + "' for name '" + name + "': " + e.getMessage().trim()); } negativeCache.put(name, System.currentTimeMillis()); return defaultID; }
From source file:hdfs.FileUtil.java
License:Apache License
static String execCommand(File f, String... cmd) throws IOException { String[] args = new String[cmd.length + 1]; System.arraycopy(cmd, 0, args, 0, cmd.length); args[cmd.length] = f.getCanonicalPath(); String output = Shell.execCommand(args); return output; }