use of org.apache.oozie.command.PurgeXCommand in project oozie by apache.
the class BaseAdminServlet method schedulePurgeCommand.
private String schedulePurgeCommand(HttpServletRequest request) throws XServletException {
final String purgeCmdDisabledMsg = "Purge service is not enabled";
if (!ConfigurationService.getBoolean(PurgeService.PURGE_COMMAND_ENABLED)) {
LOG.warn(purgeCmdDisabledMsg);
throw new XServletException(HttpServletResponse.SC_BAD_REQUEST, ErrorCode.E0307, purgeCmdDisabledMsg);
}
String wfAgeStr = request.getParameter(RestConstants.PURGE_WF_AGE);
String coordAgeStr = request.getParameter(RestConstants.PURGE_COORD_AGE);
String bundleAgeStr = request.getParameter(RestConstants.PURGE_BUNDLE_AGE);
String purgeLimitStr = request.getParameter(RestConstants.PURGE_LIMIT);
String oldCoordActionStr = request.getParameter(RestConstants.PURGE_OLD_COORD_ACTION);
int workflowAge = StringUtils.isBlank(wfAgeStr) ? ConfigurationService.getInt(PurgeService.CONF_OLDER_THAN) : ValidationUtil.parsePositiveInteger(wfAgeStr);
int coordAge = StringUtils.isBlank(coordAgeStr) ? ConfigurationService.getInt(PurgeService.COORD_CONF_OLDER_THAN) : ValidationUtil.parsePositiveInteger(coordAgeStr);
int bundleAge = StringUtils.isBlank(bundleAgeStr) ? ConfigurationService.getInt(PurgeService.BUNDLE_CONF_OLDER_THAN) : ValidationUtil.parsePositiveInteger(bundleAgeStr);
int purgeLimit = StringUtils.isBlank(purgeLimitStr) ? ConfigurationService.getInt(PurgeService.PURGE_LIMIT) : ValidationUtil.parsePositiveInteger(purgeLimitStr);
boolean purgeOldCoordAction = StringUtils.isBlank(oldCoordActionStr) ? ConfigurationService.getBoolean(PurgeService.PURGE_OLD_COORD_ACTION) : Boolean.parseBoolean(oldCoordActionStr);
LOG.info("Executing oozie purge command.");
PurgeXCommand purgeXCommand = new PurgeXCommand(workflowAge, coordAge, bundleAge, purgeLimit, purgeOldCoordAction);
try {
purgeXCommand.call();
return "Purge command executed successfully";
} catch (CommandException e) {
throw new XServletException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getErrorCode(), e.getMessage(), e.getCause());
}
}
use of org.apache.oozie.command.PurgeXCommand in project oozie by apache.
the class TestPurgeService method testPurgeServiceForWorkflow.
/**
* Tests the {@link org.apache.oozie.service.PurgeService}.
* </p>
* Creates and runs a new workflow job to completion.
* Attempts to purge jobs older than a day. Verifies the presence of the job in the system.
* </p>
* Sets the end date for the same job to make it qualify for the purge criteria.
* Calls the purge service, and ensure the job does not exist in the system.
*/
public void testPurgeServiceForWorkflow() throws Exception {
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, getTestCaseFileUri("workflow.xml"));
conf.setStrings(OozieClient.USER_NAME, getTestUser());
conf.setStrings(OozieClient.GROUP_NAME, getTestGroup());
conf.set(OozieClient.LOG_TOKEN, "t");
conf.set("external-status", "ok");
conf.set("signal-value", "based_on_action_status");
final String jobId = engine.submitJob(conf, true);
waitFor(5000, new Predicate() {
public boolean evaluate() throws Exception {
return (engine.getJob(jobId).getStatus() == WorkflowJob.Status.SUCCEEDED);
}
});
assertEquals(WorkflowJob.Status.SUCCEEDED, engine.getJob(jobId).getStatus());
new PurgeXCommand(1, 1, 1, 10000).call();
sleep(1000);
JPAService jpaService = Services.get().get(JPAService.class);
WorkflowJobGetJPAExecutor wfJobGetCmd = new WorkflowJobGetJPAExecutor(jobId);
WorkflowJobBean wfBean = jpaService.execute(wfJobGetCmd);
Date endDate = new Date(System.currentTimeMillis() - 2 * 24 * 60 * 60 * 1000);
wfBean.setEndTime(endDate);
wfBean.setLastModifiedTime(new Date());
WorkflowJobQueryExecutor.getInstance().executeUpdate(WorkflowJobQuery.UPDATE_WORKFLOW_STATUS_INSTANCE_MOD_END, wfBean);
Runnable purgeRunnable = new PurgeRunnable(1, 1, 1, 100);
purgeRunnable.run();
waitFor(10000, new Predicate() {
public boolean evaluate() throws Exception {
try {
engine.getJob(jobId).getStatus();
} catch (Exception ex) {
return true;
}
return false;
}
});
try {
engine.getJob(jobId).getStatus();
fail("Job should be purged. Should fail.");
} catch (Exception ex) {
assertEquals(ex.getClass(), DagEngineException.class);
DagEngineException dex = (DagEngineException) ex;
assertEquals(ErrorCode.E0604, dex.getErrorCode());
}
}
Aggregations