Search in sources :

Example 21 with LiteWorkflowApp

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

Example 22 with LiteWorkflowApp

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

the class TestWorkflowIdGetForExternalIdJPAExecutor method addRecordToWfJobTable.

@Override
protected WorkflowJobBean addRecordToWfJobTable(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();
    conf.set(OozieClient.APP_PATH, "testPath");
    conf.set(OozieClient.LOG_TOKEN, "testToken");
    conf.set(OozieClient.USER_NAME, getTestUser());
    WorkflowJobBean wfBean = createWorkflow(app, conf, jobStatus, instanceStatus);
    wfBean.setExternalId("external-id");
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        assertNotNull(jpaService);
        WorkflowJobInsertJPAExecutor wfInsertCmd = new WorkflowJobInsertJPAExecutor(wfBean);
        jpaService.execute(wfInsertCmd);
    } catch (JPAExecutorException je) {
        je.printStackTrace();
        fail("Unable to insert the test wf job record to table");
        throw je;
    }
    return wfBean;
}
Also used : LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) WorkflowApp(org.apache.oozie.workflow.WorkflowApp) EndNodeDef(org.apache.oozie.workflow.lite.EndNodeDef) Configuration(org.apache.hadoop.conf.Configuration) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) LiteWorkflowStoreService(org.apache.oozie.service.LiteWorkflowStoreService) WorkflowJobInsertJPAExecutor(org.apache.oozie.executor.jpa.WorkflowJobInsertJPAExecutor) JPAService(org.apache.oozie.service.JPAService) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) StartNodeDef(org.apache.oozie.workflow.lite.StartNodeDef)

Example 23 with LiteWorkflowApp

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

the class TestWorkflowJobsGetForPurgeJPAExecutor method addRecordToWfJobTable.

@Override
protected WorkflowJobBean addRecordToWfJobTable(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);
    Timestamp startTS = new Timestamp(System.currentTimeMillis() - (3 * DAY_IN_MS));
    Timestamp endTS = new Timestamp(System.currentTimeMillis() - (2 * DAY_IN_MS));
    wfBean.setStartTime(DateUtils.toDate(startTS));
    wfBean.setEndTime(DateUtils.toDate(endTS));
    try {
        JPAService jpaService = Services.get().get(JPAService.class);
        assertNotNull(jpaService);
        WorkflowJobInsertJPAExecutor wfInsertCmd = new WorkflowJobInsertJPAExecutor(wfBean);
        jpaService.execute(wfInsertCmd);
    } catch (JPAExecutorException je) {
        je.printStackTrace();
        fail("Unable to insert the test wf job record to table");
        throw je;
    }
    return wfBean;
}
Also used : LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) WorkflowApp(org.apache.oozie.workflow.WorkflowApp) 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) WorkflowJobBean(org.apache.oozie.WorkflowJobBean) Timestamp(java.sql.Timestamp) StartNodeDef(org.apache.oozie.workflow.lite.StartNodeDef) LiteWorkflowStoreService(org.apache.oozie.service.LiteWorkflowStoreService) JPAService(org.apache.oozie.service.JPAService)

Example 24 with LiteWorkflowApp

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

the class TestLiteWorkflowAppService method testActionNameLength.

public void testActionNameLength() throws Exception {
    setSystemProperty("oozie.service.ActionService.executor.ext.classes", TestActionExecutor.class.getName());
    Services services = new Services();
    try {
        services.init();
        Reader reader = IOUtils.getResourceAsReader("wf-schema-action-name-too-long.xml", -1);
        Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
        IOUtils.copyCharStream(reader, writer);
        WorkflowAppService wps = services.get(WorkflowAppService.class);
        Configuration jobConf = new XConfiguration();
        jobConf.set(OozieClient.APP_PATH, getTestCaseFileUri("workflow.xml"));
        jobConf.set(OozieClient.USER_NAME, getTestUser());
        try {
            LiteWorkflowApp app = (LiteWorkflowApp) wps.parseDef(jobConf);
            fail();
        } catch (WorkflowException ex) {
            assertEquals(ErrorCode.E0724, ex.getErrorCode());
        // nop
        }
    } finally {
        services.destroy();
    }
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) FileWriter(java.io.FileWriter) WorkflowException(org.apache.oozie.workflow.WorkflowException) Reader(java.io.Reader) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 25 with LiteWorkflowApp

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

the class TestLiteWorkflowAppService method testParsing.

public void testParsing() throws Exception {
    Services services = new Services();
    try {
        services.init();
        WorkflowAppService wps = services.get(WorkflowAppService.class);
        Reader reader = IOUtils.getResourceAsReader("wf-schema-valid.xml", -1);
        Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
        IOUtils.copyCharStream(reader, writer);
        Configuration jobConf = new XConfiguration();
        jobConf.set(OozieClient.APP_PATH, getTestCaseFileUri("workflow.xml"));
        jobConf.set(OozieClient.USER_NAME, getTestUser());
        LiteWorkflowApp app = (LiteWorkflowApp) wps.parseDef(jobConf);
        assertNotNull(app);
        assertEquals("test-wf", app.getName());
        assertNotNull(app.getNode(StartNodeDef.START));
        assertEquals("a", app.getNode(StartNodeDef.START).getTransitions().get(0));
        assertEquals("b", app.getNode("a").getTransitions().get(0));
        assertEquals("c", app.getNode("a").getTransitions().get(1));
        assertEquals("c", app.getNode("a").getTransitions().get(2));
        assertTrue(app.getNode("b").getConf().contains("kill"));
        assertEquals("d", app.getNode("c").getTransitions().get(0));
        assertEquals("e", app.getNode("c").getTransitions().get(1));
        assertEquals(2, app.getNode("c").getTransitions().size());
        assertEquals("f", app.getNode("d").getTransitions().get(0));
        assertEquals("b", app.getNode("d").getTransitions().get(1));
        assertTrue(app.getNode("d").getConf().startsWith("<map-reduce"));
        assertEquals("f", app.getNode("e").getTransitions().get(0));
        assertEquals("b", app.getNode("e").getTransitions().get(1));
        assertTrue(app.getNode("e").getConf().startsWith("<pig"));
        assertEquals("g", app.getNode("f").getTransitions().get(0));
        assertEquals("z", app.getNode("g").getTransitions().get(0));
        assertEquals("b", app.getNode("g").getTransitions().get(1));
        assertTrue(app.getNode("g").getConf().startsWith("<fs"));
        assertNotNull(app.getNode("z"));
    } finally {
        services.destroy();
    }
}
Also used : XConfiguration(org.apache.oozie.util.XConfiguration) XConfiguration(org.apache.oozie.util.XConfiguration) Configuration(org.apache.hadoop.conf.Configuration) LiteWorkflowApp(org.apache.oozie.workflow.lite.LiteWorkflowApp) FileWriter(java.io.FileWriter) Reader(java.io.Reader) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

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