Search in sources :

Example 66 with ELEvaluator

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

the class TestDagELFunctions method testLastErrorNodeWithRetrySucceed.

// This test simulates an action that gets retried because of an Error and succeeds on one of the retries.  The lastErrorNode
// EL function should never be set to this node.
public void testLastErrorNodeWithRetrySucceed() throws Exception {
    WorkflowJobBean job = this.addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING);
    WorkflowActionBean action = this.addRecordToWfActionTable(job.getId(), "1", WorkflowAction.Status.END_RETRY, true);
    action.setType("java");
    action.setExternalStatus("FAILED");
    action.setErrorInfo("JA018", "some error occurred");
    WorkflowActionQueryExecutor.getInstance().executeUpdate(WorkflowActionQueryExecutor.WorkflowActionQuery.UPDATE_ACTION, action);
    new ActionEndXCommandIgnoreSignalException(action.getId(), action.getType()).call();
    ELEvaluator eval = Services.get().get(ELService.class).createEvaluator("workflow");
    job = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQueryExecutor.WorkflowJobQuery.GET_WORKFLOW, job.getId());
    action = WorkflowActionQueryExecutor.getInstance().get(WorkflowActionQueryExecutor.WorkflowActionQuery.GET_ACTION, action.getId());
    DagELFunctions.configureEvaluator(eval, job, action);
    assertEquals("", eval.evaluate("${wf:lastErrorNode()}", String.class));
    action.setExternalStatus("SUCCEEDED");
    action.setStatus(WorkflowAction.Status.DONE);
    WorkflowActionQueryExecutor.getInstance().executeUpdate(WorkflowActionQueryExecutor.WorkflowActionQuery.UPDATE_ACTION, action);
    new ActionEndXCommandIgnoreSignalException(action.getId(), action.getType()).call();
    job = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQueryExecutor.WorkflowJobQuery.GET_WORKFLOW, job.getId());
    action = WorkflowActionQueryExecutor.getInstance().get(WorkflowActionQueryExecutor.WorkflowActionQuery.GET_ACTION, action.getId());
    assertEquals(WorkflowAction.Status.OK, action.getStatus());
    DagELFunctions.configureEvaluator(eval, job, action);
    assertEquals("", eval.evaluate("${wf:lastErrorNode()}", String.class));
}
Also used : ELService(org.apache.oozie.service.ELService) ELEvaluator(org.apache.oozie.util.ELEvaluator) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 67 with ELEvaluator

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

the class CoordELExtensions method ph1_today_echo.

public static String ph1_today_echo(int hr, int min) {
    ELEvaluator eval = ELEvaluator.getCurrent();
    eval.setVariable(".wrap", "true");
    // Unresolved
    return PREFIX + "today(" + hr + ", " + min + ")";
}
Also used : ELEvaluator(org.apache.oozie.util.ELEvaluator)

Example 68 with ELEvaluator

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

the class TestCoordELEvaluator method testCreateLazyEvaluator.

public void testCreateLazyEvaluator() throws Exception {
    // Configuration conf = new
    // XConfiguration(IOUtils.getResourceAsReader("org/apache/oozie/coord/conf.xml",
    // -1));
    String testCaseDir = getTestCaseDir();
    Configuration conf = new XConfiguration(new StringReader(getConfString()));
    Date actualTime = DateUtils.parseDateOozieTZ("2009-09-01T01:00Z");
    Date nominalTime = DateUtils.parseDateOozieTZ("2009-09-01T00:00Z");
    String dataEvntXML = "<data-in name=\"A\" dataset=\"a\"><uris>" + getTestCaseFileUri("US/2009/1/30") + "|file:///tmp/coord/US/2009/1/31</uris>";
    dataEvntXML += "<dataset name=\"a\" frequency=\"1440\" initial-instance=\"2009-01-01T00:00Z\"" + "  freq_timeunit=\"MINUTE\" timezone=\"UTC\" end_of_duration=\"NONE\">";
    dataEvntXML += "<uri-template>" + getTestCaseFileUri("${YEAR}/${MONTH}/${DAY}") + "</uri-template></dataset></data-in>";
    Element dEvent = XmlUtils.parseXml(dataEvntXML);
    ELEvaluator eval = CoordELEvaluator.createLazyEvaluator(actualTime, nominalTime, dEvent, conf);
    createTestCaseSubDir("2009/01/02/_SUCCESS".split("/"));
    String expr = "${coord:latest(0)} ${coord:latest(-1)}";
    // Dependent on the directory structure
    // TODO: Create the directory
    assertEquals("2009-01-02T00:00Z ${coord:latest(-1)}", eval.evaluate(expr, String.class));
    // future
    createTestCaseSubDir("2009/09/04/_SUCCESS".split("/"));
    createTestCaseSubDir("2009/09/05/_SUCCESS".split("/"));
    expr = "${coord:future(1, 30)}";
    assertEquals("2009-09-05T00:00Z", eval.evaluate(expr, String.class));
// System.out.println("OUTPUT :" + eval.evaluate(expr, String.class));
}
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) ELEvaluator(org.apache.oozie.util.ELEvaluator) Date(java.util.Date)

Example 69 with ELEvaluator

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

the class TestCoordELEvaluator method testCreateFreqELValuator.

