Search in sources :

Example 96 with XConfiguration

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

the class CoordRerunXCommand method refreshAction.

/**
 * Refresh an action's input and ouput events.
 *
 * @param coordJob coordinator job bean
 * @param coordAction coordinator action bean
 * @throws Exception thrown if failed to materialize coordinator action
 */
private void refreshAction(CoordinatorJobBean coordJob, CoordinatorActionBean coordAction) throws Exception {
    Configuration jobConf = null;
    try {
        jobConf = new XConfiguration(new StringReader(coordJob.getConf()));
    } catch (IOException ioe) {
        LOG.warn("Configuration parse error. read from DB :" + coordJob.getConf(), ioe);
        throw new CommandException(ErrorCode.E1005, ioe.getMessage(), ioe);
    }
    String jobXml = coordJob.getJobXml();
    Element eJob = XmlUtils.parseXml(jobXml);
    Date actualTime = new Date();
    String actionXml = CoordCommandUtils.materializeOneInstance(jobId, dryrun, (Element) eJob.clone(), coordAction.getNominalTime(), actualTime, coordAction.getActionNumber(), jobConf, coordAction);
    LOG.debug("Refresh Action actionId=" + coordAction.getId() + ", actionXml=" + XmlUtils.prettyPrint(actionXml).toString());
    coordAction.setActionXml(actionXml);
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) Element(org.jdom.Element) StringReader(java.io.StringReader) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) Date(java.util.Date)

Example 97 with XConfiguration

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

the class CoordRerunXCommand method rerunChildren.

@Override
public void rerunChildren() throws CommandException {
    boolean isError = false;
    try {
        CoordinatorActionInfo coordInfo = null;
        InstrumentUtils.incrJobCounter(getName(), 1, getInstrumentation());
        List<CoordinatorActionBean> coordActions = CoordUtils.getCoordActions(rerunType, jobId, scope, false);
        if (checkAllActionsRunnable(coordActions)) {
            Map<String, Context> uriHandlerContextMap = new HashMap<String, Context>();
            Configuration coordJobConf = null;
            try {
                coordJobConf = new XConfiguration(new StringReader(coordJob.getConf()));
            } catch (IOException e) {
                throw new CommandException(ErrorCode.E0907, "failed to read coord job conf to clean up output data");
            }
            try {
                for (CoordinatorActionBean coordAction : coordActions) {
                    String actionXml = coordAction.getActionXml();
                    // Cleanup activity should not run when failed option has been provided
                    if (!noCleanup && !failed) {
                        Element eAction = XmlUtils.parseXml(actionXml);
                        cleanupOutputEvents(eAction, coordJobConf, uriHandlerContextMap);
                    }
                    if (refresh) {
                        refreshAction(coordJob, coordAction);
                    }
                    updateAction(coordJob, coordAction);
                    if (SLAService.isEnabled()) {
                        SLAOperations.updateRegistrationEvent(coordAction.getId());
                    }
                    queue(new CoordActionNotificationXCommand(coordAction), 100);
                    queue(new CoordActionInputCheckXCommand(coordAction.getId(), coordAction.getJobId()), 100);
                    if (coordAction.getPushMissingDependencies() != null) {
                        queue(new CoordPushDependencyCheckXCommand(coordAction.getId(), true), 100);
                    }
                }
            } finally {
                Iterator<Entry<String, Context>> itr = uriHandlerContextMap.entrySet().iterator();
                while (itr.hasNext()) {
                    Entry<String, Context> entry = itr.next();
                    entry.getValue().destroy();
                    itr.remove();
                }
            }
        } else {
            isError = true;
            throw new CommandException(ErrorCode.E1018, "part or all actions are not eligible to rerun!");
        }
        coordInfo = new CoordinatorActionInfo(coordActions);
        ret = coordInfo;
    } catch (XException xex) {
        isError = true;
        throw new CommandException(xex);
    } catch (JDOMException jex) {
        isError = true;
        throw new CommandException(ErrorCode.E0700, jex.getMessage(), jex);
    } catch (Exception ex) {
        isError = true;
        throw new CommandException(ErrorCode.E1018, ex.getMessage(), ex);
    } finally {
        if (isError) {
            transitToPrevious();
        }
    }
}
Also used : Context(org.apache.oozie.dependency.URIHandler.Context) CoordinatorActionInfo(org.apache.oozie.CoordinatorActionInfo) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) HashMap(java.util.HashMap) Element(org.jdom.Element) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) JDOMException(org.jdom.JDOMException) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) URISyntaxException(java.net.URISyntaxException) JDOMException(org.jdom.JDOMException) CommandException(org.apache.oozie.command.CommandException) PreconditionException(org.apache.oozie.command.PreconditionException) URIHandlerException(org.apache.oozie.dependency.URIHandlerException) IOException(java.io.IOException) XException(org.apache.oozie.XException) XConfiguration(org.apache.oozie.util.XConfiguration) UpdateEntry(org.apache.oozie.executor.jpa.BatchQueryExecutor.UpdateEntry) Entry(java.util.Map.Entry) XException(org.apache.oozie.XException) StringReader(java.io.StringReader)

Example 98 with XConfiguration

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

the class TestCoordinatorInputLogic method testSingeSetWithMin.

