Search in sources :

Example 16 with LiteWorkflowApp

use of org.apache.oozie.workflow.lite.LiteWorkflowApp in project oozie by apache.

the class TestFsELFunctions method testFunctions.

public void testFunctions() throws Exception {
    String file1 = new Path(getFsTestCaseDir(), "file1").toString();
    String file2 = new Path(getFsTestCaseDir(), "file2").toString();
    String dir = new Path(getFsTestCaseDir(), "dir").toString();
    Configuration protoConf = new Configuration();
    protoConf.set(OozieClient.USER_NAME, getTestUser());
    protoConf.set("hadoop.job.ugi", getTestUser() + "," + "group");
    FileSystem fs = getFileSystem();
    fs.mkdirs(new Path(dir));
    fs.create(new Path(file1)).close();
    OutputStream os = fs.create(new Path(dir, "a"));
    byte[] arr = new byte[1];
    os.write(arr);
    os.close();
    os = fs.create(new Path(dir, "b"));
    arr = new byte[2];
    os.write(arr);
    os.close();
    Configuration conf = new XConfiguration();
    conf.set(OozieClient.APP_PATH, "appPath");
    conf.set(OozieClient.USER_NAME, getTestUser());
    conf.set("test.dir", getTestCaseDir());
    conf.set("file1", file1);
    conf.set("file2", file2);
    conf.set("file3", "${file2}");
    conf.set("file4", getFsTestCaseDir() + "/file{1,2}");
    conf.set("file5", getFsTestCaseDir() + "/file*");
    conf.set("file6", getFsTestCaseDir() + "/file_*");
    conf.set("dir", dir);
    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("${fs:exists(wf:conf('file1'))}", Boolean.class));
    assertEquals(false, (boolean) eval.evaluate("${fs:exists(wf:conf('file2'))}", Boolean.class));
    assertEquals(true, (boolean) eval.evaluate("${fs:exists(wf:conf('file4'))}", Boolean.class));
    assertEquals(true, (boolean) eval.evaluate("${fs:exists(wf:conf('file5'))}", Boolean.class));
    assertEquals(false, (boolean) eval.evaluate("${fs:exists(wf:conf('file6'))}", Boolean.class));
    assertEquals(true, (boolean) eval.evaluate("${fs:exists(wf:conf('dir'))}", Boolean.class));
    assertEquals(false, (boolean) eval.evaluate("${fs:isDir(wf:conf('file1'))}", Boolean.class));
    assertEquals(0, (int) eval.evaluate("${fs:fileSize(wf:conf('file1'))}", Integer.class));
    assertEquals(-1, (int) eval.evaluate("${fs:fileSize(wf:conf('file2'))}", Integer.class));
    assertEquals(3, (int) eval.evaluate("${fs:dirSize(wf:conf('dir'))}", Integer.class));
    assertEquals(-1, (int) eval.evaluate("${fs:blockSize(wf:conf('file2'))}", Integer.class));
    assertTrue(eval.evaluate("${fs:blockSize(wf:conf('file1'))}", Integer.class) > 0);
}
Also used : Path(org.apache.hadoop.fs.Path) 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) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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) FileSystem(org.apache.hadoop.fs.FileSystem) LiteWorkflowStoreService(org.apache.oozie.service.LiteWorkflowStoreService) ELEvaluator(org.apache.oozie.util.ELEvaluator)

Example 17 with LiteWorkflowApp

use of org.apache.oozie.workflow.lite.LiteWorkflowApp in project oozie by apache.

the class TestDagELFunctions method testFunctions.

