Search in sources :

Example 1 with InternalQueueConfiguration

use of org.apache.sling.event.impl.jobs.config.InternalQueueConfiguration in project sling by apache.

the class WebConsolePlugin method doGet.

@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse res) throws ServletException, IOException {
    final String msg = req.getParameter("message");
    final PrintWriter pw = res.getWriter();
    pw.println("<form method='POST' name='eventingcmd'>" + "<input type='hidden' name='action' value=''/>" + "<input type='hidden' name='queue' value=''/>" + "</form>");
    pw.println("<script type='text/javascript'>");
    pw.println("function eventingsubmit(action, queue) {" + " document.forms['eventingcmd'].action.value = action;" + " document.forms['eventingcmd'].queue.value = queue;" + " document.forms['eventingcmd'].submit();" + "} </script>");
    pw.printf("<p class='statline ui-state-highlight'>Apache Sling Job Handling%s%n</p>", msg != null ? " : " + ResponseUtil.escapeXml(msg) : "");
    pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>");
    pw.println("<span style='float: left; margin-left: 1em'>Apache Sling Job Handling: Overall Statistics</span>");
    this.printForm(pw, null, "Reset Stats", "reset");
    pw.println("</div>");
    pw.println("<table class='nicetable'><tbody>");
    String topics = this.jobConsumerManager.getTopics();
    if (topics == null) {
        topics = "";
    } else {
        final String[] allTopics = topics.split(",");
        final StringBuilder sb = new StringBuilder();
        boolean first = true;
        for (final String t : allTopics) {
            if (first) {
                first = false;
            } else {
                sb.append("<br/>");
            }
            sb.append(ResponseUtil.escapeXml(t));
        }
        topics = sb.toString();
    }
    Statistics s = this.jobManager.getStatistics();
    pw.printf("<tr><td>Start Time</td><td>%s</td></tr>", formatDate(s.getStartTime()));
    pw.printf("<tr><td>Local topic consumers: </td><td>%s</td></tr>", topics);
    pw.printf("<tr><td>Last Activated</td><td>%s</td></tr>", formatDate(s.getLastActivatedJobTime()));
    pw.printf("<tr><td>Last Finished</td><td>%s</td></tr>", formatDate(s.getLastFinishedJobTime()));
    pw.printf("<tr><td>Queued Jobs</td><td>%s</td></tr>", s.getNumberOfQueuedJobs());
    pw.printf("<tr><td>Active Jobs</td><td>%s</td></tr>", s.getNumberOfActiveJobs());
    pw.printf("<tr><td>Jobs</td><td>%s</td></tr>", s.getNumberOfJobs());
    pw.printf("<tr><td>Finished Jobs</td><td>%s</td></tr>", s.getNumberOfFinishedJobs());
    pw.printf("<tr><td>Failed Jobs</td><td>%s</td></tr>", s.getNumberOfFailedJobs());
    pw.printf("<tr><td>Cancelled Jobs</td><td>%s</td></tr>", s.getNumberOfCancelledJobs());
    pw.printf("<tr><td>Processed Jobs</td><td>%s</td></tr>", s.getNumberOfProcessedJobs());
    pw.printf("<tr><td>Average Processing Time</td><td>%s</td></tr>", formatTime(s.getAverageProcessingTime()));
    pw.printf("<tr><td>Average Waiting Time</td><td>%s</td></tr>", formatTime(s.getAverageWaitingTime()));
    pw.println("</tbody></table>");
    pw.println("<br/>");
    pw.println("<table class='nicetable'><tbody>");
    pw.println("<tr><th colspan='2'>Topology Capabilities</th></tr>");
    final TopologyCapabilities cap = this.configuration.getTopologyCapabilities();
    if (cap == null) {
        pw.print("<tr><td colspan='2'>No topology information available !</td></tr>");
    } else {
        final Map<String, List<InstanceDescription>> instanceCaps = cap.getInstanceCapabilities();
        for (final Map.Entry<String, List<InstanceDescription>> entry : instanceCaps.entrySet()) {
            final StringBuilder sb = new StringBuilder();
            for (final InstanceDescription id : entry.getValue()) {
                if (sb.length() > 0) {
                    sb.append("<br/>");
                }
                if (id.isLocal()) {
                    sb.append("<b>local</b>");
                } else {
                    sb.append(ResponseUtil.escapeXml(id.getSlingId()));
                }
            }
            pw.printf("<tr><td>%s</td><td>%s</td></tr>", ResponseUtil.escapeXml(entry.getKey()), sb.toString());
        }
    }
    pw.println("</tbody></table>");
    pw.println("<br/>");
    pw.println("<p class='statline'>Scheduled Jobs</p>");
    pw.println("<table class='nicetable'><tbody>");
    final Collection<ScheduledJobInfo> infos = this.jobManager.getScheduledJobs();
    if (infos.size() == 0) {
        pw.print("<tr><td colspan='5'>No jobs currently scheduled.</td></tr>");
    } else {
        pw.println("<tr><th>Schedule</th><th>Job Topic</th><th>Schedules</th></tr>");
        int index = 1;
        for (final ScheduledJobInfo info : infos) {
            pw.printf("<tr><td><b>%s</b></td><td>%s</td><td>", String.valueOf(index), ResponseUtil.escapeXml(info.getJobTopic()));
            boolean first = true;
            for (final ScheduleInfo si : info.getSchedules()) {
                if (!first) {
                    pw.print("<br/>");
                }
                first = false;
                switch(si.getType()) {
                    case YEARLY:
                        pw.printf("YEARLY %s %s : %s:%s", si.getMonthOfYear(), si.getDayOfMonth(), si.getHourOfDay(), si.getMinuteOfHour());
                        break;
                    case MONTHLY:
                        pw.printf("MONTHLY %s : %s:%s", si.getDayOfMonth(), si.getHourOfDay(), si.getMinuteOfHour());
                        break;
                    case WEEKLY:
                        pw.printf("WEEKLY %s : %s:%s", si.getDayOfWeek(), si.getHourOfDay(), si.getMinuteOfHour());
                        break;
                    case DAILY:
                        pw.printf("DAILY %s:%s", si.getHourOfDay(), si.getMinuteOfHour());
                        break;
                    case HOURLY:
                        pw.printf("HOURLY %s", si.getMinuteOfHour());
                        break;
                    case CRON:
                        pw.printf("CRON %s", ResponseUtil.escapeXml(si.getExpression()));
                        break;
                    default:
                        pw.printf("AT %s", si.getAt());
                }
            }
            pw.print("</td></tr>");
            index++;
        }
    }
    pw.println("</tbody></table>");
    pw.println("<br/>");
    boolean isEmpty = true;
    for (final Queue q : this.jobManager.getQueues()) {
        isEmpty = false;
        final String queueName = q.getName();
        pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>");
        pw.printf("<span style='float: left; margin-left: 1em'>Active JobQueue: %s %s</span>", ResponseUtil.escapeXml(queueName), q.isSuspended() ? "(SUSPENDED)" : "");
        this.printForm(pw, queueName, "Reset Stats", "reset");
        if (q.isSuspended()) {
            this.printForm(pw, queueName, "Resume", "resume");
        } else {
            this.printForm(pw, queueName, "Suspend", "suspend");
        }
        this.printForm(pw, queueName, "Test", "test");
        this.printForm(pw, queueName, "Drop All", "dropall");
        pw.println("</div>");
        pw.println("<table class='nicetable'><tbody>");
        s = q.getStatistics();
        final QueueConfiguration c = q.getConfiguration();
        pw.println("<tr><th colspan='2'>Statistics</th><th colspan='2'>Configuration</th></tr>");
        pw.printf("<tr><td>Start Time</td><td>%s</td><td>Type</td><td>%s</td></tr>", formatDate(s.getStartTime()), formatType(c.getType()));
        pw.printf("<tr><td>Last Activated</td><td>%s</td><td>Topics</td><td>%s</td></tr>", formatDate(s.getLastActivatedJobTime()), formatArray(c.getTopics()));
        pw.printf("<tr><td>Last Finished</td><td>%s</td><td>Max Parallel</td><td>%s</td></tr>", formatDate(s.getLastFinishedJobTime()), c.getMaxParallel());
        pw.printf("<tr><td>Queued Jobs</td><td>%s</td><td>Max Retries</td><td>%s</td></tr>", s.getNumberOfQueuedJobs(), c.getMaxRetries());
        pw.printf("<tr><td>Active Jobs</td><td>%s</td><td>Retry Delay</td><td>%s ms</td></tr>", s.getNumberOfActiveJobs(), c.getRetryDelayInMs());
        pw.printf("<tr><td>Jobs</td><td>%s</td><td>Priority</td><td>%s</td></tr>", s.getNumberOfJobs(), c.getThreadPriority());
        pw.printf("<tr><td>Finished Jobs</td><td>%s</td><td colspan='2'>&nbsp</td></tr>", s.getNumberOfFinishedJobs());
        pw.printf("<tr><td>Failed Jobs</td><td>%s</td><td colspan='2'>&nbsp</td></tr>", s.getNumberOfFailedJobs());
        pw.printf("<tr><td>Cancelled Jobs</td><td>%s</td><td colspan='2'>&nbsp</td></tr>", s.getNumberOfCancelledJobs());
        pw.printf("<tr><td>Processed Jobs</td><td>%s</td><td colspan='2'>&nbsp</td></tr>", s.getNumberOfProcessedJobs());
        pw.printf("<tr><td>Average Processing Time</td><td>%s</td><td colspan='2'>&nbsp</td></tr>", formatTime(s.getAverageProcessingTime()));
        pw.printf("<tr><td>Average Waiting Time</td><td>%s</td><td colspan='2'>&nbsp</td></tr>", formatTime(s.getAverageWaitingTime()));
        pw.printf("<tr><td>Status Info</td><td colspan='3'>%s</td></tr>", ResponseUtil.escapeXml(q.getStateInfo()));
        pw.println("</tbody></table>");
        pw.println("<br/>");
    }
    if (isEmpty) {
        pw.println("<p>No active queues.</p>");
        pw.println("<br/>");
    }
    for (final TopicStatistics ts : this.jobManager.getTopicStatistics()) {
        pw.println("<table class='nicetable'><tbody>");
        pw.printf("<tr><th colspan='2'>Topic Statistics: %s</th></tr>", ResponseUtil.escapeXml(ts.getTopic()));
        pw.printf("<tr><td>Last Activated</td><td>%s</td></tr>", formatDate(ts.getLastActivatedJobTime()));
        pw.printf("<tr><td>Last Finished</td><td>%s</td></tr>", formatDate(ts.getLastFinishedJobTime()));
        pw.printf("<tr><td>Finished Jobs</td><td>%s</td></tr>", ts.getNumberOfFinishedJobs());
        pw.printf("<tr><td>Failed Jobs</td><td>%s</td></tr>", ts.getNumberOfFailedJobs());
        pw.printf("<tr><td>Cancelled Jobs</td><td>%s</td></tr>", ts.getNumberOfCancelledJobs());
        pw.printf("<tr><td>Processed Jobs</td><td>%s</td></tr>", ts.getNumberOfProcessedJobs());
        pw.printf("<tr><td>Average Processing Time</td><td>%s</td></tr>", formatTime(ts.getAverageProcessingTime()));
        pw.printf("<tr><td>Average Waiting Time</td><td>%s</td></tr>", formatTime(ts.getAverageWaitingTime()));
        pw.println("</tbody></table>");
        pw.println("<br/>");
    }
    pw.println("<p class='statline'>Apache Sling Job Handling - Job Queue Configurations</p>");
    this.printQueueConfiguration(req, pw, this.configuration.getQueueConfigurationManager().getMainQueueConfiguration());
    final InternalQueueConfiguration[] configs = this.configuration.getQueueConfigurationManager().getConfigurations();
    for (final InternalQueueConfiguration c : configs) {
        this.printQueueConfiguration(req, pw, c);
    }
}
Also used : TopologyCapabilities(org.apache.sling.event.impl.jobs.config.TopologyCapabilities) TopicStatistics(org.apache.sling.event.jobs.TopicStatistics) Statistics(org.apache.sling.event.jobs.Statistics) TopicStatistics(org.apache.sling.event.jobs.TopicStatistics) ScheduleInfo(org.apache.sling.event.jobs.ScheduleInfo) InternalQueueConfiguration(org.apache.sling.event.impl.jobs.config.InternalQueueConfiguration) ScheduledJobInfo(org.apache.sling.event.jobs.ScheduledJobInfo) QueueConfiguration(org.apache.sling.event.jobs.QueueConfiguration) InternalQueueConfiguration(org.apache.sling.event.impl.jobs.config.InternalQueueConfiguration) List(java.util.List) InstanceDescription(org.apache.sling.discovery.InstanceDescription) Map(java.util.Map) Queue(org.apache.sling.event.jobs.Queue) PrintWriter(java.io.PrintWriter)

