Search in sources :

Example 1 with ScheduledJobInfo

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);
    }
}
Also used : DateTimeValue(org.exist.xquery.value.DateTimeValue) XPathException(org.exist.xquery.XPathException) IOException(java.io.IOException) Subject(org.exist.security.Subject) Date(java.util.Date) SAXException(org.xml.sax.SAXException) ScheduledJobInfo(org.exist.scheduler.ScheduledJobInfo)

Example 2 with ScheduledJobInfo

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;
}
Also used : ScheduledJobInfo(org.exist.scheduler.ScheduledJobInfo) ArrayList(java.util.ArrayList)

Example 3 with ScheduledJobInfo

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();
    }
}
Also used : MemTreeBuilder(org.exist.dom.memtree.MemTreeBuilder) ScheduledJobInfo(org.exist.scheduler.ScheduledJobInfo) XPathException(org.exist.xquery.XPathException) QName(org.exist.dom.QName) BrokerPool(org.exist.storage.BrokerPool)

Aggregations

ScheduledJobInfo (org.exist.scheduler.ScheduledJobInfo)3 XPathException (org.exist.xquery.XPathException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 QName (org.exist.dom.QName)1 MemTreeBuilder (org.exist.dom.memtree.MemTreeBuilder)1 Subject (org.exist.security.Subject)1 BrokerPool (org.exist.storage.BrokerPool)1 DateTimeValue (org.exist.xquery.value.DateTimeValue)1 SAXException (org.xml.sax.SAXException)1