}
private static String JOB_ID_PREFIX = "job: ";
private void jobCommand(CommandLine commandLine) throws IOException, OozieCLIException {
XOozieClient wc = createXOozieClient(commandLine);
List<String> options = new ArrayList<String>();
for (Option option : commandLine.getOptions()) {
options.add(option.getOpt());
}
try {
if (options.contains(SUBMIT_OPTION)) {
System.out.println(JOB_ID_PREFIX + wc.submit(getConfiguration(commandLine)));
}
else if (options.contains(START_OPTION)) {
wc.start(commandLine.getOptionValue(START_OPTION));
}
else if (options.contains(DRYRUN_OPTION)) {
String[] dryrunStr = wc.dryrun(getConfiguration(commandLine)).split("action for new instance");
int arraysize = dryrunStr.length;
System.out.println("***coordJob after parsing: ***");
System.out.println(dryrunStr[0]);
int aLen = dryrunStr.length - 1;
if (aLen < 0) {
aLen = 0;
}
System.out.println("***total coord actions is " + aLen + " ***");
for (int i = 1; i <= arraysize - 1; i++) {
System.out.println(RULER);
System.out.println("coordAction instance: " + i + ":");
System.out.println(dryrunStr[i]);
}
}
else if (options.contains(SUSPEND_OPTION)) {
wc.suspend(commandLine.getOptionValue(SUSPEND_OPTION));
}
else if (options.contains(RESUME_OPTION)) {
wc.resume(commandLine.getOptionValue(RESUME_OPTION));
}
else if (options.contains(KILL_OPTION)) {
wc.kill(commandLine.getOptionValue(KILL_OPTION));
}
else if (options.contains(CHANGE_OPTION)) {
wc.change(commandLine.getOptionValue(CHANGE_OPTION), getChangeValue(commandLine));
}
else if (options.contains(RUN_OPTION)) {
System.out.println(JOB_ID_PREFIX + wc.run(getConfiguration(commandLine)));
}
else if (options.contains(RERUN_OPTION)) {
if (commandLine.getOptionValue(RERUN_OPTION).contains("-W")) {
wc.reRun(commandLine.getOptionValue(RERUN_OPTION), getConfiguration(commandLine));
}
else if (commandLine.getOptionValue(RERUN_OPTION).contains("-B")) {
String bundleJobId = commandLine.getOptionValue(RERUN_OPTION);
String coordScope = null;
String dateScope = null;
boolean refresh = false;
boolean noCleanup = false;
if (options.contains(ACTION_OPTION)) {
throw new OozieCLIException("Invalid options provided for bundle rerun. " + ACTION_OPTION
+ " is not valid for bundle rerun");
}
if (options.contains(RERUN_DATE_OPTION)) {
dateScope = commandLine.getOptionValue(RERUN_DATE_OPTION);
}
if (options.contains(RERUN_COORD_OPTION)) {
coordScope = commandLine.getOptionValue(RERUN_COORD_OPTION);
}
if (options.contains(RERUN_REFRESH_OPTION)) {
refresh = true;
}
if (options.contains(RERUN_NOCLEANUP_OPTION)) {
noCleanup = true;
}
wc.reRunBundle(bundleJobId, coordScope, dateScope, refresh, noCleanup);
if (coordScope != null && !coordScope.isEmpty()) {
System.out.println("Coordinators [" + coordScope + "] of bundle " + bundleJobId
+ " are scheduled to rerun on date ranges [" + dateScope + "].");
}
else {
System.out.println("All coordinators of bundle " + bundleJobId
+ " are scheduled to rerun on the date ranges [" + dateScope + "].");
}
}
else {
String coordJobId = commandLine.getOptionValue(RERUN_OPTION);
String scope = null;
String rerunType = null;
boolean refresh = false;
boolean noCleanup = false;
if (options.contains(RERUN_DATE_OPTION) && options.contains(ACTION_OPTION)) {
throw new OozieCLIException("Invalid options provided for rerun: either" + RERUN_DATE_OPTION
+ " or " + ACTION_OPTION + " expected. Don't use both at the same time.");
}
if (options.contains(RERUN_DATE_OPTION)) {
rerunType = RestConstants.JOB_COORD_RERUN_DATE;
scope = commandLine.getOptionValue(RERUN_DATE_OPTION);
}
else if (options.contains(ACTION_OPTION)) {
rerunType = RestConstants.JOB_COORD_RERUN_ACTION;
scope = commandLine.getOptionValue(ACTION_OPTION);
}
else {
throw new OozieCLIException("Invalid options provided for rerun: " + RERUN_DATE_OPTION + " or "
+ ACTION_OPTION + " expected.");
}
if (options.contains(RERUN_REFRESH_OPTION)) {
refresh = true;
}
if (options.contains(RERUN_NOCLEANUP_OPTION)) {
noCleanup = true;
}
printRerunCoordActions(wc.reRunCoord(coordJobId, rerunType, scope, refresh, noCleanup));
}
}
else if (options.contains(INFO_OPTION)) {
if (commandLine.getOptionValue(INFO_OPTION).endsWith("-B")) {
printBundleJob(wc.getBundleJobInfo(commandLine.getOptionValue(INFO_OPTION)), options
.contains(LOCAL_TIME_OPTION), options.contains(VERBOSE_OPTION));
}
else if (commandLine.getOptionValue(INFO_OPTION).endsWith("-C")) {
String s = commandLine.getOptionValue(OFFSET_OPTION);
int start = Integer.parseInt((s != null) ? s : "0");
s = commandLine.getOptionValue(LEN_OPTION);
int len = Integer.parseInt((s != null) ? s : "0");
printCoordJob(wc.getCoordJobInfo(commandLine.getOptionValue(INFO_OPTION), start, len), options
.contains(LOCAL_TIME_OPTION), options.contains(VERBOSE_OPTION));
}
else if (commandLine.getOptionValue(INFO_OPTION).contains("-C@")) {
printCoordAction(wc.getCoordActionInfo(commandLine.getOptionValue(INFO_OPTION)), options
.contains(LOCAL_TIME_OPTION));
}
else if (commandLine.getOptionValue(INFO_OPTION).contains("-W@")) {
printWorkflowAction(wc.getWorkflowActionInfo(commandLine.getOptionValue(INFO_OPTION)), options
.contains(LOCAL_TIME_OPTION));
}
else {
String s = commandLine.getOptionValue(OFFSET_OPTION);
int start = Integer.parseInt((s != null) ? s : "0");
s = commandLine.getOptionValue(LEN_OPTION);
String jobtype = commandLine.getOptionValue(JOBTYPE_OPTION);
jobtype = (jobtype != null) ? jobtype : "wf";
int len = Integer.parseInt((s != null) ? s : "0");
printJob(wc.getJobInfo(commandLine.getOptionValue(INFO_OPTION), start, len), options
.contains(LOCAL_TIME_OPTION), options.contains(VERBOSE_OPTION));
}
}
else if (options.contains(LOG_OPTION)) {
PrintStream ps = System.out;
if (commandLine.getOptionValue(LOG_OPTION).contains("-C")) {
String logRetrievalScope = null;
String logRetrievalType = null;
if (options.contains(ACTION_OPTION)) {
logRetrievalType = RestConstants.JOB_LOG_ACTION;
logRetrievalScope = commandLine.getOptionValue(ACTION_OPTION);
}
try {
wc.getJobLog(commandLine.getOptionValue(LOG_OPTION), logRetrievalType, logRetrievalScope, ps);
}
finally {
ps.close();
}
}
else {
if (!options.contains(ACTION_OPTION)) {
wc.getJobLog(commandLine.getOptionValue(LOG_OPTION), null, null, ps);
}
else {
throw new OozieCLIException("Invalid options provided for log retrieval. " + ACTION_OPTION
+ " is valid only for coordinator job log retrieval");
}
}
}
else if (options.contains(DEFINITION_OPTION)) {
System.out.println(wc.getJobDefinition(commandLine.getOptionValue(DEFINITION_OPTION)));
}
else if (options.contains(CONFIG_CONTENT_OPTION)) {
if (commandLine.getOptionValue(CONFIG_CONTENT_OPTION).endsWith("-C")) {
System.out.println(wc.getCoordJobInfo(commandLine.getOptionValue(CONFIG_CONTENT_OPTION)).getConf());
}
else if (commandLine.getOptionValue(CONFIG_CONTENT_OPTION).endsWith("-W")) {
System.out.println(wc.getJobInfo(commandLine.getOptionValue(CONFIG_CONTENT_OPTION)).getConf());
}
else if (commandLine.getOptionValue(CONFIG_CONTENT_OPTION).endsWith("-B")) {
System.out
.println(wc.getBundleJobInfo(commandLine.getOptionValue(CONFIG_CONTENT_OPTION)).getConf());
}
else {
System.out.println("ERROR: job id [" + commandLine.getOptionValue(CONFIG_CONTENT_OPTION)
+ "] doesn't end with either C or W or B");
}