use of com.google.cloud.servicedirectory.v1.Namespace in project oozie by apache.
the class EmailActionExecutor method validateAndMail.
@SuppressWarnings("unchecked")
protected void validateAndMail(Context context, Element element) throws ActionExecutorException {
// The XSD does the min/max occurrence validation for us.
Namespace ns = element.getNamespace();
String[] tos = new String[0];
String[] ccs = new String[0];
String[] bccs;
String subject = "";
String body = "";
String[] attachments = new String[0];
String contentType;
Element child = null;
// <to> - One ought to exist.
String text = element.getChildTextTrim(TO, ns);
if (text.isEmpty()) {
throw new ActionExecutorException(ErrorType.ERROR, "EM001", "No recipients were specified in the to-address field.");
}
tos = text.split(COMMA);
// <cc> - Optional, but only one ought to exist.
try {
ccs = element.getChildTextTrim(CC, ns).split(COMMA);
} catch (Exception e) {
// It is alright for cc to be given empty or not be present.
ccs = new String[0];
}
// <bcc> - Optional, but only one ought to exist.
try {
bccs = element.getChildTextTrim(BCC, ns).split(COMMA);
} catch (Exception e) {
// It is alright for bcc to be given empty or not be present.
bccs = new String[0];
}
// <subject> - One ought to exist.
subject = element.getChildTextTrim(SUB, ns);
// <body> - One ought to exist.
body = element.getChildTextTrim(BOD, ns);
// <attachment> - Optional
String attachment = element.getChildTextTrim(ATTACHMENT, ns);
if (attachment != null) {
attachments = attachment.split(COMMA);
}
contentType = element.getChildTextTrim(CONTENT_TYPE, ns);
if (contentType == null || contentType.isEmpty()) {
contentType = DEFAULT_CONTENT_TYPE;
}
// All good - lets try to mail!
email(tos, ccs, bccs, subject, body, attachments, contentType, context.getWorkflow().getUser());
}
use of com.google.cloud.servicedirectory.v1.Namespace in project oozie by apache.
the class SubmitHttpXCommand method getWorkflowXml.
/**
* Generate workflow xml from conf object
*
* @param conf the configuration object
* @return workflow xml def string representation
*/
protected String getWorkflowXml(Configuration conf) {
checkMandatoryConf(conf);
Namespace ns = getWorkflowNamespace();
Element root = new Element("workflow-app", ns);
String name = getWorkflowName();
root.setAttribute("name", "oozie-" + name);
Element start = new Element("start", ns);
String nodeName = name + "1";
start.setAttribute("to", nodeName);
root.addContent(start);
Element action = new Element("action", ns);
action.setAttribute("name", nodeName);
Element ele = generateSection(conf, getSectionNamespace());
action.addContent(ele);
Element ok = new Element("ok", ns);
ok.setAttribute("to", "end");
action.addContent(ok);
Element error = new Element("error", ns);
error.setAttribute("to", "fail");
action.addContent(error);
root.addContent(action);
Element kill = new Element("kill", ns);
kill.setAttribute("name", "fail");
Element message = new Element("message", ns);
message.addContent(name + " failed, error message[${wf:errorMessage(wf:lastErrorNode())}]");
kill.addContent(message);
root.addContent(kill);
Element end = new Element("end", ns);
end.setAttribute("name", "end");
root.addContent(end);
return XmlUtils.prettyPrint(root).toString();
}
use of com.google.cloud.servicedirectory.v1.Namespace in project oozie by apache.
the class CoordSubmitXCommand method checkMultipleTimeInstances.
/*
* Check against multiple data instance values inside a single <instance> <start-instance> or <end-instance> tag
* If found, the job is not submitted and user is informed to correct the error,
* instead of defaulting to the first instance value in the list
*/
private void checkMultipleTimeInstances(Element eCoordJob, String eventType, String dataType) throws CoordinatorJobException {
Element eventsSpec, dataSpec, instance;
List<Element> instanceSpecList;
Namespace ns = eCoordJob.getNamespace();
String instanceValue;
eventsSpec = eCoordJob.getChild(eventType, ns);
if (eventsSpec != null) {
dataSpec = eventsSpec.getChild(dataType, ns);
if (dataSpec != null) {
// In case of input-events, there can be multiple child <instance> datasets.
// Iterating to ensure none of them have errors
instanceSpecList = dataSpec.getChildren("instance", ns);
Iterator instanceIter = instanceSpecList.iterator();
while (instanceIter.hasNext()) {
instance = ((Element) instanceIter.next());
if (instance.getContentSize() == 0) {
// empty string or whitespace
throw new CoordinatorJobException(ErrorCode.E1021, "<instance> tag within " + eventType + " is empty!");
}
instanceValue = instance.getContent(0).toString();
boolean isInvalid = false;
try {
isInvalid = StringUtils.checkStaticExistence(instanceValue, ",");
} catch (Exception e) {
handleELParseException(eventType, dataType, instanceValue);
}
if (isInvalid) {
// reaching this block implies instance is not empty i.e. length > 0
handleExpresionWithMultipleInstances(eventType, dataType, instanceValue);
}
}
// In case of input-events, there can be multiple child <start-instance> datasets.
// Iterating to ensure none of them have errors
instanceSpecList = dataSpec.getChildren("start-instance", ns);
instanceIter = instanceSpecList.iterator();
while (instanceIter.hasNext()) {
instance = ((Element) instanceIter.next());
if (instance.getContentSize() == 0) {
// empty string or whitespace
throw new CoordinatorJobException(ErrorCode.E1021, "<start-instance> tag within " + eventType + " is empty!");
}
instanceValue = instance.getContent(0).toString();
boolean isInvalid = false;
try {
isInvalid = StringUtils.checkStaticExistence(instanceValue, ",");
} catch (Exception e) {
handleELParseException(eventType, dataType, instanceValue);
}
if (isInvalid) {
// reaching this block implies start instance is not empty i.e. length > 0
handleExpresionWithStartMultipleInstances(eventType, dataType, instanceValue);
}
}
// In case of input-events, there can be multiple child <end-instance> datasets.
// Iterating to ensure none of them have errors
instanceSpecList = dataSpec.getChildren("end-instance", ns);
instanceIter = instanceSpecList.iterator();
while (instanceIter.hasNext()) {
instance = ((Element) instanceIter.next());
if (instance.getContentSize() == 0) {
// empty string or whitespace
throw new CoordinatorJobException(ErrorCode.E1021, "<end-instance> tag within " + eventType + " is empty!");
}
instanceValue = instance.getContent(0).toString();
boolean isInvalid = false;
try {
isInvalid = StringUtils.checkStaticExistence(instanceValue, ",");
} catch (Exception e) {
handleELParseException(eventType, dataType, instanceValue);
}
if (isInvalid) {
// reaching this block implies instance is not empty i.e. length > 0
handleExpresionWithMultipleEndInstances(eventType, dataType, instanceValue);
}
}
}
}
}
use of com.google.cloud.servicedirectory.v1.Namespace in project oozie by apache.
the class JavaActionExecutor method parseJobXmlAndConfiguration.
public static void parseJobXmlAndConfiguration(Context context, Element element, Path appPath, Configuration conf, boolean isLauncher) throws IOException, ActionExecutorException, HadoopAccessorException, URISyntaxException {
Namespace ns = element.getNamespace();
@SuppressWarnings("unchecked") Iterator<Element> it = element.getChildren("job-xml", ns).iterator();
HashMap<String, FileSystem> filesystemsMap = new HashMap<String, FileSystem>();
HadoopAccessorService has = Services.get().get(HadoopAccessorService.class);
while (it.hasNext()) {
Element e = it.next();
String jobXml = e.getTextTrim();
Path pathSpecified = new Path(jobXml);
Path path = pathSpecified.isAbsolute() ? pathSpecified : new Path(appPath, jobXml);
FileSystem fs;
if (filesystemsMap.containsKey(path.toUri().getAuthority())) {
fs = filesystemsMap.get(path.toUri().getAuthority());
} else {
if (path.toUri().getAuthority() != null) {
fs = has.createFileSystem(context.getWorkflow().getUser(), path.toUri(), has.createConfiguration(path.toUri().getAuthority()));
} else {
fs = context.getAppFileSystem();
}
filesystemsMap.put(path.toUri().getAuthority(), fs);
}
Configuration jobXmlConf = new XConfiguration(fs.open(path));
try {
String jobXmlConfString = XmlUtils.prettyPrint(jobXmlConf).toString();
jobXmlConfString = XmlUtils.removeComments(jobXmlConfString);
jobXmlConfString = context.getELEvaluator().evaluate(jobXmlConfString, String.class);
jobXmlConf = new XConfiguration(new StringReader(jobXmlConfString));
} catch (ELEvaluationException ex) {
throw new ActionExecutorException(ActionExecutorException.ErrorType.TRANSIENT, "EL_EVAL_ERROR", ex.getMessage(), ex);
} catch (Exception ex) {
context.setErrorInfo("EL_ERROR", ex.getMessage());
}
checkForDisallowedProps(jobXmlConf, "job-xml");
if (isLauncher) {
new LauncherConfigurationInjector(jobXmlConf).inject(conf);
} else {
XConfiguration.copy(jobXmlConf, conf);
}
}
Element e = element.getChild("configuration", ns);
if (e != null) {
String strConf = XmlUtils.prettyPrint(e).toString();
XConfiguration inlineConf = new XConfiguration(new StringReader(strConf));
checkForDisallowedProps(inlineConf, "inline configuration");
if (isLauncher) {
new LauncherConfigurationInjector(inlineConf).inject(conf);
} else {
XConfiguration.copy(inlineConf, conf);
}
}
}
use of com.google.cloud.servicedirectory.v1.Namespace in project oozie by apache.
the class JavaActionExecutor method setupLauncherConf.
Configuration setupLauncherConf(Configuration conf, Element actionXml, Path appPath, Context context) throws ActionExecutorException {
try {
Namespace ns = actionXml.getNamespace();
XConfiguration launcherConf = new XConfiguration();
// Inject action defaults for launcher
HadoopAccessorService has = Services.get().get(HadoopAccessorService.class);
XConfiguration actionDefaultConf = has.createActionDefaultConf(conf.get(HADOOP_YARN_RM), getType());
new LauncherConfigurationInjector(actionDefaultConf).inject(launcherConf);
// Inject <job-xml> and <configuration> for launcher
try {
parseJobXmlAndConfiguration(context, actionXml, appPath, launcherConf, true);
} catch (HadoopAccessorException ex) {
throw convertException(ex);
} catch (URISyntaxException ex) {
throw convertException(ex);
}
XConfiguration.copy(launcherConf, conf);
// Inject config-class for launcher to use for action
Element e = actionXml.getChild("config-class", ns);
if (e != null) {
conf.set(LauncherAMUtils.OOZIE_ACTION_CONFIG_CLASS, e.getTextTrim());
}
checkForDisallowedProps(launcherConf, "launcher configuration");
return conf;
} catch (IOException ex) {
throw convertException(ex);
}
}
Aggregations