public void testFunctions() throws Exception {
    XConfiguration conf = new XConfiguration();
    conf.set(OozieClient.APP_PATH, "appPath");
    conf.set(OozieClient.USER_NAME, "user");
    conf.set("a", "A");
    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("user");
    wf.setGroup("group");
    wf.setWorkflowInstance(job);
    wf.setRun(2);
    wf.setProtoActionConf(conf.toXmlString());
    WorkflowActionBean action = new WorkflowActionBean();
    action.setId("actionId");
    action.setName("actionName");
    action.setErrorInfo("ec", "em");
    action.setData("b=B");
    action.setExternalId("ext");
    action.setTrackerUri("tracker");
    action.setExternalStatus("externalStatus");
    ELEvaluator eval = Services.get().get(ELService.class).createEvaluator("workflow");
    DagELFunctions.configureEvaluator(eval, wf, action);
    assertEquals("wfId", eval.evaluate("${wf:id()}", String.class));
    assertEquals("name", eval.evaluate("${wf:name()}", String.class));
    assertEquals("appPath", eval.evaluate("${wf:appPath()}", String.class));
    assertEquals("A", eval.evaluate("${wf:conf('a')}", String.class));
    assertEquals("A", eval.evaluate("${a}", String.class));
    assertEquals("user", eval.evaluate("${wf:user()}", String.class));
    assertEquals("group", eval.evaluate("${wf:group()}", String.class));
    assertTrue(eval.evaluate("${wf:callback('XX')}", String.class).contains("id=actionId"));
    assertTrue(eval.evaluate("${wf:callback('XX')}", String.class).contains("status=XX"));
    assertTrue(eval.evaluate("${wf:callback('XX')}", String.class).contains("status=XX"));
    assertEquals(2, (int) eval.evaluate("${wf:run()}", Integer.class));
    action.setStatus(WorkflowAction.Status.ERROR);
    System.out.println("WorkflowInstance " + wf.getWorkflowInstance().getStatus().toString());
    WorkflowInstance wfInstance = wf.getWorkflowInstance();
    DagELFunctions.setActionInfo(wfInstance, action);
    wf.setWorkflowInstance(wfInstance);
    assertEquals("actionName", eval.evaluate("${wf:lastErrorNode()}", String.class));
    assertEquals("ec", eval.evaluate("${wf:errorCode('actionName')}", String.class));
    assertEquals("em", eval.evaluate("${wf:errorMessage('actionName')}", String.class));
    assertEquals("B", eval.evaluate("${wf:actionData('actionName')['b']}", String.class));
    String expected = XmlUtils.escapeCharsForXML("{\"b\":\"B\"}");
    assertEquals(expected, eval.evaluate("${toJsonStr(wf:actionData('actionName'))}", String.class));
    expected = XmlUtils.escapeCharsForXML("b=B");
    assertTrue(eval.evaluate("${toPropertiesStr(wf:actionData('actionName'))}", String.class).contains(expected));
    conf = new XConfiguration();
    conf.set("b", "B");
    expected = XmlUtils.escapeCharsForXML(XmlUtils.prettyPrint(conf).toString());
    assertTrue(eval.evaluate("${toConfigurationStr(wf:actionData('actionName'))}", String.class).contains(expected));
    assertEquals("ext", eval.evaluate("${wf:actionExternalId('actionName')}", String.class));
    assertEquals("tracker", eval.evaluate("${wf:actionTrackerUri('actionName')}", String.class));
    assertEquals("externalStatus", eval.evaluate("${wf:actionExternalStatus('actionName')}", String.class));
}
Also used : EndNodeDef(org.apache.oozie.workflow.lite.EndNodeDef) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) ELService(org.apache.oozie.service.ELService) LiteWorkflowInstance(org.apache.oozie.workflow.lite.LiteWorkflowInstance) WorkflowInstance(org.apache.oozie.workflow.WorkflowInstance) 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)

Example 18 with LiteWorkflowApp

use of org.apache.oozie.workflow.lite.LiteWorkflowApp in project oozie by apache.

the class ActionExecutorTestCase method createBaseWorkflowWithCredentials.

/**
 * Return a workflow job which contains one action with no configuration and workflow contains credentials information.
 *
 * @param protoConf
 * @param actionName
 * @return workflow job bean
 * @throws Exception
 */
