Author: mpetria Date: Wed Jul 29 12:17:10 2015 New Revision: 1693250 URL: http://svn.apache.org/r1693250 Log: SLING-4916: refactoring distributionqueueitems
Modified: 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/DistributionPackageInfo.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/packaging/impl/exporter/AgentDistributionPackageExporter.java sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/DistributionQueue.java sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/DistributionQueueItem.java sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/ErrorAwareQueueDispatchingStrategy.java sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/MultipleQueueDispatchingStrategy.java sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/PriorityPathQueueDispatchingStrategy.java sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingDistributionQueue.java sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingUtils.java sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/ExtendedDistributionServiceResourceProvider.java sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/serialization/impl/AbstractDistributionPackage.java sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/serialization/impl/AbstractDistributionPackageBuilder.java sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/serialization/impl/SimpleDistributionPackage.java sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/serialization/impl/vlt/FileVaultDistributionPackage.java sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/serialization/impl/vlt/JcrVaultDistributionPackage.java sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/servlet/DistributionAgentQueueServlet.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/agent/impl/SimpleDistributionAgentTest.java sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/queue/impl/PriorityPathQueueDistributionStrategyTest.java sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingDistributionQueueTest.java sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingUtilsTest.java sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/serialization/impl/vlt/FileVaultDistributionPackageBuilderTest.java sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/transport/impl/SimpleHttpDistributionTransportTest.java sling/trunk/contrib/extensions/distribution/it/src/test/java/org/apache/sling/distribution/it/DistributionUtils.java 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=1693250&r1=1693249&r2=1693250&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 Wed Jul 29 12:17:10 2015 @@ -54,6 +54,7 @@ import org.apache.sling.distribution.pac import org.apache.sling.distribution.packaging.DistributionPackageExporter; import org.apache.sling.distribution.packaging.DistributionPackageImportException; import org.apache.sling.distribution.packaging.DistributionPackageImporter; +import org.apache.sling.distribution.packaging.DistributionPackageInfo; import org.apache.sling.distribution.packaging.impl.DistributionPackageUtils; import org.apache.sling.distribution.queue.DistributionQueue; import org.apache.sling.distribution.queue.DistributionQueueState; @@ -384,8 +385,9 @@ public class SimpleDistributionAgent imp distributionPackage = distributionPackageExporter.getPackage(agentResourceResolver, queueItem.getId()); if (distributionPackage != null) { - distributionPackage.getInfo().fillInfo(queueItem.getPackageInfo()); - distributionPackage.getInfo().setQueue(queueName); + distributionPackage.getInfo().putAll(queueItem); + distributionPackage.getInfo().put(DistributionPackageInfo.PROPERTY_ORIGIN_QUEUE, queueName); + distributionPackageImporter.importPackage(agentResourceResolver, distributionPackage); Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/packaging/DistributionPackageInfo.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/packaging/DistributionPackageInfo.java?rev=1693250&r1=1693249&r2=1693250&view=diff ============================================================================== --- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/packaging/DistributionPackageInfo.java (original) +++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/packaging/DistributionPackageInfo.java Wed Jul 29 12:17:10 2015 @@ -19,106 +19,129 @@ package org.apache.sling.distribution.packaging; import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; import java.net.URI; import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import org.apache.sling.api.resource.ValueMap; +import org.apache.sling.api.wrappers.ValueMapDecorator; import org.apache.sling.distribution.DistributionRequestType; +import org.apache.sling.distribution.queue.DistributionQueueItem; /** * Additional information about a package. * Additional information is optional and components should expect every piece of it to be null. */ -public final class DistributionPackageInfo { +public final class DistributionPackageInfo extends ValueMapDecorator implements ValueMap { - private URI origin; - private String queue; - private DistributionRequestType requestType; - private String[] paths; /** - * get the paths covered by the package holding this info - * - * @return an array of paths + * distribution package type */ - @CheckForNull - public String[] getPaths() { - return paths; - } + public static String PROPERTY_PACKAGE_TYPE = "package.type"; /** - * get the request type associated to the package holding this info - * - * @return the request type + * distribution request paths */ - @CheckForNull - public DistributionRequestType getRequestType() { - return requestType; - } + public static String PROPERTY_REQUEST_PATHS = "request.paths"; /** - * retrieves the origin of the package holding this info + * distribution request type + */ + 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. * - * @return the package origin + * @param base wrapped object */ - @CheckForNull - public URI getOrigin() { - return origin; + public DistributionPackageInfo(Map<String, Object> base) { + super(init(null, base)); } /** - * sets the origin of the package. + * Creates a new wrapper around a given map. * - * @param origin the originating instance of this package */ - public void setOrigin(URI origin) { - this.origin = origin; + public DistributionPackageInfo(String type) { + super(init(type, null)); + } + + + 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); } /** - * sets the request type for the package holding this info + * get the paths covered by the package holding this info * - * @param requestType the request type that originated this package + * @return an array of paths */ - public void setRequestType(DistributionRequestType requestType) { - this.requestType = requestType; + @CheckForNull + public String[] getPaths() { + return get(PROPERTY_REQUEST_PATHS, String[].class); } /** - * sets the paths "covered" by the package holding this info + * get the request type associated to the package holding this info * - * @param paths the paths "covered" by this package + * @return the request type */ - public void setPaths(String[] paths) { - this.paths = paths; + @CheckForNull + public DistributionRequestType getRequestType() { + return get(PROPERTY_REQUEST_TYPE, DistributionRequestType.class); } /** - * fills the current info object from the provided one. + * retrieves the origin of the package holding this info * - * @param packageInfo package metadata + * @return the package origin */ - public void fillInfo(DistributionPackageInfo packageInfo) { - if (packageInfo != null) { - this.setOrigin(packageInfo.getOrigin()); - this.setPaths(packageInfo.getPaths()); - this.setRequestType(packageInfo.getRequestType()); - } + @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{" + - "origin=" + origin + - ", requestType=" + requestType + - ", paths=" + Arrays.toString(paths) + + "origin=" + getOrigin() + + ", requestType=" + getRequestType() + + ", paths=" + Arrays.toString(getPaths()) + '}'; } - - public String getQueue() { - return queue; - } - - public void setQueue(String queue) { - this.queue = queue; - } } 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=1693250&r1=1693249&r2=1693250&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 Wed Jul 29 12:17:10 2015 @@ -21,7 +21,9 @@ package org.apache.sling.distribution.pa import org.apache.sling.distribution.packaging.DistributionPackage; +import org.apache.sling.distribution.packaging.DistributionPackageInfo; import org.apache.sling.distribution.packaging.SharedDistributionPackage; +import org.apache.sling.distribution.queue.DistributionQueueItem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -62,4 +64,14 @@ public class DistributionPackageUtils { } } + public static DistributionQueueItem toQueueItem(DistributionPackage distributionPackage) { + return new DistributionQueueItem(distributionPackage.getId(), distributionPackage.getInfo()); + } + + + public static DistributionPackageInfo fromQueueItem(DistributionQueueItem queueItem) { + return new DistributionPackageInfo(queueItem); + } + + } Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/packaging/impl/exporter/AgentDistributionPackageExporter.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/packaging/impl/exporter/AgentDistributionPackageExporter.java?rev=1693250&r1=1693249&r2=1693250&view=diff ============================================================================== --- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/packaging/impl/exporter/AgentDistributionPackageExporter.java (original) +++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/packaging/impl/exporter/AgentDistributionPackageExporter.java Wed Jul 29 12:17:10 2015 @@ -29,6 +29,7 @@ import org.apache.sling.distribution.Dis import org.apache.sling.distribution.packaging.DistributionPackage; import org.apache.sling.distribution.packaging.DistributionPackageExportException; import org.apache.sling.distribution.packaging.DistributionPackageExporter; +import org.apache.sling.distribution.packaging.DistributionPackageInfo; import org.apache.sling.distribution.packaging.impl.DistributionPackageUtils; import org.apache.sling.distribution.queue.DistributionQueue; import org.apache.sling.distribution.queue.DistributionQueueItem; @@ -77,13 +78,14 @@ public class AgentDistributionPackageExp log.debug("getting packages from queue {}", queueName); DistributionQueue queue = agent.getQueue(queueName); - DistributionQueueItem info = queue.getHead(); + DistributionQueueItem queueItem = queue.getHead(); DistributionPackage distributionPackage; - if (info != null) { + if (queueItem != null) { + DistributionPackageInfo info = DistributionPackageUtils.fromQueueItem(queueItem); DistributionPackageBuilder packageBuilder = packageBuilderProvider.getPackageBuilder(info.getType()); if (packageBuilder != null) { - distributionPackage = packageBuilder.getPackage(resourceResolver, info.getId()); + distributionPackage = packageBuilder.getPackage(resourceResolver, queueItem.getId()); log.info("item {} fetched from the queue", info); if (distributionPackage != null) { result.add(new AgentDistributionPackage(distributionPackage, queue)); @@ -109,13 +111,16 @@ public class AgentDistributionPackageExp log.debug("getting package from queue {}", queueName); DistributionQueue queue = agent.getQueue(queueName); - DistributionQueueItem info = queue.getItem(distributionPackageId); + DistributionQueueItem queueItem = queue.getHead(); DistributionPackage distributionPackage; - if (info != null) { + + if (queueItem != null) { + DistributionPackageInfo info = DistributionPackageUtils.fromQueueItem(queueItem); + DistributionPackageBuilder packageBuilder = packageBuilderProvider.getPackageBuilder(info.getType()); if (packageBuilder != null) { - distributionPackage = packageBuilder.getPackage(resourceResolver, info.getId()); + distributionPackage = packageBuilder.getPackage(resourceResolver, queueItem.getId()); log.info("item {} fetched from the queue", info); if (distributionPackage != null) { return new AgentDistributionPackage(distributionPackage, queue); Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/DistributionQueue.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/DistributionQueue.java?rev=1693250&r1=1693249&r2=1693250&view=diff ============================================================================== --- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/DistributionQueue.java (original) +++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/DistributionQueue.java Wed Jul 29 12:17:10 2015 @@ -47,9 +47,9 @@ public interface DistributionQueue { /** * add a distribution item to this queue * - * @param item a distribution item representing a {@link org.apache.sling.distribution.packaging.DistributionPackage} + * @param item a distribution item, typically representing a {@link org.apache.sling.distribution.packaging.DistributionPackage} * to distribute - * @return {@code true} if the distribution item was added correctly to the queue, + * @return {@code true} if the item was added correctly to the queue, * {@code false} otherwise */ boolean add(@Nonnull DistributionQueueItem item); @@ -87,22 +87,22 @@ public interface DistributionQueue { /** * gets an item from the queue by specifying its id * - * @param packageId the id of the package represented by the item + * @param itemId the id of the item * @return the item, or {@code null} if the item with the given id * doesn't exist */ @CheckForNull - DistributionQueueItem getItem(@Nonnull String packageId); + DistributionQueueItem getItem(@Nonnull String itemId); /** * remove an item from the queue by specifying its id * - * @param packageId the id of the package represented by the item + * @param itemId the id the item * @return the removed item, or {@code null} if the item with the given id * doesn't exist */ @CheckForNull - DistributionQueueItem remove(@Nonnull String packageId); + DistributionQueueItem remove(@Nonnull String itemId); /** Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/DistributionQueueItem.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/DistributionQueueItem.java?rev=1693250&r1=1693249&r2=1693250&view=diff ============================================================================== --- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/DistributionQueueItem.java (original) +++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/DistributionQueueItem.java Wed Jul 29 12:17:10 2015 @@ -20,8 +20,12 @@ package org.apache.sling.distribution.qu import javax.annotation.Nonnull; +import org.apache.sling.api.resource.ValueMap; +import org.apache.sling.api.wrappers.ValueMapDecorator; import org.apache.sling.distribution.packaging.DistributionPackageInfo; +import java.util.Map; + /** * An item in a {@link DistributionQueue} * <p/> @@ -29,18 +33,13 @@ import org.apache.sling.distribution.pac * to keep the package {@link org.apache.sling.distribution.packaging.DistributionPackage#createInputStream() stream} into * the queues. */ -public class DistributionQueueItem { +public class DistributionQueueItem extends ValueMapDecorator implements ValueMap { private final String id; - private final String type; - - private final DistributionPackageInfo packageInfo; - - public DistributionQueueItem(@Nonnull String id, @Nonnull String type, @Nonnull DistributionPackageInfo packageInfo) { + public DistributionQueueItem(@Nonnull String id, Map<String, Object> base) { + super(base); this.id = id; - this.type = type; - this.packageInfo = packageInfo; } @Nonnull @@ -48,22 +47,13 @@ public class DistributionQueueItem { return id; } - @Nonnull - public String getType() { - return type; - } - @Nonnull - public DistributionPackageInfo getPackageInfo() { - return packageInfo; - } @Override public String toString() { return "DistributionQueueItem{" + "id='" + id + '\'' + - ", type='" + type + '\'' + - ", packageInfo=" + packageInfo + + ", info=" + super.toString() + '}'; } } Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/ErrorAwareQueueDispatchingStrategy.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/ErrorAwareQueueDispatchingStrategy.java?rev=1693250&r1=1693249&r2=1693250&view=diff ============================================================================== --- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/ErrorAwareQueueDispatchingStrategy.java (original) +++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/ErrorAwareQueueDispatchingStrategy.java Wed Jul 29 12:17:10 2015 @@ -28,6 +28,7 @@ import org.apache.felix.scr.annotations. import org.apache.felix.scr.annotations.PropertyOption; import org.apache.sling.commons.osgi.PropertiesUtil; import org.apache.sling.distribution.packaging.DistributionPackage; +import org.apache.sling.distribution.packaging.impl.DistributionPackageUtils; import org.apache.sling.distribution.queue.DistributionQueue; import org.apache.sling.distribution.queue.DistributionQueueException; import org.apache.sling.distribution.queue.DistributionQueueItem; @@ -123,9 +124,7 @@ public class ErrorAwareQueueDispatchingS } private DistributionQueueItem getItem(DistributionPackage distributionPackage) { - DistributionQueueItem distributionQueueItem = new DistributionQueueItem(distributionPackage.getId(), - distributionPackage.getType(), - distributionPackage.getInfo()); + DistributionQueueItem distributionQueueItem = DistributionPackageUtils.toQueueItem(distributionPackage); return distributionQueueItem; } Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/MultipleQueueDispatchingStrategy.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/MultipleQueueDispatchingStrategy.java?rev=1693250&r1=1693249&r2=1693250&view=diff ============================================================================== --- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/MultipleQueueDispatchingStrategy.java (original) +++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/MultipleQueueDispatchingStrategy.java Wed Jul 29 12:17:10 2015 @@ -95,9 +95,7 @@ public class MultipleQueueDispatchingStr private DistributionQueueItem getItem(DistributionPackage distributionPackage) { - DistributionQueueItem distributionQueueItem = new DistributionQueueItem(distributionPackage.getId(), - distributionPackage.getType(), - distributionPackage.getInfo()); + DistributionQueueItem distributionQueueItem = DistributionPackageUtils.toQueueItem(distributionPackage); return distributionQueueItem; } Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/PriorityPathQueueDispatchingStrategy.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/PriorityPathQueueDispatchingStrategy.java?rev=1693250&r1=1693249&r2=1693250&view=diff ============================================================================== --- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/PriorityPathQueueDispatchingStrategy.java (original) +++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/PriorityPathQueueDispatchingStrategy.java Wed Jul 29 12:17:10 2015 @@ -23,6 +23,8 @@ import java.util.Arrays; import java.util.List; import org.apache.sling.distribution.packaging.DistributionPackage; +import org.apache.sling.distribution.packaging.DistributionPackageInfo; +import org.apache.sling.distribution.packaging.impl.DistributionPackageUtils; import org.apache.sling.distribution.queue.DistributionQueue; import org.apache.sling.distribution.queue.DistributionQueueException; import org.apache.sling.distribution.queue.DistributionQueueItem; @@ -46,9 +48,10 @@ public class PriorityPathQueueDispatchin } - private DistributionQueue getQueue(DistributionQueueItem distributionPackage, DistributionQueueProvider queueProvider) + private DistributionQueue getQueue(DistributionQueueItem queueItem, DistributionQueueProvider queueProvider) throws DistributionQueueException { - String[] paths = distributionPackage.getPackageInfo().getPaths(); + DistributionPackageInfo packageInfo = DistributionPackageUtils.fromQueueItem(queueItem); + String[] paths = packageInfo.getPaths(); String pp = null; @@ -96,9 +99,7 @@ public class PriorityPathQueueDispatchin } private DistributionQueueItem getItem(DistributionPackage distributionPackage) { - DistributionQueueItem distributionQueueItem = new DistributionQueueItem(distributionPackage.getId(), - distributionPackage.getType(), - distributionPackage.getInfo()); + DistributionQueueItem distributionQueueItem = DistributionPackageUtils.toQueueItem(distributionPackage); return distributionQueueItem; } Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingDistributionQueue.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingDistributionQueue.java?rev=1693250&r1=1693249&r2=1693250&view=diff ============================================================================== --- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingDistributionQueue.java (original) +++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingDistributionQueue.java Wed Jul 29 12:17:10 2015 @@ -88,13 +88,11 @@ public class JobHandlingDistributionQueu Job job = jobManager.getJob(topic, properties); if (job != null) { - DistributionQueueItemStatus itemState = new DistributionQueueItemStatus(job.getCreated(), - ItemState.valueOf(job.getJobState().toString()), - job.getRetryCount(), name); + DistributionQueueItemStatus status = JobHandlingUtils.getStatus(job); - log.info("status of job {} is {}", job.getId(), job.getJobState()); + log.debug("status of job {} is {}", job.getId(), job.getJobState()); - return itemState; + return status; } else { DistributionQueueItemStatus itemState = new DistributionQueueItemStatus(ItemState.DROPPED, name); return itemState; Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingUtils.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingUtils.java?rev=1693250&r1=1693249&r2=1693250&view=diff ============================================================================== --- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingUtils.java (original) +++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingUtils.java Wed Jul 29 12:17:10 2015 @@ -25,48 +25,38 @@ import java.util.Map; import org.apache.sling.distribution.DistributionRequestType; import org.apache.sling.distribution.packaging.DistributionPackageInfo; import org.apache.sling.distribution.queue.DistributionQueueItem; +import org.apache.sling.distribution.queue.DistributionQueueItemStatus; import org.apache.sling.event.jobs.Job; public class JobHandlingUtils { - private static final String PATHS = "distribution.package.paths"; + private static final String DISTRIBUTION_PACKAGE_PREFIX = "distribution."; + private static final String ID = DISTRIBUTION_PACKAGE_PREFIX + "item.id"; - public static final String ID = "distribution.package.id"; - - private static final String TYPE = "distribution.package.type"; - - protected static final String REQUEST_TYPE = "distribution.package.request.type"; + public static DistributionQueueItem getItem(final Job job) { - protected static final String ORIGIN = "distribution.package.origin"; + Map<String, Object> properties = new HashMap<String, Object>(); + for (String key: job.getPropertyNames()) { + if (key.startsWith(DISTRIBUTION_PACKAGE_PREFIX)) { + String infoKey = key.substring(DISTRIBUTION_PACKAGE_PREFIX.length()); + properties.put(infoKey, job.getProperty(key)); + } + } - public static DistributionQueueItem getItem(final Job job) { - DistributionPackageInfo packageInfo = new DistributionPackageInfo(); - packageInfo.setOrigin((URI) job.getProperty(ORIGIN)); - packageInfo.setPaths((String[]) job.getProperty(PATHS)); - packageInfo.setRequestType((DistributionRequestType) job.getProperty(REQUEST_TYPE)); + String id = (String) job.getProperty(ID); - return new DistributionQueueItem((String) job.getProperty(ID), - String.valueOf(job.getProperty(TYPE)), packageInfo); + return new DistributionQueueItem(id, properties); } - public static Map<String, Object> createFullProperties( - DistributionQueueItem distributionQueueItem) { + public static Map<String, Object> createFullProperties(DistributionQueueItem queueItem) { Map<String, Object> properties = new HashMap<String, Object>(); - properties.put(ID, distributionQueueItem.getId()); - properties.put(TYPE, distributionQueueItem.getType()); - - DistributionPackageInfo info = distributionQueueItem.getPackageInfo(); - if (info.getPaths() != null) { - properties.put(PATHS, info.getPaths()); - } - if (info.getRequestType() != null) { - properties.put(REQUEST_TYPE, info.getRequestType()); - } - if (info.getOrigin() != null) { - properties.put(ORIGIN, info.getOrigin()); + for (String key : queueItem.keySet()) { + properties.put(DISTRIBUTION_PACKAGE_PREFIX + key, queueItem.get(key)); } + properties.put(ID, queueItem.getId()); + return properties; } @@ -89,4 +79,15 @@ public class JobHandlingUtils { return queue.substring(idx + 1); } + public static DistributionQueueItemStatus getStatus(final Job job) { + String queueName = getQueueName(job); + + DistributionQueueItemStatus status = new DistributionQueueItemStatus(job.getCreated(), + DistributionQueueItemStatus.ItemState.valueOf(job.getJobState().toString()), + job.getRetryCount(), queueName); + + return status; + } + + } Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/ExtendedDistributionServiceResourceProvider.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/ExtendedDistributionServiceResourceProvider.java?rev=1693250&r1=1693249&r2=1693250&view=diff ============================================================================== --- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/ExtendedDistributionServiceResourceProvider.java (original) +++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/ExtendedDistributionServiceResourceProvider.java Wed Jul 29 12:17:10 2015 @@ -26,6 +26,8 @@ import org.apache.sling.distribution.com import org.apache.sling.distribution.component.impl.DistributionComponentKind; import org.apache.sling.distribution.component.impl.DistributionComponentProvider; import org.apache.sling.distribution.log.DistributionLog; +import org.apache.sling.distribution.packaging.DistributionPackageInfo; +import org.apache.sling.distribution.packaging.impl.DistributionPackageUtils; import org.apache.sling.distribution.queue.DistributionQueue; import org.apache.sling.distribution.queue.DistributionQueueException; import org.apache.sling.distribution.queue.DistributionQueueItem; @@ -160,14 +162,15 @@ public class ExtendedDistributionService String itemId = queueInfo.getChildResourceName(); DistributionQueueItem item = queue.getItem(itemId); + DistributionPackageInfo packageInfo = DistributionPackageUtils.fromQueueItem(item); if (item != null) { result.put(SLING_RESOURCE_TYPE, DistributionResourceTypes.AGENT_QUEUE_ITEM_RESOURCE_TYPE); result.put("id", item.getId()); - result.put("paths", item.getPackageInfo().getPaths()); - result.put("action", item.getPackageInfo().getRequestType()); - result.put("type", item.getType()); + result.put("paths", packageInfo.getPaths()); + result.put("action", packageInfo.getRequestType()); + result.put("type", packageInfo.getType()); DistributionQueueItemStatus status = queue.getStatus(item); result.put("attempts", status.getAttempts()); Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/serialization/impl/AbstractDistributionPackage.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/serialization/impl/AbstractDistributionPackage.java?rev=1693250&r1=1693249&r2=1693250&view=diff ============================================================================== --- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/serialization/impl/AbstractDistributionPackage.java (original) +++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/serialization/impl/AbstractDistributionPackage.java Wed Jul 29 12:17:10 2015 @@ -27,11 +27,27 @@ import org.apache.sling.distribution.pac * abstract implementation of a {@link org.apache.sling.distribution.packaging.DistributionPackage} */ public abstract class AbstractDistributionPackage implements DistributionPackage { - private final DistributionPackageInfo info = new DistributionPackageInfo(); + private final DistributionPackageInfo info; + private final String id; + + protected AbstractDistributionPackage(String id, String type) { + this.id = id; + this.info = new DistributionPackageInfo(type); + } @Nonnull public DistributionPackageInfo getInfo() { return info; } + @Nonnull + public String getId() { + return id; + } + + @Nonnull + public String getType() { + return info.getType(); + } + } Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/serialization/impl/AbstractDistributionPackageBuilder.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/serialization/impl/AbstractDistributionPackageBuilder.java?rev=1693250&r1=1693249&r2=1693250&view=diff ============================================================================== --- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/serialization/impl/AbstractDistributionPackageBuilder.java (original) +++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/serialization/impl/AbstractDistributionPackageBuilder.java Wed Jul 29 12:17:10 2015 @@ -29,6 +29,7 @@ import org.apache.sling.api.resource.Res import org.apache.sling.distribution.DistributionRequest; import org.apache.sling.distribution.DistributionRequestType; import org.apache.sling.distribution.packaging.DistributionPackage; +import org.apache.sling.distribution.packaging.DistributionPackageInfo; import org.apache.sling.distribution.serialization.DistributionPackageBuilder; import org.apache.sling.distribution.serialization.DistributionPackageBuildingException; import org.apache.sling.distribution.serialization.DistributionPackageReadingException; @@ -69,10 +70,12 @@ public abstract class AbstractDistributi throw new DistributionPackageBuildingException("unknown action type " + request.getRequestType()); } + if (distributionPackage != null) { - distributionPackage.getInfo().setRequestType(request.getRequestType()); - distributionPackage.getInfo().setPaths(request.getPaths()); + distributionPackage.getInfo().put(DistributionPackageInfo.PROPERTY_REQUEST_TYPE, request.getRequestType()); + distributionPackage.getInfo().put(DistributionPackageInfo.PROPERTY_REQUEST_PATHS, request.getPaths()); } + return distributionPackage; } Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/serialization/impl/SimpleDistributionPackage.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/serialization/impl/SimpleDistributionPackage.java?rev=1693250&r1=1693249&r2=1693250&view=diff ============================================================================== --- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/serialization/impl/SimpleDistributionPackage.java (original) +++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/serialization/impl/SimpleDistributionPackage.java Wed Jul 29 12:17:10 2015 @@ -28,6 +28,7 @@ import org.apache.sling.distribution.Dis import org.apache.sling.distribution.DistributionRequestType; import org.apache.sling.distribution.SimpleDistributionRequest; import org.apache.sling.distribution.packaging.DistributionPackage; +import org.apache.sling.distribution.packaging.DistributionPackageInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,24 +43,18 @@ public class SimpleDistributionPackage e private final static String DELIM = "|"; private final static String PATH_DELIM = ","; - - private final String type; - private final String[] paths; - private final String id; - private final DistributionRequestType requestType; public SimpleDistributionPackage(DistributionRequest request, String type) { - this.type = type; + super(toIdString(request, type), type); this.paths = request.getPaths(); this.requestType = request.getRequestType(); - this.id = toIdString(request, type); - this.getInfo().setPaths(paths); - this.getInfo().setRequestType(requestType); + this.getInfo().put(DistributionPackageInfo.PROPERTY_REQUEST_PATHS, paths); + this.getInfo().put(DistributionPackageInfo.PROPERTY_REQUEST_TYPE, requestType); } public static String toIdString(DistributionRequest request, String type) { @@ -120,19 +115,11 @@ public class SimpleDistributionPackage e @Nonnull - public String getType() { - return type; - } - - @Nonnull public InputStream createInputStream() throws IOException { - return IOUtils.toInputStream(id, "UTF-8"); + return IOUtils.toInputStream(getId(), "UTF-8"); } - @Nonnull - public String getId() { - return id; - } + public void close() { @@ -145,7 +132,7 @@ public class SimpleDistributionPackage e @Override public String toString() { - return id; + return getId(); } public static SimpleDistributionPackage fromStream(InputStream stream, String type) { Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/serialization/impl/vlt/FileVaultDistributionPackage.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/serialization/impl/vlt/FileVaultDistributionPackage.java?rev=1693250&r1=1693249&r2=1693250&view=diff ============================================================================== --- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/serialization/impl/vlt/FileVaultDistributionPackage.java (original) +++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/serialization/impl/vlt/FileVaultDistributionPackage.java Wed Jul 29 12:17:10 2015 @@ -27,6 +27,7 @@ import java.io.InputStream; import org.apache.jackrabbit.vault.packaging.VaultPackage; import org.apache.sling.distribution.DistributionRequestType; import org.apache.sling.distribution.packaging.DistributionPackage; +import org.apache.sling.distribution.packaging.DistributionPackageInfo; import org.apache.sling.distribution.serialization.impl.AbstractDistributionPackage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,25 +39,15 @@ public class FileVaultDistributionPackag Logger log = LoggerFactory.getLogger(FileVaultDistributionPackage.class); - private static final long serialVersionUID = 1L; - - private final String id; - - private final String type; private final VaultPackage pkg; public FileVaultDistributionPackage(String type, VaultPackage pkg) { - this.type = type; + super(pkg.getFile().getAbsolutePath(), type); this.pkg = pkg; String[] paths = VltUtils.getPaths(pkg.getMetaInf()); - this.getInfo().setPaths(paths); - this.getInfo().setRequestType(DistributionRequestType.ADD); - this.id = pkg.getFile().getAbsolutePath(); - } - @Nonnull - public String getId() { - return id; + this.getInfo().put(DistributionPackageInfo.PROPERTY_REQUEST_PATHS, paths); + this.getInfo().put(DistributionPackageInfo.PROPERTY_REQUEST_TYPE, DistributionRequestType.ADD); } @Nonnull @@ -64,10 +55,6 @@ public class FileVaultDistributionPackag return new FileInputStream(pkg.getFile()); } - @Nonnull - public String getType() { - return type; - } public void close() { pkg.close(); @@ -84,7 +71,7 @@ public class FileVaultDistributionPackag @Override public String toString() { return "FileVaultDistributionPackage{" + - "id='" + id + '\'' + + "id='" + getId() + '\'' + ", pkg=" + pkg + '}'; } Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/serialization/impl/vlt/JcrVaultDistributionPackage.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/serialization/impl/vlt/JcrVaultDistributionPackage.java?rev=1693250&r1=1693249&r2=1693250&view=diff ============================================================================== --- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/serialization/impl/vlt/JcrVaultDistributionPackage.java (original) +++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/serialization/impl/vlt/JcrVaultDistributionPackage.java Wed Jul 29 12:17:10 2015 @@ -29,6 +29,7 @@ import javax.jcr.Session; import org.apache.jackrabbit.vault.packaging.JcrPackage; import org.apache.sling.distribution.DistributionRequestType; import org.apache.sling.distribution.packaging.DistributionPackage; +import org.apache.sling.distribution.packaging.DistributionPackageInfo; import org.apache.sling.distribution.serialization.impl.AbstractDistributionPackage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,13 +39,11 @@ import org.slf4j.LoggerFactory; public class JcrVaultDistributionPackage extends AbstractDistributionPackage implements DistributionPackage { private final Logger log = LoggerFactory.getLogger(getClass()); - - private final String type; private final JcrPackage jcrPackage; private final Session session; public JcrVaultDistributionPackage(String type, JcrPackage jcrPackage, Session session) { - this.type = type; + super(getIdFromPackage(jcrPackage), type); this.jcrPackage = jcrPackage; this.session = session; String[] paths = new String[0]; @@ -53,30 +52,23 @@ public class JcrVaultDistributionPackage } catch (RepositoryException e) { log.error("cannot read paths", e); } - this.getInfo().setPaths(paths); - this.getInfo().setRequestType(DistributionRequestType.ADD); + + this.getInfo().put(DistributionPackageInfo.PROPERTY_REQUEST_PATHS, paths); + this.getInfo().put(DistributionPackageInfo.PROPERTY_REQUEST_TYPE, DistributionRequestType.ADD); } - @Nonnull - public String getId() { + public static String getIdFromPackage(JcrPackage jcrPackage) { try { return jcrPackage.getPackage().getId().getName(); } catch (RepositoryException e) { - log.error("Cannot obtain package id", e); } catch (IOException e) { - log.error("Cannot obtain package id", e); } return null; } @Nonnull - public String getType() { - return type; - } - - @Nonnull public InputStream createInputStream() throws IOException { try { return jcrPackage.getData().getBinary().getStream(); Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/servlet/DistributionAgentQueueServlet.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/servlet/DistributionAgentQueueServlet.java?rev=1693250&r1=1693249&r2=1693250&view=diff ============================================================================== --- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/servlet/DistributionAgentQueueServlet.java (original) +++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/servlet/DistributionAgentQueueServlet.java Wed Jul 29 12:17:10 2015 @@ -28,6 +28,7 @@ import org.apache.sling.api.SlingHttpSer import org.apache.sling.api.resource.ResourceResolver; import org.apache.sling.api.servlets.SlingAllMethodsServlet; import org.apache.sling.distribution.packaging.DistributionPackage; +import org.apache.sling.distribution.packaging.DistributionPackageInfo; import org.apache.sling.distribution.packaging.impl.DistributionPackageUtils; import org.apache.sling.distribution.queue.DistributionQueue; import org.apache.sling.distribution.queue.DistributionQueueItem; @@ -97,7 +98,8 @@ public class DistributionAgentQueueServl protected void deleteItem(ResourceResolver resourceResolver, DistributionQueue queue, DistributionQueueItem item) { String id = item.getId(); queue.remove(id); - String type = item.getType(); + DistributionPackageInfo info = DistributionPackageUtils.fromQueueItem(item); + String type = info.getType(); DistributionPackageBuilder packageBuilder = packageBuilderProvider.getPackageBuilder(type); 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=1693250&r1=1693249&r2=1693250&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 Wed Jul 29 12:17:10 2015 @@ -43,6 +43,7 @@ import org.apache.sling.distribution.Dis import org.apache.sling.distribution.DistributionRequestType; import org.apache.sling.distribution.log.impl.DefaultDistributionLog; import org.apache.sling.distribution.packaging.DistributionPackage; +import org.apache.sling.distribution.packaging.DistributionPackageInfo; import org.apache.sling.distribution.serialization.DistributionPackageBuilder; import org.apache.sling.distribution.servlet.ServletJsonUtils; import org.apache.sling.distribution.transport.DistributionTransportSecretProvider; @@ -158,7 +159,7 @@ public class SimpleHttpDistributionTrans final DistributionPackage responsePackage = packageBuilder.readPackage(resourceResolver, inputStream); if (responsePackage != null) { - responsePackage.getInfo().setOrigin(distributionURI); + responsePackage.getInfo().put(DistributionPackageInfo.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/agent/impl/SimpleDistributionAgentTest.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/agent/impl/SimpleDistributionAgentTest.java?rev=1693250&r1=1693249&r2=1693250&view=diff ============================================================================== --- sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/agent/impl/SimpleDistributionAgentTest.java (original) +++ sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/agent/impl/SimpleDistributionAgentTest.java Wed Jul 29 12:17:10 2015 @@ -77,7 +77,7 @@ public class SimpleDistributionAgentTest DistributionPackage distributionPackage = mock(DistributionPackage.class); ResourceResolver resourceResolver = mock(ResourceResolver.class); - when(distributionPackage.getInfo()).thenReturn(new DistributionPackageInfo()); + when(distributionPackage.getInfo()).thenReturn(new DistributionPackageInfo("type")); when(packageExporter.exportPackages(any(ResourceResolver.class), any(DistributionRequest.class))) .thenReturn(Arrays.asList(distributionPackage)); when(queueProvider.getQueue(DistributionQueueDispatchingStrategy.DEFAULT_QUEUE_NAME)).thenReturn( @@ -107,7 +107,7 @@ public class SimpleDistributionAgentTest DistributionPackage distributionPackage = mock(DistributionPackage.class); ResourceResolver resourceResolver = mock(ResourceResolver.class); - when(distributionPackage.getInfo()).thenReturn(new DistributionPackageInfo()); + when(distributionPackage.getInfo()).thenReturn(new DistributionPackageInfo("type")); Iterable<DistributionQueueItemStatus> states = Arrays.asList(new DistributionQueueItemStatus(DistributionQueueItemStatus.ItemState.QUEUED, DistributionQueueDispatchingStrategy.DEFAULT_QUEUE_NAME)); when(distributionHandler.add(any(DistributionPackage.class), any(DistributionQueueProvider.class))).thenReturn(states); @@ -139,7 +139,7 @@ public class SimpleDistributionAgentTest distributionEventFactory, resolverFactory, mock(DefaultDistributionLog.class), null, null); DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, "/"); DistributionPackage distributionPackage = mock(DistributionPackage.class); - DistributionPackageInfo packageInfo = new DistributionPackageInfo(); + DistributionPackageInfo packageInfo = new DistributionPackageInfo("type"); when(distributionPackage.getInfo()).thenReturn(packageInfo); ResourceResolver resourceResolver = mock(ResourceResolver.class); @@ -243,7 +243,7 @@ public class SimpleDistributionAgentTest DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, "/content"); DistributionPackage distributionPackage = mock(DistributionPackage.class); - DistributionPackageInfo packageInfo = new DistributionPackageInfo(); + DistributionPackageInfo packageInfo = new DistributionPackageInfo("type"); when(distributionPackage.getInfo()).thenReturn(packageInfo); ResourceResolver resourceResolver = mock(ResourceResolver.class); @@ -282,7 +282,7 @@ public class SimpleDistributionAgentTest DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, "/home"); DistributionPackage distributionPackage = mock(DistributionPackage.class); - DistributionPackageInfo packageInfo = new DistributionPackageInfo(); + DistributionPackageInfo packageInfo = new DistributionPackageInfo("type"); when(distributionPackage.getInfo()).thenReturn(packageInfo); ResourceResolver resourceResolver = mock(ResourceResolver.class); Modified: sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/queue/impl/PriorityPathQueueDistributionStrategyTest.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/queue/impl/PriorityPathQueueDistributionStrategyTest.java?rev=1693250&r1=1693249&r2=1693250&view=diff ============================================================================== --- sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/queue/impl/PriorityPathQueueDistributionStrategyTest.java (original) +++ sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/queue/impl/PriorityPathQueueDistributionStrategyTest.java Wed Jul 29 12:17:10 2015 @@ -44,8 +44,8 @@ public class PriorityPathQueueDistributi PriorityPathQueueDispatchingStrategy priorityPathDistributionStrategy = new PriorityPathQueueDispatchingStrategy(new String[]{"/content", "/apps"}); DistributionPackage distributionPackage = mock(DistributionPackage.class); - DistributionPackageInfo packageInfo = new DistributionPackageInfo(); - packageInfo.setPaths(new String[]{"/etc"}); + DistributionPackageInfo packageInfo = new DistributionPackageInfo("type"); + packageInfo.put(DistributionPackageInfo.PROPERTY_REQUEST_PATHS, new String[]{"/etc"}); when(distributionPackage.getInfo()).thenReturn(packageInfo); DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class); DistributionQueue queue = mock(DistributionQueue.class); @@ -67,8 +67,8 @@ public class PriorityPathQueueDistributi PriorityPathQueueDispatchingStrategy priorityPathDistributionStrategy = new PriorityPathQueueDispatchingStrategy(new String[]{"/content", "/apps"}); DistributionPackage distributionPackage = mock(DistributionPackage.class); - DistributionPackageInfo packageInfo = new DistributionPackageInfo(); - packageInfo.setPaths(new String[]{"/content/sample1"}); + DistributionPackageInfo packageInfo = new DistributionPackageInfo("type"); + packageInfo.put(DistributionPackageInfo.PROPERTY_REQUEST_PATHS, new String[]{"/content/sample1"}); when(distributionPackage.getInfo()).thenReturn(packageInfo); DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class); DistributionQueue queue = mock(DistributionQueue.class); @@ -90,7 +90,7 @@ public class PriorityPathQueueDistributi PriorityPathQueueDispatchingStrategy priorityPathDistributionStrategy = new PriorityPathQueueDispatchingStrategy(new String[]{"/content", "/apps"}); DistributionPackage distributionPackage = mock(DistributionPackage.class); - DistributionPackageInfo info = new DistributionPackageInfo(); + DistributionPackageInfo info = new DistributionPackageInfo("type"); when(distributionPackage.getInfo()).thenReturn(info); DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class); DistributionQueue queue = mock(DistributionQueue.class); @@ -110,8 +110,8 @@ public class PriorityPathQueueDistributi PriorityPathQueueDispatchingStrategy priorityPathDistributionStrategy = new PriorityPathQueueDispatchingStrategy(new String[]{"/content", "/apps"}); DistributionPackage distributionPackage = mock(DistributionPackage.class); - DistributionPackageInfo packageInfo = new DistributionPackageInfo(); - packageInfo.setPaths(new String[]{"/content/sample2"}); + DistributionPackageInfo packageInfo = new DistributionPackageInfo("type"); + packageInfo.put(DistributionPackageInfo.PROPERTY_REQUEST_PATHS, new String[]{"/content/sample2"}); when(distributionPackage.getInfo()).thenReturn(packageInfo); DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class); DistributionQueue queue = mock(DistributionQueue.class); @@ -132,8 +132,8 @@ public class PriorityPathQueueDistributi PriorityPathQueueDispatchingStrategy priorityPathDistributionStrategy = new PriorityPathQueueDispatchingStrategy(new String[]{"/content", "/apps"}); DistributionPackage distributionPackage = mock(DistributionPackage.class); - DistributionPackageInfo packageInfo = new DistributionPackageInfo(); - packageInfo.setPaths(new String[]{"/etc"}); + DistributionPackageInfo packageInfo = new DistributionPackageInfo("type"); + packageInfo.put(DistributionPackageInfo.PROPERTY_REQUEST_PATHS, new String[]{"/etc"}); when(distributionPackage.getInfo()).thenReturn(packageInfo); DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class); DistributionQueue queue = mock(DistributionQueue.class); @@ -155,8 +155,8 @@ public class PriorityPathQueueDistributi PriorityPathQueueDispatchingStrategy priorityPathDistributionStrategy = new PriorityPathQueueDispatchingStrategy(new String[]{"/content", "/apps"}); DistributionPackage distributionPackage = mock(DistributionPackage.class); - DistributionPackageInfo packageInfo = new DistributionPackageInfo(); - packageInfo.setPaths(new String[]{"/apps"}); + DistributionPackageInfo packageInfo = new DistributionPackageInfo("type"); + packageInfo.put(DistributionPackageInfo.PROPERTY_REQUEST_PATHS, new String[]{"/apps"}); when(distributionPackage.getInfo()).thenReturn(packageInfo); DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class); DistributionQueue queue = mock(DistributionQueue.class); Modified: sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingDistributionQueueTest.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingDistributionQueueTest.java?rev=1693250&r1=1693249&r2=1693250&view=diff ============================================================================== --- sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingDistributionQueueTest.java (original) +++ sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingDistributionQueueTest.java Wed Jul 29 12:17:10 2015 @@ -59,11 +59,11 @@ public class JobHandlingDistributionQueu when(jobManager.findJobs(JobManager.QueryType.ALL, topic, -1)).thenReturn(Collections.<Job>emptySet()); when(builder.properties(any(Map.class))).thenReturn(builder); DistributionQueue queue = new JobHandlingDistributionQueue("aname", topic, jobManager, true); - DistributionQueueItem distributionQueueItem = mock(DistributionQueueItem.class); - DistributionPackageInfo packageInfo = new DistributionPackageInfo(); - packageInfo.setPaths(new String[]{"/foo"}); - packageInfo.setRequestType(DistributionRequestType.ADD); - when(distributionQueueItem.getPackageInfo()).thenReturn(packageInfo); + DistributionPackageInfo packageInfo = new DistributionPackageInfo("type"); + packageInfo.put(DistributionPackageInfo.PROPERTY_REQUEST_PATHS, new String[]{"/foo"}); + packageInfo.put(DistributionPackageInfo.PROPERTY_REQUEST_TYPE, DistributionRequestType.ADD); + + DistributionQueueItem distributionQueueItem = new DistributionQueueItem("an-id", packageInfo); assertTrue(queue.add(distributionQueueItem)); } @@ -81,11 +81,10 @@ public class JobHandlingDistributionQueu when(jobManager.findJobs(JobManager.QueryType.ALL, topic, -1)).thenReturn(Collections.<Job>emptySet()); when(builder.properties(any(Map.class))).thenReturn(builder); DistributionQueue queue = new JobHandlingDistributionQueue("aname", topic, jobManager, true); - DistributionQueueItem distributionQueueItem = mock(DistributionQueueItem.class); - DistributionPackageInfo packageInfo = new DistributionPackageInfo(); - packageInfo.setPaths(new String[]{"/foo"}); - packageInfo.setRequestType(DistributionRequestType.ADD); - when(distributionQueueItem.getPackageInfo()).thenReturn(packageInfo); + DistributionPackageInfo packageInfo = new DistributionPackageInfo("type"); + packageInfo.put(DistributionPackageInfo.PROPERTY_REQUEST_PATHS, new String[]{"/foo"}); + packageInfo.put(DistributionPackageInfo.PROPERTY_REQUEST_TYPE, DistributionRequestType.ADD); + DistributionQueueItem distributionQueueItem = new DistributionQueueItem("an-id", packageInfo); assertTrue(queue.add(distributionQueueItem)); DistributionQueueItemStatus status = queue.getStatus(distributionQueueItem); assertNotNull(status); Modified: sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingUtilsTest.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingUtilsTest.java?rev=1693250&r1=1693249&r2=1693250&view=diff ============================================================================== --- sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingUtilsTest.java (original) +++ sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingUtilsTest.java Wed Jul 29 12:17:10 2015 @@ -36,24 +36,20 @@ import static org.mockito.Mockito.when; public class JobHandlingUtilsTest { @Test public void testFullPropertiesFromPackageCreation() throws Exception { - DistributionQueueItem distributionQueueItem = mock(DistributionQueueItem.class); - DistributionPackageInfo info = new DistributionPackageInfo(); - info.setRequestType(DistributionRequestType.ADD); - info.setPaths(new String[]{"/content", "/apps"}); - when(distributionQueueItem.getPackageInfo()).thenReturn(info); - when(distributionQueueItem.getId()).thenReturn("an-id"); - when(distributionQueueItem.getType()).thenReturn("vlt"); - DistributionPackageInfo packageInfo = new DistributionPackageInfo(); - packageInfo.setPaths(new String[]{"/foo"}); - packageInfo.setRequestType(DistributionRequestType.ADD); - when(distributionQueueItem.getPackageInfo()).thenReturn(packageInfo); - Map<String, Object> fullPropertiesFromPackage = JobHandlingUtils.createFullProperties(distributionQueueItem); + DistributionPackageInfo packageInfo = new DistributionPackageInfo("vlt"); + packageInfo.put(DistributionPackageInfo.PROPERTY_REQUEST_PATHS, new String[]{"/foo"}); + packageInfo.put(DistributionPackageInfo.PROPERTY_REQUEST_TYPE, DistributionRequestType.ADD); + packageInfo.put(DistributionPackageInfo.PROPERTY_PACKAGE_TYPE, "vlt"); + + DistributionQueueItem queueItem = new DistributionQueueItem("an-id", packageInfo); + + Map<String, Object> fullPropertiesFromPackage = JobHandlingUtils.createFullProperties(queueItem); assertNotNull(fullPropertiesFromPackage); assertEquals(4, fullPropertiesFromPackage.size()); - assertNotNull(fullPropertiesFromPackage.get("distribution.package.paths")); - assertNotNull(fullPropertiesFromPackage.get("distribution.package.id")); + assertNotNull(fullPropertiesFromPackage.get("distribution.request.paths")); + assertNotNull(fullPropertiesFromPackage.get("distribution.item.id")); assertNotNull(fullPropertiesFromPackage.get("distribution.package.type")); - assertNotNull(fullPropertiesFromPackage.get("distribution.package.request.type")); + assertNotNull(fullPropertiesFromPackage.get("distribution.request.type")); } @Test @@ -63,6 +59,6 @@ public class JobHandlingUtilsTest { Map<String, Object> idPropertiesFromPackage = JobHandlingUtils.createIdProperties(distributionPackage.getId()); assertNotNull(idPropertiesFromPackage); assertEquals(1, idPropertiesFromPackage.size()); - assertNotNull(idPropertiesFromPackage.get("distribution.package.id")); + assertNotNull(idPropertiesFromPackage.get("distribution.item.id")); } } Modified: sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/serialization/impl/vlt/FileVaultDistributionPackageBuilderTest.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/serialization/impl/vlt/FileVaultDistributionPackageBuilderTest.java?rev=1693250&r1=1693249&r2=1693250&view=diff ============================================================================== --- sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/serialization/impl/vlt/FileVaultDistributionPackageBuilderTest.java (original) +++ sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/serialization/impl/vlt/FileVaultDistributionPackageBuilderTest.java Wed Jul 29 12:17:10 2015 @@ -138,9 +138,9 @@ public class FileVaultDistributionPackag DistributionPackage distributionPackage = mock(DistributionPackage.class); when(distributionPackage.getId()).thenReturn(tempFile.getAbsolutePath()); when(distributionPackage.getType()).thenReturn("filevlt"); - DistributionPackageInfo info = new DistributionPackageInfo(); - info.setRequestType(DistributionRequestType.ADD); - info.setPaths(new String[]{"/something"}); + DistributionPackageInfo info = new DistributionPackageInfo("filevlt"); + info.put(DistributionPackageInfo.PROPERTY_REQUEST_TYPE, DistributionRequestType.ADD); + info.put(DistributionPackageInfo.PROPERTY_REQUEST_PATHS, new String[]{"/something"}); when(distributionPackage.getInfo()).thenReturn(info); boolean success = fileVaultdistributionPackageBuilder.installPackage(resourceResolver, distributionPackage); @@ -169,9 +169,9 @@ public class FileVaultDistributionPackag DistributionPackage distributionPackage = mock(DistributionPackage.class); when(distributionPackage.getId()).thenReturn(tempFile.getAbsolutePath()); when(distributionPackage.getType()).thenReturn("filevlt"); - DistributionPackageInfo info = new DistributionPackageInfo(); - info.setRequestType(DistributionRequestType.ADD); - info.setPaths(new String[]{"/something"}); + DistributionPackageInfo info = new DistributionPackageInfo("filevlt"); + info.put(DistributionPackageInfo.PROPERTY_REQUEST_TYPE, DistributionRequestType.ADD); + info.put(DistributionPackageInfo.PROPERTY_REQUEST_PATHS, new String[]{"/something"}); when(distributionPackage.getInfo()).thenReturn(info); boolean success = fileVaultdistributionPackageBuilder.installPackage(resourceResolver, distributionPackage); Modified: sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/transport/impl/SimpleHttpDistributionTransportTest.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/transport/impl/SimpleHttpDistributionTransportTest.java?rev=1693250&r1=1693249&r2=1693250&view=diff ============================================================================== --- sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/transport/impl/SimpleHttpDistributionTransportTest.java (original) +++ sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/transport/impl/SimpleHttpDistributionTransportTest.java Wed Jul 29 12:17:10 2015 @@ -78,7 +78,7 @@ public class SimpleHttpDistributionTrans endpoint, packageBuilder, secretProvider, maxNoOfPackages); ResourceResolver resourceResolver = mock(ResourceResolver.class); DistributionPackage distributionPackage = mock(DistributionPackage.class); - when(distributionPackage.getInfo()).thenReturn(new DistributionPackageInfo()); + when(distributionPackage.getInfo()).thenReturn(new DistributionPackageInfo("type")); InputStream stream = mock(InputStream.class); when(distributionPackage.createInputStream()).thenReturn(stream); simpleHttpDistributionTransport.deliverPackage(resourceResolver, distributionPackage); @@ -139,7 +139,7 @@ public class SimpleHttpDistributionTrans DistributionEndpoint endpoint = new DistributionEndpoint("http://127.0.0.1:8080/some/resource"); DistributionPackageBuilder packageBuilder = mock(DistributionPackageBuilder.class); DistributionPackage distributionPackage = mock(DistributionPackage.class); - when(distributionPackage.getInfo()).thenReturn(new DistributionPackageInfo()); + when(distributionPackage.getInfo()).thenReturn(new DistributionPackageInfo("type")); when(packageBuilder.readPackage(any(ResourceResolver.class), any(InputStream.class))).thenReturn(distributionPackage); int maxNoOfPackages = 1; SimpleHttpDistributionTransport simpleHttpDistributionTransport = new SimpleHttpDistributionTransport(mock(DefaultDistributionLog.class), Modified: sling/trunk/contrib/extensions/distribution/it/src/test/java/org/apache/sling/distribution/it/DistributionUtils.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/it/src/test/java/org/apache/sling/distribution/it/DistributionUtils.java?rev=1693250&r1=1693249&r2=1693250&view=diff ============================================================================== --- sling/trunk/contrib/extensions/distribution/it/src/test/java/org/apache/sling/distribution/it/DistributionUtils.java (original) +++ sling/trunk/contrib/extensions/distribution/it/src/test/java/org/apache/sling/distribution/it/DistributionUtils.java Wed Jul 29 12:17:10 2015 @@ -29,7 +29,7 @@ import org.apache.http.NameValuePair; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.entity.ByteArrayEntity; import org.apache.http.message.BasicNameValuePair; -import org.apache.jackrabbit.vault.util.Text; +import org.apache.jackrabbit.util.Text; import org.apache.sling.commons.json.JSONArray; import org.apache.sling.commons.json.JSONException; import org.apache.sling.commons.json.JSONObject; @@ -205,6 +205,7 @@ public class DistributionUtils { if (!slingClient.exists(parentPath)) { createNode(slingClient, parentPath); } + slingClient.createNode(nodePath, "jcr:primaryType", "nt:unstructured", "propName", "propValue"); return nodePath; } @@ -222,7 +223,6 @@ public class DistributionUtils { slingClient.createNode(path, "jcr:primaryType", "nt:unstructured"); } - public static String agentRootUrl() { return DISTRIBUTION_ROOT_PATH + "/services/agents"; }