use of org.jumpmind.symmetric.job.IJob in project symmetric-ds by JumpMind.
the class RestService method invokeJob.
/**
* Execute the named job. This can be used to control when jobs are run via and external application. You would typically
* disable the job first so it no longer runs automatically.
*/
@ApiOperation(value = "Execute the named job. This can be used to control when jobs are run via and external application. " + "You would typically disable the job first so it no longer runs automatically. Jobs you might want to control include: " + "job.route, job.push, job.pull, job.offline.push, job.offline.pull")
@RequestMapping(value = "engine/{engine}/invokejob", method = { RequestMethod.GET, RequestMethod.POST })
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public boolean invokeJob(@PathVariable("engine") String engineName, @RequestParam("jobname") String jobName) {
IJobManager jobManager = getSymmetricEngine(engineName).getJobManager();
IJob job = jobManager.getJob(jobName);
if (job == null) {
log.warn("Could not find a job with the name '{}' in the '{}' engine", jobName, engineName);
return false;
} else if (!job.isRunning()) {
log.info("Invoking '{}' via the REST API", jobName);
return job.invoke(true);
} else {
log.info("Could not invoke the '{}' job via the REST API because it is already running", jobName);
return false;
}
}
use of org.jumpmind.symmetric.job.IJob in project symmetric-ds by JumpMind.
the class SnapshotUtil method writeJobsStats.
protected static void writeJobsStats(ISymmetricEngine engine, File tmpDir) {
FileWriter writer = null;
try {
writer = new FileWriter(new File(tmpDir, "jobs.txt"));
IJobManager jobManager = engine.getJobManager();
IClusterService clusterService = engine.getClusterService();
INodeService nodeService = engine.getNodeService();
writer.write("Clustering is " + (clusterService.isClusteringEnabled() ? "" : "not ") + "enabled and there are " + nodeService.findNodeHosts(nodeService.findIdentityNodeId()).size() + " instances in the cluster\n\n");
writer.write(StringUtils.rightPad("Job Name", 30) + StringUtils.rightPad("Schedule", 20) + StringUtils.rightPad("Status", 10) + StringUtils.rightPad("Server Id", 30) + StringUtils.rightPad("Last Server Id", 30) + StringUtils.rightPad("Last Finish Time", 30) + StringUtils.rightPad("Last Run Period", 20) + StringUtils.rightPad("Avg. Run Period", 20) + "\n");
List<IJob> jobs = jobManager.getJobs();
Map<String, Lock> locks = clusterService.findLocks();
for (IJob job : jobs) {
Lock lock = locks.get(job.getClusterLockName());
String status = getJobStatus(job, lock);
String runningServerId = lock != null ? lock.getLockingServerId() : "";
String lastServerId = clusterService.getServerId();
if (lock != null) {
lastServerId = lock.getLastLockingServerId();
}
String schedule = StringUtils.isBlank(job.getCronExpression()) ? Long.toString(job.getTimeBetweenRunsInMs()) : job.getCronExpression();
String lastFinishTime = getLastFinishTime(job, lock);
writer.write(StringUtils.rightPad(job.getClusterLockName().replace("_", " "), 30) + StringUtils.rightPad(schedule, 20) + StringUtils.rightPad(status, 10) + StringUtils.rightPad(runningServerId == null ? "" : runningServerId, 30) + StringUtils.rightPad(lastServerId == null ? "" : lastServerId, 30) + StringUtils.rightPad(lastFinishTime == null ? "" : lastFinishTime, 30) + StringUtils.rightPad(job.getLastExecutionTimeInMs() + "", 20) + StringUtils.rightPad(job.getAverageExecutionTimeInMs() + "", 20) + "\n");
}
} catch (Exception e) {
log.warn("Failed to write jobs information", e);
} finally {
IOUtils.closeQuietly(writer);
}
}
Aggregations