Search in sources :

Example 6 with TopologyCapabilities

use of org.apache.sling.event.impl.jobs.config.TopologyCapabilities 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

TopologyCapabilities (org.apache.sling.event.impl.jobs.config.TopologyCapabilities)6 List (java.util.List)3 Map (java.util.Map)3 InstanceDescription (org.apache.sling.discovery.InstanceDescription)3 InternalQueueConfiguration (org.apache.sling.event.impl.jobs.config.InternalQueueConfiguration)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 PersistenceException (org.apache.sling.api.resource.PersistenceException)2 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)2 QueueInfo (org.apache.sling.event.impl.jobs.config.QueueConfigurationManager.QueueInfo)2 ScheduleInfo (org.apache.sling.event.jobs.ScheduleInfo)2 ScheduledJobInfo (org.apache.sling.event.jobs.ScheduledJobInfo)2 PrintWriter (java.io.PrintWriter)1 HashMap (java.util.HashMap)1 ModifiableValueMap (org.apache.sling.api.resource.ModifiableValueMap)1 Resource (org.apache.sling.api.resource.Resource)1 ValueMap (org.apache.sling.api.resource.ValueMap)1