protected WorkflowActionBean createWorkflowActionSetPending( String wfId, WorkflowAction.Status status) throws Exception { WorkflowActionBean action = new WorkflowActionBean(); String actionname = "testAction"; action.setName(actionname); action.setCred("null"); action.setId(Services.get().get(UUIDService.class).generateChildId(wfId, actionname)); action.setJobId(wfId); action.setType("map-reduce"); action.setTransition("transition"); action.setStatus(status); action.setStartTime(new Date()); action.setEndTime(new Date()); action.setLastCheckTime(new Date()); action.setPending(); action.setExecutionPath("/"); Path inputDir = new Path(getFsTestCaseDir(), "input"); Path outputDir = new Path(getFsTestCaseDir(), "output"); FileSystem fs = getFileSystem(); Writer w = new OutputStreamWriter(fs.create(new Path(inputDir, "data.txt"))); w.write("dummy\n"); w.write("dummy\n"); w.close(); String actionXml = "<map-reduce>" + "<job-tracker>" + getJobTrackerUri() + "</job-tracker>" + "<name-node>" + getNameNodeUri() + "</name-node>" + "<prepare><delete path=\"" + outputDir.toString() + "\"/></prepare>" + "<configuration>" + "<property><name>mapred.mapper.class</name><value>" + MapperReducerForTest.class.getName() + "</value></property>" + "<property><name>mapred.reducer.class</name><value>" + MapperReducerForTest.class.getName() + "</value></property>" + "<property><name>mapred.input.dir</name><value>" + inputDir.toString() + "</value></property>" + "<property><name>mapred.output.dir</name><value>" + outputDir.toString() + "</value></property>" + "</configuration>" + "</map-reduce>"; action.setConf(actionXml); return action; }
public void testInsert() throws Exception { WorkflowActionBean bean = new WorkflowActionBean(); bean.setId("test-oozie-action"); bean.setName("test"); WorkflowJobQueryExecutor.getInstance().insert(bean); WorkflowActionBean retBean = WorkflowActionQueryExecutor.getInstance() .get(WorkflowActionQuery.GET_ACTION, "test-oozie-action"); assertEquals(retBean.getName(), "test"); }
public void testExecuteUpdate() throws Exception { WorkflowJobBean job = this.addRecordToWfJobTable(WorkflowJob.Status.RUNNING, WorkflowInstance.Status.RUNNING); WorkflowActionBean bean = addRecordToWfActionTable(job.getId(), "1", WorkflowAction.Status.PREP); bean.setStatus(WorkflowAction.Status.RUNNING); bean.setName("test-name"); WorkflowActionQueryExecutor.getInstance() .executeUpdate(WorkflowActionQuery.UPDATE_ACTION, bean); WorkflowActionBean retBean = WorkflowActionQueryExecutor.getInstance().get(WorkflowActionQuery.GET_ACTION, bean.getId()); assertEquals("test-name", retBean.getName()); assertEquals(retBean.getStatus(), WorkflowAction.Status.RUNNING); }
public void testSubWorkflowRecovery() throws Exception { Path subWorkflowAppPath = getFsTestCaseDir(); FileSystem fs = getFileSystem(); Writer writer = new OutputStreamWriter(fs.create(new Path(subWorkflowAppPath, "workflow.xml"))); writer.write(APP1); writer.close(); XConfiguration protoConf = getBaseProtoConf(); WorkflowJobBean workflow = createBaseWorkflow(protoConf, "W"); final WorkflowActionBean action = (WorkflowActionBean) workflow.getActions().get(0); action.setConf( "<sub-workflow xmlns='uri:oozie:workflow:0.1'>" + " <app-path>" + subWorkflowAppPath + File.separator + "workflow.xml" + "</app-path>" + " <configuration>" + " <property>" + " <name>a</name>" + " <value>A</value>" + " </property>" + " </configuration>" + "</sub-workflow>"); SubWorkflowActionExecutor subWorkflow = new SubWorkflowActionExecutor(); subWorkflow.start(new Context(workflow, action), action); final OozieClient oozieClient = subWorkflow.getWorkflowClient( new Context(workflow, action), SubWorkflowActionExecutor.LOCAL); waitFor( JOB_TIMEOUT, new Predicate() { public boolean evaluate() throws Exception { return oozieClient.getJobInfo(action.getExternalId()).getStatus() == WorkflowJob.Status.SUCCEEDED; } }); String extId = action.getExternalId(); assertEquals(WorkflowJob.Status.SUCCEEDED, oozieClient.getJobInfo(extId).getStatus()); WorkflowActionBean action1 = new WorkflowActionBean(); action1.setId(action.getId()); action1.setName(action.getName()); action1.setConf( "<sub-workflow xmlns='uri:oozie:workflow:0.1'>" + " <app-path>wrongAppPath</app-path>" + " <configuration>" + " <property>" + " <name>a</name>" + " <value>A</value>" + " </property>" + " </configuration>" + "</sub-workflow>"); subWorkflow.start(new Context(workflow, action1), action1); assertEquals(extId, action1.getExternalId()); subWorkflow.check(new Context(workflow, action1), action1); assertEquals(WorkflowAction.Status.DONE, action1.getStatus()); subWorkflow.end(new Context(workflow, action1), action1); assertEquals(WorkflowAction.Status.OK, action1.getStatus()); }