use of org.apache.oozie.workflow.WorkflowException in project oozie by apache.
the class LiteWorkflowAppParser method handleDefaultsAndGlobal.
private void handleDefaultsAndGlobal(GlobalSectionData gData, Configuration configDefault, Element actionElement, Namespace ns) throws WorkflowException {
ActionExecutor ae = Services.get().get(ActionService.class).getExecutor(actionElement.getName());
if (ae == null && !GLOBAL.equals(actionElement.getName())) {
throw new WorkflowException(ErrorCode.E0723, actionElement.getName(), ActionService.class.getName());
}
Namespace actionNs = actionElement.getNamespace();
// Also, we only parse the NN (not the JT) for the FS Action.
if (SubWorkflowActionExecutor.ACTION_TYPE.equals(actionElement.getName()) || FsActionExecutor.ACTION_TYPE.equals(actionElement.getName()) || GLOBAL.equals(actionElement.getName()) || ae.requiresNameNodeJobTracker()) {
if (actionElement.getChild(NAME_NODE, actionNs) == null) {
if (gData != null && gData.nameNode != null) {
addChildElement(actionElement, actionNs, NAME_NODE, gData.nameNode);
} else if (defaultNameNode != null) {
addChildElement(actionElement, actionNs, NAME_NODE, defaultNameNode);
} else if (!(SubWorkflowActionExecutor.ACTION_TYPE.equals(actionElement.getName()) || FsActionExecutor.ACTION_TYPE.equals(actionElement.getName()) || GLOBAL.equals(actionElement.getName()))) {
throw new WorkflowException(ErrorCode.E0701, "No " + NAME_NODE + " defined");
}
}
if (getResourceManager(actionNs, actionElement) == null && !FsActionExecutor.ACTION_TYPE.equals(actionElement.getName())) {
if (gData != null && gData.jobTracker != null) {
addResourceManagerOrJobTracker(actionElement, actionNs, gData.jobTracker, isResourceManagerTagUsed);
} else if (defaultResourceManager != null) {
addResourceManagerOrJobTracker(actionElement, actionNs, defaultResourceManager, true);
} else if (defaultJobTracker != null) {
addResourceManagerOrJobTracker(actionElement, actionNs, defaultJobTracker, false);
} else if (!(SubWorkflowActionExecutor.ACTION_TYPE.equals(actionElement.getName()) || GLOBAL.equals(actionElement.getName()))) {
throw new WorkflowException(ErrorCode.E0701, "No " + JOB_TRACKER + " or " + RESOURCE_MANAGER + " defined");
}
}
}
// defined, empty values are placed. Exceptions are thrown if there's an error parsing, but not if they're not given.
if (GLOBAL.equals(actionElement.getName()) || ae.supportsConfigurationJobXML()) {
@SuppressWarnings("unchecked") List<Element> actionJobXmls = actionElement.getChildren(JOB_XML, actionNs);
if (gData != null && gData.jobXmls != null) {
for (String gJobXml : gData.jobXmls) {
boolean alreadyExists = false;
for (Element actionXml : actionJobXmls) {
if (gJobXml.equals(actionXml.getText())) {
alreadyExists = true;
break;
}
}
if (!alreadyExists) {
Element ejobXml = new Element(JOB_XML, actionNs);
ejobXml.setText(gJobXml);
actionElement.addContent(ejobXml);
}
}
}
try {
XConfiguration actionConf = new XConfiguration();
if (configDefault != null)
XConfiguration.copy(configDefault, actionConf);
if (gData != null && gData.conf != null) {
XConfiguration.copy(gData.conf, actionConf);
}
Element launcherConfiguration = actionElement.getChild(LAUNCHER_E, actionNs);
if (launcherConfiguration != null) {
LauncherConfigHandler launcherConfigHandler = new LauncherConfigHandler(actionConf, launcherConfiguration, actionNs);
launcherConfigHandler.processSettings();
}
Element actionConfiguration = actionElement.getChild(CONFIGURATION, actionNs);
if (actionConfiguration != null) {
// copy and override
XConfiguration.copy(new XConfiguration(new StringReader(XmlUtils.prettyPrint(actionConfiguration).toString())), actionConf);
}
int position = actionElement.indexOf(actionConfiguration);
// replace with enhanced one
actionElement.removeContent(actionConfiguration);
Element eConfXml = XmlUtils.parseXml(actionConf.toXmlString(false));
eConfXml.detach();
eConfXml.setNamespace(actionNs);
if (position > 0) {
actionElement.addContent(position, eConfXml);
} else {
actionElement.addContent(eConfXml);
}
} catch (IOException e) {
throw new WorkflowException(ErrorCode.E0700, "Error while processing action conf");
} catch (JDOMException e) {
throw new WorkflowException(ErrorCode.E0700, "Error while processing action conf");
}
}
}
use of org.apache.oozie.workflow.WorkflowException in project oozie by apache.
the class LiteWorkflowAppParser method parse.
/**
* Parse xml to {@link LiteWorkflowApp}
*
* @param strDef
* @param root
* @param configDefault
* @param jobConf
* @return LiteWorkflowApp
* @throws WorkflowException
*/
@SuppressWarnings({ "unchecked" })
private LiteWorkflowApp parse(String strDef, Element root, Configuration configDefault, Configuration jobConf) throws WorkflowException {
Namespace ns = root.getNamespace();
LiteWorkflowApp def = null;
GlobalSectionData gData = jobConf.get(OOZIE_GLOBAL) == null ? null : getGlobalFromString(jobConf.get(OOZIE_GLOBAL));
boolean serializedGlobalConf = false;
for (Element eNode : (List<Element>) root.getChildren()) {
if (eNode.getName().equals(START_E)) {
def = new LiteWorkflowApp(root.getAttributeValue(NAME_A), strDef, new StartNodeDef(controlNodeHandler, eNode.getAttributeValue(TO_A)));
} else if (eNode.getName().equals(END_E)) {
def.addNode(new EndNodeDef(eNode.getAttributeValue(NAME_A), controlNodeHandler));
} else if (eNode.getName().equals(KILL_E)) {
def.addNode(new KillNodeDef(eNode.getAttributeValue(NAME_A), eNode.getChildText(KILL_MESSAGE_E, ns), controlNodeHandler));
} else if (eNode.getName().equals(FORK_E)) {
List<String> paths = new ArrayList<String>();
for (Element tran : (List<Element>) eNode.getChildren(FORK_PATH_E, ns)) {
paths.add(tran.getAttributeValue(FORK_START_A));
}
def.addNode(new ForkNodeDef(eNode.getAttributeValue(NAME_A), controlNodeHandler, paths));
} else if (eNode.getName().equals(JOIN_E)) {
def.addNode(new JoinNodeDef(eNode.getAttributeValue(NAME_A), controlNodeHandler, eNode.getAttributeValue(TO_A)));
} else if (eNode.getName().equals(DECISION_E)) {
Element eSwitch = eNode.getChild(DECISION_SWITCH_E, ns);
List<String> transitions = new ArrayList<String>();
for (Element e : (List<Element>) eSwitch.getChildren(DECISION_CASE_E, ns)) {
transitions.add(e.getAttributeValue(TO_A));
}
transitions.add(eSwitch.getChild(DECISION_DEFAULT_E, ns).getAttributeValue(TO_A));
String switchStatement = XmlUtils.prettyPrint(eSwitch).toString();
def.addNode(new DecisionNodeDef(eNode.getAttributeValue(NAME_A), switchStatement, decisionHandlerClass, transitions));
} else if (ACTION_E.equals(eNode.getName())) {
String[] transitions = new String[2];
Element eActionConf = null;
for (Element elem : (List<Element>) eNode.getChildren()) {
if (ACTION_OK_E.equals(elem.getName())) {
transitions[0] = elem.getAttributeValue(TO_A);
} else if (ACTION_ERROR_E.equals(elem.getName())) {
transitions[1] = elem.getAttributeValue(TO_A);
} else if (SLA_INFO.equals(elem.getName()) || CREDENTIALS.equals(elem.getName())) {
continue;
} else {
if (!serializedGlobalConf && elem.getName().equals(SubWorkflowActionExecutor.ACTION_TYPE) && elem.getChild(("propagate-configuration"), ns) != null && gData != null) {
serializedGlobalConf = true;
jobConf.set(OOZIE_GLOBAL, getGlobalString(gData));
}
eActionConf = elem;
if (SUBWORKFLOW_E.equals(elem.getName())) {
handleDefaultsAndGlobal(gData, null, elem, ns);
} else {
handleDefaultsAndGlobal(gData, configDefault, elem, ns);
}
}
}
String credStr = eNode.getAttributeValue(CRED_A);
String userRetryMaxStr = eNode.getAttributeValue(USER_RETRY_MAX_A);
String userRetryIntervalStr = eNode.getAttributeValue(USER_RETRY_INTERVAL_A);
String userRetryPolicyStr = eNode.getAttributeValue(USER_RETRY_POLICY_A);
try {
if (!StringUtils.isEmpty(userRetryMaxStr)) {
userRetryMaxStr = ELUtils.resolveAppName(userRetryMaxStr, jobConf);
}
if (!StringUtils.isEmpty(userRetryIntervalStr)) {
userRetryIntervalStr = ELUtils.resolveAppName(userRetryIntervalStr, jobConf);
}
if (!StringUtils.isEmpty(userRetryPolicyStr)) {
userRetryPolicyStr = ELUtils.resolveAppName(userRetryPolicyStr, jobConf);
}
} catch (Exception e) {
throw new WorkflowException(ErrorCode.E0703, e.getMessage());
}
String actionConf = XmlUtils.prettyPrint(eActionConf).toString();
def.addNode(new ActionNodeDef(eNode.getAttributeValue(NAME_A), actionConf, actionHandlerClass, transitions[0], transitions[1], credStr, userRetryMaxStr, userRetryIntervalStr, userRetryPolicyStr));
} else if (SLA_INFO.equals(eNode.getName()) || CREDENTIALS.equals(eNode.getName())) {
// No operation is required
} else if (eNode.getName().equals(GLOBAL)) {
if (jobConf.get(OOZIE_GLOBAL) != null) {
gData = getGlobalFromString(jobConf.get(OOZIE_GLOBAL));
handleDefaultsAndGlobal(gData, null, eNode, ns);
}
gData = parseGlobalSection(ns, eNode);
} else if (eNode.getName().equals(PARAMETERS)) {
// No operation is required
} else {
throw new WorkflowException(ErrorCode.E0703, eNode.getName());
}
}
return def;
}
use of org.apache.oozie.workflow.WorkflowException in project oozie by apache.
the class LiteWorkflowAppParser method parseGlobalSection.
private GlobalSectionData parseGlobalSection(Namespace ns, Element global) throws WorkflowException {
GlobalSectionData gData = null;
if (global != null) {
String globalJobTracker = null;
Element globalJobTrackerElement = getResourceManager(ns, global);
isResourceManagerTagUsed = globalJobTrackerElement != null && globalJobTrackerElement.getName().equals(RESOURCE_MANAGER);
if (globalJobTrackerElement != null) {
globalJobTracker = globalJobTrackerElement.getValue();
}
String globalNameNode = null;
Element globalNameNodeElement = global.getChild(NAME_NODE, ns);
if (globalNameNodeElement != null) {
globalNameNode = globalNameNodeElement.getValue();
}
List<String> globalJobXmls = null;
@SuppressWarnings("unchecked") List<Element> globalJobXmlElements = global.getChildren(JOB_XML, ns);
if (!globalJobXmlElements.isEmpty()) {
globalJobXmls = new ArrayList<String>(globalJobXmlElements.size());
for (Element jobXmlElement : globalJobXmlElements) {
globalJobXmls.add(jobXmlElement.getText());
}
}
Configuration globalConf = new XConfiguration();
Element globalConfigurationElement = global.getChild(CONFIGURATION, ns);
if (globalConfigurationElement != null) {
try {
globalConf = new XConfiguration(new StringReader(XmlUtils.prettyPrint(globalConfigurationElement).toString()));
} catch (IOException ioe) {
throw new WorkflowException(ErrorCode.E0700, "Error while processing global section conf");
}
}
Element globalLauncherElement = global.getChild(LAUNCHER_E, ns);
if (globalLauncherElement != null) {
LauncherConfigHandler launcherConfigHandler = new LauncherConfigHandler(globalConf, globalLauncherElement, ns);
launcherConfigHandler.processSettings();
}
gData = new GlobalSectionData(globalJobTracker, globalNameNode, globalJobXmls, globalConf);
}
return gData;
}
use of org.apache.oozie.workflow.WorkflowException in project oozie by apache.
the class LiteWorkflowAppParser method validateAndParse.
/**
* Parse and validate xml to {@link LiteWorkflowApp}
*
* @param reader
* @return LiteWorkflowApp
* @throws WorkflowException
*/
public LiteWorkflowApp validateAndParse(Reader reader, Configuration jobConf, Configuration configDefault) throws WorkflowException {
try {
StringWriter writer = new StringWriter();
IOUtils.copyCharStream(reader, writer);
String strDef = writer.toString();
if (schema != null) {
Validator validator = SchemaService.getValidator(schema);
validator.validate(new StreamSource(new StringReader(strDef)));
}
Element wfDefElement = XmlUtils.parseXml(strDef);
ParameterVerifier.verifyParameters(jobConf, wfDefElement);
LiteWorkflowApp app = parse(strDef, wfDefElement, configDefault, jobConf);
boolean validateForkJoin = false;
if (jobConf.getBoolean(WF_VALIDATE_FORK_JOIN, true) && ConfigurationService.getBoolean(VALIDATE_FORK_JOIN)) {
validateForkJoin = true;
}
LiteWorkflowValidator validator = new LiteWorkflowValidator();
validator.validateWorkflow(app, validateForkJoin);
return app;
} catch (ParameterVerifierException ex) {
throw new WorkflowException(ex);
} catch (JDOMException ex) {
throw new WorkflowException(ErrorCode.E0700, ex.getMessage(), ex);
} catch (SAXException ex) {
throw new WorkflowException(ErrorCode.E0701, ex.getMessage(), ex);
} catch (IOException ex) {
throw new WorkflowException(ErrorCode.E0702, ex.getMessage(), ex);
}
}
use of org.apache.oozie.workflow.WorkflowException in project oozie by apache.
the class LiteWorkflowAppParser method getGlobalFromString.
/**
* Read the GlobalSectionData from Base64 string.
* @param globalStr
* @return GlobalSectionData
* @throws WorkflowException
*/
private GlobalSectionData getGlobalFromString(String globalStr) throws WorkflowException {
GlobalSectionData globalSectionData = new GlobalSectionData();
try {
byte[] data = Base64.decodeBase64(globalStr);
Inflater inflater = new Inflater();
DataInputStream ois = new DataInputStream(new InflaterInputStream(new ByteArrayInputStream(data), inflater));
globalSectionData.readFields(ois);
ois.close();
} catch (Exception ex) {
throw new WorkflowException(ErrorCode.E0700, "Error while processing global section conf");
}
return globalSectionData;
}
Aggregations