You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by dk...@apache.org on 2019/01/10 19:04:20 UTC
[sling-org-apache-sling-app-cms] branch
feature/file-metadata-loaded updated: Adding a custom queue for the sling
job
This is an automated email from the ASF dual-hosted git repository.
dklco pushed a commit to branch feature/file-metadata-loaded
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-app-cms.git
The following commit(s) were added to refs/heads/feature/file-metadata-loaded by this push:
new 032b45a Adding a custom queue for the sling job
032b45a is described below
commit 032b45a1055c6b14cb9c225dd5aef9720264de97
Author: Dan Klco <dk...@apache.org>
AuthorDate: Thu Jan 10 14:04:10 2019 -0500
Adding a custom queue for the sling job
---
.../java/org/apache/sling/cms/CMSJobManager.java | 7 ++
.../internal/jobs/FileMetadataExtractorJob.java | 23 +++++--
.../core/internal/models/CMSJobManagerImpl.java | 34 +++++++++-
.../jobs/configuration/configuration.jsp | 2 +-
.../jobs/{jobtable/jobtable.jsp => list/list.jsp} | 16 +++--
.../libs/sling-cms/components/jobs/view/view.jsp | 79 ++++++++++++++++++++++
.../content/jobs/filemetadataextractor.json | 2 +-
.../jcr_root/libs/sling-cms/content/jobs/list.json | 2 +-
.../libs/sling-cms/content/jobs/start.json | 2 +-
.../jcr_root/libs/sling-cms/content/jobs/view.json | 8 ++-
.../resources/jcr_root/libs/sling-cms/i18n.json | 45 ++++++++++++
...g.event.jobs.QueueConfiguration-cmsqueue.config | 29 ++++++++
12 files changed, 228 insertions(+), 21 deletions(-)
diff --git a/api/src/main/java/org/apache/sling/cms/CMSJobManager.java b/api/src/main/java/org/apache/sling/cms/CMSJobManager.java
index faadb16..1c6ac49 100644
--- a/api/src/main/java/org/apache/sling/cms/CMSJobManager.java
+++ b/api/src/main/java/org/apache/sling/cms/CMSJobManager.java
@@ -41,6 +41,13 @@ public interface CMSJobManager {
Collection<Job> getJobs();
/**
+ * Gets the job by id as passed in the Sling suffix.
+ *
+ * @return the job
+ */
+ Job getSuffixJob();
+
+ /**
* Starts a new job based on the request.
*
* @return the job
diff --git a/core/src/main/java/org/apache/sling/cms/core/internal/jobs/FileMetadataExtractorJob.java b/core/src/main/java/org/apache/sling/cms/core/internal/jobs/FileMetadataExtractorJob.java
index 6d1d99b..dcd61ec 100644
--- a/core/src/main/java/org/apache/sling/cms/core/internal/jobs/FileMetadataExtractorJob.java
+++ b/core/src/main/java/org/apache/sling/cms/core/internal/jobs/FileMetadataExtractorJob.java
@@ -17,7 +17,9 @@
package org.apache.sling.cms.core.internal.jobs;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.apache.sling.api.SlingConstants;
import org.apache.sling.api.resource.LoginException;
@@ -48,7 +50,7 @@ public class FileMetadataExtractorJob implements ConfigurableJobExecutor {
public static final Logger log = LoggerFactory.getLogger(FileMetadataExtractorJob.class);
- public static final String TOPIC = "org/apache/sling/cms/file/ExtractMetadata";
+ public static final String TOPIC = "cmsjob/org/apache/sling/cms/file/ExtractMetadata";
public static final String PN_RECURSIVE = "recursive";
@@ -85,7 +87,9 @@ public class FileMetadataExtractorJob implements ConfigurableJobExecutor {
ResourceResolver resolver = null;
try {
- resolver = factory.getServiceResourceResolver(null);
+ Map<String, Object> serviceParams = new HashMap<>();
+ serviceParams.put(ResourceResolverFactory.SUBSERVICE, "sling-cms-metadata");
+ resolver = factory.getServiceResourceResolver(serviceParams);
Resource root = resolver.getResource(path);
if (root != null) {
@@ -95,15 +99,22 @@ public class FileMetadataExtractorJob implements ConfigurableJobExecutor {
} else {
collectFiles(root, files);
}
- context.log("Found {} files to extract metadata", files.size());
+ context.log("Found {0} files to extract metadata", files.size());
context.initProgress(files.size(), -1);
int processed = 1;
for (File file : files) {
- extractor.extractMetadata(file);
- context.incrementProgressCount(processed++);
- context.log("Extracted metadata for {}", file.getPath());
+ try {
+ extractor.extractMetadata(file);
+ context.incrementProgressCount(processed++);
+ context.log("Extracted metadata for {0}", file.getPath());
+ } catch (Throwable t) {
+ context.log("Failed to extract matadata for {0}", file.getPath());
+ context.incrementProgressCount(processed++);
+ context.log("Exception {0}", t.getMessage());
+ log.warn("Failed to extract metadata for " + file.getPath(), t);
+ }
}
return context.result().message("Metadata Extracted").succeeded();
diff --git a/core/src/main/java/org/apache/sling/cms/core/internal/models/CMSJobManagerImpl.java b/core/src/main/java/org/apache/sling/cms/core/internal/models/CMSJobManagerImpl.java
index fc5a8c7..b707e65 100644
--- a/core/src/main/java/org/apache/sling/cms/core/internal/models/CMSJobManagerImpl.java
+++ b/core/src/main/java/org/apache/sling/cms/core/internal/models/CMSJobManagerImpl.java
@@ -21,6 +21,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
+import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -48,8 +49,9 @@ public class CMSJobManagerImpl implements CMSJobManager {
private static final Logger log = LoggerFactory.getLogger(CMSJobManagerImpl.class);
- private static final String PN_INITIATOR = "initiator";
- private static final String PN_USER_ID = "userId";
+ private static final String PN_INITIATOR = "_initiator";
+ private static final String PN_JOB_TITLE_KEY = "_titleKey";
+ private static final String PN_USER_ID = "_userId";
private static final String VALUE_SLING_CMS = "SlingCMS";
@OSGiService
@@ -83,6 +85,26 @@ public class CMSJobManagerImpl implements CMSJobManager {
jobManager.findJobs(QueryType.HISTORY, null, 0, search).stream()).collect(Collectors.toList());
}
+ private String getJobTitleKey(String jobTopic) {
+ BundleContext bundleContext = FrameworkUtil.getBundle(CMSJobManager.class).getBundleContext();
+ try {
+ Optional<String> op = bundleContext
+ .getServiceReferences(ConfigurableJobExecutor.class,
+ "(" + JobConsumer.PROPERTY_TOPICS + "=" + jobTopic + ")")
+ .stream().map(bundleContext::getService).map(ConfigurableJobExecutor::getTitleKey).findFirst();
+ return op.orElse(null);
+ } catch (InvalidSyntaxException e) {
+ log.warn("Failed to get available jobs", e);
+ }
+ return null;
+ }
+
+ @Override
+ public Job getSuffixJob() {
+ return jobManager
+ .getJobById(Optional.ofNullable(request.getRequestPathInfo().getSuffix()).orElse(" ").substring(1));
+ }
+
@Override
public Job startJob() {
Map<String, Object> properties = new HashMap<>();
@@ -98,10 +120,16 @@ public class CMSJobManagerImpl implements CMSJobManager {
}
});
properties.remove(JobConsumer.PROPERTY_TOPICS);
+
+ String jobTopic = request.getParameter(JobConsumer.PROPERTY_TOPICS);
+ String titleKey = getJobTitleKey(jobTopic);
+ if (titleKey != null) {
+ properties.put(PN_JOB_TITLE_KEY, titleKey);
+ }
properties.put(PN_USER_ID, request.getResourceResolver().getUserID());
properties.put(PN_INITIATOR, VALUE_SLING_CMS);
- return jobManager.addJob(request.getParameter(JobConsumer.PROPERTY_TOPICS), properties);
+ return jobManager.addJob(jobTopic, properties);
}
}
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/components/jobs/configuration/configuration.jsp b/ui/src/main/resources/jcr_root/libs/sling-cms/components/jobs/configuration/configuration.jsp
index 9a368d8..56c4c4e 100644
--- a/ui/src/main/resources/jcr_root/libs/sling-cms/components/jobs/configuration/configuration.jsp
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/components/jobs/configuration/configuration.jsp
@@ -17,5 +17,5 @@
* under the License.
*/ --%>
<%@include file="/libs/sling-cms/global.jsp"%>
-<div class="page-properties-container field" data-path="${resource.path}.include.html" data-source="select[name=job]">
+<div class="page-properties-container field" data-path="${resource.path}.include.html" data-source="select[name=_job]">
</div>
\ No newline at end of file
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/components/jobs/jobtable/jobtable.jsp b/ui/src/main/resources/jcr_root/libs/sling-cms/components/jobs/list/list.jsp
similarity index 82%
rename from ui/src/main/resources/jcr_root/libs/sling-cms/components/jobs/jobtable/jobtable.jsp
rename to ui/src/main/resources/jcr_root/libs/sling-cms/components/jobs/list/list.jsp
index 92b6281..a83d646 100644
--- a/ui/src/main/resources/jcr_root/libs/sling-cms/components/jobs/jobtable/jobtable.jsp
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/components/jobs/list/list.jsp
@@ -25,16 +25,16 @@
#
</th>
<th>
- Job Name
+ <fmt:message key="slingcms.jobs.name" />
</th>
<th>
- Started
+ <fmt:message key="slingcms.started" />
</th>
<th>
- Finished
+ <fmt:message key="slingcms.finished" />
</th>
<th>
- State
+ <fmt:message key="slingcms.state" />
</th>
</tr>
</thead>
@@ -42,12 +42,16 @@
<sling:adaptTo var="jobManager" adaptable="${slingRequest}" adaptTo="org.apache.sling.cms.CMSJobManager" />
<c:set var="count" value="1" />
<c:forEach var="job" items="${jobManager.jobs}">
+
<tr class="sortable__row">
<td class="Cell-Static" title="# ${status.index + 1}" data-sort-value="<fmt:formatNumber pattern="0000" value="${count}" />">
${count}
</td>
<td>
- ${job.topic}
+ <a href="/cms/jobs/view.html/${job.id}">
+ <fmt:message key="${job.properties._titleKey}" />
+ </a><br/>
+ <small>${job.topic}</small>
</td>
<td>
<fmt:formatDate value="${job.created.time}" type="both" dateStyle="long" timeStyle="long" />
@@ -62,7 +66,7 @@
</td>
</tr>
<c:set var="count" value="${count + 1}" />
- </c:forEach>
+ </c:forEach>
</tbody>
</table>
</div>
\ No newline at end of file
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/components/jobs/view/view.jsp b/ui/src/main/resources/jcr_root/libs/sling-cms/components/jobs/view/view.jsp
new file mode 100644
index 0000000..e8639f5
--- /dev/null
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/components/jobs/view/view.jsp
@@ -0,0 +1,79 @@
+<%-- /*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */ --%>
+<%@include file="/libs/sling-cms/global.jsp"%>
+<sling:adaptTo var="jobMgr" adaptable="${slingRequest}" adaptTo="org.apache.sling.cms.CMSJobManager" />
+<c:set var="job" value="${jobMgr.suffixJob}" />
+<nav class="breadcrumb" aria-label="breadcrumbs">
+ <ul>
+ <li>
+ <a href="/cms/jobs/list.html">
+ <fmt:message key="slingcms.jobs" />
+ </a>
+ </li>
+ <li class="is-active">
+ <a href="#">
+ <fmt:message key="${job.properties._titleKey}" />
+ </a>
+ </li>
+ </ul>
+</nav>
+<h2><fmt:message key="${job.properties._titleKey}" /></h2>
+<dl>
+ <dt><fmt:message key="slingcms.state" /></dt>
+ <dd>${job.jobState}</dd>
+ <c:if test="${not empty job.resultMessage}">
+ <dt><fmt:message key="slingcms.jobs.resultmessage" /></dt>
+ <dd>${sling:encode(job.resultMessage,'HTML')}</dd>
+ </c:if>
+ <dt><fmt:message key="slingcms.started" /></dt>
+ <dd><fmt:formatDate value="${job.created.time}" type="both" dateStyle="long" timeStyle="long" /></dd>
+ <c:if test="${job.finishedDate != null}">
+ <dt><fmt:message key="slingcms.finished" /></dt>
+ <dd>
+ <fmt:formatDate value="${job.finishedDate.time}" type="both" dateStyle="long" timeStyle="long" />
+ </dd>
+ </c:if>
+ <c:if test="${job.progressStepCount > 0}">
+ <dt><fmt:message key="slingcms.jobs.progress" /></dt>
+ <dd>
+ ${job.finishedProgressStep} / ${job.progressStepCount}
+ </dd>
+ </c:if>
+ <c:if test="${job.progressLog != null && fn:length(job.progressLog) > 0}">
+ <dt><fmt:message key="slingcms.jobs.progresslog" /></dt>
+ <dd>
+ <ul>
+ <c:forEach var="log" items="${job.progressLog}">
+ <li>${sling:encode(log,'HTML')}</li>
+ </c:forEach>
+ </ul>
+ </dd>
+ </c:if>
+ <dt><fmt:message key="slingcms.jobs.properties" /></dt>
+ <dd>
+ <ul>
+ <c:forEach var="el" items="${job.properties}">
+ <c:if test="${not fn:contains(el.key, ':') && not fn:startsWith(el.key, '_') && not fn:startsWith(el.key, 'event.job.')}">
+ <li><strong>${sling:encode(el.key,'HTML')}:</strong>
+ ${sling:encode(el.value,'HTML')}
+ </c:if>
+ </c:forEach>
+ </ul>
+ </dd>
+</dl>
\ No newline at end of file
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/content/jobs/filemetadataextractor.json b/ui/src/main/resources/jcr_root/libs/sling-cms/content/jobs/filemetadataextractor.json
index f41310d..1ac87a0 100644
--- a/ui/src/main/resources/jcr_root/libs/sling-cms/content/jobs/filemetadataextractor.json
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/content/jobs/filemetadataextractor.json
@@ -12,6 +12,6 @@
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "sling-cms/components/editor/fields/hidden",
"name": "job.topics",
- "value": "org/apache/sling/cms/file/ExtractMetadata"
+ "value": "cmsjob/org/apache/sling/cms/file/ExtractMetadata"
}
}
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/content/jobs/list.json b/ui/src/main/resources/jcr_root/libs/sling-cms/content/jobs/list.json
index cdef10b..2b288d7 100644
--- a/ui/src/main/resources/jcr_root/libs/sling-cms/content/jobs/list.json
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/content/jobs/list.json
@@ -20,7 +20,7 @@
},
"contenttable": {
"jcr:primaryType": "nt:unstructured",
- "sling:resourceType": "sling-cms/components/jobs/jobtable"
+ "sling:resourceType": "sling-cms/components/jobs/list"
}
}
}
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/content/jobs/start.json b/ui/src/main/resources/jcr_root/libs/sling-cms/content/jobs/start.json
index 79d2812..0312b7f 100644
--- a/ui/src/main/resources/jcr_root/libs/sling-cms/content/jobs/start.json
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/content/jobs/start.json
@@ -18,7 +18,7 @@
"jcr:primaryType": "nt:unstructured",
"sling:resourceType": "sling-cms/components/editor/fields/select",
"label": "Job",
- "name": "job",
+ "name": "_job",
"optionsScript": "/libs/sling-cms/components/jobs/jobOptions.jsp"
},
"jobconfiguration": {
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/content/jobs/view.json b/ui/src/main/resources/jcr_root/libs/sling-cms/content/jobs/view.json
index fefdec4..fea6f07 100644
--- a/ui/src/main/resources/jcr_root/libs/sling-cms/content/jobs/view.json
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/content/jobs/view.json
@@ -3,10 +3,14 @@
"jcr:content": {
"jcr:primaryType": "nt:unstructured",
"jcr:title": "View Job",
- "sling:resourceType": "sling-cms/components/pages/editor",
+ "sling:resourceType": "sling-cms/components/pages/base",
"container": {
"jcr:primaryType": "nt:unstructured",
- "sling:resourceType": "sling-cms/components/general/container"
+ "sling:resourceType": "sling-cms/components/general/container",
+ "contenttable": {
+ "jcr:primaryType": "nt:unstructured",
+ "sling:resourceType": "sling-cms/components/jobs/view"
+ }
}
}
}
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/i18n.json b/ui/src/main/resources/jcr_root/libs/sling-cms/i18n.json
index b32d204..e74c0d2 100644
--- a/ui/src/main/resources/jcr_root/libs/sling-cms/i18n.json
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/i18n.json
@@ -10,6 +10,11 @@
],
"jcr:language": "en",
"sling:resourceType": "sling-cms/components/cms/blank",
+ "slingcms-finished": {
+ "jcr:primaryType": "sling:MessageEntry",
+ "sling:message": "Finished",
+ "sling:key": "slingcms.finished"
+ },
"slingcms-insights-moredetails": {
"jcr:primaryType": "sling:MessageEntry",
"sling:message": "More Details",
@@ -35,6 +40,11 @@
"sling:message": "There were {0} validation warnings",
"sling:key": "slingcms.htmlvalidator.warn"
},
+ "slingcms-jobs": {
+ "jcr:primaryType": "sling:MessageEntry",
+ "sling:message": "Jobs",
+ "sling:key": "slingcms.jobs"
+ },
"slingcms-jobs-badrequest": {
"jcr:primaryType": "sling:MessageEntry",
"sling:message": "Invalid Job Request",
@@ -45,6 +55,31 @@
"sling:message": "Job Started",
"sling:key": "slingcms.jobs.jobstarted"
},
+ "slingcms-jobs-progress": {
+ "jcr:primaryType": "sling:MessageEntry",
+ "sling:message": "Job Progress",
+ "sling:key": "slingcms.jobs.progress"
+ },
+ "slingcms-jobs-progresslog": {
+ "jcr:primaryType": "sling:MessageEntry",
+ "sling:message": "Job Progress Logs",
+ "sling:key": "slingcms.jobs.progresslog"
+ },
+ "slingcms-jobs-name": {
+ "jcr:primaryType": "sling:MessageEntry",
+ "sling:message": "Job Name",
+ "sling:key": "slingcms.jobs.name"
+ },
+ "slingcms-jobs-properties": {
+ "jcr:primaryType": "sling:MessageEntry",
+ "sling:message": "Job Properties",
+ "sling:key": "slingcms.jobs.properties"
+ },
+ "slingcms-jobs-resultmessage": {
+ "jcr:primaryType": "sling:MessageEntry",
+ "sling:message": "Result Message",
+ "sling:key": "slingcms.jobs.resultmessage"
+ },
"slingcms-pagespeed-danger": {
"jcr:primaryType": "sling:MessageEntry",
"sling:message": "This website is much slower than average, page performance must be optimized",
@@ -79,6 +114,16 @@
"jcr:primaryType": "sling:MessageEntry",
"sling:message": "Readability grade {2} is outside expected range: ({0}-{1})",
"sling:key": "slingcms.readability.warn"
+ },
+ "slingcms-started": {
+ "jcr:primaryType": "sling:MessageEntry",
+ "sling:message": "Started",
+ "sling:key": "slingcms.started"
+ },
+ "slingcms-state": {
+ "jcr:primaryType": "sling:MessageEntry",
+ "sling:message": "State",
+ "sling:key": "slingcms.state"
}
}
}
\ No newline at end of file
diff --git a/ui/src/main/resources/jcr_root/libs/sling-cms/install/org.apache.sling.event.jobs.QueueConfiguration-cmsqueue.config b/ui/src/main/resources/jcr_root/libs/sling-cms/install/org.apache.sling.event.jobs.QueueConfiguration-cmsqueue.config
new file mode 100644
index 0000000..9a8d548
--- /dev/null
+++ b/ui/src/main/resources/jcr_root/libs/sling-cms/install/org.apache.sling.event.jobs.QueueConfiguration-cmsqueue.config
@@ -0,0 +1,29 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+queue.name="Sling\ CMS\ Jobs"
+queue.priority="NORM"
+queue.maxparallel=D"4624633867356078080"
+queue.topics=["cmsjob/*"]
+queue.retries=I"10"
+queue.preferRunOnCreationInstance=B"true"
+queue.threadPoolSize=I"0"
+queue.retrydelay=L"2000"
+service.ranking=I"0"
+queue.type="UNORDERED"
+queue.keepJobs=B"true"
\ No newline at end of file