use of org.apache.oozie.workflow.WorkflowException in project oozie by apache.
the class SubmitHttpXCommand method execute.
/* (non-Javadoc)
* @see org.apache.oozie.command.XCommand#execute()
*/
@Override
protected String execute() throws CommandException {
InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
WorkflowAppService wps = Services.get().get(WorkflowAppService.class);
try {
XLog.Info.get().setParameter(DagXLogInfoService.TOKEN, conf.get(OozieClient.LOG_TOKEN));
String wfXml = getWorkflowXml(conf);
LOG.debug("workflow xml created on the server side is :\n");
LOG.debug(wfXml);
WorkflowApp app = wps.parseDef(wfXml, conf);
XConfiguration protoActionConf = wps.createProtoActionConf(conf, false);
WorkflowLib workflowLib = Services.get().get(WorkflowStoreService.class).getWorkflowLibWithNoDB();
PropertiesUtils.checkDisallowedProperties(conf, DISALLOWED_USER_PROPERTIES);
// Resolving all variables in the job properties.
// This ensures the Hadoop Configuration semantics is preserved.
XConfiguration resolvedVarsConf = new XConfiguration();
for (Map.Entry<String, String> entry : conf) {
resolvedVarsConf.set(entry.getKey(), conf.get(entry.getKey()));
}
conf = resolvedVarsConf;
WorkflowInstance wfInstance;
try {
wfInstance = workflowLib.createInstance(app, conf);
} catch (WorkflowException e) {
throw new StoreException(e);
}
Configuration conf = wfInstance.getConf();
WorkflowJobBean workflow = new WorkflowJobBean();
workflow.setId(wfInstance.getId());
workflow.setAppName(app.getName());
workflow.setAppPath(conf.get(OozieClient.APP_PATH));
workflow.setConf(XmlUtils.prettyPrint(conf).toString());
workflow.setProtoActionConf(protoActionConf.toXmlString());
workflow.setCreatedTime(new Date());
workflow.setLastModifiedTime(new Date());
workflow.setLogToken(conf.get(OozieClient.LOG_TOKEN, ""));
workflow.setStatus(WorkflowJob.Status.PREP);
workflow.setRun(0);
workflow.setUser(conf.get(OozieClient.USER_NAME));
workflow.setGroup(conf.get(OozieClient.GROUP_NAME));
workflow.setWorkflowInstance(wfInstance);
workflow.setExternalId(conf.get(OozieClient.EXTERNAL_ID));
LogUtils.setLogInfo(workflow);
JPAService jpaService = Services.get().get(JPAService.class);
if (jpaService != null) {
jpaService.execute(new WorkflowJobInsertJPAExecutor(workflow));
} else {
LOG.error(ErrorCode.E0610);
return null;
}
return workflow.getId();
} catch (WorkflowException ex) {
throw new CommandException(ex);
} catch (Exception ex) {
throw new CommandException(ErrorCode.E0803, ex.getMessage(), ex);
}
}
use of org.apache.oozie.workflow.WorkflowException in project oozie by apache.
the class LiteWorkflowStoreService method getUserRetryMax.
private static int getUserRetryMax(NodeHandler.Context context) throws WorkflowException {
XLog log = XLog.getLog(LiteWorkflowStoreService.class);
int ret = ConfigurationService.getInt(CONF_USER_RETRY_MAX);
int max = ret;
String userRetryMax = context.getNodeDef().getUserRetryMax();
if (!userRetryMax.equals("null")) {
try {
ret = Integer.parseInt(userRetryMax);
if (ret > max) {
ret = max;
log.warn(ErrorCode.E0820.getTemplate(), ret, max);
}
} catch (NumberFormatException nfe) {
throw new WorkflowException(ErrorCode.E0700, nfe.getMessage(), nfe);
}
} else {
ret = 0;
}
return ret;
}
use of org.apache.oozie.workflow.WorkflowException in project oozie by apache.
the class LiteWorkflowStoreService method liteExecute.
/**
* Delegation method used by the Action and Decision {@link NodeHandler} on start. <p> This method provides the
* necessary information to create ActionExecutors.
*
* @param context NodeHandler context.
* @param actionType the action type.
* @throws WorkflowException thrown if there was an error parsing the action configuration.
*/
@SuppressWarnings("unchecked")
protected static void liteExecute(NodeHandler.Context context, String actionType) throws WorkflowException {
XLog log = XLog.getLog(LiteWorkflowStoreService.class);
String jobId = context.getProcessInstance().getId();
String nodeName = context.getNodeDef().getName();
String skipVar = context.getProcessInstance().getVar(context.getNodeDef().getName() + WorkflowInstance.NODE_VAR_SEPARATOR + ReRunXCommand.TO_SKIP);
boolean skipAction = false;
if (skipVar != null) {
skipAction = skipVar.equals("true");
}
WorkflowActionBean action = new WorkflowActionBean();
String actionId = Services.get().get(UUIDService.class).generateChildId(jobId, nodeName);
if (!skipAction) {
String nodeConf = context.getNodeDef().getConf();
if (actionType == null) {
try {
Element element = XmlUtils.parseXml(nodeConf);
actionType = element.getName();
nodeConf = XmlUtils.prettyPrint(element).toString();
} catch (JDOMException ex) {
throw new WorkflowException(ErrorCode.E0700, ex.getMessage(), ex);
}
}
log.debug(" Creating action for node [{0}]", nodeName);
action.setType(actionType);
action.setConf(nodeConf);
action.setLogToken(((WorkflowJobBean) context.getTransientVar(WORKFLOW_BEAN)).getLogToken());
action.setStatus(WorkflowAction.Status.PREP);
action.setJobId(jobId);
}
String executionPath = context.getExecutionPath();
action.setExecutionPath(executionPath);
action.setCred(context.getNodeDef().getCred());
log.debug("Setting action for cred: '" + context.getNodeDef().getCred() + "', name: '" + context.getNodeDef().getName() + "'");
action.setUserRetryCount(0);
int userRetryMax = getUserRetryMax(context);
int userRetryInterval = getUserRetryInterval(context);
action.setUserRetryMax(userRetryMax);
action.setUserRetryInterval(userRetryInterval);
log.debug("Setting action for userRetryMax: '" + userRetryMax + "', userRetryInterval: '" + userRetryInterval + "', name: '" + context.getNodeDef().getName() + "'");
action.setName(nodeName);
action.setId(actionId);
context.setVar(nodeName + WorkflowInstance.NODE_VAR_SEPARATOR + ACTION_ID, actionId);
List list = (List) context.getTransientVar(ACTIONS_TO_START);
if (list == null) {
list = new ArrayList();
context.setTransientVar(ACTIONS_TO_START, list);
}
list.add(action);
}
use of org.apache.oozie.workflow.WorkflowException in project oozie by apache.
the class WorkflowAppService method createProtoActionConf.
/**
* Create proto configuration. <p> The proto configuration includes the user,group and the paths which need to be
* added to distributed cache. These paths include .jar,.so and the resource file paths.
*
* @param jobConf job configuration.
* @param isWorkflowJob indicates if the job is a workflow job or not.
* @return proto configuration.
* @throws WorkflowException thrown if the proto action configuration could not be created.
*/
public XConfiguration createProtoActionConf(Configuration jobConf, boolean isWorkflowJob) throws WorkflowException {
try {
HadoopAccessorService has = Services.get().get(HadoopAccessorService.class);
URI uri = new URI(jobConf.get(OozieClient.APP_PATH));
Configuration conf = has.createConfiguration(uri.getAuthority());
XConfiguration protoConf = new XConfiguration();
String user = jobConf.get(OozieClient.USER_NAME);
conf.set(OozieClient.USER_NAME, user);
protoConf.set(OozieClient.USER_NAME, user);
FileSystem fs = has.createFileSystem(user, uri, conf);
Path appPath = new Path(uri);
XLog.getLog(getClass()).debug("jobConf.libPath = " + jobConf.get(OozieClient.LIBPATH));
XLog.getLog(getClass()).debug("jobConf.appPath = " + appPath);
Collection<String> filePaths;
if (isWorkflowJob) {
// app path could be a directory
Path path = new Path(uri.getPath());
if (!fs.isFile(path)) {
filePaths = getLibFiles(fs, new Path(appPath + "/lib"));
} else {
filePaths = getLibFiles(fs, new Path(appPath.getParent(), "lib"));
}
} else {
filePaths = new LinkedHashSet<String>();
}
String[] libPaths = jobConf.getStrings(OozieClient.LIBPATH);
if (libPaths != null && libPaths.length > 0) {
for (int i = 0; i < libPaths.length; i++) {
if (libPaths[i].trim().length() > 0) {
Path libPath = new Path(libPaths[i].trim());
Collection<String> libFilePaths = getLibFiles(fs, libPath);
filePaths.addAll(libFilePaths);
}
}
}
// If OOZIE_WF_SUBWORKFLOW_CLASSPATH_INHERITANCE isn't specified, we use OOZIE_SUBWORKFLOW_CLASSPATH_INHERITANCE
if (jobConf.getBoolean(OOZIE_WF_SUBWORKFLOW_CLASSPATH_INHERITANCE, oozieSubWfCPInheritance)) {
// Keep any libs from a parent workflow that might already be in APP_LIB_PATH_LIST and also remove duplicates
String[] parentFilePaths = jobConf.getStrings(APP_LIB_PATH_LIST);
if (parentFilePaths != null && parentFilePaths.length > 0) {
String[] filePathsNames = filePaths.toArray(new String[filePaths.size()]);
for (int i = 0; i < filePathsNames.length; i++) {
Path p = new Path(filePathsNames[i]);
filePathsNames[i] = p.getName();
}
Arrays.sort(filePathsNames);
List<String> nonDuplicateParentFilePaths = new ArrayList<String>();
for (String parentFilePath : parentFilePaths) {
Path p = new Path(parentFilePath);
if (Arrays.binarySearch(filePathsNames, p.getName()) < 0) {
nonDuplicateParentFilePaths.add(parentFilePath);
}
}
filePaths.addAll(nonDuplicateParentFilePaths);
}
}
protoConf.setStrings(APP_LIB_PATH_LIST, filePaths.toArray(new String[filePaths.size()]));
// Add all properties start with 'oozie.'
for (Map.Entry<String, String> entry : jobConf) {
if (entry.getKey().startsWith("oozie.")) {
String name = entry.getKey();
String value = entry.getValue();
// if property already exists, should not overwrite
if (protoConf.get(name) == null) {
protoConf.set(name, value);
}
}
}
return protoConf;
} catch (IOException ex) {
throw new WorkflowException(ErrorCode.E0712, jobConf.get(OozieClient.APP_PATH), ex.getMessage(), ex);
} catch (URISyntaxException ex) {
throw new WorkflowException(ErrorCode.E0711, jobConf.get(OozieClient.APP_PATH), ex.getMessage(), ex);
} catch (HadoopAccessorException ex) {
throw new WorkflowException(ex);
} catch (Exception ex) {
throw new WorkflowException(ErrorCode.E0712, jobConf.get(OozieClient.APP_PATH), ex.getMessage(), ex);
}
}
use of org.apache.oozie.workflow.WorkflowException in project oozie by apache.
the class WorkflowAppService method readDefinition.
/**
* Read workflow definition.
*
* @param appPath application path.
* @param user user name.
* @return workflow definition.
* @throws WorkflowException thrown if the definition could not be read.
*/
protected String readDefinition(String appPath, String user, Configuration conf) throws WorkflowException {
try {
URI uri = new URI(appPath);
HadoopAccessorService has = Services.get().get(HadoopAccessorService.class);
Configuration appConf = has.createConfiguration(uri.getAuthority());
FileSystem fs = has.createFileSystem(user, uri, appConf);
// app path could be a directory
Path path = new Path(uri.getPath());
if (!fs.isFile(path)) {
path = new Path(path, "workflow.xml");
}
FileStatus fsStatus = fs.getFileStatus(path);
if (fsStatus.getLen() > this.maxWFLength) {
throw new WorkflowException(ErrorCode.E0736, fsStatus.getLen(), this.maxWFLength);
}
Reader reader = new InputStreamReader(fs.open(path));
StringWriter writer = new StringWriter();
IOUtils.copyCharStream(reader, writer);
return writer.toString();
} catch (WorkflowException wfe) {
throw wfe;
} catch (IOException ex) {
throw new WorkflowException(ErrorCode.E0710, ex.getMessage(), ex);
} catch (URISyntaxException ex) {
throw new WorkflowException(ErrorCode.E0711, appPath, ex.getMessage(), ex);
} catch (HadoopAccessorException ex) {
throw new WorkflowException(ex);
} catch (Exception ex) {
throw new WorkflowException(ErrorCode.E0710, ex.getMessage(), ex);
}
}
Aggregations