use of org.apache.oozie.CoordinatorActionBean in project oozie by apache.
the class TestSLAJobEventListener method createCoordAction.
private CoordinatorActionBean createCoordAction(String id, String parentId) throws Exception {
List<JsonBean> insertList = new ArrayList<JsonBean>();
CoordinatorActionBean action = new CoordinatorActionBean();
action.setId(id);
action.setJobId(parentId);
insertList.add(action);
BatchQueryExecutor.getInstance().executeBatchInsertUpdateDelete(insertList, null, null);
return action;
}
use of org.apache.oozie.CoordinatorActionBean in project oozie by apache.
the class XDataTestCase method addRecordToCoordActionTable.
/**
* Insert coord action for testing.
*
* @param jobId coord job id
* @param actionNum action number
* @param status coord action status
* @param resourceXmlName xml file name
* @param pending pending counter
* @param actionNominalTime
* @return coord action bean
* @throws Exception thrown if unable to create coord action bean
*/
protected CoordinatorActionBean addRecordToCoordActionTable(String jobId, int actionNum, CoordinatorAction.Status status, String resourceXmlName, int pending, Date actionNominalTime) throws Exception {
CoordinatorActionBean action = createCoordAction(jobId, actionNum, status, resourceXmlName, pending, actionNominalTime);
try {
JPAService jpaService = Services.get().get(JPAService.class);
assertNotNull(jpaService);
CoordActionInsertJPAExecutor coordActionInsertCmd = new CoordActionInsertJPAExecutor(action);
jpaService.execute(coordActionInsertCmd);
} catch (JPAExecutorException je) {
je.printStackTrace();
fail("Unable to insert the test coord action record to table");
throw je;
}
return action;
}
use of org.apache.oozie.CoordinatorActionBean in project oozie by apache.
the class XDataTestCase method setCoordActionStatus.
protected void setCoordActionStatus(String actionId, CoordinatorAction.Status status) throws Exception {
JPAService jpaService = Services.get().get(JPAService.class);
CoordinatorActionBean action = jpaService.execute(new CoordActionGetJPAExecutor(actionId));
action.setStatus(status);
CoordActionQueryExecutor.getInstance().executeUpdate(CoordActionQuery.UPDATE_COORD_ACTION, action);
}
use of org.apache.oozie.CoordinatorActionBean in project oozie by apache.
the class XDataTestCase method createCoordAction.
/**
* Create coord action bean
*
* @param jobId coord job id
* @param actionNum action number
* @param status coord action status
* @param resourceXmlName xml file name
* @param pending pending counter
* @return coord action bean
* @throws Exception thrown if unable to create coord action bean
*/
protected CoordinatorActionBean createCoordAction(String jobId, int actionNum, CoordinatorAction.Status status, String resourceXmlName, int pending, String oozieTimeZoneMask, Date actionNominalTime) throws Exception {
String actionId = Services.get().get(UUIDService.class).generateChildId(jobId, actionNum + "");
Path appPath = new Path(getFsTestCaseDir(), "coord");
String actionXml = getCoordActionXml(appPath, resourceXmlName);
actionXml = actionXml.replace("${TZ}", oozieTimeZoneMask);
CoordinatorActionBean action = new CoordinatorActionBean();
action.setId(actionId);
if (status != CoordinatorAction.Status.SUBMITTED && status != CoordinatorAction.Status.READY) {
action.setExternalId(actionId + "_E");
}
action.setJobId(jobId);
action.setActionNumber(actionNum);
action.setPending(pending);
try {
if (actionNominalTime == null) {
String nominalTime = getActionNominalTime(actionXml);
action.setNominalTime(DateUtils.parseDateOozieTZ(nominalTime));
} else {
action.setNominalTime(actionNominalTime);
}
} catch (Exception e) {
e.printStackTrace();
fail("Unable to get action nominal time");
throw new IOException(e);
}
action.setLastModifiedTime(new Date());
action.setCreatedTime(new Date());
action.setStatus(status);
action.setActionXml(actionXml);
action.setTimeOut(10);
Configuration conf = getCoordConf(appPath);
action.setCreatedConf(XmlUtils.prettyPrint(conf).toString());
action.setRunConf(XmlUtils.prettyPrint(conf).toString());
return action;
}
use of org.apache.oozie.CoordinatorActionBean in project oozie by apache.
the class TestCoordActionsInDateRange method testCoordActionsInDateRange.
/**
* This is unit test case for the 'getCoordActionsFromDates()' method. The method is supposed to retrieve the list of
* coordinator actions running between a range of start and end date. The following test case tests its accuracy and fails
* otherwise.
*/
public void testCoordActionsInDateRange() {
try {
int actionNum = 1;
CoordinatorJobBean job = addRecordToCoordJobTable(CoordinatorJob.Status.RUNNING, false, false);
CoordinatorActionBean actionId1 = addRecordToCoordActionTable(job.getId(), actionNum, CoordinatorAction.Status.SUCCEEDED, "coord-action-get.xml", 0);
Date nominalTime = actionId1.getNominalTime();
long nominalTimeMilliseconds = nominalTime.getTime();
long noOfMillisecondsinOneHour = 3600000;
String date1 = DateUtils.formatDateOozieTZ(new Date(nominalTimeMilliseconds - (noOfMillisecondsinOneHour / 2)));
String date2 = DateUtils.formatDateOozieTZ(new Date(nominalTimeMilliseconds + noOfMillisecondsinOneHour));
// Test a bad date format.
try {
String badDate = "bad" + date1;
CoordActionsInDateRange.getCoordActionIdsFromDates(job.getId().toString(), badDate + "::" + date2);
fail("Accepted badly formatted date: " + badDate);
} catch (XException e) {
// Pass
assertEquals(ErrorCode.E0308, e.getErrorCode());
}
// Test a bad scope.
try {
String badScope = date1 + "0xbad5c09e" + date2;
CoordActionsInDateRange.getCoordActionIdsFromDates(job.getId().toString(), badScope);
fail("Accepted bad range scope: " + badScope);
} catch (XException e) {
// Pass
assertEquals(ErrorCode.E0308, e.getErrorCode());
}
// Test inverted start and end dates.
try {
CoordActionsInDateRange.getCoordActionIdsFromDates(job.getId().toString(), date2 + "::" + date1);
fail("Accepted inverted dates: [Start::End] = " + date2 + "::" + date1);
} catch (XException e) {
// Pass
assertEquals(ErrorCode.E0308, e.getErrorCode());
}
// Test a lenient date
try {
// Like date2 but with the 50th day of the month
String lenientDate = date2.replaceAll("[^-]*T", "50T");
CoordActionsInDateRange.getCoordActionIdsFromDates(job.getId().toString(), date1 + "::" + lenientDate);
fail("Accepted lenient date: " + lenientDate);
} catch (XException e) {
// Pass
assertEquals(ErrorCode.E0308, e.getErrorCode());
}
// Testing for the number of coordinator actions in a date range that spans from half an hour prior to the nominal
// time to 1 hour after the nominal time
int noOfActions = CoordActionsInDateRange.getCoordActionIdsFromDates(job.getId().toString(), date1 + "::" + date2).size();
assertEquals(1, noOfActions);
// Testing for the number of coordinator actions in a date range that spans from half an hour after the nominal
// time to 1 hour after the nominal time
date1 = DateUtils.formatDateOozieTZ(new Date(nominalTimeMilliseconds + (noOfMillisecondsinOneHour / 2)));
noOfActions = CoordActionsInDateRange.getCoordActionIdsFromDates(job.getId().toString(), date1 + "::" + date2).size();
assertEquals(0, noOfActions);
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
Aggregations