use of org.apache.oozie.BundleActionBean in project oozie by apache.
the class TestBundleKillXCommand method testBundleKill2.
/**
* Test : Kill bundle job
*
* @throws Exception
*/
public void testBundleKill2() throws Exception {
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);
}
Path appPath = new Path(jobConf.get(OozieClient.BUNDLE_APP_PATH), "bundle.xml");
jobConf.set(OozieClient.BUNDLE_APP_PATH, appPath.toString());
new BundleKillXCommand(job.getId()).call();
BundleSubmitXCommand submitCmd = new BundleSubmitXCommand(jobConf);
submitCmd.call();
BundleJobGetJPAExecutor bundleJobGetCmd = new BundleJobGetJPAExecutor(submitCmd.getJob().getId());
job = jpaService.execute(bundleJobGetCmd);
assertEquals(Job.Status.PREP, job.getStatus());
new BundleStartXCommand(job.getId()).call();
job = jpaService.execute(bundleJobGetCmd);
assertEquals(Job.Status.RUNNING, job.getStatus());
sleep(2000);
List<BundleActionBean> actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, job.getId());
assertEquals(2, actions.size());
assertNotNull(actions.get(0).getCoordId());
assertNotNull(actions.get(1).getCoordId());
new BundleKillXCommand(job.getId()).call();
job = jpaService.execute(bundleJobGetCmd);
assertEquals(Job.Status.KILLED, job.getStatus());
actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, job.getId());
assertEquals(true, actions.get(0).isPending());
assertEquals(true, actions.get(1).isPending());
final CoordJobGetJPAExecutor coordGetCmd1 = new CoordJobGetJPAExecutor(actions.get(0).getCoordId());
final CoordJobGetJPAExecutor coordGetCmd2 = new CoordJobGetJPAExecutor(actions.get(1).getCoordId());
waitFor(200000, new Predicate() {
public boolean evaluate() throws Exception {
CoordinatorJobBean job1 = jpaService.execute(coordGetCmd1);
return job1.getStatus().equals(CoordinatorJobBean.Status.KILLED);
}
});
CoordinatorJobBean job1 = jpaService.execute(coordGetCmd1);
assertEquals(CoordinatorJobBean.Status.KILLED, job1.getStatus());
waitFor(200000, new Predicate() {
public boolean evaluate() throws Exception {
CoordinatorJobBean job2 = jpaService.execute(coordGetCmd2);
return job2.getStatus().equals(CoordinatorJobBean.Status.KILLED);
}
});
CoordinatorJobBean job2 = jpaService.execute(coordGetCmd2);
assertEquals(CoordinatorJobBean.Status.KILLED, job2.getStatus());
final Runnable runnable = new StatusTransitRunnable();
runnable.run();
sleep(1000);
job = jpaService.execute(bundleJobGetCmd);
assertEquals(Job.Status.KILLED, job.getStatus());
actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, job.getId());
for (BundleActionBean action : actions) {
assertEquals(0, action.getPending());
assertEquals(CoordinatorJobBean.Status.KILLED, action.getStatus());
}
// If bundle kill + Status Transit service left the bundle action with Pending=1
// due to race condition, killing the bundle again should reset the pending.
job.setPending();
job.setStatus(Status.RUNNING);
actions.get(0).incrementAndGetPending();
BundleJobQueryExecutor.getInstance().executeUpdate(BundleJobQuery.UPDATE_BUNDLE_JOB_STATUS_PENDING, job);
BundleActionQueryExecutor.getInstance().executeUpdate(BundleActionQuery.UPDATE_BUNDLE_ACTION_PENDING_MODTIME, actions.get(0));
runnable.run();
sleep(1000);
new BundleKillXCommand(job.getId()).call();
job = jpaService.execute(bundleJobGetCmd);
assertEquals(Job.Status.KILLED, job.getStatus());
runnable.run();
sleep(1000);
job = jpaService.execute(bundleJobGetCmd);
assertEquals(Job.Status.KILLED, job.getStatus());
actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, job.getId());
for (BundleActionBean action : actions) {
assertEquals(0, action.getPending());
assertEquals(CoordinatorJobBean.Status.KILLED, action.getStatus());
}
}
use of org.apache.oozie.BundleActionBean in project oozie by apache.
the class TestBundleRerunXCommand method testBundleRerunKilledCoordinator.
/**
* Test : Rerun bundle job with a killed coordinator. Make sure the bundle action pending flag is reset.
*
* @throws Exception
*/
public void testBundleRerunKilledCoordinator() throws Exception {
BundleJobBean job = this.addRecordToBundleJobTable(Job.Status.DONEWITHERROR, false);
String bundleId = job.getId();
addRecordToBundleActionTable(bundleId, "action1", 0, Job.Status.KILLED);
addRecordToCoordJobTableWithBundle(bundleId, "action1", CoordinatorJob.Status.KILLED, false, false, 1);
JPAService jpaService = Services.get().get(JPAService.class);
assertNotNull(jpaService);
new BundleRerunXCommand(bundleId, "action1", null, false, true).call();
sleep(1000);
BundleActionGetJPAExecutor bundleActionJPA = new BundleActionGetJPAExecutor(bundleId, "action1");
BundleActionBean ba = jpaService.execute(bundleActionJPA);
assertEquals(0, ba.getPending());
}
use of org.apache.oozie.BundleActionBean in project oozie by apache.
the class TestBundleStartXCommand method testBundleStart3.
/**
* Test : Start bundle job when certain coord jobs are not enabled
*
* @throws Exception
*/
public void testBundleStart3() throws Exception {
BundleJobBean job = this.addRecordToBundleJobTableDisabledCoord(Job.Status.PREP);
JPAService jpaService = Services.get().get(JPAService.class);
assertNotNull(jpaService);
BundleJobGetJPAExecutor bundleJobGetExecutor = new BundleJobGetJPAExecutor(job.getId());
job = jpaService.execute(bundleJobGetExecutor);
assertEquals(job.getStatus(), Job.Status.PREP);
new BundleStartXCommand(job.getId()).call();
job = jpaService.execute(bundleJobGetExecutor);
assertEquals(job.getStatus(), Job.Status.RUNNING);
sleep(2000);
List<BundleActionBean> actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, job.getId());
assertEquals(1, actions.size());
assertEquals(job.getId(), actions.get(0).getBundleId());
}
use of org.apache.oozie.BundleActionBean in project oozie by apache.
the class TestBundleStartXCommand method testBundleStart2.
/**
* Test : Start bundle job
*
* @throws Exception
*/
public void testBundleStart2() throws Exception {
BundleJobBean job = this.addRecordToBundleJobTable(Job.Status.PREP, false);
final JPAService jpaService = Services.get().get(JPAService.class);
assertNotNull(jpaService);
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);
}
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("bundle-app-name", job.getAppName());
job = jpaService.execute(bundleJobGetExecutor);
assertEquals(job.getStatus(), Job.Status.PREP);
new BundleStartXCommand(job.getId()).call();
job = jpaService.execute(bundleJobGetExecutor);
assertEquals(job.getStatus(), Job.Status.RUNNING);
sleep(2000);
List<BundleActionBean> actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, job.getId());
assertEquals(2, actions.size());
final String jobId = 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, jobId);
return actions.get(0).getStatus().equals(Job.Status.RUNNING) && actions.get(1).getStatus().equals(Job.Status.RUNNING);
}
});
actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, job.getId());
assertEquals(Job.Status.RUNNING, actions.get(0).getStatus());
assertEquals(true, actions.get(0).isCritical());
assertEquals(job.getId(), actions.get(0).getBundleId());
assertEquals(Job.Status.RUNNING, actions.get(1).getStatus());
assertEquals(false, actions.get(1).isCritical());
assertEquals(job.getId(), actions.get(1).getBundleId());
}
use of org.apache.oozie.BundleActionBean in project oozie by apache.
the class TestBundleStartXCommand method testBundleStart1.
/**
* Test : Start bundle job
*
* @throws Exception
*/
public void testBundleStart1() throws Exception {
BundleJobBean job = this.addRecordToBundleJobTable(Job.Status.PREP, false);
JPAService jpaService = Services.get().get(JPAService.class);
assertNotNull(jpaService);
BundleJobGetJPAExecutor bundleJobGetExecutor = new BundleJobGetJPAExecutor(job.getId());
job = jpaService.execute(bundleJobGetExecutor);
assertEquals(job.getStatus(), Job.Status.PREP);
new BundleStartXCommand(job.getId()).call();
job = jpaService.execute(bundleJobGetExecutor);
assertEquals(job.getStatus(), Job.Status.RUNNING);
sleep(2000);
List<BundleActionBean> actions = BundleActionQueryExecutor.getInstance().getList(BundleActionQuery.GET_BUNDLE_ACTIONS_STATUS_UNIGNORED_FOR_BUNDLE, job.getId());
assertEquals(2, actions.size());
assertEquals(true, actions.get(0).isCritical());
assertEquals(job.getId(), actions.get(0).getBundleId());
assertEquals(false, actions.get(1).isCritical());
assertEquals(job.getId(), actions.get(0).getBundleId());
}
Aggregations