use of org.apache.oozie.WorkflowActionBean in project oozie by apache.
the class TestWorkflowActionRetryInfoXCommand method validateRetryConsoleUrl.
public void validateRetryConsoleUrl(String wfXml) throws Exception {
Configuration conf = new XConfiguration();
File workflowUri = new File(getTestCaseDir(), "workflow.xml");
writeToFile(wfXml, workflowUri);
conf.set(OozieClient.APP_PATH, workflowUri.toURI().toString());
conf.set(OozieClient.USER_NAME, getTestUser());
conf.set("external-status", "error");
conf.set("signal-value", "based_on_action_status");
conf.set("external-childIds", "1");
SubmitXCommand sc = new SubmitXCommand(conf);
final String jobId = sc.call();
new StartXCommand(jobId).call();
final WorkflowActionsGetForJobJPAExecutor actionsGetExecutor = new WorkflowActionsGetForJobJPAExecutor(jobId);
final JPAService jpaService = Services.get().get(JPAService.class);
waitFor(20 * 1000, new Predicate() {
public boolean evaluate() throws Exception {
List<WorkflowActionBean> actions = jpaService.execute(actionsGetExecutor);
WorkflowActionBean action = null;
for (WorkflowActionBean bean : actions) {
if (bean.getType().equals("test")) {
action = bean;
break;
}
}
return (action != null && action.getUserRetryCount() == 2);
}
});
List<WorkflowActionBean> actions = jpaService.execute(actionsGetExecutor);
WorkflowActionBean action1 = null;
WorkflowActionBean action2 = null;
for (WorkflowActionBean bean : actions) {
if (bean.getType().equals("test") && bean.getName().equals("action1")) {
action1 = bean;
} else if (bean.getType().equals("test") && bean.getName().equals("action2")) {
action2 = bean;
}
}
WorkflowActionRetryInfoXCommand command = new WorkflowActionRetryInfoXCommand(action1.getId());
List<Map<String, String>> retriesList = command.call();
assertEquals(2, retriesList.size());
assertEquals(2, action1.getUserRetryCount());
assertEquals(retriesList.get(0).get(JsonTags.ACTION_ATTEMPT), "1");
assertEquals(retriesList.get(0).get(JsonTags.WORKFLOW_ACTION_START_TIME), JsonUtils.formatDateRfc822(action1.getStartTime()));
assertNotNull(retriesList.get(0).get(JsonTags.WORKFLOW_ACTION_CONSOLE_URL));
assertNotNull(retriesList.get(0).get(JsonTags.WORKFLOW_ACTION_EXTERNAL_CHILD_IDS));
assertNotNull(retriesList.get(1).get(JsonTags.WORKFLOW_ACTION_CONSOLE_URL));
assertNotNull(retriesList.get(1).get(JsonTags.WORKFLOW_ACTION_EXTERNAL_CHILD_IDS));
final Date actionEndTime = action2 == null ? action1.getEndTime() : action2.getEndTime();
final Date secondRetryEndTime = JsonUtils.parseDateRfc822(retriesList.get(1).get(JsonTags.WORKFLOW_ACTION_END_TIME));
assertTrue("action end time should be within ten seconds of second retry end time", new Interval(secondRetryEndTime.getTime(), secondRetryEndTime.getTime() + 10_000).contains(actionEndTime.getTime()));
}
use of org.apache.oozie.WorkflowActionBean in project oozie by apache.
the class TestWorkflowActionKillXCommand method testWfActionKillSuccess.
/**
* Test : kill action successfully.
*
* @throws Exception
*/
public void testWfActionKillSuccess() throws Exception {
String externalJobID = launchSleepJob(1000);
WorkflowJobBean job = this.addRecordToWfJobTable(WorkflowJob.Status.KILLED, WorkflowInstance.Status.KILLED);
WorkflowActionBean action = this.addRecordToWfActionTable(job.getId(), externalJobID, "1", WorkflowAction.Status.KILLED, null);
JPAService jpaService = Services.get().get(JPAService.class);
assertNotNull(jpaService);
WorkflowActionGetJPAExecutor wfActionGetCmd = new WorkflowActionGetJPAExecutor(action.getId());
action = jpaService.execute(wfActionGetCmd);
assertEquals(WorkflowAction.Status.KILLED, action.getStatus());
assertEquals("RUNNING", action.getExternalStatus());
new ActionKillXCommand(action.getId()).call();
action = jpaService.execute(wfActionGetCmd);
assertEquals(WorkflowAction.Status.KILLED, action.getStatus());
assertEquals("KILLED", action.getExternalStatus());
}
use of org.apache.oozie.WorkflowActionBean in project oozie by apache.
the class TestWorkflowActionKillXCommand method addRecordToWfActionTable.
protected WorkflowActionBean addRecordToWfActionTable(String wfId, String externalJobID, String actionName, WorkflowAction.Status status, String childID) throws Exception {
WorkflowActionBean action = new WorkflowActionBean();
action.setId(Services.get().get(UUIDService.class).generateChildId(wfId, actionName));
action.setJobId(wfId);
action.setName(actionName);
action.setType("map-reduce");
action.setStatus(status);
action.setStartTime(new Date());
action.setEndTime(new Date());
action.setLastCheckTime(new Date());
action.setPending();
action.setExternalId(externalJobID);
action.setExternalStatus("RUNNING");
action.setExternalChildIDs(childID);
String actionXml = "<map-reduce>" + "<job-tracker>" + getJobTrackerUri() + "</job-tracker>" + "<name-node>" + getNameNodeUri() + "</name-node>" + "<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</value></property>" + "<property><name>mapred.output.dir</name><value>outputDir</value></property>" + "</configuration>" + "</map-reduce>";
action.setConf(actionXml);
try {
JPAService jpaService = Services.get().get(JPAService.class);
assertNotNull(jpaService);
WorkflowActionInsertJPAExecutor actionInsertExe = new WorkflowActionInsertJPAExecutor(action);
jpaService.execute(actionInsertExe);
} catch (JPAExecutorException je) {
je.printStackTrace();
fail("Unable to insert the test wf action record to table");
throw je;
}
return action;
}
use of org.apache.oozie.WorkflowActionBean in project oozie by apache.
the class TestHCatELFunctions method testHCatTableExists.
@Test
public void testHCatTableExists() throws Exception {
dropTable("db1", "table1", true);
dropDatabase("db1", true);
createDatabase("db1");
createTable("db1", "table1");
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("table1", getHCatURI("db1", "table1").toString());
conf.set("table2", getHCatURI("db1", "table2").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('table1'))}", Boolean.class));
assertEquals(false, (boolean) eval.evaluate("${hcat:exists(wf:conf('table2'))}", Boolean.class));
dropTable("db1", "table1", true);
dropDatabase("db1", true);
}
use of org.apache.oozie.WorkflowActionBean in project oozie by apache.
the class TestBatchQueryExecutor method testExecuteBatchUpdateInsertDelete.
public void testExecuteBatchUpdateInsertDelete() throws Exception {
BatchQueryExecutor executor = BatchQueryExecutor.getInstance();
// for update
CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.PREP, true, true);
WorkflowJobBean wfJob = addRecordToWfJobTable(WorkflowJob.Status.PREP, WorkflowInstance.Status.PREP);
WorkflowActionBean wfAction = addRecordToWfActionTable(wfJob.getId(), "1", WorkflowAction.Status.PREP);
// for insert
CoordinatorActionBean coordAction = new CoordinatorActionBean();
coordAction.setId("testCoordAction1");
JPAService jpaService = Services.get().get(JPAService.class);
// update the status
coordJob.setStatus(CoordinatorJob.Status.RUNNING);
wfJob.setStatus(WorkflowJob.Status.SUCCEEDED);
// update the list for doing bulk writes
List<UpdateEntry> updateList = new ArrayList<UpdateEntry>();
updateList.add(new UpdateEntry<CoordJobQuery>(CoordJobQuery.UPDATE_COORD_JOB_STATUS_MODTIME, coordJob));
updateList.add(new UpdateEntry<WorkflowJobQuery>(WorkflowJobQuery.UPDATE_WORKFLOW, wfJob));
// insert beans
Collection<JsonBean> insertList = new ArrayList<JsonBean>();
insertList.add(coordAction);
// delete beans
Collection<JsonBean> deleteList = new ArrayList<JsonBean>();
deleteList.add(wfAction);
BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, updateList, deleteList);
// check update after running ExecuteBatchUpdateInsertDelete
coordJob = CoordJobQueryExecutor.getInstance().get(CoordJobQuery.GET_COORD_JOB, coordJob.getId());
assertEquals("RUNNING", coordJob.getStatusStr());
wfJob = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW, wfJob.getId());
assertEquals("SUCCEEDED", wfJob.getStatusStr());
coordAction = CoordActionQueryExecutor.getInstance().get(CoordActionQuery.GET_COORD_ACTION, coordAction.getId());
assertEquals("testCoordAction1", coordAction.getId());
try {
wfAction = WorkflowActionQueryExecutor.getInstance().get(WorkflowActionQuery.GET_ACTION, wfJob.getId());
fail();
} catch (JPAExecutorException ex) {
assertEquals(ex.getErrorCode().toString(), "E0605");
}
}
Aggregations