You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by np...@apache.org on 2021/09/14 11:09:51 UTC
[sling-org-apache-sling-pipes] branch master updated: SLING-10809
adding parsed command and result
This is an automated email from the ASF dual-hosted git repository.
npeltier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-pipes.git
The following commit(s) were added to refs/heads/master by this push:
new 5f4ec49 SLING-10809 adding parsed command and result
5f4ec49 is described below
commit 5f4ec499f0fb1da8e3663ed63c339638cb2dcadf
Author: Nicolas Peltier <np...@apache.org>
AuthorDate: Tue Sep 14 13:09:28 2021 +0200
SLING-10809 adding parsed command and result
---
.../apache/sling/pipes/internal/CommandExecutorImpl.java | 5 ++++-
.../org/apache/sling/pipes/internal/PlumberImpl.java | 16 +++++++++++-----
2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/apache/sling/pipes/internal/CommandExecutorImpl.java b/src/main/java/org/apache/sling/pipes/internal/CommandExecutorImpl.java
index b96639b..7438989 100644
--- a/src/main/java/org/apache/sling/pipes/internal/CommandExecutorImpl.java
+++ b/src/main/java/org/apache/sling/pipes/internal/CommandExecutorImpl.java
@@ -39,6 +39,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.request.RequestParameter;
+import org.apache.sling.api.resource.ModifiableValueMap;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.servlets.ServletResolverConstants;
@@ -66,7 +67,6 @@ import static org.apache.commons.lang3.StringUtils.EMPTY;
import static org.apache.sling.pipes.internal.CommandUtil.keyValuesToArray;
import static org.apache.sling.pipes.internal.CommandUtil.writeToMap;
-import javax.json.Json;
import javax.json.JsonException;
import javax.servlet.Servlet;
@@ -83,6 +83,7 @@ public class CommandExecutorImpl extends AbstractPlumberServlet implements Comma
static final String REQ_PARAM_CMD = "pipe_cmd";
static final String REQ_PARAM_HELP = "pipe_help";
static final String CMD_LINE_PREFIX = "cmd_line_";
+ static final String PN_DESCRIPTION = "commandParsed";
static final String WHITE_SPACE_SEPARATOR = "\\s";
static final String COMMENT_PREFIX = "#";
static final String SEPARATOR = "|";
@@ -184,6 +185,8 @@ public class CommandExecutorImpl extends AbstractPlumberServlet implements Comma
PipeBuilder pipeBuilder = parse(resolver, command);
Pipe pipe = pipeBuilder.build();
bindings.put(CMD_LINE_PREFIX + idxLine++, pipe.getResource().getPath());
+ ModifiableValueMap root = pipe.getResource().adaptTo(ModifiableValueMap.class);
+ root.put(PN_DESCRIPTION, command);
plumber.execute(resolver, pipe, bindings, pipeWriter, true);
}
}
diff --git a/src/main/java/org/apache/sling/pipes/internal/PlumberImpl.java b/src/main/java/org/apache/sling/pipes/internal/PlumberImpl.java
index f51155a..855afe7 100644
--- a/src/main/java/org/apache/sling/pipes/internal/PlumberImpl.java
+++ b/src/main/java/org/apache/sling/pipes/internal/PlumberImpl.java
@@ -114,6 +114,8 @@ public class PlumberImpl implements Plumber, JobConsumer, PlumberMXBean, Runnabl
static final String PERMISSION_EXECUTION = "/system/sling/permissions/pipes/exec";
+ static final int MAX_LENGTH = 1000;
+
public static final String PIPES_REPOSITORY_PATH = "/var/pipes";
@ObjectClassDefinition(name="Apache Sling Pipes : Plumber configuration")
@@ -167,6 +169,8 @@ public class PlumberImpl implements Plumber, JobConsumer, PlumberMXBean, Runnabl
private Map<String, PipeMonitor> monitoredPipes;
+ public static final String PN_NBOUTPUTRESOURCES = "nbOutputResources";
+
@Activate
public void activate(Configuration configuration){
this.configuration = configuration;
@@ -346,6 +350,7 @@ public class PlumberImpl implements Plumber, JobConsumer, PlumberMXBean, Runnabl
checkPermissions(resolver, configuration.executionPermissionResource());
boolean success = false;
PipeMonitor monitor = null;
+ ExecutionResult result = null;
long start = System.currentTimeMillis();
try {
boolean readOnly = false;
@@ -365,12 +370,12 @@ public class PlumberImpl implements Plumber, JobConsumer, PlumberMXBean, Runnabl
throw new IllegalStateException("Pipe is already running");
}
monitor = monitoredPipes.get(confResource.getPath());
- writeStatus(pipe, STATUS_STARTED);
+ writeStatus(pipe, STATUS_STARTED, null);
resolver.commit();
if (monitor != null){
monitor.starts();
}
- ExecutionResult result = internalExecute(resolver, writer, pipe);
+ result = internalExecute(resolver, writer, pipe);
if (save && pipe.modifiesContent()) {
persist(resolver, pipe, result, null);
}
@@ -390,7 +395,7 @@ public class PlumberImpl implements Plumber, JobConsumer, PlumberMXBean, Runnabl
Thread.currentThread().interrupt();
} finally {
try {
- writeStatus(pipe, STATUS_FINISHED);
+ writeStatus(pipe, STATUS_FINISHED, result);
resolver.commit();
} catch (PersistenceException e) {
log.error("unable to make final save", e);
@@ -438,7 +443,7 @@ public class PlumberImpl implements Plumber, JobConsumer, PlumberMXBean, Runnabl
void persist(ResourceResolver resolver, Pipe pipe, ExecutionResult result, Resource currentResource) throws PersistenceException, InterruptedException {
if (shouldSave(resolver, pipe, result, currentResource)) {
log.info("[{}] saving changes...", pipe.getName());
- writeStatus(pipe, currentResource == null ? STATUS_FINISHED : currentResource.getPath());
+ writeStatus(pipe, currentResource == null ? STATUS_FINISHED : currentResource.getPath(), result);
resolver.commit();
if (currentResource == null && distributor != null && StringUtils.isNotBlank(pipe.getDistributionAgent())) {
log.info("a distribution agent is configured, will try to distribute the changes");
@@ -473,11 +478,12 @@ public class PlumberImpl implements Plumber, JobConsumer, PlumberMXBean, Runnabl
* @param status status to write
* @throws RepositoryException in case write goes wrong
*/
- void writeStatus(Pipe pipe, String status){
+ void writeStatus(Pipe pipe, String status, ExecutionResult result){
if (StringUtils.isNotBlank(status)){
ModifiableValueMap vm = pipe.getResource().adaptTo(ModifiableValueMap.class);
if( vm != null) {
vm.put(PN_STATUS, status);
+ vm.put(PN_NBOUTPUTRESOURCES, result != null ? result.size() : -1);
Calendar cal = new GregorianCalendar();
cal.setTime(new Date());
vm.put(PN_STATUS_MODIFIED, cal);