use of org.jumpmind.symmetric.job.IJobManager 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.IJobManager 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("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 (IOException e) {
log.warn("Failed to write jobs information", e);
} finally {
IOUtils.closeQuietly(writer);
}
}
use of org.jumpmind.symmetric.job.IJobManager in project symmetric-ds by JumpMind.
the class ConfigurationChangedDataRouter method contextCommitted.
@Override
public void contextCommitted(SimpleRouterContext routingContext) {
if (engine.getParameterService().is(ParameterConstants.AUTO_REFRESH_AFTER_CONFIG_CHANGED, true)) {
if (routingContext.get(CTX_KEY_FLUSH_PARAMETERS_NEEDED) != null && engine.getParameterService().is(ParameterConstants.AUTO_SYNC_CONFIGURATION)) {
log.info("About to refresh the cache of parameters because new configuration came through the data router");
engine.getParameterService().rereadParameters();
}
if (routingContext.get(CTX_KEY_FLUSH_CHANNELS_NEEDED) != null) {
log.info("Channels flushed because new channels came through the data router");
engine.getConfigurationService().clearCache();
}
Object needsSynced = routingContext.get(CTX_KEY_RESYNC_NEEDED);
if (needsSynced != null && engine.getParameterService().is(ParameterConstants.AUTO_SYNC_TRIGGERS) && engine.getParameterService().is(ParameterConstants.AUTO_SYNC_TRIGGERS_AFTER_CONFIG_CHANGED)) {
if (Boolean.TRUE.equals(needsSynced)) {
log.info("About to syncTriggers because new configuration came through the data router");
engine.getTriggerRouterService().syncTriggers();
} else if (needsSynced instanceof Set) {
@SuppressWarnings("unchecked") Set<Trigger> triggers = (Set<Trigger>) needsSynced;
for (Trigger trigger : triggers) {
log.info("About to sync the " + trigger.getTriggerId() + " trigger because a change was detected by the config data router");
engine.getTriggerRouterService().syncTrigger(trigger.getTriggerId(), null);
}
}
}
if (routingContext.get(CTX_KEY_FLUSH_TRANSFORMS_NEEDED) != null) {
log.info("About to refresh the cache of transformation because new configuration came through the data router");
engine.getTransformService().clearCache();
log.info("About to clear the staging area because new transform configuration came through the data router");
engine.getStagingManager().clean(0);
}
if (routingContext.get(CTX_KEY_FLUSH_CONFLICTS_NEEDED) != null) {
log.info("About to refresh the cache of conflict settings because new configuration came through the data router");
engine.getDataLoaderService().clearCache();
}
if (routingContext.get(CTX_KEY_FLUSH_LOADFILTERS_NEEDED) != null) {
log.info("About to refresh the cache of load filters because new configuration came through the data router");
engine.getLoadFilterService().clearCache();
}
insertReloadEvents(routingContext);
if (routingContext.get(CTX_KEY_RESTART_JOBMANAGER_NEEDED) != null) {
IJobManager jobManager = engine.getJobManager();
if (jobManager != null) {
log.info("About to restart jobs because new configuration come through the data router");
jobManager.stopJobs();
jobManager.startJobs();
}
}
if (routingContext.get(CTX_KEY_REFRESH_EXTENSIONS_NEEDED) != null) {
log.info("About to refresh the cache of extensions because new configuration came through the data router");
engine.getExtensionService().refresh();
}
}
}
use of org.jumpmind.symmetric.job.IJobManager in project symmetric-ds by JumpMind.
the class ConfigurationChangedDatabaseWriterFilter method syncEnded.
public void syncEnded(DataContext context, List<IncomingBatch> batchesProcessed, Throwable ex) {
IParameterService parameterService = engine.getParameterService();
if (context.get(CTX_KEY_RESTART_JOBMANAGER_NEEDED) != null) {
IJobManager jobManager = engine.getJobManager();
if (jobManager != null) {
log.info("About to restart jobs because a new schedule came through the data loader");
jobManager.stopJobs();
jobManager.startJobs();
}
context.remove(CTX_KEY_RESTART_JOBMANAGER_NEEDED);
}
/**
* No need to sync triggers until the entire sync process has finished just in case there
* are multiple batches that contain configuration changes
*/
if (context.get(CTX_KEY_RESYNC_NEEDED) != null && parameterService.is(ParameterConstants.AUTO_SYNC_TRIGGERS)) {
log.info("About to syncTriggers because new configuration came through the data loader");
engine.getTriggerRouterService().syncTriggers();
context.remove(CTX_KEY_RESYNC_NEEDED);
}
}
Aggregations