in tajo-client/src/main/java/org/apache/tajo/client/TajoAdmin.java [85:171]
public static void main(String [] args) throws ParseException, IOException, ServiceException, SQLException {
TajoConf conf = new TajoConf();
CommandLineParser parser = new PosixParser();
CommandLine cmd = parser.parse(options, args);
String param = "";
int cmdType = 0;
String hostName = null;
Integer port = null;
if (cmd.hasOption("h")) {
hostName = cmd.getOptionValue("h");
}
if (cmd.hasOption("p")) {
port = Integer.parseInt(cmd.getOptionValue("p"));
}
String queryId = null;
if (cmd.hasOption("list")) {
cmdType = 1;
} else if (cmd.hasOption("desc")) {
cmdType = 2;
} else if (cmd.hasOption("cluster")) {
cmdType = 3;
} else if (cmd.hasOption("kill")) {
cmdType = 4;
queryId = cmd.getOptionValue("kill");
}
// if there is no "-h" option,
if(hostName == null) {
if (conf.getVar(TajoConf.ConfVars.TAJO_MASTER_CLIENT_RPC_ADDRESS) != null) {
// it checks if the client service address is given in configuration and distributed mode.
// if so, it sets entryAddr.
hostName = conf.getVar(TajoConf.ConfVars.TAJO_MASTER_CLIENT_RPC_ADDRESS).split(":")[0];
}
}
if (port == null) {
if (conf.getVar(TajoConf.ConfVars.TAJO_MASTER_CLIENT_RPC_ADDRESS) != null) {
// it checks if the client service address is given in configuration and distributed mode.
// if so, it sets entryAddr.
port = Integer.parseInt(conf.getVar(TajoConf.ConfVars.TAJO_MASTER_CLIENT_RPC_ADDRESS).split(":")[1]);
}
}
if (cmdType == 0) {
printUsage();
System.exit(0);
}
TajoClient client = null;
if ((hostName == null) ^ (port == null)) {
System.err.println("ERROR: cannot find valid Tajo server address");
System.exit(-1);
} else if (hostName != null && port != null) {
conf.setVar(TajoConf.ConfVars.TAJO_MASTER_CLIENT_RPC_ADDRESS, hostName+":"+port);
client = new TajoClient(conf);
} else if (hostName == null && port == null) {
client = new TajoClient(conf);
}
Writer writer = new PrintWriter(System.out);
switch (cmdType) {
case 1:
processList(writer, client);
break;
case 2:
processDesc(writer, client);
break;
case 3:
processCluster(writer, client);
break;
case 4:
processKill(writer, client, queryId);
break;
default:
printUsage();
break;
}
writer.flush();
writer.close();
System.exit(0);
}