Search in sources :

Example 41 with XConfiguration

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

the class TestActionUserRetry method testUserRetry.

public void testUserRetry() throws JPAExecutorException, IOException, CommandException {
    Configuration conf = new XConfiguration();
    String workflowUri = getTestCaseFileUri("workflow.xml");
    // @formatter:off
    String appXml = "<workflow-app xmlns=\"uri:oozie:workflow:0.3\" name=\"wf-fork\">" + "<start to=\"fork1\"/>" + "<fork name=\"fork1\">" + "<path start=\"action1\"/>" + "<path start=\"action2\"/>" + "</fork>" + "<action name=\"action1\" retry-max=\"2\" retry-interval=\"0\">" + "<test xmlns=\"uri:test\">" + "<signal-value>${wf:conf('signal-value')}</signal-value>" + "<external-status>${wf:conf('external-status')}</external-status> " + "<error>${wf:conf('error')}</error>" + "<avoid-set-execution-data>${wf:conf('avoid-set-execution-data')}</avoid-set-execution-data>" + "<avoid-set-end-data>${wf:conf('avoid-set-end-data')}</avoid-set-end-data>" + "<running-mode>${wf:conf('running-mode')}</running-mode>" + "</test>" + "<ok to=\"join1\"/>" + "<error to=\"kill\"/>" + "</action>" + "<action name=\"action2\">" + "<fs></fs><ok to=\"join1\"/>" + "<error to=\"kill\"/>" + "</action>" + "<join name=\"join1\" to=\"end\"/>" + "<kill name=\"kill\"><message>killed</message></kill>" + "<end name=\"end\"/>" + "</workflow-app>";
    // @Formatter:on
    writeToFile(appXml, workflowUri);
    conf.set(OozieClient.APP_PATH, workflowUri);
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("error", "start.error");
    conf.set("external-status", "error");
    conf.set("signal-value", "based_on_action_status");
    SubmitXCommand sc = new SubmitXCommand(conf);
    final String jobId = sc.call();
    new StartXCommand(jobId).call();
    final WorkflowActionsGetForJobJPAExecutor actionsGetExecutor = new WorkflowActionsGetForJobJPAExecutor(jobId);
    final JPAService jpaService = Services.get().get(JPAService.class);
    waitFor(20 * 1000, new Predicate() {

        public boolean evaluate() throws Exception {
            List<WorkflowActionBean> actions = jpaService.execute(actionsGetExecutor);
            WorkflowActionBean action = null;
            for (WorkflowActionBean bean : actions) {
                if (bean.getType().equals("test")) {
                    action = bean;
                    break;
                }
            }
            return (action != null && action.getUserRetryCount() == 2);
        }
    });
    List<WorkflowActionBean> actions = jpaService.execute(actionsGetExecutor);
    WorkflowActionBean action = null;
    for (WorkflowActionBean bean : actions) {
        if (bean.getType().equals("test")) {
            action = bean;
            break;
        }
    }
    assertNotNull(action);
    assertEquals(2, action.getUserRetryCount());
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) WorkflowActionsGetForJobJPAExecutor(org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) List(java.util.List) JPAService(org.apache.oozie.service.JPAService) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) IOException(java.io.IOException) CommandException(org.apache.oozie.command.CommandException) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 42 with XConfiguration

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

the class TestCoordSubmitXCommand method testSubmitWithDoneFlag.

/**
 * Test Done Flag in Schema
 *
 * @throws Exception
 */