protected WorkflowJobBean createBaseWorkflowWithCredentials(XConfiguration protoConf, String actionName) throws Exception {
    Path appUri = new Path(getAppPath(), "workflow.xml");
    Reader reader = IOUtils.getResourceAsReader("wf-credentials.xml", -1);
    String wfxml = IOUtils.getReaderAsString(reader, -1);
    writeToFile(wfxml, getAppPath(), "workflow.xml");
    WorkflowApp app = new LiteWorkflowApp("test-wf-cred", wfxml, new StartNodeDef(LiteWorkflowStoreService.LiteControlNodeHandler.class, "start")).addNode(new EndNodeDef("end", LiteWorkflowStoreService.LiteControlNodeHandler.class));
    XConfiguration wfConf = new XConfiguration();
    wfConf.set(OozieClient.USER_NAME, getTestUser());
    wfConf.set(OozieClient.APP_PATH, appUri.toString());
    WorkflowJobBean workflow = createWorkflow(app, wfConf, protoConf);
    WorkflowActionBean action = new WorkflowActionBean();
    action.setName(actionName);
    action.setId(Services.get().get(UUIDService.class).generateChildId(workflow.getId(), actionName));
    workflow.getActions().add(action);
    return workflow;
}
Also used : Path(org.apache.hadoop.fs.Path) WorkflowApp(org.apache.oozie.workflow.WorkflowApp) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) EndNodeDef(org.apache.oozie.workflow.lite.EndNodeDef) XConfiguration(org.apache.oozie.util.XConfiguration) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) LiteWorkflowStoreService(org.apache.oozie.service.LiteWorkflowStoreService) Reader(java.io.Reader) StringReader(java.io.StringReader) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) StartNodeDef(org.apache.oozie.workflow.lite.StartNodeDef) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 19 with LiteWorkflowApp

use of org.apache.oozie.workflow.lite.LiteWorkflowApp in project oozie by apache.

the class ActionExecutorTestCase method createBaseWorkflow.

/**
 * Return a workflow job which contains one action with no configuration.
 *
 * @param protoConf
 * @param actionName
 * @return workflow job bean
 * @throws Exception
 */
protected WorkflowJobBean createBaseWorkflow(XConfiguration protoConf, String actionName) throws Exception {
    Path appUri = new Path(getAppPath(), "workflow.xml");
    String content = "<workflow-app xmlns='uri:oozie:workflow:1.0'  xmlns:sla='uri:oozie:sla:0.1' name='no-op-wf'>";
    content += "<start to='end' />";
    content += "<end name='end' /></workflow-app>";
    writeToFile(content, getAppPath(), "workflow.xml");
    WorkflowApp app = new LiteWorkflowApp("testApp", "<workflow-app/>", new StartNodeDef(LiteWorkflowStoreService.LiteControlNodeHandler.class, "end")).addNode(new EndNodeDef("end", LiteWorkflowStoreService.LiteControlNodeHandler.class));
    XConfiguration wfConf = new XConfiguration();
    wfConf.set(OozieClient.USER_NAME, getTestUser());
    wfConf.set(OozieClient.APP_PATH, appUri.toString());
    WorkflowJobBean workflow = createWorkflow(app, wfConf, protoConf);
    WorkflowActionBean action = new WorkflowActionBean();
    action.setName(actionName);
    action.setId(Services.get().get(UUIDService.class).generateChildId(workflow.getId(), actionName));
    workflow.getActions().add(action);
    return workflow;
}
Also used : Path(org.apache.hadoop.fs.Path) WorkflowApp(org.apache.oozie.workflow.WorkflowApp) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) EndNodeDef(org.apache.oozie.workflow.lite.EndNodeDef) XConfiguration(org.apache.oozie.util.XConfiguration) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) LiteWorkflowStoreService(org.apache.oozie.service.LiteWorkflowStoreService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) StartNodeDef(org.apache.oozie.workflow.lite.StartNodeDef) WorkflowActionBean(org.apache.oozie.WorkflowActionBean)

