use of org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor 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.executor.jpa.WorkflowActionsGetForJobJPAExecutor in project oozie by apache.
the class KillXCommand method loadState.
@Override
protected void loadState() throws CommandException {
try {
jpaService = Services.get().get(JPAService.class);
if (jpaService != null) {
this.wfJob = WorkflowJobQueryExecutor.getInstance().get(WorkflowJobQuery.GET_WORKFLOW_KILL, wfId);
this.actionList = jpaService.execute(new WorkflowActionsGetForJobJPAExecutor(wfId));
LogUtils.setLogInfo(wfJob);
} else {
throw new CommandException(ErrorCode.E0610);
}
actionService = Services.get().get(ActionService.class);
} catch (XException ex) {
throw new CommandException(ex);
}
}
use of org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor in project oozie by apache.
the class TestOozieJobInfo method testInfoWithBundle.
public void testInfoWithBundle() throws Exception {
Services.get().getConf().setBoolean(OozieJobInfo.CONF_JOB_INFO, true);
OozieJobInfo.setJobInfo(true);
BundleJobBean job = this.addRecordToBundleJobTable(Job.Status.PREP, false);
final JPAService jpaService = Services.get().get(JPAService.class);
Configuration jobConf = null;
try {
jobConf = new XConfiguration(new StringReader(job.getConf()));
} catch (IOException ioe) {
log.warn("Configuration parse error. read from DB :" + job.getConf(), ioe);
throw new CommandException(ErrorCode.E1005, ioe);
}
setCoordConf(jobConf);
Path appPath = new Path(jobConf.get(OozieClient.BUNDLE_APP_PATH), "bundle.xml");
jobConf.set(OozieClient.BUNDLE_APP_PATH, appPath.toString());
BundleSubmitXCommand submitCmd = new BundleSubmitXCommand(jobConf);
submitCmd.call();
BundleJobGetJPAExecutor bundleJobGetExecutor = new BundleJobGetJPAExecutor(submitCmd.getJob().getId());
job = jpaService.execute(bundleJobGetExecutor);
assertEquals(job.getStatus(), Job.Status.PREP);
new BundleStartXCommand(job.getId()).call();
sleep(2000);
List<BundleActionBean> actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, job.getId());
assertEquals(1, actions.size());
final String bundleID = job.getId();
waitFor(200000, new Predicate() {
public boolean evaluate() throws Exception {
List<BundleActionBean> actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, bundleID);
return actions.get(0).getStatus().equals(Job.Status.RUNNING);
}
});
actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, job.getId());
final String cordID = actions.get(0).getCoordId();
waitFor(200000, new Predicate() {
public boolean evaluate() throws Exception {
CoordJobGetJPAExecutor coordGetCmd2 = new CoordJobGetJPAExecutor(cordID);
CoordinatorJobBean cc = jpaService.execute(coordGetCmd2);
return cc.getStatus().equals(Job.Status.RUNNING);
}
});
final String jobID = jpaService.execute(new WorkflowJobsGetFromCoordParentIdJPAExecutor(cordID, 1)).get(0);
final WorkflowActionsGetForJobJPAExecutor actionsGetExecutor = new WorkflowActionsGetForJobJPAExecutor(jobID);
waitFor(200000, new Predicate() {
public boolean evaluate() throws Exception {
List<WorkflowActionBean> actions = jpaService.execute(actionsGetExecutor);
WorkflowActionBean action = null;
for (WorkflowActionBean bean : actions) {
if (bean.getName().contains("hadoop")) {
action = bean;
break;
}
}
return action.getStatus().toString().equalsIgnoreCase(Job.Status.RUNNING.toString());
}
});
final WorkflowJobGetJPAExecutor wfeExc = new WorkflowJobGetJPAExecutor(jobID);
WorkflowJobBean wfbean = jpaService.execute(wfeExc);
List<WorkflowActionBean> actionList = jpaService.execute(actionsGetExecutor);
ActionExecutorContext context = new ActionXCommand.ActionExecutorContext(wfbean, actionList.get(1), false, false);
MapReduceActionExecutor actionExecutor = new MapReduceActionExecutor();
Configuration conf = actionExecutor.createBaseHadoopConf(context, XmlUtils.parseXml(actionList.get(1).getConf()));
String user = conf.get("user.name");
FileSystem fs = getFileSystem();
Configuration jobXmlConf = new XConfiguration(fs.open(getPathToWorkflowResource(user, wfbean, services, context, LauncherAM.LAUNCHER_JOB_CONF_XML)));
String jobInfo = jobXmlConf.get(OozieJobInfo.JOB_INFO_KEY);
// BUNDLE_ID;BUNDLE_NAME;COORDINATOR_NAME;COORDINATOR_NOMINAL_TIME;
// WORKFLOW_ID;WORKFLOW_NAME;WORKFLOW_DEPTH;WORKFLOW_SUPERPARENT;
// ACTION_TYPE;ACTION_NAME,JOB_INFO,custom_info;
assertEquals(jobInfo.split(OozieJobInfo.SEPARATOR).length, 13);
assertTrue(jobInfo.contains(bundleID));
assertTrue(jobInfo.contains("bundle.name=test_bundle,"));
assertTrue(jobInfo.contains(cordID));
assertTrue(jobInfo.contains("action.type=map-reduce"));
assertTrue(jobInfo.contains("wf.depth=0"));
assertTrue(jobInfo.contains("wf.superparent.id=" + cordID));
assertTrue(jobInfo.contains(",testing=test,"));
assertTrue(jobInfo.contains(",coord.nominal.time="));
assertTrue(jobInfo.contains("launcher=true"));
}
use of org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor in project oozie by apache.
the class TestActionErrors method _testNonTransientWithCoordActionUpdate.
/**
* Provides functionality to test non transient failures and coordinator action update
*
* @param errorType the error type. (start.non-transient, end.non-transient)
* @param expStatus1 expected status. (START_MANUAL, END_MANUAL)
* @param expErrorMsg expected error message.
* @throws Exception
*/
private void _testNonTransientWithCoordActionUpdate(String errorType, WorkflowActionBean.Status expStatus1, String expErrorMsg) throws Exception {
String workflowPath = getTestCaseFileUri("workflow.xml");
Reader reader = IOUtils.getResourceAsReader("wf-ext-schema-valid.xml", -1);
Writer writer = new FileWriter(new File(getTestCaseDir(), "workflow.xml"));
IOUtils.copyCharStream(reader, writer);
final DagEngine engine = new DagEngine("u");
Configuration conf = new XConfiguration();
conf.set(OozieClient.APP_PATH, workflowPath);
conf.set(OozieClient.USER_NAME, getTestUser());
conf.set(OozieClient.LOG_TOKEN, "t");
conf.set("signal-value", "OK");
conf.set("external-status", "ok");
conf.set("error", errorType);
final String jobId = engine.submitJob(conf, false);
final JPAService jpaService = Services.get().get(JPAService.class);
final CoordinatorJobBean coordJob = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
CoordinatorActionBean coordAction = addRecordToCoordActionTable(coordJob.getId(), 1, CoordinatorAction.Status.RUNNING, "coord-action-get.xml", jobId, "RUNNING", 0);
engine.start(jobId);
waitFor(5000, new Predicate() {
public boolean evaluate() throws Exception {
return (engine.getJob(jobId).getStatus() == WorkflowJob.Status.SUSPENDED);
}
});
assertNotNull(jpaService);
WorkflowJobGetJPAExecutor wfGetCmd = new WorkflowJobGetJPAExecutor(jobId);
WorkflowJobBean job = jpaService.execute(wfGetCmd);
WorkflowActionsGetForJobJPAExecutor actionsGetExe = new WorkflowActionsGetForJobJPAExecutor(jobId);
List<WorkflowActionBean> actionsList = jpaService.execute(actionsGetExe);
int n = actionsList.size();
WorkflowActionBean action = actionsList.get(n - 1);
assertEquals("TEST_ERROR", action.getErrorCode());
assertEquals(expErrorMsg, action.getErrorMessage());
assertEquals(expStatus1, action.getStatus());
assertFalse(action.isPending());
assertEquals(WorkflowJob.Status.SUSPENDED, job.getStatus());
waitFor(5000, new Predicate() {
public boolean evaluate() throws Exception {
CoordinatorActionBean coordAction2 = jpaService.execute(new CoordActionGetForExternalIdJPAExecutor(jobId));
return coordAction2.getStatus().equals(CoordinatorAction.Status.SUSPENDED);
}
});
coordAction = jpaService.execute(new CoordActionGetForExternalIdJPAExecutor(jobId));
assertEquals(CoordinatorAction.Status.SUSPENDED, coordAction.getStatus());
}
use of org.apache.oozie.executor.jpa.WorkflowActionsGetForJobJPAExecutor in project oozie by apache.
the class TestWorkflowActionsGetForJobJPAExecutor method _testGetActions.
private void _testGetActions(String jobId) throws Exception {
JPAService jpaService = Services.get().get(JPAService.class);
assertNotNull(jpaService);
WorkflowActionsGetForJobJPAExecutor actionsGetExe = new WorkflowActionsGetForJobJPAExecutor(jobId);
List<WorkflowActionBean> list = jpaService.execute(actionsGetExe);
assertNotNull(list);
assertEquals(list.size(), 3);
}
Aggregations