public void testSubmitWithDoneFlag() throws Exception {
    Configuration conf = new XConfiguration();
    File appPathFile = new File(getTestCaseDir(), "coordinator.xml");
    String appXml = "<coordinator-app name=\"NAME\" frequency=\"${coord:days(1)}\" start=\"2009-02-01T01:00Z\"" + " end=\"2009-02-03T23:59Z\" timezone=\"UTC\" " + "xmlns=\"uri:oozie:coordinator:0.2\"> <controls> <timeout>10</timeout> <concurrency>2</concurrency> " + "<execution>LIFO</execution> </controls> <datasets> " + "<dataset name=\"a\" frequency=\"${coord:days(7)}\" initial-instance=\"2009-02-01T01:00Z\" " + "timezone=\"UTC\"> <uri-template>" + getTestCaseFileUri("coord/workflows/${YEAR}/${DAY}") + "</uri-template>" + "  </dataset> " + "<dataset name=\"local_a\" frequency=\"${coord:days(7)}\" initial-instance=\"2009-02-01T01:00Z\" " + "timezone=\"UTC\"> <uri-template>file:///tmp/coord/workflows/${YEAR}/${DAY}</uri-template> " + "<done-flag>consume_me</done-flag> </dataset>" + "<dataset name=\"local_b\" frequency=\"${coord:days(7)}\" initial-instance=\"2009-02-01T01:00Z\" " + "timezone=\"UTC\"> <uri-template>file:///tmp/coord/workflowsb/${YEAR}/${DAY}</uri-template> " + "<done-flag>${MY_DONE_FLAG}</done-flag> </dataset>" + "</datasets> <input-events> " + "<data-in name=\"A\" dataset=\"a\"> <instance>${coord:latest(0)}</instance> </data-in>  " + "<data-in name=\"B\" dataset=\"local_b\"> <instance>${coord:latest(0)}</instance> </data-in>  " + "</input-events> " + "<output-events> <data-out name=\"LOCAL_A\" dataset=\"local_a\"> " + "<instance>${coord:current(-1)}</instance> </data-out> </output-events> <action> <workflow>" + " <app-path>hdfs:///tmp/workflows/</app-path> " + "<configuration> <property> <name>inputA</name> <value>${coord:dataIn('A')}</value> </property> " + "<property> <name>inputB</name> <value>${coord:dataOut('LOCAL_A')}</value> " + "</property></configuration> </workflow> </action> </coordinator-app>";
    writeToFile(appXml, appPathFile);
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("MY_DONE_FLAG", "complete");
    CoordSubmitXCommand sc = new CoordSubmitXCommand(conf);
    String jobId = sc.call();
    assertEquals(jobId.substring(jobId.length() - 2), "-C");
    checkCoordJobs(jobId);
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) File(java.io.File)

Example 43 with XConfiguration

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

the class TestCoordSubmitXCommand method testBasicSubmitWithCronFrequency.

private void testBasicSubmitWithCronFrequency(String appXml, Boolean isValidFrequency) throws Exception {
    Configuration conf = new XConfiguration();
    File appPathFile = new File(getTestCaseDir(), "coordinator.xml");
    writeToFile(appXml, appPathFile);
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
    conf.set(OozieClient.USER_NAME, getTestUser());
    CoordSubmitXCommand sc = new CoordSubmitXCommand(conf);
    if (isValidFrequency) {
        String jobId = sc.call();
        assertEquals(jobId.substring(jobId.length() - 2), "-C");
        CoordinatorJobBean job = (CoordinatorJobBean) sc.getJob();
        assertEquals(job.getTimeUnitStr(), "CRON");
    } else {
        try {
            String jobId = sc.call();
        } catch (Exception ex) {
            assertTrue(ex.getMessage().contains("Invalid coordinator cron frequency"));
        }
    }
}
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) File(java.io.File) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) CommandException(org.apache.oozie.command.CommandException)

Example 44 with XConfiguration

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

the class TestCoordSubmitXCommand method testSubmitWithSLAAlertsDisable.