Example 20 with LiteWorkflowApp

use of org.apache.oozie.workflow.lite.LiteWorkflowApp in project oozie by apache.

the class TestPurgeXCommand method addRecordToWfJobTableForNegCase.

protected WorkflowJobBean addRecordToWfJobTableForNegCase(WorkflowJob.Status jobStatus, WorkflowInstance.Status instanceStatus) throws Exception {
    WorkflowApp app = new LiteWorkflowApp("testApp", "<workflow-app/>", new StartNodeDef(LiteWorkflowStoreService.LiteControlNodeHandler.class, "end")).addNode(new EndNodeDef("end", LiteWorkflowStoreService.LiteControlNodeHandler.class));
    Configuration conf = new Configuration();
    Path appUri = new Path(getAppPath(), "workflow.xml");
    conf.set(OozieClient.APP_PATH, appUri.toString());
    conf.set(OozieClient.LOG_TOKEN, "testToken");
    conf.set(OozieClient.USER_NAME, getTestUser());
    WorkflowJobBean wfBean = createWorkflow(app, conf, jobStatus, instanceStatus);
    // Set start time to 100 days from now
    wfBean.setStartTime(new Date(System.currentTimeMillis() + (long) 100 * 24 * 60 * 60 * 1000));
    // Set end time to 100 days + 2 hours from now
    wfBean.setEndTime(new Date(System.currentTimeMillis() + (long) 100 * 24 * 60 * 60 * 1000 + (long) 2 * 60 * 60 * 1000));
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        assertNotNull(jpaService);
        WorkflowJobInsertJPAExecutor wfInsertCmd = new WorkflowJobInsertJPAExecutor(wfBean);
        jpaService.execute(wfInsertCmd);
    } catch (JPAExecutorException ce) {
        ce.printStackTrace();
        fail("Unable to insert the test wf job record to table");
        throw ce;
    }
    return wfBean;
}
Also used : WorkflowApp(org.apache.oozie.workflow.WorkflowApp) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) EndNodeDef(org.apache.oozie.workflow.lite.EndNodeDef) Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) WorkflowJobInsertJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobInsertJPAExecutor) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) StartNodeDef(org.apache.oozie.workflow.lite.StartNodeDef) Date(java.util.Date) JPAExecutorException(org.apache.oozie.executor.jpa.JPAExecutorException) LiteWorkflowStoreService(org.apache.oozie.service.LiteWorkflowStoreService) JPAService(org.apache.oozie.service.JPAService)

Aggregations

LiteWorkflowApp (org.apache.oozie.workflow.lite.LiteWorkflowApp)25 EndNodeDef (org.apache.oozie.workflow.lite.EndNodeDef)21 StartNodeDef (org.apache.oozie.workflow.lite.StartNodeDef)21 WorkflowJobBean (org.apache.oozie.WorkflowJobBean)20 XConfiguration (org.apache.oozie.util.XConfiguration)17 Configuration (org.apache.hadoop.conf.Configuration)16 LiteWorkflowStoreService (org.apache.oozie.service.LiteWorkflowStoreService)15 WorkflowActionBean (org.apache.oozie.WorkflowActionBean)13 WorkflowApp (org.apache.oozie.workflow.WorkflowApp)13 LiteWorkflowInstance (org.apache.oozie.workflow.lite.LiteWorkflowInstance)10 Path (org.apache.hadoop.fs.Path)9 WorkflowJobInsertJPAExecutor (org.apache.oozie.executor.jpa.WorkflowJobInsertJPAExecutor)7 ELService (org.apache.oozie.service.ELService)7 ELEvaluator (org.apache.oozie.util.ELEvaluator)7 JPAService (org.apache.oozie.service.JPAService)6 WorkflowInstance (org.apache.oozie.workflow.WorkflowInstance)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Reader (java.io.Reader)4 JPAExecutorException (org.apache.oozie.executor.jpa.JPAExecutorException)4 File (java.io.File)3