sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mpet...@apache.org
Subject svn commit: r1710007 - in /sling/trunk/contrib/extensions/distribution: api/src/main/java/org/apache/sling/distribution/serialization/ core/src/main/java/org/apache/sling/distribution/agent/impl/ core/src/main/java/org/apache/sling/distribution/packagi...
Date Thu, 22 Oct 2015 12:44:36 GMT
Author: mpetria
Date: Thu Oct 22 12:44:36 2015
New Revision: 1710007

URL: http://svn.apache.org/viewvc?rev=1710007&view=rev
Log:
SLING-5180: cleaned DistributionPackageInfo

Modified:
    sling/trunk/contrib/extensions/distribution/api/src/main/java/org/apache/sling/distribution/serialization/DistributionPackage.java
    sling/trunk/contrib/extensions/distribution/api/src/main/java/org/apache/sling/distribution/serialization/DistributionPackageBuilder.java
    sling/trunk/contrib/extensions/distribution/api/src/main/java/org/apache/sling/distribution/serialization/DistributionPackageInfo.java
    sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/agent/impl/SimpleDistributionAgent.java
    sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/packaging/impl/DistributionPackageUtils.java
    sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/ErrorQueueDispatchingStrategy.java
    sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/transport/impl/MultipleEndpointDistributionTransport.java
    sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/transport/impl/SimpleHttpDistributionTransport.java
    sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/queue/impl/SelectiveQueueDispatchingStrategyTest.java
    sling/trunk/contrib/extensions/distribution/it/pom.xml

Modified: sling/trunk/contrib/extensions/distribution/api/src/main/java/org/apache/sling/distribution/serialization/DistributionPackage.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/api/src/main/java/org/apache/sling/distribution/serialization/DistributionPackage.java?rev=1710007&r1=1710006&r2=1710007&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/api/src/main/java/org/apache/sling/distribution/serialization/DistributionPackage.java
(original)
+++ sling/trunk/contrib/extensions/distribution/api/src/main/java/org/apache/sling/distribution/serialization/DistributionPackage.java
Thu Oct 22 12:44:36 2015
@@ -22,12 +22,12 @@ import javax.annotation.Nonnull;
 import java.io.IOException;
 import java.io.InputStream;
 
-import aQute.bnd.annotation.ConsumerType;
+import aQute.bnd.annotation.ProviderType;
 
 /**
  * A distribution package
  */