public void testSubmitWithSLAAlertsDisable() throws Exception {
    Configuration conf = new XConfiguration();
    File appPathFile = new File(getTestCaseDir(), "coordinator.xml");
    // CASE 1: Failure case i.e. multiple data-in instances
    Reader reader = IOUtils.getResourceAsReader("coord-action-sla.xml", -1);
    Writer writer = new FileWriter(appPathFile);
    IOUtils.copyCharStream(reader, writer);
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
    conf.set("start", DateUtils.formatDateOozieTZ(new Date()));
    conf.set("end", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), 1)));
    conf.set("frequency", "coord:days(1)");
    conf.set(OozieClient.USER_NAME, getTestUser());
    reader = IOUtils.getResourceAsReader("wf-credentials.xml", -1);
    appPathFile = new File(getTestCaseDir(), "workflow.xml");
    writer = new FileWriter(appPathFile);
    IOUtils.copyCharStream(reader, writer);
    conf.set("wfAppPath", appPathFile.getPath());
    Date nominalTime = new Date();
    conf.set("nominal_time", DateUtils.formatDateOozieTZ(nominalTime));
    String coordId = new CoordSubmitXCommand(conf).call();
    new CoordMaterializeTransitionXCommand(coordId, 3600).call();
    SLAService slaService = services.get(SLAService.class);
    SLACalculator calc = slaService.getSLACalculator();
    SLACalcStatus slaCalc = calc.get(coordId + "@" + 1);
    assertFalse(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
    Configuration conf1 = new Configuration(conf);
    // CASE I: "ALL"
    conf1.set(OozieClient.SLA_DISABLE_ALERT, "ALL");
    coordId = new CoordSubmitXCommand(conf1).call();
    new CoordMaterializeTransitionXCommand(coordId, 3600).call();
    slaService = services.get(SLAService.class);
    calc = slaService.getSLACalculator();
    slaCalc = calc.get(coordId + "@" + 1);
    assertTrue(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
    // CASE II: Date Range
    Configuration conf2 = new Configuration(conf);
    Date startRangeDate = new Date(nominalTime.getTime() - 3600 * 1000);
    conf2.set(OozieClient.SLA_DISABLE_ALERT, DateUtils.formatDateOozieTZ(startRangeDate) + "::" + DateUtils.formatDateOozieTZ(nominalTime));
    coordId = new CoordSubmitXCommand(conf2).call();
    new CoordMaterializeTransitionXCommand(coordId, 3600).call();
    slaCalc = calc.get(coordId + "@" + 1);
    assertTrue(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
    // CASE III: Coord name (negative test)
    Configuration conf3 = new Configuration(conf);
    conf3.set(OozieClient.SLA_DISABLE_ALERT_COORD, "test-coord-sla-x");
    coordId = new CoordSubmitXCommand(conf3).call();
    new CoordMaterializeTransitionXCommand(coordId, 3600).call();
    slaCalc = calc.get(coordId + "@" + 1);
    assertFalse(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
    // CASE IV: Older than n(hours)
    Date otherNominalTime = new Date(nominalTime.getTime() - 73 * 3600 * 1000);
    conf = new XConfiguration();
    appPathFile = new File(getTestCaseDir(), "coordinator.xml");
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
    conf.set("wfAppPath", appPathFile.getPath());
    conf.set("start", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), -1)));
    conf.set("end", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), 1)));
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("nominal_time", DateUtils.formatDateOozieTZ(otherNominalTime));
    conf.setInt(OozieClient.SLA_DISABLE_ALERT_OLDER_THAN, 72);
    coordId = new CoordSubmitXCommand(conf).call();
    new CoordMaterializeTransitionXCommand(coordId, 3600).call();
    slaCalc = calc.get(coordId + "@" + 1);
    assertTrue(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
    // catchup mode
    conf = new XConfiguration();
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
    conf.set("wfAppPath", appPathFile.getPath());
    conf.set("start", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), -1)));
    conf.set("end", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), 1)));
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("nominal_time", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), -1)));
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("nominal_time", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), -1)));
    coordId = new CoordSubmitXCommand(conf).call();
    new CoordMaterializeTransitionXCommand(coordId, 3600).call();
    slaCalc = calc.get(coordId + "@" + 1);
    assertTrue(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
    // normal mode
    conf = new XConfiguration();
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
    conf.set("wfAppPath", appPathFile.getPath());
    conf.set("start", DateUtils.formatDateOozieTZ(new Date()));
    conf.set("end", DateUtils.formatDateOozieTZ(org.apache.commons.lang.time.DateUtils.addMonths(new Date(), 1)));
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("nominal_time", DateUtils.formatDateOozieTZ(new Date()));
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("nominal_time", DateUtils.formatDateOozieTZ(new Date()));
    coordId = new CoordSubmitXCommand(conf).call();
    new CoordMaterializeTransitionXCommand(coordId, 3600).call();
    slaCalc = calc.get(coordId + "@" + 1);
    assertFalse(Boolean.valueOf(slaCalc.getSLAConfigMap().get(OozieClient.SLA_DISABLE_ALERT)));
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) SLAService(org.apache.oozie.sla.service.SLAService) SLACalcStatus(org.apache.oozie.sla.SLACalcStatus) FileWriter(java.io.FileWriter) Reader(java.io.Reader) Date(java.util.Date) XConfiguration(org.apache.oozie.util.XConfiguration) SLACalculator(org.apache.oozie.sla.SLACalculator) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 45 with XConfiguration

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

the class TestCoordSubmitXCommand method testSubmitNoControls.

/**
 * Don't include controls in XML.
 *
 * @throws Exception
 */
public void testSubmitNoControls() throws Exception {
    Configuration conf = new XConfiguration();
    File appPathFile = new File(getTestCaseDir(), "coordinator.xml");
    String appXml = "<coordinator-app name=\"NAME\" frequency=\"10\" start=\"2009-02-01T01:00Z\"" + " end=\"2009-02-03T23:59Z\" timezone=\"UTC\" " + "xmlns=\"uri:oozie:coordinator:0.2\"> " + "<action> <workflow> <app-path>hdfs:///tmp/workflows/</app-path> " + "<configuration> <property> <name>inputA</name> <value>blah</value> </property> " + "</configuration> </workflow> </action> </coordinator-app>";
    writeToFile(appXml, appPathFile);
    conf.set(OozieClient.COORDINATOR_APP_PATH, appPathFile.toURI().toString());
    conf.set(OozieClient.USER_NAME, getTestUser());
    CoordSubmitXCommand sc = new CoordSubmitXCommand(conf);
    String jobId = sc.call();
    assertEquals(jobId.substring(jobId.length() - 2), "-C");
    checkCoordJobs(jobId);
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) File(java.io.File)

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