Example 2 with InternalQueueConfiguration

use of org.apache.sling.event.impl.jobs.config.InternalQueueConfiguration in project sling by apache.

the class InventoryPlugin method printJson.

private void printJson(final PrintWriter pw) {
    pw.println("{");
    Statistics s = this.jobManager.getStatistics();
    pw.println("  \"statistics\" : {");
    pw.printf("    \"startTime\" : %s,%n", s.getStartTime());
    pw.printf("    \"startTimeText\" : \"%s\",%n", formatDate(s.getStartTime()));
    pw.printf("    \"lastActivatedJobTime\" : %s,%n", s.getLastActivatedJobTime());
    pw.printf("    \"lastActivatedJobTimeText\" : \"%s\",%n", formatDate(s.getLastActivatedJobTime()));
    pw.printf("    \"lastFinishedJobTime\" : %s,%n", s.getLastFinishedJobTime());
    pw.printf("    \"lastFinishedJobTimeText\" : \"%s\",%n", formatDate(s.getLastFinishedJobTime()));
    pw.printf("    \"numberOfQueuedJobs\" : %s,%n", s.getNumberOfQueuedJobs());
    pw.printf("    \"numberOfActiveJobs\" : %s,%n", s.getNumberOfActiveJobs());
    pw.printf("    \"numberOfJobs\" : %s,%n", s.getNumberOfJobs());
    pw.printf("    \"numberOfFinishedJobs\" : %s,%n", s.getNumberOfFinishedJobs());
    pw.printf("    \"numberOfFailedJobs\" : %s,%n", s.getNumberOfFailedJobs());
    pw.printf("    \"numberOfCancelledJobs\" : %s,%n", s.getNumberOfCancelledJobs());
    pw.printf("    \"numberOfProcessedJobs\" : %s,%n", s.getNumberOfProcessedJobs());
    pw.printf("    \"averageProcessingTime\" : %s,%n", s.getAverageProcessingTime());
    pw.printf("    \"averageProcessingTimeText\" : \"%s\",%n", formatTime(s.getAverageProcessingTime()));
    pw.printf("    \"averageWaitingTime\" : %s,%n", s.getAverageWaitingTime());
    pw.printf("    \"averageWaitingTimeText\" : \"%s\"%n", formatTime(s.getAverageWaitingTime()));
    pw.print("  }");
    final TopologyCapabilities cap = this.configuration.getTopologyCapabilities();
    if (cap != null) {
        pw.println(",");
        pw.println("  \"capabilities\" : [");
        final Map<String, List<InstanceDescription>> instanceCaps = cap.getInstanceCapabilities();
        final Iterator<Map.Entry<String, List<InstanceDescription>>> iter = instanceCaps.entrySet().iterator();
        while (iter.hasNext()) {
            final Map.Entry<String, List<InstanceDescription>> entry = iter.next();
            final List<String> instances = new ArrayList<>();
            for (final InstanceDescription id : entry.getValue()) {
                if (id.isLocal()) {
                    instances.add("local");
                } else {
                    instances.add(id.getSlingId());
                }
            }
            pw.println("    {");
            pw.printf("       \"topic\" : \"%s\",%n", entry.getKey());
            pw.printf("       \"instances\" : %s%n", formatArrayAsJson(instances.toArray(new String[instances.size()])));
            if (iter.hasNext()) {
                pw.println("    },");
            } else {
                pw.println("    }");
            }
        }
        pw.print("  ]");
    }
    boolean first = true;
    for (final Queue q : this.jobManager.getQueues()) {
        pw.println(",");
        if (first) {
            pw.println("  \"queues\" : [");
            first = false;
        }
        pw.println("    {");
        pw.printf("      \"name\" : \"%s\",%n", q.getName());
        pw.printf("      \"suspended\" : %s,%n", q.isSuspended());
        s = q.getStatistics();
        pw.println("      \"statistics\" : {");
        pw.printf("        \"startTime\" : %s,%n", s.getStartTime());
        pw.printf("        \"startTimeText\" : \"%s\",%n", formatDate(s.getStartTime()));
        pw.printf("        \"lastActivatedJobTime\" : %s,%n", s.getLastActivatedJobTime());
        pw.printf("        \"lastActivatedJobTimeText\" : \"%s\",%n", formatDate(s.getLastActivatedJobTime()));
        pw.printf("        \"lastFinishedJobTime\" : %s,%n", s.getLastFinishedJobTime());
        pw.printf("        \"lastFinishedJobTimeText\" : \"%s\",%n", formatDate(s.getLastFinishedJobTime()));
        pw.printf("        \"numberOfQueuedJobs\" : %s,%n", s.getNumberOfQueuedJobs());
        pw.printf("        \"numberOfActiveJobs\" : %s,%n", s.getNumberOfActiveJobs());
        pw.printf("        \"numberOfJobs\" : %s,%n", s.getNumberOfJobs());
        pw.printf("        \"numberOfFinishedJobs\" : %s,%n", s.getNumberOfFinishedJobs());
        pw.printf("        \"numberOfFailedJobs\" : %s,%n", s.getNumberOfFailedJobs());
        pw.printf("        \"numberOfCancelledJobs\" : %s,%n", s.getNumberOfCancelledJobs());
        pw.printf("        \"numberOfProcessedJobs\" : %s,%n", s.getNumberOfProcessedJobs());
        pw.printf("        \"averageProcessingTime\" : %s,%n", s.getAverageProcessingTime());
        pw.printf("        \"averageProcessingTimeText\" : \"%s\",%n", formatTime(s.getAverageProcessingTime()));
        pw.printf("        \"averageWaitingTime\" : %s,%n", s.getAverageWaitingTime());
        pw.printf("        \"averageWaitingTimeText\" : \"%s\"%n", formatTime(s.getAverageWaitingTime()));
        pw.print("      },");
        final QueueConfiguration c = q.getConfiguration();
        pw.printf("      \"stateInfo\" : \"%s\",%n", q.getStateInfo());
        pw.println("      \"configuration\" : {");
        pw.printf("        \"type\" : \"%s\",%n", c.getType());
        pw.printf("        \"topics\" : \"%s\",%n", formatArrayAsJson(c.getTopics()));
        pw.printf("        \"maxParallel\" : %s,%n", c.getMaxParallel());
        pw.printf("        \"maxRetries\" : %s,%n", c.getMaxRetries());
        pw.printf("        \"retryDelayInMs\" : %s,%n", c.getRetryDelayInMs());
        pw.printf("        \"priority\" : \"%s\"%n", c.getThreadPriority());
        pw.println("      }");
        pw.print("    }");
    }
    if (!first) {
        pw.print("  ]");
    }
    first = true;
    for (final TopicStatistics ts : this.jobManager.getTopicStatistics()) {
        pw.println(",");
        if (first) {
            pw.println("  \"topicStatistics\" : [");
            first = false;
        }
        pw.println("    {");
        pw.printf("      \"topic\" : \"%s\",%n", ts.getTopic());
        pw.printf("      \"lastActivatedJobTime\" : %s,%n", ts.getLastActivatedJobTime());
        pw.printf("      \"lastActivatedJobTimeText\" : \"%s\",%n", formatDate(ts.getLastActivatedJobTime()));
        pw.printf("      \"lastFinishedJobTime\" : %s,%n", ts.getLastFinishedJobTime());
        pw.printf("      \"lastFinishedJobTimeText\" : \"%s\",%n", formatDate(ts.getLastFinishedJobTime()));
        pw.printf("      \"numberOfFinishedJobs\" : %s,%n", ts.getNumberOfFinishedJobs());
        pw.printf("      \"numberOfFailedJobs\" : %s,%n", ts.getNumberOfFailedJobs());
        pw.printf("      \"numberOfCancelledJobs\" : %s,%n", ts.getNumberOfCancelledJobs());
        pw.printf("      \"numberOfProcessedJobs\" : %s,%n", ts.getNumberOfProcessedJobs());
        pw.printf("      \"averageProcessingTime\" : %s,%n", ts.getAverageProcessingTime());
        pw.printf("      \"averageProcessingTimeText\" : \"%s\",%n", formatTime(ts.getAverageProcessingTime()));
        pw.printf("      \"averageWaitingTime\" : %s,%n", ts.getAverageWaitingTime());
        pw.printf("      \"averageWaitingTimeText\" : \"%s\"%n", formatTime(ts.getAverageWaitingTime()));
        pw.print("    }");
    }
    if (!first) {
        pw.print("  ]");
    }
    pw.println(",");
    pw.println("  \"configurations\" : [");
    this.printQueueConfigurationJson(pw, this.configuration.getQueueConfigurationManager().getMainQueueConfiguration());
    final InternalQueueConfiguration[] configs = this.configuration.getQueueConfigurationManager().getConfigurations();
    for (final InternalQueueConfiguration c : configs) {
        pw.println(",");
        this.printQueueConfigurationJson(pw, c);
    }
    pw.println();
    pw.println("  ]");
    pw.println("}");
}
Also used : ArrayList(java.util.ArrayList) TopologyCapabilities(org.apache.sling.event.impl.jobs.config.TopologyCapabilities) TopicStatistics(org.apache.sling.event.jobs.TopicStatistics) Statistics(org.apache.sling.event.jobs.Statistics) TopicStatistics(org.apache.sling.event.jobs.TopicStatistics) InternalQueueConfiguration(org.apache.sling.event.impl.jobs.config.InternalQueueConfiguration) QueueConfiguration(org.apache.sling.event.jobs.QueueConfiguration) InternalQueueConfiguration(org.apache.sling.event.impl.jobs.config.InternalQueueConfiguration) ArrayList(java.util.ArrayList) List(java.util.List) InstanceDescription(org.apache.sling.discovery.InstanceDescription) Map(java.util.Map) Queue(org.apache.sling.event.jobs.Queue)

