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);
}
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;
}
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;
}
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();
}
}
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();
}
}
Aggregations