You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by tm...@apache.org on 2021/03/09 13:47:43 UTC

[sling-org-apache-sling-distribution-core] branch SLING-10200 created (now e0aca7e)

This is an automated email from the ASF dual-hosted git repository.

tmaret pushed a change to branch SLING-10200
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-distribution-core.git.


      at e0aca7e  SLING-10200 - Provide the importer errors as queue properties

This branch includes the following new commits:

     new e0aca7e  SLING-10200 - Provide the importer errors as queue properties

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[sling-org-apache-sling-distribution-core] 01/01: SLING-10200 - Provide the importer errors as queue properties

Posted by tm...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tmaret pushed a commit to branch SLING-10200
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-distribution-core.git

commit e0aca7ebdd0617398654914a793b6afbbc61cafc
Author: tmaret <tm...@adobe.com>
AuthorDate: Tue Mar 9 14:46:51 2021 +0100

    SLING-10200 - Provide the importer errors as queue properties
---
 .../queue/DistributionQueueItemStatus.java         | 16 ++++++-
 .../sling/distribution/queue/package-info.java     |  2 +-
 ...xtendedDistributionServiceResourceProvider.java |  7 ++-
 .../queue/DistributionQueueItemStatusTest.java     | 50 ++++++++++++++++++++++
 4 files changed, 71 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/sling/distribution/queue/DistributionQueueItemStatus.java b/src/main/java/org/apache/sling/distribution/queue/DistributionQueueItemStatus.java
index 95cb786..7cb06d6 100644
--- a/src/main/java/org/apache/sling/distribution/queue/DistributionQueueItemStatus.java
+++ b/src/main/java/org/apache/sling/distribution/queue/DistributionQueueItemStatus.java
@@ -35,11 +35,18 @@ public final class DistributionQueueItemStatus {
 
     private final String queueName;
 
-    public DistributionQueueItemStatus(Calendar entered, DistributionQueueItemState state, int attempts, String queueName) {
+    private final Throwable error;
+
+    public DistributionQueueItemStatus(Calendar entered, DistributionQueueItemState state, int attempts, String queueName, Throwable error) {
         this.entered = entered;
         this.state = state;
         this.attempts = attempts;
         this.queueName = queueName;
+        this.error = error;
+    }
+
+    public DistributionQueueItemStatus(Calendar entered, DistributionQueueItemState state, int attempts, String queueName) {
+        this(entered, state, attempts, queueName, null);
     }
 
     public DistributionQueueItemStatus(DistributionQueueItemState state, String queueName) {
@@ -58,10 +65,15 @@ public final class DistributionQueueItemStatus {
         return queueName;
     }
 
+    public Throwable getError() {
+        return error;
+    }
+
     @Override
     public String toString() {
         return "{\"attempts\":\"" + attempts + "\",\"" + "\",\"" + "state\":\"" + state +
-                "\",\"" + "queueName\":\"" + queueName + "\"}";
+                "\",\"" + "queueName\":\"" + queueName +
+                "\",\"" + "error\":\"" + error + "\"}";
     }
 
     public Calendar getEntered() {
diff --git a/src/main/java/org/apache/sling/distribution/queue/package-info.java b/src/main/java/org/apache/sling/distribution/queue/package-info.java
index 70795e9..6f003ea 100644
--- a/src/main/java/org/apache/sling/distribution/queue/package-info.java
+++ b/src/main/java/org/apache/sling/distribution/queue/package-info.java
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-@Version("0.1.0")
+@Version("0.2.0")
 package org.apache.sling.distribution.queue;
 
 import aQute.bnd.annotation.Version;
diff --git a/src/main/java/org/apache/sling/distribution/resources/impl/ExtendedDistributionServiceResourceProvider.java b/src/main/java/org/apache/sling/distribution/resources/impl/ExtendedDistributionServiceResourceProvider.java
index 2733d90..da86780 100644
--- a/src/main/java/org/apache/sling/distribution/resources/impl/ExtendedDistributionServiceResourceProvider.java
+++ b/src/main/java/org/apache/sling/distribution/resources/impl/ExtendedDistributionServiceResourceProvider.java
@@ -209,7 +209,12 @@ public class ExtendedDistributionServiceResourceProvider extends DistributionSer
             result.put("attempts", status.getAttempts());
             result.put("time", status.getEntered().getTime());
             result.put("state", status.getItemState().name());
-
+            if (status.getError() != null) {
+                Map<String, String> error = new HashMap<>();
+                error.put("message", status.getError().getMessage());
+                error.put("stackTrace", status.getError().toString());
+                result.put("error", error);
+            }
         }
 
         return result;
diff --git a/src/test/java/org/apache/sling/distribution/queue/DistributionQueueItemStatusTest.java b/src/test/java/org/apache/sling/distribution/queue/DistributionQueueItemStatusTest.java
new file mode 100644
index 0000000..2ad28cb
--- /dev/null
+++ b/src/test/java/org/apache/sling/distribution/queue/DistributionQueueItemStatusTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ */
+package org.apache.sling.distribution.queue;
+
+import java.util.Calendar;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+
+public class DistributionQueueItemStatusTest {
+
+    @Test
+    public void getNoErrorByDefault() {
+        DistributionQueueItemStatus status = new DistributionQueueItemStatus(any(Calendar.class),
+                any(DistributionQueueItemState.class), anyInt(), anyString());
+        assertNull(status.getError());
+    }
+
+    @Test
+    public void getErrorByDefault() {
+        Throwable cause = mock(Throwable.class);
+        DistributionQueueItemStatus status = new DistributionQueueItemStatus(any(Calendar.class),
+                any(DistributionQueueItemState.class), anyInt(), anyString(), cause);
+        assertNotNull(status.getError());
+        assertEquals(cause, status.getError());
+    }
+}
\ No newline at end of file