use of org.apache.sling.event.impl.jobs.config.TopologyCapabilities 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'> </td></tr>", s.getNumberOfFinishedJobs());
pw.printf("<tr><td>Failed Jobs</td><td>%s</td><td colspan='2'> </td></tr>", s.getNumberOfFailedJobs());
pw.printf("<tr><td>Cancelled Jobs</td><td>%s</td><td colspan='2'> </td></tr>", s.getNumberOfCancelledJobs());
pw.printf("<tr><td>Processed Jobs</td><td>%s</td><td colspan='2'> </td></tr>", s.getNumberOfProcessedJobs());
pw.printf("<tr><td>Average Processing Time</td><td>%s</td><td colspan='2'> </td></tr>", formatTime(s.getAverageProcessingTime()));
pw.printf("<tr><td>Average Waiting Time</td><td>%s</td><td colspan='2'> </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);
}
}
use of org.apache.sling.event.impl.jobs.config.TopologyCapabilities 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("}");
}
use of org.apache.sling.event.impl.jobs.config.TopologyCapabilities in project sling by apache.
the class JobManagerImpl method addJobInternal.
/**
* Persist the job in the resource tree
* @param jobTopic The required job topic
* @param jobName The optional job name
* @param passedJobProperties The optional job properties
* @return The persisted job or <code>null</code>.
*/
private Job addJobInternal(final String jobTopic, final Map<String, Object> jobProperties, final List<String> errors) {
final QueueInfo info = this.configuration.getQueueConfigurationManager().getQueueInfo(jobTopic);
final TopologyCapabilities caps = this.configuration.getTopologyCapabilities();
info.targetId = (caps == null ? null : caps.detectTarget(jobTopic, jobProperties, info));
if (logger.isDebugEnabled()) {
if (info.targetId != null) {
logger.debug("Persisting job {} into queue {}, target={}", new Object[] { Utility.toString(jobTopic, jobProperties), info.queueName, info.targetId });
} else {
logger.debug("Persisting job {} into queue {}", Utility.toString(jobTopic, jobProperties), info.queueName);
}
}
final ResourceResolver resolver = this.configuration.createResourceResolver();
try {
final JobImpl job = this.writeJob(resolver, jobTopic, jobProperties, info);
if (info.targetId != null) {
this.configuration.getAuditLogger().debug("ASSIGN OK {} : {}", info.targetId, job.getId());
} else {
this.configuration.getAuditLogger().debug("UNASSIGN OK : {}", job.getId());
}
return job;
} catch (final PersistenceException re) {
// something went wrong, so let's log it
this.logger.error("Exception during persisting new job '" + Utility.toString(jobTopic, jobProperties) + "'", re);
} finally {
resolver.close();
}
if (errors != null) {
errors.add("Unable to persist new job.");
}
return null;
}
use of org.apache.sling.event.impl.jobs.config.TopologyCapabilities in project sling by apache.
the class CleanUpTask method run.
/**
* One maintenance run
*/
public void run() {
this.schedulerRuns++;
logger.debug("Job manager maintenance: Starting #{}", this.schedulerRuns);
final TopologyCapabilities topologyCapabilities = configuration.getTopologyCapabilities();
if (topologyCapabilities != null) {
// Clean up
final String cleanUpUnassignedPath;
;
if (topologyCapabilities.isLeader()) {
cleanUpUnassignedPath = this.configuration.getUnassignedJobsPath();
} else {
cleanUpUnassignedPath = null;
}
// job scheduler is handled every third run
if (schedulerRuns % 3 == 1) {
this.jobScheduler.maintenance();
}
if (schedulerRuns % 60 == 0) {
// full clean up is done every hour
this.fullEmptyFolderCleanup(topologyCapabilities, this.configuration.getLocalJobsPath());
if (cleanUpUnassignedPath != null) {
this.fullEmptyFolderCleanup(topologyCapabilities, cleanUpUnassignedPath);
}
} else if (schedulerRuns % 5 == 0) {
// simple clean up every 5 minutes
this.simpleEmptyFolderCleanup(topologyCapabilities, this.configuration.getLocalJobsPath());
if (cleanUpUnassignedPath != null) {
this.simpleEmptyFolderCleanup(topologyCapabilities, cleanUpUnassignedPath);
}
}
}
logger.debug("Job manager maintenance: Finished #{}", this.schedulerRuns);
}
use of org.apache.sling.event.impl.jobs.config.TopologyCapabilities in project sling by apache.
the class JobHandler method reassign.
/**
* Reassign to a new instance.
*/
public void reassign() {
final QueueInfo queueInfo = this.configuration.getQueueConfigurationManager().getQueueInfo(job.getTopic());
// Sanity check if queue configuration has changed
final TopologyCapabilities caps = this.configuration.getTopologyCapabilities();
final String targetId = (caps == null ? null : caps.detectTarget(job.getTopic(), job.getProperties(), queueInfo));
final ResourceResolver resolver = this.configuration.createResourceResolver();
try {
final Resource jobResource = resolver.getResource(job.getResourcePath());
if (jobResource != null) {
try {
final ValueMap vm = ResourceHelper.getValueMap(jobResource);
final String newPath = this.configuration.getUniquePath(targetId, job.getTopic(), job.getId(), job.getProperties());
final Map<String, Object> props = new HashMap<>(vm);
props.remove(Job.PROPERTY_JOB_QUEUE_NAME);
if (targetId == null) {
props.remove(Job.PROPERTY_JOB_TARGET_INSTANCE);
} else {
props.put(Job.PROPERTY_JOB_TARGET_INSTANCE, targetId);
}
props.remove(Job.PROPERTY_JOB_STARTED_TIME);
try {
ResourceHelper.getOrCreateResource(resolver, newPath, props);
resolver.delete(jobResource);
resolver.commit();
} catch (final PersistenceException pe) {
this.configuration.getMainLogger().warn("Unable to reassign job " + job.getId(), pe);
}
} catch (final InstantiationException ie) {
// something happened with the resource in the meantime
this.configuration.getMainLogger().debug("Unable to instantiate job", ie);
}
}
} finally {
resolver.close();
}
}
Aggregations