Search in sources :

Example 36 with CoordinatorJobBean

use of org.apache.oozie.CoordinatorJobBean in project oozie by apache.

the class TestCoordUpdateXCommand method testReRunRefresh.

// test coord re-run with refresh. will use the updated coord definition.
public void testReRunRefresh() throws Exception {
    Configuration conf = new XConfiguration();
    File appPathFile1 = new File(getTestCaseDir(), "coordinator.xml");
    String jobId = setupCoord(conf, "coord-multiple-input-instance3.xml");
    sleep(1000);
    final int actionNum = 1;
    final String actionId = jobId + "@" + actionNum;
    final OozieClient coordClient = LocalOozie.getCoordClient();
    waitFor(120 * 1000, new Predicate() {

        @Override
        public boolean evaluate() throws Exception {
            CoordinatorAction bean = coordClient.getCoordActionInfo(actionId);
            return (bean.getStatus() == CoordinatorAction.Status.WAITING || bean.getStatus() == CoordinatorAction.Status.SUBMITTED);
        }
    });
    CoordinatorAction bean = coordClient.getCoordActionInfo(actionId);
    assertEquals(bean.getMissingDependencies(), "!!${coord:latest(0)}#${coord:latest(-1)}");
    CoordinatorJobBean job = getCoordJobs(jobId);
    Reader reader = IOUtils.getResourceAsReader("coord-multiple-input-instance4.xml", -1);
    Writer writer = new FileWriter(appPathFile1);
    IOUtils.copyCharStream(reader, writer);
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile1.toURI().toString());
    new CoordUpdateXCommand(false, conf, jobId).call();
    job = getCoordJobs(jobId);
    Element processedJobXml = XmlUtils.parseXml(job.getJobXml());
    Namespace namespace = processedJobXml.getNamespace();
    String text = ((Element) processedJobXml.getChild("input-events", namespace).getChild("data-in", namespace).getChildren("instance", namespace).get(0)).getText();
    assertEquals(text, "${coord:future(0, 1)}");
    new CoordActionsKillXCommand(jobId, RestConstants.JOB_COORD_SCOPE_ACTION, Integer.toString(actionNum)).call();
    coordClient.reRunCoord(jobId, RestConstants.JOB_COORD_SCOPE_ACTION, Integer.toString(actionNum), true, true);
    bean = coordClient.getCoordActionInfo(actionId);
    sleep(1000);
    assertEquals(bean.getMissingDependencies(), "!!${coord:future(0, 1)}");
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) FileWriter(java.io.FileWriter) Element(org.jdom.Element) Reader(java.io.Reader) StringReader(java.io.StringReader) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) IOException(java.io.IOException) XException(org.apache.oozie.XException) CommandException(org.apache.oozie.command.CommandException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Namespace(org.jdom.Namespace) XConfiguration(org.apache.oozie.util.XConfiguration) OozieClient(org.apache.oozie.client.OozieClient) CoordinatorAction(org.apache.oozie.client.CoordinatorAction) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 37 with CoordinatorJobBean

use of org.apache.oozie.CoordinatorJobBean in project oozie by apache.

the class TestCoordUpdateXCommand method testCoordFromBundleJobChangeDefinition.

public void testCoordFromBundleJobChangeDefinition() throws Exception {
    final XConfiguration jobConf = new XConfiguration();
    String coordJobId = setUpBundleAndGetCoordID(jobConf);
    CoordinatorJobBean job = getCoordJobs(coordJobId);
    Element processedJobXml = XmlUtils.parseXml(job.getJobXml());
    Namespace namespace = processedJobXml.getNamespace();
    String text = ((Element) processedJobXml.getChild("input-events", namespace).getChild("data-in", namespace).getChildren("instance", namespace).get(0)).getText();
    assertEquals(text, "${coord:latest(0)}");
    final Path coordPath1 = new Path(getFsTestCaseDir(), "coord1");
    writeCoordXml(coordPath1, "coord-multiple-input-instance4.xml");
    Configuration newConf = new Configuration();
    newConf.set(OozieClient.USER_NAME, getTestUser());
    CoordUpdateXCommand update = new CoordUpdateXCommand(false, newConf, coordJobId);
    update.call();
    job = getCoordJobs(coordJobId);
    processedJobXml = XmlUtils.parseXml(job.getJobXml());
    namespace = processedJobXml.getNamespace();
    text = ((Element) processedJobXml.getChild("input-events", namespace).getChild("data-in", namespace).getChildren("instance", namespace).get(0)).getText();
    assertEquals(text, "${coord:future(0, 1)}");
}
Also used : Path(org.apache.hadoop.fs.Path) XConfiguration(org.apache.oozie.util.XConfiguration) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) Element(org.jdom.Element) Namespace(org.jdom.Namespace)

