Search in sources :

Example 1 with IJob

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;
    }
}
Also used : IJob(org.jumpmind.symmetric.job.IJob) IJobManager(org.jumpmind.symmetric.job.IJobManager) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with IJob

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);
    }
}
Also used : IJob(org.jumpmind.symmetric.job.IJob) FileWriter(java.io.FileWriter) INodeService(org.jumpmind.symmetric.service.INodeService) IJobManager(org.jumpmind.symmetric.job.IJobManager) File(java.io.File) IClusterService(org.jumpmind.symmetric.service.IClusterService) IoException(org.jumpmind.exception.IoException) IOException(java.io.IOException) Lock(org.jumpmind.symmetric.model.Lock)

Aggregations

IJob (org.jumpmind.symmetric.job.IJob)2 IJobManager (org.jumpmind.symmetric.job.IJobManager)2 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 IoException (org.jumpmind.exception.IoException)1 Lock (org.jumpmind.symmetric.model.Lock)1 IClusterService (org.jumpmind.symmetric.service.IClusterService)1 INodeService (org.jumpmind.symmetric.service.INodeService)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1