Example 3 with InternalQueueConfiguration

use of org.apache.sling.event.impl.jobs.config.InternalQueueConfiguration in project sling by apache.

the class QueueManager method start.

/**
     * Start a new queue
     * This method first searches the corresponding queue - if such a queue
     * does not exist yet, it is created and started.
     *
     * @param queueInfo The queue info
     * @param topics The topics
     */
private void start(final QueueInfo queueInfo, final Set<String> topics) {
    final InternalQueueConfiguration config = queueInfo.queueConfiguration;
    // get or create queue
    boolean isNewQueue = false;
    JobQueueImpl queue = null;
    // we synchronize to avoid creating a queue which is about to be removed during cleanup
    synchronized (queuesLock) {
        queue = this.queues.get(queueInfo.queueName);
        // check for reconfiguration, we really do an identity check here(!)
        if (queue != null && queue.getConfiguration() != config) {
            this.outdateQueue(queue);
            // we use a new queue with the configuration
            queue = null;
        }
        if (queue == null) {
            queue = JobQueueImpl.createQueue(queueInfo.queueName, config, queueServices, topics);
            // on startup the queue might be empty and we get null back from createQueue
            if (queue != null) {
                isNewQueue = true;
                queues.put(queueInfo.queueName, queue);
                ((QueuesMBeanImpl) queuesMBean).sendEvent(new QueueStatusEvent(queue, null));
            }
        }
    }
    if (queue != null) {
        if (!isNewQueue) {
            queue.wakeUpQueue(topics);
        }
        queue.startJobs();
    }
}
Also used : QueueStatusEvent(org.apache.sling.event.impl.jobs.jmx.QueueStatusEvent) QueuesMBeanImpl(org.apache.sling.event.impl.jobs.jmx.QueuesMBeanImpl) InternalQueueConfiguration(org.apache.sling.event.impl.jobs.config.InternalQueueConfiguration)

