void injectLauncherCallback(Context context, Configuration launcherConf) {
injectCallback(context, launcherConf);
}
public void submitLauncher(FileSystem actionFs, Context context, WorkflowAction action) throws ActionExecutorException {
JobClient jobClient = null;
boolean exception = false;
try {
Path appPathRoot = new Path(context.getWorkflow().getAppPath());
// app path could be a file
if (actionFs.isFile(appPathRoot)) {
appPathRoot = appPathRoot.getParent();
}
Element actionXml = XmlUtils.parseXml(action.getConf());
// action job configuration
Configuration actionConf = createBaseHadoopConf(context, actionXml);
setupActionConf(actionConf, context, actionXml, appPathRoot);
XLog.getLog(getClass()).debug("Setting LibFilesArchives ");
setLibFilesArchives(context, actionXml, appPathRoot, actionConf);
String jobName = XLog.format("oozie:action:T={0}:W={1}:A={2}:ID={3}", getType(), context.getWorkflow()
.getAppName(), action.getName(), context.getWorkflow().getId());
actionConf.set("mapred.job.name", jobName);
injectActionCallback(context, actionConf);
if (context.getWorkflow().getAcl() != null) {
// setting the group owning the Oozie job to allow anybody in that
// group to kill the jobs.
actionConf.set("mapreduce.job.acl-modify-job", context.getWorkflow().getAcl());
}
// Setting the credential properties in launcher conf
HashMap<String, CredentialsProperties> credentialsProperties = setCredentialPropertyToActionConf(context,
action, actionConf);
// Adding if action need to set more credential tokens
JobConf credentialsConf = new JobConf(false);
XConfiguration.copy(actionConf, credentialsConf);
setCredentialTokens(credentialsConf, context, action, credentialsProperties);
// insert conf to action conf from credentialsConf
for (Entry<String, String> entry : credentialsConf) {
if (actionConf.get(entry.getKey()) == null) {
actionConf.set(entry.getKey(), entry.getValue());
}
}
JobConf launcherJobConf = createLauncherConf(actionFs, context, action, actionXml, actionConf);
injectLauncherCallback(context, launcherJobConf);
XLog.getLog(getClass()).debug("Creating Job Client for action " + action.getId());
jobClient = createJobClient(context, launcherJobConf);
String launcherId = LauncherMapper.getRecoveryId(launcherJobConf, context.getActionDir(), context
.getRecoveryId());
boolean alreadyRunning = launcherId != null;
RunningJob runningJob;
// if user-retry is on, always submit new launcher
boolean isUserRetry = ((WorkflowActionBean)action).isUserRetry();
if (alreadyRunning && !isUserRetry) {
runningJob = jobClient.getJob(JobID.forName(launcherId));
if (runningJob == null) {
String jobTracker = launcherJobConf.get("mapred.job.tracker");
throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "JA017",
"unknown job [{0}@{1}], cannot recover", launcherId, jobTracker);
}
}
else {
XLog.getLog(getClass()).debug("Submitting the job through Job Client for action " + action.getId());
// setting up propagation of the delegation token.
Token<DelegationTokenIdentifier> mrdt = jobClient.getDelegationToken(new Text("mr token"));
launcherJobConf.getCredentials().addToken(new Text("mr token"), mrdt);
// insert credentials tokens to launcher job conf if needed
if (needInjectCredentials()) {
for (Token<? extends TokenIdentifier> tk : credentialsConf.getCredentials().getAllTokens()) {
log.debug("ADDING TOKEN: " + tk.getKind().toString());
launcherJobConf.getCredentials().addToken(tk.getKind(), tk);
}
}
else {
log.info("No need to inject credentials.");
}
runningJob = jobClient.submitJob(launcherJobConf);
if (runningJob == null) {
throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "JA017",
"Error submitting launcher for action [{0}]", action.getId());
}
launcherId = runningJob.getID().toString();
XLog.getLog(getClass()).debug("After submission get the launcherId " + launcherId);
}
String jobTracker = launcherJobConf.get(HADOOP_JOB_TRACKER);
String consoleUrl = runningJob.getTrackingURL();
context.setStartData(launcherId, jobTracker, consoleUrl);
}
catch (Exception ex) {
exception = true;
throw convertException(ex);
}
finally {
if (jobClient != null) {
try {
jobClient.close();
}
catch (Exception e) {
if (exception) {
log.error("JobClient error: ", e);
}