Example 38 with CoordinatorJobBean

use of org.apache.oozie.CoordinatorJobBean in project oozie by apache.

the class TestCoordUpdateXCommand method testCoordFromBundleJobChangeConf.

public void testCoordFromBundleJobChangeConf() throws Exception {
    final XConfiguration jobConf = new XConfiguration();
    String coordJobId = setUpBundleAndGetCoordID(jobConf);
    jobConf.set("newvalue", "yes");
    CoordUpdateXCommand update = new CoordUpdateXCommand(false, jobConf, coordJobId);
    update.call();
    CoordinatorJobBean job = getCoordJobs(coordJobId);
    Configuration xConf = new XConfiguration(new StringReader(job.getConf()));
    assertEquals(xConf.get("newvalue"), "yes");
    /*
         * testProperty is part of bundle.xml <property> <name>testProperty</name> <value>abc</value> </property>
         */
    jobConf.set("testProperty", "xyz");
    new CoordUpdateXCommand(false, jobConf, coordJobId).call();
    job = getCoordJobs(coordJobId);
    xConf = new XConfiguration(new StringReader(job.getConf()));
    assertEquals(xConf.get("testProperty"), "xyz");
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) StringReader(java.io.StringReader)

Example 39 with CoordinatorJobBean

use of org.apache.oozie.CoordinatorJobBean in project oozie by apache.

the class TestCoordActionReadyXCommand method _testActionsInREADY.

private void _testActionsInREADY(Execution execPolicy) throws Exception {
    Date now = new Date();
    Date start = new Date(now.getTime() - 16 * 60 * 1000);
    Date end = new Date(now.getTime() + 20 * 60 * 1000);
    CoordinatorJobBean job = createCoordJob(Job.Status.RUNNING, start, end, true, true, 5);
    job.setStartTime(start);
    job.setEndTime(end);
    job.setExecutionOrder(execPolicy);
    job.setFrequency("5");
    job.setTimeUnit(Timeunit.MINUTE);
    // Concurrency=1 ensures that with the 1 RUNNING action, CoordActionReadyXCommand won't actually start another action
    // (CoordActionStartXCommand), which would throw an Exception because the DB only has partial info
    job.setConcurrency(1);
    addRecordToCoordJobTable(job);
    final CoordinatorActionBean action1 = addRecordToCoordActionTable(job.getId(), 1, CoordinatorAction.Status.RUNNING, "wf-no-op.xml", 1, start);
    final CoordinatorActionBean action2 = addRecordToCoordActionTable(job.getId(), 2, CoordinatorAction.Status.READY, "wf-no-op.xml", 1, new Date(start.getTime() + 5 * 60 * 1000));
    final CoordinatorActionBean action3 = addRecordToCoordActionTable(job.getId(), 3, CoordinatorAction.Status.READY, "wf-no-op.xml", 1, new Date(start.getTime() + 10 * 60 * 1000));
    final CoordinatorActionBean action4 = addRecordToCoordActionTable(job.getId(), 4, CoordinatorAction.Status.READY, "wf-no-op.xml", 1, new Date(start.getTime() + 15 * 60 * 1000));
    final CoordinatorActionBean action5 = addRecordToCoordActionTable(job.getId(), 5, CoordinatorAction.Status.WAITING, "wf-no-op.xml", 1, new Date(start.getTime() + 20 * 60 * 1000));
    checkCoordActionStatus(action1.getId(), CoordinatorAction.Status.RUNNING);
    checkCoordActionStatus(action2.getId(), CoordinatorAction.Status.READY);
    checkCoordActionStatus(action3.getId(), CoordinatorAction.Status.READY);
    checkCoordActionStatus(action4.getId(), CoordinatorAction.Status.READY);
    checkCoordActionStatus(action5.getId(), CoordinatorAction.Status.WAITING);
    new CoordActionReadyXCommand(job.getId()).call();
    checkCoordActionStatus(action1.getId(), CoordinatorAction.Status.RUNNING);
    checkCoordActionStatus(action2.getId(), CoordinatorAction.Status.SKIPPED);
    checkCoordActionStatus(action3.getId(), CoordinatorAction.Status.SKIPPED);
    checkCoordActionStatus(action4.getId(), CoordinatorAction.Status.READY);
    checkCoordActionStatus(action5.getId(), CoordinatorAction.Status.WAITING);
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) Date(java.util.Date)

