You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by GitBox <gi...@apache.org> on 2018/05/24 12:48:33 UTC
[GitHub] mpetria closed pull request #8: SLING-7555: option to drop ghost
packages from and agent exporter
mpetria closed pull request #8: SLING-7555: option to drop ghost packages from and agent exporter
URL: https://github.com/apache/sling-org-apache-sling-distribution-core/pull/8
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/pom.xml b/pom.xml
index 123393b..8e19597 100644
--- a/pom.xml
+++ b/pom.xml
@@ -71,13 +71,7 @@
<Export-Package>
org.apache.sling.distribution.util,
org.apache.sling.distribution.common,
- org.apache.sling.distribution.serialization,
- org.apache.sling.distribution.queue.spi,
- org.apache.sling.distribution.queue,
- org.apache.sling.distribution.log.spi,
- org.apache.sling.distribution.agent,
- org.apache.sling.distribution.agent.spi,
- org.apache.sling.distribution.packaging
+ org.apache.sling.distribution.serialization
</Export-Package>
<Import-Package>
org.apache.http.nio.*;resolution:=optional,
diff --git a/src/main/java/org/apache/sling/distribution/packaging/impl/exporter/AgentDistributionPackageExporter.java b/src/main/java/org/apache/sling/distribution/packaging/impl/exporter/AgentDistributionPackageExporter.java
index 63744a0..6662b13 100644
--- a/src/main/java/org/apache/sling/distribution/packaging/impl/exporter/AgentDistributionPackageExporter.java
+++ b/src/main/java/org/apache/sling/distribution/packaging/impl/exporter/AgentDistributionPackageExporter.java
@@ -50,15 +50,17 @@
private final Logger log = LoggerFactory.getLogger(getClass());
private final DistributionPackageBuilderProvider packageBuilderProvider;
private final String name;
+ private boolean dropInvalidItems;
private final static String PACKAGE_TYPE = "agentexporter";
private DistributionAgent agent;
private String queueName;
- public AgentDistributionPackageExporter(String queueName, DistributionAgent agent, DistributionPackageBuilderProvider packageBuilderProvider, String name) {
+ public AgentDistributionPackageExporter(String queueName, DistributionAgent agent, DistributionPackageBuilderProvider packageBuilderProvider, String name, boolean dropInvalidItems) {
this.packageBuilderProvider = packageBuilderProvider;
this.name = name;
+ this.dropInvalidItems = dropInvalidItems;
if (agent == null || packageBuilderProvider == null) {
throw new IllegalArgumentException("Agent and package builder are required");
@@ -99,7 +101,12 @@ public void exportPackages(@Nonnull ResourceResolver resourceResolver, @Nonnull
packageProcessor.process(new AgentDistributionPackage(distributionPackage, queue, entry.getId()));
} else {
- log.warn("cannot get package {}", info);
+ if (dropInvalidItems) {
+ queue.remove(entry.getId());
+ log.warn("ghost package: cannot get package {} dropping from queue", info);
+ } else {
+ log.warn("ghost package: cannot get package {} keeping in queue", info);
+ }
}
} else {
log.warn("cannot find package builder with type {}", info.getType());
diff --git a/src/main/java/org/apache/sling/distribution/packaging/impl/exporter/AgentDistributionPackageExporterFactory.java b/src/main/java/org/apache/sling/distribution/packaging/impl/exporter/AgentDistributionPackageExporterFactory.java
index 1d6fd01..8671c0d 100644
--- a/src/main/java/org/apache/sling/distribution/packaging/impl/exporter/AgentDistributionPackageExporterFactory.java
+++ b/src/main/java/org/apache/sling/distribution/packaging/impl/exporter/AgentDistributionPackageExporterFactory.java
@@ -34,6 +34,7 @@
import org.apache.sling.distribution.agent.spi.DistributionAgent;
import org.apache.sling.distribution.common.DistributionException;
import org.apache.sling.distribution.component.impl.DistributionComponentConstants;
+import org.apache.sling.distribution.component.impl.SettingsUtils;
import org.apache.sling.distribution.packaging.DistributionPackage;
import org.apache.sling.distribution.packaging.impl.DistributionPackageBuilderProvider;
import org.apache.sling.distribution.packaging.impl.DistributionPackageExporter;
@@ -61,10 +62,14 @@
@Property(label = "Queue", description = "The name of the queue from which the packages should be exported.")
private static final String QUEUE_NAME = "queue";
+ @Property(label = "Drop invalid queue items", description = "Remove invalid items from the queue.", boolValue = false)
+ private static final String DROP_INVALID_QUEUE_ITEMS = "drop.invalid.items";
+
@Property(name = "agent.target", label = "The target reference for the DistributionAgent that will be used to export packages.")
@Reference(name = "agent")
private DistributionAgent agent;
+
@Reference
private DistributionPackageBuilderProvider packageBuilderProvider;
@@ -75,10 +80,14 @@
public void activate(Map<String, Object> config) throws Exception {
String queueName = PropertiesUtil.toString(config.get(QUEUE_NAME), DistributionQueueDispatchingStrategy.DEFAULT_QUEUE_NAME);
+ queueName = SettingsUtils.removeEmptyEntry(queueName);
+ queueName = queueName == null ? DistributionQueueDispatchingStrategy.DEFAULT_QUEUE_NAME : queueName;
+
String name = PropertiesUtil.toString(config.get(NAME), "");
+ boolean dropInvalidItems = PropertiesUtil.toBoolean(config.get(DROP_INVALID_QUEUE_ITEMS), false);
- packageExporter = new AgentDistributionPackageExporter(queueName, agent, packageBuilderProvider, name);
+ packageExporter = new AgentDistributionPackageExporter(queueName, agent, packageBuilderProvider, name, dropInvalidItems);
}
public void exportPackages(@Nonnull ResourceResolver resourceResolver, @Nonnull DistributionRequest distributionRequest, @Nonnull DistributionPackageProcessor packageProcessor) throws DistributionException {
diff --git a/src/main/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingDistributionQueue.java b/src/main/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingDistributionQueue.java
index 9a7ee28..e2b383e 100644
--- a/src/main/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingDistributionQueue.java
+++ b/src/main/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingDistributionQueue.java
@@ -98,8 +98,8 @@ private Job getFirstJob() {
List<Job> jobs = getJobs(0, 1);
if (jobs.size() > 0) {
Job firstItem = jobs.get(0);
- log.debug("first item in the queue is {}, retried {} times", firstItem.getId(), firstItem.getRetryCount());
- return firstItem;
+ log.debug("first item in the queue is {}, retried {} times, state {}",
+ new Object[]{ firstItem.getId(), firstItem.getRetryCount(), firstItem.getJobState() }); return firstItem;
}
return null;
}
@@ -110,6 +110,9 @@ private Job getJob(String itemId) {
if (job == null) {
log.warn("item with id {} cannot be found", itemId);
+ } else {
+ log.debug("retrieved item with id {}, retried {} times, state {}",
+ new Object[]{ job.getId(), job.getRetryCount(), job.getJobState() });
}
return job;
diff --git a/src/test/java/org/apache/sling/distribution/packaging/impl/exporter/AgentDistributionPackageExporterTest.java b/src/test/java/org/apache/sling/distribution/packaging/impl/exporter/AgentDistributionPackageExporterTest.java
index ff811a8..32699aa 100644
--- a/src/test/java/org/apache/sling/distribution/packaging/impl/exporter/AgentDistributionPackageExporterTest.java
+++ b/src/test/java/org/apache/sling/distribution/packaging/impl/exporter/AgentDistributionPackageExporterTest.java
@@ -42,7 +42,7 @@
@Test
public void testTestExport() throws Exception {
AgentDistributionPackageExporter distributionPackageExporter = new AgentDistributionPackageExporter(null,
- mock(DistributionAgent.class), mock(DistributionPackageBuilderProvider.class), null);
+ mock(DistributionAgent.class), mock(DistributionPackageBuilderProvider.class), null, true);
ResourceResolver resourceResolver = mock(ResourceResolver.class);
String[] args = new String[0]; // vargarg doesn't match and causes compiler warning
DistributionRequest distributionRequest = new SimpleDistributionRequest(DistributionRequestType.TEST, args);
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services