use of org.apache.oozie.util.XConfiguration 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);
}
}
use of org.apache.oozie.util.XConfiguration 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 org.apache.oozie.util.XConfiguration in project oozie by apache.
the class JavaActionExecutor method getShareLibNames.
/**
* Return the sharelib names for the action.
* See {@link SharelibResolver} for details.
*
* @param context executor context.
* @param actionXml the action xml.
* @param conf action configuration.
* @return the action sharelib names.
*/
protected String[] getShareLibNames(final Context context, final Element actionXml, Configuration conf) {
final String sharelibFromConfigurationProperty = ACTION_SHARELIB_FOR + getType();
try {
final String defaultShareLibName = getDefaultShareLibName(actionXml);
final Configuration oozieServerConfiguration = Services.get().get(ConfigurationService.class).getConf();
final XConfiguration workflowConfiguration = getWorkflowConf(context);
return new SharelibResolver(sharelibFromConfigurationProperty, conf, workflowConfiguration, oozieServerConfiguration, defaultShareLibName).resolve();
} catch (IOException ex) {
throw new RuntimeException("Can't get workflow configuration: " + ex.toString(), ex);
}
}
use of org.apache.oozie.util.XConfiguration in project oozie by apache.
the class JavaActionExecutor method getCredProperties.
@SuppressWarnings("unchecked")
protected CredentialsProperties getCredProperties(Context context, String credName) throws Exception {
CredentialsProperties credProp = null;
String workflowXml = ((WorkflowJobBean) context.getWorkflow()).getWorkflowInstance().getApp().getDefinition();
XConfiguration wfjobConf = getWorkflowConf(context);
Element elementJob = XmlUtils.parseXml(workflowXml);
Element credentials = elementJob.getChild("credentials", elementJob.getNamespace());
if (credentials != null) {
for (Element credential : (List<Element>) credentials.getChildren("credential", credentials.getNamespace())) {
String name = credential.getAttributeValue("name");
String type = credential.getAttributeValue("type");
LOG.debug("getCredProperties: Name: " + name + ", Type: " + type);
if (name.equalsIgnoreCase(credName)) {
credProp = new CredentialsProperties(name, type);
for (Element property : (List<Element>) credential.getChildren("property", credential.getNamespace())) {
String propertyName = property.getChildText("name", property.getNamespace());
String propertyValue = property.getChildText("value", property.getNamespace());
ELEvaluator eval = new ELEvaluator();
for (Map.Entry<String, String> entry : wfjobConf) {
eval.setVariable(entry.getKey(), entry.getValue().trim());
}
propertyName = eval.evaluate(propertyName, String.class);
propertyValue = eval.evaluate(propertyValue, String.class);
credProp.getProperties().put(propertyName, propertyValue);
LOG.debug("getCredProperties: Properties name :'" + propertyName + "', Value : '" + propertyValue + "'");
}
}
}
if (credProp == null && credName != null) {
throw new ActionExecutorException(ActionExecutorException.ErrorType.ERROR, "JA021", "Could not load credentials with name [{0}]].", credName);
}
} else {
LOG.debug("credentials is null for the action");
}
return credProp;
}
use of org.apache.oozie.util.XConfiguration in project oozie by apache.
the class JavaActionExecutor method setCredentialPropertyToActionConf.
Map<String, CredentialsProperties> setCredentialPropertyToActionConf(final Context context, final WorkflowAction action, final Configuration actionConf) throws Exception {
final Map<String, CredentialsProperties> credPropertiesMap = new HashMap<>();
if (context == null || action == null) {
LOG.warn("context or action is null");
return credPropertiesMap;
}
final XConfiguration wfJobConf = getWorkflowConf(context);
final boolean skipCredentials = actionConf.getBoolean(OOZIE_CREDENTIALS_SKIP, wfJobConf.getBoolean(OOZIE_CREDENTIALS_SKIP, ConfigurationService.getBoolean(OOZIE_CREDENTIALS_SKIP)));
if (skipCredentials) {
LOG.info("Skipping credentials (" + OOZIE_CREDENTIALS_SKIP + "=true)");
} else {
credPropertiesMap.putAll(getActionCredentialsProperties(context, action));
if (credPropertiesMap.isEmpty()) {
LOG.warn("No credential properties found for action : " + action.getId() + ", cred : " + action.getCred());
return credPropertiesMap;
}
for (final Entry<String, CredentialsProperties> entry : credPropertiesMap.entrySet()) {
if (entry.getValue() != null) {
final CredentialsProperties prop = entry.getValue();
LOG.debug("Credential Properties set for action : " + action.getId());
for (final Entry<String, String> propEntry : prop.getProperties().entrySet()) {
final String key = propEntry.getKey();
final String value = propEntry.getValue();
actionConf.set(key, value);
LOG.debug("property : '" + key + "', value : '" + value + "'");
}
}
}
}
return credPropertiesMap;
}
Aggregations