コード例 #1
0
    /** Return the status information about the Map-Reduce cluster */
    public HiveClusterStatus getClusterStatus() throws HiveServerException, TException {
      HiveClusterStatus hcs;
      try {
        ClusterStatus cs = driver.getClusterStatus();
        JobTracker.State jbs = cs.getJobTrackerState();

        // Convert the ClusterStatus to its Thrift equivalent: HiveClusterStatus
        int state;
        switch (jbs) {
          case INITIALIZING:
            state = JobTrackerState.INITIALIZING;
            break;
          case RUNNING:
            state = JobTrackerState.RUNNING;
            break;
          default:
            String errorMsg = "Unrecognized JobTracker state: " + jbs.toString();
            throw new Exception(errorMsg);
        }

        hcs =
            new HiveClusterStatus(
                cs.getTaskTrackers(),
                cs.getMapTasks(),
                cs.getReduceTasks(),
                cs.getMaxMapTasks(),
                cs.getMaxReduceTasks(),
                state);
      } catch (Exception e) {
        LOG.error(e.toString());
        e.printStackTrace();
        throw new HiveServerException("Unable to get cluster status: " + e.toString());
      }
      return hcs;
    }
コード例 #2
0
    /** Return the Thrift schema of the query result */
    public Schema getThriftSchema() throws HiveServerException, TException {
      if (!isHiveQuery)
        // Return empty schema if the last command was not a Hive query
        return new Schema();

      try {
        Schema schema = driver.getThriftSchema();
        if (schema == null) {
          schema = new Schema();
        }
        LOG.info("Returning schema: " + schema);
        return schema;
      } catch (Exception e) {
        LOG.error(e.toString());
        e.printStackTrace();
        throw new HiveServerException("Unable to get schema: " + e.toString());
      }
    }
コード例 #3
0
 public static void main(String[] args) {
   try {
     int port = 10000;
     if (args.length >= 1) {
       port = Integer.parseInt(args[0]);
     }
     TServerTransport serverTransport = new TServerSocket(port);
     ThriftHiveProcessorFactory hfactory = new ThriftHiveProcessorFactory(null);
     TThreadPoolServer.Options options = new TThreadPoolServer.Options();
     TServer server =
         new TThreadPoolServer(
             hfactory,
             serverTransport,
             new TTransportFactory(),
             new TTransportFactory(),
             new TBinaryProtocol.Factory(),
             new TBinaryProtocol.Factory(),
             options);
     HiveServerHandler.LOG.info("Starting hive server on port " + port);
     server.serve();
   } catch (Exception x) {
     x.printStackTrace();
   }
 }