Example 40 with CoordinatorJobBean

use of org.apache.oozie.CoordinatorJobBean in project oozie by apache.

the class TestCoordActionSkipXCommand method testVerifyPrecondition.

public void testVerifyPrecondition() throws Exception {
    Date startTime = new Date();
    Date endTime = new Date(startTime.getTime() + 1 * 60 * 1000);
    CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, startTime, endTime, false, true, 0);
    int actionNum = 1;
    for (CoordinatorAction.Status actionStatus : CoordinatorAction.Status.values()) {
        CoordinatorActionBean action = addRecordToCoordActionTable(job.getId(), actionNum, actionStatus, "coord-action-get.xml", 0);
        try {
            new CoordActionSkipXCommand(action, getTestUser(), "my-app-name").verifyPrecondition();
            if (!(actionStatus.equals(CoordinatorAction.Status.WAITING) || actionStatus.equals(CoordinatorAction.Status.READY))) {
                fail();
            }
        } catch (PreconditionException pe) {
            assertEquals(ErrorCode.E1100, pe.getErrorCode());
            assertTrue(pe.getMessage().endsWith("[" + actionStatus + "]]"));
        }
        actionNum++;
    }
}
Also used : CoordinatorJobBean(org.apache.oozie.CoordinatorJobBean) CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) CoordinatorAction(org.apache.oozie.client.CoordinatorAction) Date(java.util.Date) PreconditionException(org.apache.oozie.command.PreconditionException)

Aggregations

CoordinatorJobBean (org.apache.oozie.CoordinatorJobBean)373 Date (java.util.Date)177 JPAService (org.apache.oozie.service.JPAService)153 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)149 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)121 CoordJobGetJPAExecutor (org.apache.oozie.executor.jpa.CoordJobGetJPAExecutor)114 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)53 CommandException (org.apache.oozie.command.CommandException)49 BundleJobBean (org.apache.oozie.BundleJobBean)46 CoordActionGetJPAExecutor (org.apache.oozie.executor.jpa.CoordActionGetJPAExecutor)43 IOException (java.io.IOException)39 XConfiguration (org.apache.oozie.util.XConfiguration)38 ArrayList (java.util.ArrayList)36 BundleActionBean (org.apache.oozie.BundleActionBean)36 StatusTransitRunnable (org.apache.oozie.service.StatusTransitService.StatusTransitRunnable)34 Configuration (org.apache.hadoop.conf.Configuration)33 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)32 BundleJobGetJPAExecutor (org.apache.oozie.executor.jpa.BundleJobGetJPAExecutor)30 WorkflowJobGetJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobGetJPAExecutor)30 Path (org.apache.hadoop.fs.Path)24