Search in sources :

Example 26 with XConfiguration

use of org.apache.oozie.util.XConfiguration in project oozie by apache.

the class FsActionExecutor method getFileSystemFor.

/**
 * @param path
 * @param context
 * @param fsConf
 * @return FileSystem
 * @throws HadoopAccessorException
 */
private FileSystem getFileSystemFor(Path path, Context context, XConfiguration fsConf) throws HadoopAccessorException {
    String user = context.getWorkflow().getUser();
    HadoopAccessorService has = Services.get().get(HadoopAccessorService.class);
    Configuration conf = has.createConfiguration(path.toUri().getAuthority());
    XConfiguration.copy(context.getProtoActionConf(), conf);
    if (fsConf != null) {
        XConfiguration.copy(fsConf, conf);
    }
    return has.createFileSystem(user, path.toUri(), conf);
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) HadoopAccessorService(org.apache.oozie.service.HadoopAccessorService)

Example 27 with XConfiguration

use of org.apache.oozie.util.XConfiguration in project oozie by apache.

the class BundleSubmitXCommand method submit.

/* (non-Javadoc)
     * @see org.apache.oozie.command.SubmitTransitionXCommand#submit()
     */
@Override
protected String submit() throws CommandException {
    LOG.info("STARTED Bundle Submit");
    try {
        InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
        ParameterVerifier.verifyParameters(conf, XmlUtils.parseXml(bundleBean.getOrigJobXml()));
        String jobXmlWithNoComment = XmlUtils.removeComments(this.bundleBean.getOrigJobXml().toString());
        // 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;
        String resolvedJobXml = resolvedVarsandFunctions(jobXmlWithNoComment, conf);
        // verify the uniqueness of coord names
        verifyCoordNameUnique(resolvedJobXml);
        this.jobId = storeToDB(bundleBean, resolvedJobXml);
        LogUtils.setLogInfo(bundleBean);
        if (dryrun) {
            Date startTime = bundleBean.getStartTime();
            long startTimeMilli = startTime.getTime();
            long endTimeMilli = startTimeMilli + (3600 * 1000);
            Date jobEndTime = bundleBean.getEndTime();
            Date endTime = new Date(endTimeMilli);
            if (endTime.compareTo(jobEndTime) > 0) {
                endTime = jobEndTime;
            }
            jobId = bundleBean.getId();
            LOG.info("[" + jobId + "]: Update status to PREP");
            bundleBean.setStatus(Job.Status.PREP);
            try {
                new XConfiguration(new StringReader(bundleBean.getConf()));
            } catch (IOException e1) {
                LOG.warn("Configuration parse error. read from DB :" + bundleBean.getConf(), e1);
            }
            String output = bundleBean.getJobXml() + System.getProperty("line.separator");
            return output;
        } else {
            if (bundleBean.getKickoffTime() == null) {
                // If there is no KickOffTime, default kickoff is NOW.
                LOG.debug("Since kickoff time is not defined for job id " + jobId + ". Queuing and BundleStartXCommand immediately after submission");
                queue(new BundleStartXCommand(jobId));
            }
        }
    } catch (Exception ex) {
        throw new CommandException(ErrorCode.E1310, ex.getMessage(), ex);
    }
    LOG.info("ENDED Bundle Submit");
    return this.jobId;
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) StringReader(java.io.StringReader) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) Map(java.util.Map) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) JDOMException(org.jdom.JDOMException) HadoopAccessorException(org.apache.oozie.service.HadoopAccessorException) CommandException(org.apache.oozie.command.CommandException) SAXException(org.xml.sax.SAXException) PreconditionException(org.apache.oozie.command.PreconditionException) IOException(java.io.IOException)

Example 28 with XConfiguration

use of org.apache.oozie.util.XConfiguration in project oozie by apache.

the class DagELFunctions method configureEvaluator.

public static void configureEvaluator(ELEvaluator evaluator, WorkflowJobBean workflow, WorkflowActionBean action) {
    evaluator.setVariable(WORKFLOW, workflow);
    evaluator.setVariable(ACTION, action);
    for (Map.Entry<String, String> entry : workflow.getWorkflowInstance().getConf()) {
        if (ParamChecker.isValidIdentifier(entry.getKey())) {
            String value = entry.getValue().trim();
            try {
                String valueElem = "<value>" + value + "</value>";
                XmlUtils.parseXml(valueElem);
            } catch (JDOMException ex) {
                // If happens, try escaping the characters for XML. The escaping may or
                // may not solve the problem since the JDOMException could be for a range of issues.
                value = XmlUtils.escapeCharsForXML(value);
            }
            evaluator.setVariable(entry.getKey().trim(), value);
        }
    }
    try {
        evaluator.setVariable(ACTION_PROTO_CONF, new XConfiguration(new StringReader(workflow.getProtoActionConf())));
    } catch (IOException ex) {
        throw new RuntimeException("It should not happen", ex);
    }
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) StringReader(java.io.StringReader) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) Map(java.util.Map)

Example 29 with XConfiguration

use of org.apache.oozie.util.XConfiguration in project oozie by apache.

the class DagEngine method reRun.

/**
 * Rerun a job.
 *
 * @param jobId job Id to rerun.
 * @param conf configuration information for the rerun.
 * @throws DagEngineException thrown if the job could not be rerun.
 */
@Override
public void reRun(String jobId, Configuration conf) throws DagEngineException {
    try {
        WorkflowJobBean wfBean = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW, jobId);
        Configuration wfConf = new XConfiguration(new StringReader(wfBean.getConf()));
        XConfiguration.copy(conf, wfConf);
        validateReRunConfiguration(wfConf);
        new ReRunXCommand(jobId, wfConf).call();
    } catch (CommandException ex) {
        throw new DagEngineException(ex);
    } catch (JPAExecutorException ex) {
        throw new DagEngineException(ex);
    } catch (IOException ex) {
        throw new DagEngineException(ErrorCode.E0803, ex.getMessage());
    }
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) ReRunXCommand(org.apache.oozie.command.wf.ReRunXCommand) StringReader(java.io.StringReader) CommandException(org.apache.oozie.command.CommandException) IOException(java.io.IOException)

Example 30 with XConfiguration

use of org.apache.oozie.util.XConfiguration in project oozie by apache.

the class MapReduceActionExecutor method evaluateConfigurationProperty.

// Return the value of the specified configuration property
private String evaluateConfigurationProperty(Element actionConf, String key, String defaultValue) throws ActionExecutorException {
    try {
        String ret = defaultValue;
        if (actionConf != null) {
            Namespace ns = actionConf.getNamespace();
            Element e = actionConf.getChild("configuration", ns);
            if (e != null) {
                String strConf = XmlUtils.prettyPrint(e).toString();
                XConfiguration inlineConf = new XConfiguration(new StringReader(strConf));
                ret = inlineConf.get(key, defaultValue);
            }
        }
        return ret;
    } catch (IOException ex) {
        throw convertException(ex);
    }
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Element(org.jdom.Element) StringReader(java.io.StringReader) IOException(java.io.IOException) Namespace(org.jdom.Namespace)

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