Example 4 with InternalQueueConfiguration

use of org.apache.sling.event.impl.jobs.config.InternalQueueConfiguration in project sling by apache.

the class InventoryPlugin method printText.

private void printText(final PrintWriter pw) {
    pw.println("Apache Sling Job Handling");
    pw.println("-------------------------");
    String topics = this.jobConsumerManager.getTopics();
    if (topics == null) {
        topics = "";
    }
    Statistics s = this.jobManager.getStatistics();
    pw.println("Overall Statistics");
    pw.printf("Start Time : %s%n", formatDate(s.getStartTime()));
    pw.printf("Local topic consumers: %s%n", topics);
    pw.printf("Last Activated : %s%n", formatDate(s.getLastActivatedJobTime()));
    pw.printf("Last Finished : %s%n", formatDate(s.getLastFinishedJobTime()));
    pw.printf("Queued Jobs : %s%n", s.getNumberOfQueuedJobs());
    pw.printf("Active Jobs : %s%n", s.getNumberOfActiveJobs());
    pw.printf("Jobs : %s%n", s.getNumberOfJobs());
    pw.printf("Finished Jobs : %s%n", s.getNumberOfFinishedJobs());
    pw.printf("Failed Jobs : %s%n", s.getNumberOfFailedJobs());
    pw.printf("Cancelled Jobs : %s%n", s.getNumberOfCancelledJobs());
    pw.printf("Processed Jobs : %s%n", s.getNumberOfProcessedJobs());
    pw.printf("Average Processing Time : %s%n", formatTime(s.getAverageProcessingTime()));
    pw.printf("Average Waiting Time : %s%n", formatTime(s.getAverageWaitingTime()));
    pw.println();
    pw.println("Topology Capabilities");
    final TopologyCapabilities cap = this.configuration.getTopologyCapabilities();
    if (cap == null) {
        pw.print("No topology information available !");
    } else {
        final Map<String, List<InstanceDescription>> instanceCaps = cap.getInstanceCapabilities();
        for (final Map.Entry<String, List<InstanceDescription>> entry : instanceCaps.entrySet()) {
            final StringBuilder sb = new StringBuilder();
            for (final InstanceDescription id : entry.getValue()) {
                if (sb.length() > 0) {
                    sb.append(", ");
                }
                if (id.isLocal()) {
                    sb.append("local");
                } else {
                    sb.append(id.getSlingId());
                }
            }
            pw.printf("%s : %s%n", entry.getKey(), sb.toString());
        }
    }
    pw.println();
    pw.println("Scheduled Jobs");
    final Collection<ScheduledJobInfo> infos = this.jobManager.getScheduledJobs();
    if (infos.size() == 0) {
        pw.print("No jobs currently scheduled");
    } else {
        for (final ScheduledJobInfo info : infos) {
            pw.println("Schedule");
            pw.printf("Job Topic< : %s%n", info.getJobTopic());
            pw.print("Schedules : ");
            boolean first = true;
            for (final ScheduleInfo si : info.getSchedules()) {
                if (!first) {
                    pw.print(", ");
                }
                first = false;
                switch(si.getType()) {
                    case YEARLY:
                        pw.printf("YEARLY %s %s : %s:%s", si.getMonthOfYear(), si.getDayOfMonth(), si.getHourOfDay(), si.getMinuteOfHour());
                        break;
                    case MONTHLY:
                        pw.printf("MONTHLY %s : %s:%s", si.getDayOfMonth(), si.getHourOfDay(), si.getMinuteOfHour());
                        break;
                    case WEEKLY:
                        pw.printf("WEEKLY %s : %s:%s", si.getDayOfWeek(), si.getHourOfDay(), si.getMinuteOfHour());
                        break;
                    case DAILY:
                        pw.printf("DAILY %s:%s", si.getHourOfDay(), si.getMinuteOfHour());
                        break;
                    case HOURLY:
                        pw.printf("HOURLY %s", si.getMinuteOfHour());
                        break;
                    case CRON:
                        pw.printf("CRON %s", si.getExpression());
                        break;
                    default:
                        pw.printf("AT %s", si.getAt());
                }
            }
            pw.println();
            pw.println();
        }
    }
    pw.println();
    boolean isEmpty = true;
    for (final Queue q : this.jobManager.getQueues()) {
        isEmpty = false;
        pw.printf("Active JobQueue: %s %s%n", q.getName(), q.isSuspended() ? "(SUSPENDED)" : "");
        s = q.getStatistics();
        final QueueConfiguration c = q.getConfiguration();
        pw.println("Statistics");
        pw.printf("Start Time : %s%n", formatDate(s.getStartTime()));
        pw.printf("Last Activated : %s%n", formatDate(s.getLastActivatedJobTime()));
        pw.printf("Last Finished : %s%n", formatDate(s.getLastFinishedJobTime()));
        pw.printf("Queued Jobs : %s%n", s.getNumberOfQueuedJobs());
        pw.printf("Active Jobs : %s%n", s.getNumberOfActiveJobs());
        pw.printf("Jobs : %s%n", s.getNumberOfJobs());
        pw.printf("Finished Jobs : %s%n", s.getNumberOfFinishedJobs());
        pw.printf("Failed Jobs : %s%n", s.getNumberOfFailedJobs());
        pw.printf("Cancelled Jobs : %s%n", s.getNumberOfCancelledJobs());
        pw.printf("Processed Jobs : %s%n", s.getNumberOfProcessedJobs());
        pw.printf("Average Processing Time : %s%n", formatTime(s.getAverageProcessingTime()));
        pw.printf("Average Waiting Time : %s%n", formatTime(s.getAverageWaitingTime()));
        pw.printf("Status Info : %s%n", q.getStateInfo());
        pw.println("Configuration");
        pw.printf("Type : %s%n", formatType(c.getType()));
        pw.printf("Topics : %s%n", formatArrayAsText(c.getTopics()));
        pw.printf("Max Parallel : %s%n", c.getMaxParallel());
        pw.printf("Max Retries : %s%n", c.getMaxRetries());
        pw.printf("Retry Delay : %s ms%n", c.getRetryDelayInMs());
        pw.printf("Priority : %s%n", c.getThreadPriority());
        pw.println();
    }
    if (isEmpty) {
        pw.println("No active queues.");
        pw.println();
    }
    for (final TopicStatistics ts : this.jobManager.getTopicStatistics()) {
        pw.printf("Topic Statistics - %s%n", ts.getTopic());
        pw.printf("Last Activated : %s%n", formatDate(ts.getLastActivatedJobTime()));
        pw.printf("Last Finished : %s%n", formatDate(ts.getLastFinishedJobTime()));
        pw.printf("Finished Jobs : %s%n", ts.getNumberOfFinishedJobs());
        pw.printf("Failed Jobs : %s%n", ts.getNumberOfFailedJobs());
        pw.printf("Cancelled Jobs : %s%n", ts.getNumberOfCancelledJobs());
        pw.printf("Processed Jobs : %s%n", ts.getNumberOfProcessedJobs());
        pw.printf("Average Processing Time : %s%n", formatTime(ts.getAverageProcessingTime()));
        pw.printf("Average Waiting Time : %s%n", formatTime(ts.getAverageWaitingTime()));
        pw.println();
    }
    pw.println("Apache Sling Job Handling - Job Queue Configurations");
    pw.println("----------------------------------------------------");
    this.printQueueConfiguration(pw, this.configuration.getQueueConfigurationManager().getMainQueueConfiguration());
    final InternalQueueConfiguration[] configs = this.configuration.getQueueConfigurationManager().getConfigurations();
    for (final InternalQueueConfiguration c : configs) {
        this.printQueueConfiguration(pw, c);
    }
}
Also used : TopologyCapabilities(org.apache.sling.event.impl.jobs.config.TopologyCapabilities) TopicStatistics(org.apache.sling.event.jobs.TopicStatistics) Statistics(org.apache.sling.event.jobs.Statistics) TopicStatistics(org.apache.sling.event.jobs.TopicStatistics) ScheduleInfo(org.apache.sling.event.jobs.ScheduleInfo) InternalQueueConfiguration(org.apache.sling.event.impl.jobs.config.InternalQueueConfiguration) ScheduledJobInfo(org.apache.sling.event.jobs.ScheduledJobInfo) QueueConfiguration(org.apache.sling.event.jobs.QueueConfiguration) InternalQueueConfiguration(org.apache.sling.event.impl.jobs.config.InternalQueueConfiguration) ArrayList(java.util.ArrayList) List(java.util.List) InstanceDescription(org.apache.sling.discovery.InstanceDescription) Map(java.util.Map) Queue(org.apache.sling.event.jobs.Queue)

Aggregations

InternalQueueConfiguration (org.apache.sling.event.impl.jobs.config.InternalQueueConfiguration)4 List (java.util.List)3 Map (java.util.Map)3 InstanceDescription (org.apache.sling.discovery.InstanceDescription)3 TopologyCapabilities (org.apache.sling.event.impl.jobs.config.TopologyCapabilities)3 Queue (org.apache.sling.event.jobs.Queue)3 QueueConfiguration (org.apache.sling.event.jobs.QueueConfiguration)3 Statistics (org.apache.sling.event.jobs.Statistics)3 TopicStatistics (org.apache.sling.event.jobs.TopicStatistics)3 ArrayList (java.util.ArrayList)2 ScheduleInfo (org.apache.sling.event.jobs.ScheduleInfo)2 ScheduledJobInfo (org.apache.sling.event.jobs.ScheduledJobInfo)2 PrintWriter (java.io.PrintWriter)1 QueueStatusEvent (org.apache.sling.event.impl.jobs.jmx.QueueStatusEvent)1 QueuesMBeanImpl (org.apache.sling.event.impl.jobs.jmx.QueuesMBeanImpl)1