-@ConsumerType
+@ProviderType
 public interface DistributionPackage {
 
     /**

Modified: sling/trunk/contrib/extensions/distribution/api/src/main/java/org/apache/sling/distribution/serialization/DistributionPackageBuilder.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/api/src/main/java/org/apache/sling/distribution/serialization/DistributionPackageBuilder.java?rev=1710007&r1=1710006&r2=1710007&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/api/src/main/java/org/apache/sling/distribution/serialization/DistributionPackageBuilder.java
(original)
+++ sling/trunk/contrib/extensions/distribution/api/src/main/java/org/apache/sling/distribution/serialization/DistributionPackageBuilder.java
Thu Oct 22 12:44:36 2015
@@ -22,6 +22,7 @@ import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import java.io.InputStream;
 
+import aQute.bnd.annotation.ProviderType;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.distribution.DistributionException;
 import org.apache.sling.distribution.DistributionRequest;
@@ -29,6 +30,7 @@ import org.apache.sling.distribution.Dis
 /**
  * A builder for {@link DistributionPackage}s
  */
+@ProviderType
 public interface DistributionPackageBuilder {
 
     /**

Modified: sling/trunk/contrib/extensions/distribution/api/src/main/java/org/apache/sling/distribution/serialization/DistributionPackageInfo.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/api/src/main/java/org/apache/sling/distribution/serialization/DistributionPackageInfo.java?rev=1710007&r1=1710006&r2=1710007&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/api/src/main/java/org/apache/sling/distribution/serialization/DistributionPackageInfo.java
(original)
+++ sling/trunk/contrib/extensions/distribution/api/src/main/java/org/apache/sling/distribution/serialization/DistributionPackageInfo.java
Thu Oct 22 12:44:36 2015
@@ -25,6 +25,7 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 
+import aQute.bnd.annotation.ProviderType;
 import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.api.wrappers.ValueMapDecorator;
 import org.apache.sling.distribution.DistributionRequestType;
@@ -33,6 +34,7 @@ import org.apache.sling.distribution.Dis
  * Additional information about a package.
  * Additional information is optional and components should expect every piece of it to be
null.
  */
+@ProviderType
 public final class DistributionPackageInfo extends ValueMapDecorator implements ValueMap
{
 
     /**
@@ -50,49 +52,31 @@ public final class DistributionPackageIn
      */
     public static String PROPERTY_REQUEST_TYPE = "request.type";
 
-    /**
-     * distribution package origin uri
-     */
-    public static String PROPERTY_ORIGIN_URI = "package.origin.uri";
-
-    /**
-     * distribution package origin queue
-     */
-    public static String PROPERTY_ORIGIN_QUEUE = "origin.queue";
-
 
     /**
      * Creates a new wrapper around a given map.
      *
      * @param base wrapped object
      */
-    public DistributionPackageInfo(Map<String, Object> base) {
-        super(init(null, base));
+    public DistributionPackageInfo(String packageType, Map<String, Object> base) {
+        super(base);
+        if (packageType == null) {
+            throw new IllegalArgumentException("package type cannot be null");
+        }
+
+        put(PROPERTY_PACKAGE_TYPE, packageType);
     }
 
+
     /**
-     * Creates a new wrapper around a given map.
+     * Creates a new wrapper around an empty map.
      *
      */
-    public DistributionPackageInfo(String type) {
-        super(init(type, null));
+    public DistributionPackageInfo(String packageType) {
+        this(packageType, new HashMap<String, Object>());
     }
 
 
-    private static Map<String, Object> init(String type, Map<String, Object>
base) {
-        Map<String, Object> result = new HashMap<String, Object>();
-
-        if (base != null) {
-            type = (String) base.get(PROPERTY_PACKAGE_TYPE);
-
-            result = new HashMap<String, Object>(base);
-        }
-
-        result.put(PROPERTY_PACKAGE_TYPE, type);
-
-        return result;
-    }
-
     @Nonnull
     public String getType() {
         return get(PROPERTY_PACKAGE_TYPE, String.class);
@@ -118,27 +102,11 @@ public final class DistributionPackageIn
         return get(PROPERTY_REQUEST_TYPE, DistributionRequestType.class);
     }
 
-    /**
-     * retrieves the origin of the package holding this info
-     *
-     * @return the package origin
-     */
-    @CheckForNull
-    public URI getOrigin() {
-        return get(PROPERTY_ORIGIN_URI, URI.class);
-    }
-
-    @CheckForNull
-    public String getQueue() {
-        return get(PROPERTY_ORIGIN_QUEUE, String.class);
-    }
-
-
     @Override
     public String toString() {
         return "DistributionPackageInfo{" +
-                " requestType=" + getRequestType() +
-                ", paths=" + Arrays.toString(getPaths()) +
+                " request.type=" + getRequestType() +
+                ", request.paths=" + Arrays.toString(getPaths()) +
                 '}';
     }
 }

Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/agent/impl/SimpleDistributionAgent.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/agent/impl/SimpleDistributionAgent.java?rev=1710007&r1=1710006&r2=1710007&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/agent/impl/SimpleDistributionAgent.java
(original)
+++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/agent/impl/SimpleDistributionAgent.java
Thu Oct 22 12:44:36 2015
@@ -46,6 +46,7 @@ import org.apache.sling.distribution.Dis
 import org.apache.sling.distribution.impl.SimpleDistributionResponse;
 import org.apache.sling.distribution.log.DistributionLog;
 import org.apache.sling.distribution.log.impl.DefaultDistributionLog;
+import org.apache.sling.distribution.queue.impl.DistributionQueueUtils;
 import org.apache.sling.distribution.serialization.DistributionPackage;
 import org.apache.sling.distribution.packaging.DistributionPackageExporter;
 import org.apache.sling.distribution.packaging.DistributionPackageImporter;
@@ -381,8 +382,7 @@ public class SimpleDistributionAgent imp
             distributionPackage = distributionPackageExporter.getPackage(agentResourceResolver,
queueItem.getId());
 
             if (distributionPackage != null) {
-                distributionPackage.getInfo().putAll(queueItem);
-                distributionPackage.getInfo().put(DistributionPackageInfo.PROPERTY_ORIGIN_QUEUE,
queueName);
+                DistributionPackageUtils.mergeQueueEntry(distributionPackage.getInfo(), queueEntry);
 
                 if (processPackage(agentResourceResolver, distributionPackage)) {
                     success = true;

Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/packaging/impl/DistributionPackageUtils.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/packaging/impl/DistributionPackageUtils.java?rev=1710007&r1=1710006&r2=1710007&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/packaging/impl/DistributionPackageUtils.java
(original)
+++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/packaging/impl/DistributionPackageUtils.java
Thu Oct 22 12:44:36 2015
@@ -19,6 +19,8 @@
 
 package org.apache.sling.distribution.packaging.impl;
 
+import org.apache.sling.distribution.queue.DistributionQueueEntry;
+import org.apache.sling.distribution.queue.DistributionQueueStatus;
 import org.apache.sling.distribution.serialization.DistributionPackage;
 import org.apache.sling.distribution.serialization.DistributionPackageInfo;
 import org.apache.sling.distribution.packaging.SharedDistributionPackage;
@@ -34,6 +36,11 @@ public class DistributionPackageUtils {
     static Logger log = LoggerFactory.getLogger(DistributionPackageUtils.class);
 
     /**
+     * distribution package origin queue
+     */
+    public static String PACKAGE_INFO_PROPERTY_ORIGIN_QUEUE = "internal.origin.queue";
+
+    /**
      * Acquires the package if it's a {@link SharedDistributionPackage}, via {@link SharedDistributionPackage#acquire(String)}
      * @param distributionPackage a distribution package
      * @param queueName the name of the queue in which the package should be acquired
@@ -92,7 +99,17 @@ public class DistributionPackageUtils {
      * @return a {@link DistributionPackageInfo}
      */
     public static DistributionPackageInfo fromQueueItem(DistributionQueueItem queueItem)
{
-        return new DistributionPackageInfo(queueItem);
+        String type = queueItem.get(DistributionPackageInfo.PROPERTY_PACKAGE_TYPE, String.class);
+        return new DistributionPackageInfo(type, queueItem);
+    }
+
+    public static String getQueueName(DistributionPackageInfo packageInfo) {
+        return packageInfo.get(PACKAGE_INFO_PROPERTY_ORIGIN_QUEUE, String.class);
+    }
+
+    public static void mergeQueueEntry(DistributionPackageInfo packageInfo, DistributionQueueEntry
entry) {
+        packageInfo.putAll(entry.getItem());
+        packageInfo.put(PACKAGE_INFO_PROPERTY_ORIGIN_QUEUE, entry.getStatus().getQueueName());
     }
 
 }

Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/ErrorQueueDispatchingStrategy.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/ErrorQueueDispatchingStrategy.java?rev=1710007&r1=1710006&r2=1710007&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/ErrorQueueDispatchingStrategy.java
(original)
+++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/ErrorQueueDispatchingStrategy.java
Thu Oct 22 12:44:36 2015
@@ -54,7 +54,7 @@ public class ErrorQueueDispatchingStrate
     public Iterable<DistributionQueueItemStatus> add(@Nonnull DistributionPackage distributionPackage,
@Nonnull DistributionQueueProvider queueProvider) throws DistributionException {
 
         List<DistributionQueueItemStatus> result = new ArrayList<DistributionQueueItemStatus>();
-        String originQueue = distributionPackage.getInfo().getQueue();
+        String originQueue = DistributionPackageUtils.getQueueName(distributionPackage.getInfo());
 
         if (!queueNames.contains(originQueue)) {
             return result;

Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/transport/impl/MultipleEndpointDistributionTransport.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/transport/impl/MultipleEndpointDistributionTransport.java?rev=1710007&r1=1710006&r2=1710007&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/transport/impl/MultipleEndpointDistributionTransport.java
(original)
+++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/transport/impl/MultipleEndpointDistributionTransport.java
Thu Oct 22 12:44:36 2015
@@ -28,6 +28,8 @@ import org.apache.sling.api.resource.Res
 import org.apache.sling.distribution.DistributionRequest;
 import org.apache.sling.distribution.component.impl.SettingsUtils;
 import org.apache.sling.distribution.DistributionException;
+import org.apache.sling.distribution.packaging.impl.DistributionPackageUtils;
+import org.apache.sling.distribution.queue.impl.DistributionQueueUtils;
 import org.apache.sling.distribution.serialization.DistributionPackage;
 import org.apache.sling.distribution.serialization.DistributionPackageInfo;
 import org.apache.sling.distribution.transport.core.DistributionTransport;
@@ -57,7 +59,7 @@ public class MultipleEndpointDistributio
 
         if (endpointStrategyType.equals(TransportEndpointStrategyType.One)) {
             DistributionPackageInfo info = distributionPackage.getInfo();
-            String queueName = info.getQueue();
+            String queueName = DistributionPackageUtils.getQueueName(info);
 
             DistributionTransport distributionTransport = getDefaultTransport();
             if (queueName != null) {

Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/transport/impl/SimpleHttpDistributionTransport.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/transport/impl/SimpleHttpDistributionTransport.java?rev=1710007&r1=1710006&r2=1710007&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/transport/impl/SimpleHttpDistributionTransport.java
(original)
+++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/transport/impl/SimpleHttpDistributionTransport.java
Thu Oct 22 12:44:36 2015
@@ -56,6 +56,11 @@ public class SimpleHttpDistributionTrans
     private static final String USERNAME = "username";
     private static final String PASSWORD = "password";
 
+    /**
+     * distribution package origin uri
+     */
+    public static String PACKAGE_INFO_PROPERTY_ORIGIN_URI = "internal.origin.uri";
+
     protected final DefaultDistributionLog log;
     private final DistributionEndpoint distributionEndpoint;
     private final DistributionPackageBuilder packageBuilder;
@@ -77,7 +82,8 @@ public class SimpleHttpDistributionTrans
     public void deliverPackage(@Nonnull ResourceResolver resourceResolver, @Nonnull DistributionPackage
distributionPackage) throws DistributionException {
         String hostAndPort = getHostAndPort(distributionEndpoint.getUri());
 
-        URI packageOrigin = distributionPackage.getInfo().getOrigin();
+        URI packageOrigin = distributionPackage.getInfo().get(PACKAGE_INFO_PROPERTY_ORIGIN_URI,
URI.class);
+
         if (packageOrigin != null && hostAndPort.equals(getHostAndPort(packageOrigin)))
{
             log.info("skipping distribution of package {} to same origin {}", distributionPackage.getId(),
hostAndPort);
         } else {
@@ -150,7 +156,7 @@ public class SimpleHttpDistributionTrans
 
                 final DistributionPackage responsePackage = packageBuilder.readPackage(resourceResolver,
inputStream);
                 if (responsePackage != null) {
-                    responsePackage.getInfo().put(DistributionPackageInfo.PROPERTY_ORIGIN_URI,
distributionURI);
+                    responsePackage.getInfo().put(PACKAGE_INFO_PROPERTY_ORIGIN_URI, distributionURI);
                     log.debug("pulled package no {} with info {}", pulls, responsePackage.getInfo());
 
                     result.add(responsePackage);

Modified: sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/queue/impl/SelectiveQueueDispatchingStrategyTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/queue/impl/SelectiveQueueDispatchingStrategyTest.java?rev=1710007&r1=1710006&r2=1710007&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/queue/impl/SelectiveQueueDispatchingStrategyTest.java
(original)
+++ sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/queue/impl/SelectiveQueueDispatchingStrategyTest.java
Thu Oct 22 12:44:36 2015
@@ -125,9 +125,8 @@ public class SelectiveQueueDispatchingSt
         DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
 
         Map<String, Object> properties = new HashMap<String, Object>();
-        properties.put(DistributionPackageInfo.PROPERTY_PACKAGE_TYPE, "vlt");
         properties.put(DistributionPackageInfo.PROPERTY_REQUEST_PATHS, new String[] { "/content/news/a"
});
-        when(distributionPackage.getInfo()).thenReturn(new DistributionPackageInfo(properties));
+        when(distributionPackage.getInfo()).thenReturn(new DistributionPackageInfo("vlt",
properties));
 
         DistributionQueue news1 = mock(DistributionQueue.class);
         when(news1.getName()).thenReturn("news-publish1");
@@ -153,9 +152,8 @@ public class SelectiveQueueDispatchingSt
         DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
 
         Map<String, Object> properties = new HashMap<String, Object>();
-        properties.put(DistributionPackageInfo.PROPERTY_PACKAGE_TYPE, "vlt");
         properties.put(DistributionPackageInfo.PROPERTY_REQUEST_PATHS, new String[] { "/content/other"
});
-        when(distributionPackage.getInfo()).thenReturn(new DistributionPackageInfo(properties));
+        when(distributionPackage.getInfo()).thenReturn(new DistributionPackageInfo("vlt",
properties));
 
         DistributionQueue other1 = mock(DistributionQueue.class);
         when(other1.getName()).thenReturn("publish1");

Modified: sling/trunk/contrib/extensions/distribution/it/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/it/pom.xml?rev=1710007&r1=1710006&r2=1710007&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/it/pom.xml (original)
+++ sling/trunk/contrib/extensions/distribution/it/pom.xml Thu Oct 22 12:44:36 2015
@@ -403,7 +403,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.distribution.api</artifactId>
-            <version>0.2.0</version>
+            <version>0.2.1-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>



Mime
View raw message