Search in sources :

Example 16 with ExecuteException

use of org.apache.commons.exec.ExecuteException in project hive by apache.

the class HcatDelegator method descExtendedTable.

/**
 * Return a json "show table extended like" with extra info from "desc exteded"
 * This will return table with exact name match.
 */
public Response descExtendedTable(String user, String db, String table) throws HcatException, NotAuthorizedException, BusyException, ExecuteException, IOException {
    String exec = String.format("use %s; show table extended like %s;", db, table);
    try {
        // get detailed "tableInfo" from query "desc extended tablename;"
        Response res0 = descTable(user, db, table, true);
        if (res0.getStatus() != HttpStatus.OK_200)
            return res0;
        Map m = (Map) res0.getEntity();
        Map tableInfo = (Map) m.get("tableInfo");
        String res = jsonRun(user, exec);
        JsonBuilder jb = JsonBuilder.create(singleTable(res, table)).remove("tableName").put("database", db).put("table", table).put("retention", tableInfo.get("retention")).put("sd", tableInfo.get("sd")).put("parameters", tableInfo.get("parameters")).put("parametersSize", tableInfo.get("parametersSize")).put("tableType", tableInfo.get("tableType"));
        // If we can get them from HDFS, add group and permission
        String loc = (String) jb.getMap().get("location");
        if (loc != null && loc.startsWith("hdfs://")) {
            try {
                FileSystem fs = FileSystem.get(appConf);
                FileStatus status = fs.getFileStatus(new Path(new URI(loc)));
                jb.put("group", status.getGroup());
                jb.put("permission", status.getPermission().toString());
            } catch (Exception e) {
                LOG.warn(e.getMessage() + " Couldn't get permissions for " + loc);
            }
        }
        return jb.build();
    } catch (HcatException e) {
        throw new HcatException("unable to show table: " + table, e.execBean, exec);
    }
}
Also used : Response(javax.ws.rs.core.Response) Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) FileSystem(org.apache.hadoop.fs.FileSystem) HashMap(java.util.HashMap) Map(java.util.Map) URI(java.net.URI) IOException(java.io.IOException) ExecuteException(org.apache.commons.exec.ExecuteException)

Aggregations

ExecuteException (org.apache.commons.exec.ExecuteException)16 CommandLine (org.apache.commons.exec.CommandLine)11 DefaultExecutor (org.apache.commons.exec.DefaultExecutor)11 IOException (java.io.IOException)10 PumpStreamHandler (org.apache.commons.exec.PumpStreamHandler)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 File (java.io.File)5 ExecuteResultHandler (org.apache.commons.exec.ExecuteResultHandler)3 ExecuteWatchdog (org.apache.commons.exec.ExecuteWatchdog)3 ExecuteStreamHandler (org.apache.commons.exec.ExecuteStreamHandler)2 Executor (org.apache.commons.exec.Executor)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ZipFile (java.util.zip.ZipFile)1