use of org.apache.sling.distribution.queue.DistributionQueueEntry in project sling by apache.
the class DistributionAgentQueueServlet method addItems.
private void addItems(ResourceResolver resourceResolver, DistributionQueue targetQueue, DistributionQueue sourceQueue, String[] ids) {
for (String id : ids) {
DistributionQueueEntry entry = sourceQueue.getItem(id);
if (entry != null) {
targetQueue.add(entry.getItem());
DistributionPackage distributionPackage = getPackage(resourceResolver, entry.getItem());
DistributionPackageUtils.acquire(distributionPackage, targetQueue.getName());
}
}
}
use of org.apache.sling.distribution.queue.DistributionQueueEntry in project sling by apache.
the class ExtendedDistributionServiceResourceProvider method getQueueProperties.
private Map<String, Object> getQueueProperties(DistributionAgent agent, SimplePathInfo queueInfo) {
if (queueInfo.isRoot()) {
Map<String, Object> result = new HashMap<String, Object>();
List<String> nameList = new ArrayList<String>();
for (String name : agent.getQueueNames()) {
nameList.add(name);
}
result.put(ITEMS, nameList.toArray(new String[nameList.size()]));
result.put(SLING_RESOURCE_TYPE, DistributionResourceTypes.AGENT_QUEUE_LIST_RESOURCE_TYPE);
return result;
} else if (queueInfo.isMain()) {
String queueName = queueInfo.getMainResourceName();
Map<String, Object> result = new HashMap<String, Object>();
DistributionQueue queue = agent.getQueue(queueName);
if (queue != null) {
DistributionQueueStatus queueStatus = queue.getStatus();
result.put(SLING_RESOURCE_TYPE, DistributionResourceTypes.AGENT_QUEUE_RESOURCE_TYPE);
result.put("state", queueStatus.getState().name());
result.put("empty", queueStatus.isEmpty());
result.put("itemsCount", queueStatus.getItemsCount());
if (queueName.startsWith(ErrorQueueDispatchingStrategy.ERROR_PREFIX)) {
String retryQueue = queueName.replace(ErrorQueueDispatchingStrategy.ERROR_PREFIX, "");
result.put("retryQueue", retryQueue);
}
List<String> nameList = new ArrayList<String>();
DistributionQueueEntry entry = queue.getHead();
if (entry != null) {
nameList.add(entry.getId());
}
result.put(ITEMS, nameList.toArray(new String[nameList.size()]));
result.put(INTERNAL_ITEMS_ITERATOR, new QueueItemsIterator(queue));
result.put(INTERNAL_ADAPTABLE, queue);
}
return result;
} else if (queueInfo.isChild()) {
String queueName = queueInfo.getMainResourceName();
Map<String, Object> result = new HashMap<String, Object>();
DistributionQueue queue = agent.getQueue(queueName);
if (queue != null) {
String itemId = queueInfo.getChildResourceName();
DistributionQueueEntry entry = queue.getItem(itemId);
result = getItemProperties(entry);
}
return result;
}
return null;
}
use of org.apache.sling.distribution.queue.DistributionQueueEntry in project sling by apache.
the class DistributionAgentJobConsumer method process.
public JobResult process(Job job) {
log.debug("processing job {}", job.getId());
DistributionQueueEntry entry = JobHandlingUtils.getEntry(job);
boolean processingResult = false;
if (entry != null) {
String queueName = entry.getStatus().getQueueName();
log.debug("processing item {} in queue {}", entry.getId(), queueName);
processingResult = queueProcessor.process(queueName, entry);
log.debug("item {} processed {}", entry.getId());
} else {
log.warn("no entry for job {}", job.getId());
}
return processingResult ? JobResult.OK : JobResult.FAILED;
}
use of org.apache.sling.distribution.queue.DistributionQueueEntry in project sling by apache.
the class JobHandlingDistributionQueue method getItems.
@Nonnull
public List<DistributionQueueEntry> getItems(int skip, int limit) {
List<DistributionQueueEntry> items = new ArrayList<DistributionQueueEntry>();
Collection<Job> jobs = getJobs(skip, limit);
for (Job job : jobs) {
items.add(JobHandlingUtils.getEntry(job));
}
return items;
}
use of org.apache.sling.distribution.queue.DistributionQueueEntry in project sling by apache.
the class SimpleDistributionAgentQueueProcessorTest method testProcess.
@Test
public void testProcess() throws Exception {
DistributionPackageExporter packageExporter = mock(DistributionPackageExporter.class);
DistributionPackageImporter packageImporter = mock(DistributionPackageImporter.class);
int retryAttempts = 3;
DefaultDistributionLog log = mock(DefaultDistributionLog.class);
DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
DistributionEventFactory eventFactory = mock(DistributionEventFactory.class);
SimpleDistributionAgentAuthenticationInfo authenticationInfo = mock(SimpleDistributionAgentAuthenticationInfo.class);
String agentName = "dummy-a";
SimpleDistributionAgentQueueProcessor queueProcessor = new SimpleDistributionAgentQueueProcessor(packageExporter, packageImporter, retryAttempts, null, log, queueProvider, eventFactory, authenticationInfo, agentName);
String id = "123-456";
DistributionQueueItem item = new DistributionQueueItem("pckg-123", new HashMap<String, Object>());
String queueName = "queue-1";
DistributionQueueItemStatus status = new DistributionQueueItemStatus(DistributionQueueItemState.QUEUED, queueName);
DistributionQueueEntry entry = new DistributionQueueEntry(id, item, status);
queueProcessor.process(queueName, entry);
}
Aggregations