Search in sources :

Example 71 with ELEvaluator

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

the class TestCoordELEvaluator method testCreateDataEvaluator.

public void testCreateDataEvaluator() throws Exception {
    String jobXml = "<coordinator-app name=\"mycoordinator-app\" start=\"2009-02-01T01:00GMT\"" + " end=\"2009-02-03T23:59GMT\" timezone=\"UTC\"";
    jobXml += " frequency=\"720\" freq_timeunit=\"MINUTE\"";
    jobXml += " action-nominal-time='2009-09-01T00:00Z' action-actual-time='2010-10-01T00:00Z'>";
    jobXml += "<input-events><data-in name=\"A\" dataset=\"a\">" + "<uris>file:///tmp/coord/US/2009/1/30|file:///tmp/coord/US/2009/1/31</uris>";
    jobXml += "<dataset name=\"a\" frequency=\"1440\" initial-instance=\"2009-01-01T00:00Z\">";
    jobXml += "<uri-template>file:///tmp/coord/US/${YEAR}/${MONTH}/${DAY}</uri-template></dataset></data-in></input-events>";
    jobXml += "<action><workflow><url>http://foobar.com:8080/oozie</url>" + "<app-path>hdfs://foobarfoobar.com:9000/usr/tucu/mywf</app-path>";
    jobXml += "<configuration><property><name>inputA</name><value>${coord:dataIn('A')}</value></property>";
    jobXml += "<property><name>ACTIONID</name><value>${coord:actionId()}</value></property>";
    jobXml += "<property><name>NAME</name><value>${coord:name()}</value></property>";
    jobXml += "<property><name>NOMINALTIME</name><value>${coord:nominalTime()}</value></property>";
    jobXml += "<property><name>ACTUALTIME</name><value>${coord:actualTime()}</value></property>";
    jobXml += "</configuration></workflow></action></coordinator-app>";
    String reply = "<action><workflow><url>http://foobar.com:8080/oozie</url>" + "<app-path>hdfs://foobarfoobar.com:9000/usr/tucu/mywf</app-path>";
    reply += "<configuration><property><name>inputA</name>" + "<value>file:///tmp/coord/US/2009/1/30|file:///tmp/coord/US/2009/1/31</value></property>";
    reply += "<property><name>ACTIONID</name><value>00000-oozie-C@1</value></property>";
    reply += "<property><name>NAME</name><value>mycoordinator-app</value></property>";
    reply += "<property><name>NOMINALTIME</name><value>2009-09-01T00:00Z</value></property>";
    reply += "<property><name>ACTUALTIME</name><value>2010-10-01T00:00Z</value></property>";
    reply += "</configuration></workflow></action>";
    Element eJob = XmlUtils.parseXml(jobXml);
    Configuration conf = new XConfiguration(new StringReader(getConfString()));
    ELEvaluator eval = CoordELEvaluator.createDataEvaluator(eJob, conf, "00000-oozie-C@1");
    Element action = eJob.getChild("action", eJob.getNamespace());
    String str = XmlUtils.prettyPrint(action).toString();
    assertEquals(XmlUtils.prettyPrint(XmlUtils.parseXml(reply)).toString(), CoordELFunctions.evalAndWrap(eval, str));
}
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)

Example 72 with ELEvaluator

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

the class TestHCatELFunctions method testHCatPartitionExists.

@Test
public void testHCatPartitionExists() throws Exception {
    dropTable("db1", "table1", true);
    dropDatabase("db1", true);
    createDatabase("db1");
    createTable("db1", "table1", "year,month,dt,country");
    addPartition("db1", "table1", "year=2012;month=12;dt=02;country=us");
    Configuration protoConf = new Configuration();
    protoConf.set(OozieClient.USER_NAME, getTestUser());
    protoConf.set("hadoop.job.ugi", getTestUser() + "," + "group");
    Configuration conf = new XConfiguration();
    conf.set(OozieClient.APP_PATH, "appPath");
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("test.dir", getTestCaseDir());
    conf.set("partition1", getHCatURI("db1", "table1", "dt=02").toString());
    conf.set("partition2", getHCatURI("db1", "table1", "dt=05").toString());
    LiteWorkflowApp def = new LiteWorkflowApp("name", "<workflow-app/>", new StartNodeDef(LiteWorkflowStoreService.LiteControlNodeHandler.class, "end")).addNode(new EndNodeDef("end", LiteWorkflowStoreService.LiteControlNodeHandler.class));
    LiteWorkflowInstance job = new LiteWorkflowInstance(def, conf, "wfId");
    WorkflowJobBean wf = new WorkflowJobBean();
    wf.setId(job.getId());
    wf.setAppName("name");
    wf.setAppPath("appPath");
    wf.setUser(getTestUser());
    wf.setGroup("group");
    wf.setWorkflowInstance(job);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    protoConf.writeXml(baos);
    wf.setProtoActionConf(baos.toString());
    WorkflowActionBean action = new WorkflowActionBean();
    action.setId("actionId");
    action.setName("actionName");
    ELEvaluator eval = Services.get().get(ELService.class).createEvaluator("workflow");
    DagELFunctions.configureEvaluator(eval, wf, action);
    assertEquals(true, (boolean) eval.evaluate("${hcat:exists(wf:conf('partition1'))}", Boolean.class));
    assertEquals(false, (boolean) eval.evaluate("${hcat:exists(wf:conf('partition2'))}", Boolean.class));
    dropTable("db1", "table1", true);
    dropDatabase("db1", true);
}
Also used : EndNodeDef(org.apache.oozie.workflow.lite.EndNodeDef) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) ELService(org.apache.oozie.service.ELService) ByteArrayOutputStream(java.io.ByteArrayOutputStream) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) StartNodeDef(org.apache.oozie.workflow.lite.StartNodeDef) WorkflowActionBean(org.apache.oozie.WorkflowActionBean) XConfiguration(org.apache.oozie.util.XConfiguration) LiteWorkflowStoreService(org.apache.oozie.service.LiteWorkflowStoreService) ELEvaluator(org.apache.oozie.util.ELEvaluator) Test(org.junit.Test)

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