Search in sources :

Example 21 with XConfiguration

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);
    }
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Element(org.jdom.Element) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) HadoopAccessorService(org.apache.oozie.service.HadoopAccessorService) Namespace(org.jdom.Namespace)

Example 22 with XConfiguration

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);
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Element(org.jdom.Element) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) HadoopAccessorService(org.apache.oozie.service.HadoopAccessorService) Namespace(org.jdom.Namespace) URISyntaxException(java.net.URISyntaxException) JDOMException(org.jdom.JDOMException) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) FileNotFoundException(java.io.FileNotFoundException) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) ConnectException(java.net.ConnectException) ELEvaluationException(org.apache.oozie.util.ELEvaluationException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) RemoteException(org.apache.hadoop.ipc.RemoteException) AccessControlException(org.apache.hadoop.security.AccessControlException) XConfiguration(org.apache.oozie.util.XConfiguration) ELEvaluationException(org.apache.oozie.util.ELEvaluationException) FileSystem(org.apache.hadoop.fs.FileSystem) StringReader(java.io.StringReader)

Example 23 with XConfiguration

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);
    }
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) ConfigurationService(org.apache.oozie.service.ConfigurationService) IOException(java.io.IOException)

Example 24 with XConfiguration

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;
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Element(org.jdom.Element) ActionExecutorException(org.apache.oozie.action.ActionExecutorException) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) ELEvaluator(org.apache.oozie.util.ELEvaluator) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 25 with XConfiguration

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;
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

XConfiguration (org.apache.oozie.util.XConfiguration)373 Configuration (org.apache.hadoop.conf.Configuration)241 Path (org.apache.hadoop.fs.Path)106 StringReader (java.io.StringReader)97 File (java.io.File)92 IOException (java.io.IOException)78 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)75 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)70 CommandException (org.apache.oozie.command.CommandException)68 Element (org.jdom.Element)66 Writer (java.io.Writer)58 Date (java.util.Date)50 FileSystem (org.apache.hadoop.fs.FileSystem)48 FileWriter (java.io.FileWriter)45 Reader (java.io.Reader)43 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)37 CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)36 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)28 OutputStream (java.io.OutputStream)27 FileOutputStream (java.io.FileOutputStream)25