use of org.exist.scheduler.ScheduledJobInfo in project exist by eXist-db.
the class GetScheduledJobs method eval.
/**
* evaluate the call to the xquery function, it is really the main entry point of this class.
*
* @param args arguments from the function call
* @param contextSequence the Context Sequence to operate on (not used here internally!)
*
* @return A sequence representing the result of the function call
*
* @throws XPathException DOCUMENT ME!
*
* @see org.exist.xquery.BasicFunction#eval(org.exist.xquery.value.Sequence[], org.exist.xquery.value.Sequence)
*/
@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
Subject user = context.getSubject();
boolean userhasDBARole = user.hasDbaRole();
StringBuilder xmlBuf = new StringBuilder();
int iJobs = 0;
List<String> groups = scheduler.getJobGroupNames();
List<ScheduledJobInfo> scheduledJobs = scheduler.getScheduledJobs();
for (String group : groups) {
if (userhasDBARole || group.equals(UserJob.JOB_GROUP)) {
xmlBuf.append("<" + SchedulerModule.PREFIX + ":group name=\"").append(group).append("\">");
for (ScheduledJobInfo scheduledJob : scheduledJobs) {
if (scheduledJob.getGroup().equals(group)) {
xmlBuf.append("<" + SchedulerModule.PREFIX + ":job name=\"").append(scheduledJob.getName()).append("\">");
xmlBuf.append("<" + SchedulerModule.PREFIX + ":trigger name=\"").append(scheduledJob.getTriggerName()).append("\">");
xmlBuf.append("<expression>");
xmlBuf.append(scheduledJob.getTriggerExpression());
xmlBuf.append("</expression>");
xmlBuf.append("<state>");
xmlBuf.append(scheduledJob.getTriggerState());
xmlBuf.append("</state>");
xmlBuf.append("<start>");
xmlBuf.append(new DateTimeValue(scheduledJob.getStartTime()));
xmlBuf.append("</start>");
xmlBuf.append("<end>");
Date endTime = scheduledJob.getEndTime();
if (endTime != null) {
xmlBuf.append(new DateTimeValue(endTime));
}
xmlBuf.append("</end>");
xmlBuf.append("<previous>");
Date previousTime = scheduledJob.getPreviousFireTime();
if (previousTime != null) {
xmlBuf.append(new DateTimeValue(scheduledJob.getPreviousFireTime()));
}
xmlBuf.append("</previous>");
xmlBuf.append("<next>");
Date nextTime = scheduledJob.getNextFireTime();
if (nextTime != null) {
xmlBuf.append(new DateTimeValue());
}
xmlBuf.append("</next>");
xmlBuf.append("<final>");
Date finalTime = scheduledJob.getFinalFireTime();
if ((endTime != null) && (finalTime != null)) {
xmlBuf.append(new DateTimeValue());
}
xmlBuf.append("</final>");
xmlBuf.append("</" + SchedulerModule.PREFIX + ":trigger>");
xmlBuf.append("</" + SchedulerModule.PREFIX + ":job>");
iJobs++;
}
}
xmlBuf.append("</" + SchedulerModule.PREFIX + ":group>");
}
}
xmlBuf.insert(0, "<" + SchedulerModule.PREFIX + ":jobs xmlns:scheduler=\"" + SchedulerModule.NAMESPACE_URI + "\" count=\"" + iJobs + "\">");
xmlBuf.append("</" + SchedulerModule.PREFIX + ":jobs>");
try {
return ModuleUtils.stringToXML(context, xmlBuf.toString());
} catch (SAXException | IOException se) {
throw new XPathException(this, se.getMessage(), se);
}
}
use of org.exist.scheduler.ScheduledJobInfo in project exist by eXist-db.
the class ProcessReport method getScheduledJobs.
@Override
public List<Job> getScheduledJobs() {
final List<Job> jobList = new ArrayList<>();
final List<ScheduledJobInfo> jobs = scheduler.getScheduledJobs();
for (final ScheduledJobInfo job : jobs) {
jobList.add(new Job(job.getName(), job.getGroup(), job.getTriggerExpression()));
}
return jobList;
}
use of org.exist.scheduler.ScheduledJobInfo in project exist by eXist-db.
the class GetScheduledJobs method eval.
@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
if (!context.getSubject().hasDbaRole()) {
final XPathException xPathException = new XPathException(this, "Permission denied, calling user '" + context.getSubject().getName() + "' must be a DBA to get the list of scheduled jobs");
logger.error("Invalid user " + SystemModule.PREFIX + ":get-scheduled-jobs", xPathException);
throw xPathException;
}
context.pushDocumentContext();
try {
final MemTreeBuilder builder = context.getDocumentBuilder();
builder.startDocument();
builder.startElement(new QName("jobs", NAMESPACE_URI, PREFIX), null);
final BrokerPool brokerPool = context.getBroker().getBrokerPool();
logger.trace("brokerPool = {}", brokerPool.toString());
if (brokerPool != null) {
final org.exist.scheduler.Scheduler existScheduler = brokerPool.getScheduler();
if (existScheduler != null) {
final List<ScheduledJobInfo> scheduledJobsInfo = existScheduler.getScheduledJobs();
final ScheduledJobInfo[] executingJobsInfo = existScheduler.getExecutingJobs();
if (scheduledJobsInfo != null) {
for (final ScheduledJobInfo scheduledJobInfo : scheduledJobsInfo) {
addRow(scheduledJobInfo, builder, false);
}
}
if (executingJobsInfo != null) {
for (ScheduledJobInfo jobInfo : executingJobsInfo) {
addRow(jobInfo, builder, true);
}
}
}
}
builder.endElement();
builder.endDocument();
return ((NodeValue) builder.getDocument().getDocumentElement());
} finally {
context.popDocumentContext();
}
}
Aggregations