Search in sources :

Example 16 with LiteWorkflowInstance

use of org.apache.oozie.workflow.lite.LiteWorkflowInstance 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

LiteWorkflowInstance (org.apache.oozie.workflow.lite.LiteWorkflowInstance)16 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)13 WorkflowInstance (org.apache.oozie.workflow.WorkflowInstance)12 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)10 XConfiguration (org.apache.oozie.util.XConfiguration)9 EndNodeDef (org.apache.oozie.workflow.lite.EndNodeDef)9 LiteWorkflowApp (org.apache.oozie.workflow.lite.LiteWorkflowApp)9 StartNodeDef (org.apache.oozie.workflow.lite.StartNodeDef)9 ELService (org.apache.oozie.service.ELService)7 LiteWorkflowStoreService (org.apache.oozie.service.LiteWorkflowStoreService)7 ELEvaluator (org.apache.oozie.util.ELEvaluator)7 Date (java.util.Date)6 Configuration (org.apache.hadoop.conf.Configuration)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 CommandException (org.apache.oozie.command.CommandException)4 Test (org.junit.Test)4 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)3 WorkflowStoreService (org.apache.oozie.service.WorkflowStoreService)3 WorkflowLib (org.apache.oozie.workflow.WorkflowLib)3 CoordinatorActionBean (org.apache.oozie.CoordinatorActionBean)2