public void testCreateFreqELValuator() throws Exception {
    // System.out.println("CP :" + System.getProperty("java.class.path"));
    // Configuration conf = new
    // XConfiguration(IOUtils.getResourceAsReader("org/apache/oozie/coord/conf.xml",
    // -1));
    Configuration conf = new XConfiguration(new StringReader(getConfString()));
    ELEvaluator eval = CoordELEvaluator.createELEvaluatorForGroup(conf, "coord-job-submit-freq");
    String expr = "<coordinator-app name=\"mycoordinator-app\" start=\"${start}\" end=\"${end}\"" + " frequency=\"${coord:hours(12)}\"><data-in name=\"A\" dataset=\"a\"></data-in>";
    String reply = expr.replace("${start}", conf.get("start")).replace("${end}", conf.get("end")).replace("${coord:hours(12)}", "720");
    assertEquals(reply, CoordELFunctions.evalAndWrap(eval, expr));
    expr = "<coordinator-app name=\"mycoordinator-app\" start=\"${start}\" end=\"${end}\"" + " frequency=\"${coord:days(7)}\"><data-in name=\"A\" dataset=\"a\"></data-in>";
    reply = expr.replace("${start}", conf.get("start")).replace("${end}", conf.get("end")).replace("${coord:days(7)}", "7");
    assertEquals(reply, CoordELFunctions.evalAndWrap(eval, expr));
    expr = "<coordinator-app name=\"mycoordinator-app\" start=\"${start}\" end=\"${end}\"" + " frequency=\"${coord:months(1)}\"><data-in name=\"A\" dataset=\"a\"></data-in>";
    reply = expr.replace("${start}", conf.get("start")).replace("${end}", conf.get("end")).replace("${coord:months(1)}", "1");
    // System.out.println("****testCreateELValuator :"+
    // CoordELFunctions.evaluateFunction(eval, expr));
    assertEquals(reply, CoordELFunctions.evalAndWrap(eval, expr));
    expr = "frequency=${coord:days(2)}";
    expr = "frequency=60";
    CoordELFunctions.evalAndWrap(eval, expr);
    expr = "frequency=${coord:daysInMonth(2)}";
    try {
        CoordELFunctions.evalAndWrap(eval, expr);
        fail();
    } catch (Exception ex) {
    }
    expr = "frequency=${coord:hoursInDay(2)}";
    try {
        CoordELFunctions.evalAndWrap(eval, expr);
        fail();
    } catch (Exception ex) {
    }
    expr = "frequency=${coord:tzOffset()}";
    try {
        CoordELFunctions.evalAndWrap(eval, expr);
        fail();
    } catch (Exception ex) {
    }
    expr = "<frequency=120";
    assertEquals(expr, CoordELFunctions.evalAndWrap(eval, expr));
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) XConfiguration(org.apache.oozie.util.XConfiguration) StringReader(java.io.StringReader) ELEvaluator(org.apache.oozie.util.ELEvaluator)

Example 70 with ELEvaluator

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

the class TestCoordELEvaluator method testCreateInstancesELEvaluator.

public void testCreateInstancesELEvaluator() throws Exception {
    String dataEvntXML = "<data-in name=\"A\" dataset=\"a\">" + "<uris>file:///tmp/coord/US/2009/1/30|file:///tmp/coord/US/2009/1/31</uris>";
    dataEvntXML += "<dataset name=\"a\" frequency=\"1440\" initial-instance=\"2009-01-01T00:00Z\"" + " freq_timeunit=\"MINUTE\" timezone=\"UTC\" end_of_duration=\"NONE\">";
    dataEvntXML += "<uri-template>file:///tmp/coord/US/${YEAR}/${MONTH}/${DAY}</uri-template></dataset></data-in>";
    Element event = XmlUtils.parseXml(dataEvntXML);
    SyncCoordAction appInst = new SyncCoordAction();
    appInst.setNominalTime(DateUtils.parseDateOozieTZ("2009-09-08T01:00Z"));
    appInst.setActualTime(DateUtils.parseDateOozieTZ("2010-10-01T00:00Z"));
    appInst.setTimeUnit(TimeUnit.MINUTE);
    // Configuration conf = new
    // XConfiguration(IOUtils.getResourceAsReader("org/apache/oozie/coord/conf.xml",
    // -1));
    Configuration conf = new XConfiguration(new StringReader(getConfString()));
    ELEvaluator eval = CoordELEvaluator.createInstancesELEvaluator(event, appInst, conf);
    String expr = "${coord:current(0)}";
    // System.out.println("OUTPUT :" + eval.evaluate(expr, String.class));
    assertEquals("2009-09-08T00:00Z", eval.evaluate(expr, String.class));
}
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) ELEvaluator(org.apache.oozie.util.ELEvaluator)

Aggregations

ELEvaluator (org.apache.oozie.util.ELEvaluator)72 Element (org.jdom.Element)16 ELService (org.apache.oozie.service.ELService)15 XConfiguration (org.apache.oozie.util.XConfiguration)15 Configuration (org.apache.hadoop.conf.Configuration)13 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)11 URISyntaxException (java.net.URISyntaxException)9 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)9 CoordELEvaluator (org.apache.oozie.coord.CoordELEvaluator)8 EndNodeDef (org.apache.oozie.workflow.lite.EndNodeDef)7 LiteWorkflowApp (org.apache.oozie.workflow.lite.LiteWorkflowApp)7 LiteWorkflowInstance (org.apache.oozie.workflow.lite.LiteWorkflowInstance)7 StartNodeDef (org.apache.oozie.workflow.lite.StartNodeDef)7 CommandException (org.apache.oozie.command.CommandException)6 IOException (java.io.IOException)5 StringReader (java.io.StringReader)5 URI (java.net.URI)5 Date (java.util.Date)5 Map (java.util.Map)5 HCatURI (org.apache.oozie.util.HCatURI)5