public void testSingeSetWithMin() throws Exception {
    Configuration conf = getConf();
    // @formatter:off
    String inputLogic = "<or name=\"test\">" + "<data-in dataset=\"A\" min=\"3\" />" + "</or>";
    // @formatter:on
    conf.set("initial_instance_a", "2014-10-07T00:00Z");
    conf.set("initial_instance_b", "2014-10-07T00:00Z");
    String jobId = _testCoordSubmit("coord-inputlogic-range.xml", conf, inputLogic, getInputEventForRange());
    String input1 = createTestCaseSubDir("input-data/a/2014/10/08/00/_SUCCESS".split("/"));
    String input2 = createTestCaseSubDir("input-data/a/2014/10/07/23/_SUCCESS".split("/"));
    // dataset with gap
    String input3 = createTestCaseSubDir("input-data/a/2014/10/07/19/_SUCCESS".split("/"));
    startCoordAction(jobId);
    CoordinatorActionBean actionBean = CoordActionQueryExecutor.getInstance().get(CoordActionQuery.GET_COORD_ACTION, jobId + "@1");
    assertFalse(CoordinatorAction.Status.WAITING.equals(actionBean.getStatus()));
    XConfiguration runConf = new XConfiguration(new StringReader(actionBean.getRunConf()));
    String dataSets = runConf.get("inputLogicData");
    assertEquals(dataSets.split(",").length, 3);
    checkDataSets(dataSets, input1, input2, input3);
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) StringReader(java.io.StringReader)

Example 99 with XConfiguration

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

the class TestCoordinatorInputLogic method testNestedCondition.

public void testNestedCondition() throws Exception {
    Configuration conf = getConf();
    // @formatter:off
    String inputLogic = "<or name=\"test\">" + "<and>" + "<or>" + "<data-in dataset=\"A\" />" + "<data-in dataset=\"B\" />" + "</or>" + "<or>" + "<data-in dataset=\"C\" />" + "<data-in dataset=\"D\" />" + "</or>" + "</and>" + "<and>" + "<data-in dataset=\"A\" />" + "<data-in dataset=\"B\" />" + "</and>" + "</or>";
    // @formatter:on
    conf.set("partitionName", "test");
    final String jobId = _testCoordSubmit("coord-inputlogic.xml", conf, inputLogic);
    new CoordMaterializeTransitionXCommand(jobId, 3600).call();
    new CoordActionInputCheckXCommand(jobId + "@1", jobId).call();
    String input1 = createTestCaseSubDir("input-data/a/2014/10/08/00/_SUCCESS".split("/"));
    String input2 = createTestCaseSubDir("input-data/b/2014/10/08/00/_SUCCESS".split("/"));
    startCoordAction(jobId);
    CoordinatorActionBean actionBean = CoordActionQueryExecutor.getInstance().get(CoordActionQuery.GET_COORD_ACTION, jobId + "@1");
    XConfiguration runConf = new XConfiguration(new StringReader(actionBean.getRunConf()));
    String dataSets = runConf.get("inputLogicData");
    assertEquals(dataSets.split(",").length, 2);
    checkDataSets(dataSets, input1, input2);
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) StringReader(java.io.StringReader) CoordMaterializeTransitionXCommand(org.apache.oozie.command.coord.CoordMaterializeTransitionXCommand) CoordActionInputCheckXCommand(org.apache.oozie.command.coord.CoordActionInputCheckXCommand)

Example 100 with XConfiguration

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

the class TestCoordinatorInputLogic method testMinWait.

public void testMinWait() throws Exception {
    Configuration conf = getConf();
    Date now = new Date();
    String inputLogic = // @formatter:off
    "<combine name=\"test\" min= \"4\" wait=\"1\">" + "<data-in dataset=\"A\" />" + "<data-in dataset=\"B\" />" + "</combine>";
    // @formatter:on
    conf.set("start_time", DateUtils.formatDateOozieTZ(now));
    conf.set("end_time", DateUtils.formatDateOozieTZ(new Date(now.getTime() + 3 * 60 * 60 * 1000)));
    // 5 hour before
    conf.set("initial_instance_a", DateUtils.formatDateOozieTZ(new Date(now.getTime() - 5 * 60 * 60 * 1000)));
    // 5 hour before
    conf.set("initial_instance_b", DateUtils.formatDateOozieTZ(new Date(now.getTime() - 5 * 60 * 60 * 1000)));
    String jobId = _testCoordSubmit("coord-inputlogic-range.xml", conf, inputLogic, getInputEventForRange());
    new CoordMaterializeTransitionXCommand(jobId, 3600).call();
    List<String> inputDir = createDirWithTime("input-data/b/", now, 0, 1, 2, 3, 4);
    startCoordActionForWaiting(jobId);
    // wait for 1 min
    sleep(60 * 1000);
    new CoordActionInputCheckXCommand(jobId + "@1", jobId).call();
    CoordinatorActionBean actionBean = CoordActionQueryExecutor.getInstance().get(CoordActionQuery.GET_COORD_ACTION, jobId + "@1");
    assertFalse(CoordinatorAction.Status.WAITING.equals(actionBean.getStatus()));
    XConfiguration runConf = new XConfiguration(new StringReader(actionBean.getRunConf()));
    String dataSets = runConf.get("inputLogicData");
    assertEquals(dataSets.split(",").length, 5);
    checkDataSets(dataSets, inputDir.toArray(new String[inputDir.size()]));
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) StringReader(java.io.StringReader) CoordMaterializeTransitionXCommand(org.apache.oozie.command.coord.CoordMaterializeTransitionXCommand) CoordActionInputCheckXCommand(org.apache.oozie.command.coord.CoordActionInputCheckXCommand) Date(java.util.Date)

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