Search in sources :

Example 6 with DistributionQueueEntry

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());
        }
    }
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry)

Example 7 with DistributionQueueEntry

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;
}
Also used : DistributionQueueStatus(org.apache.sling.distribution.queue.DistributionQueueStatus) HashMap(java.util.HashMap) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with DistributionQueueEntry

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;
}
Also used : DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry)

Example 9 with DistributionQueueEntry

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;
}
Also used : DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) ArrayList(java.util.ArrayList) Job(org.apache.sling.event.jobs.Job) Nonnull(javax.annotation.Nonnull)

Example 10 with DistributionQueueEntry

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);
}
Also used : DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) DistributionPackageExporter(org.apache.sling.distribution.packaging.DistributionPackageExporter) DistributionEventFactory(org.apache.sling.distribution.event.impl.DistributionEventFactory) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) DistributionPackageImporter(org.apache.sling.distribution.packaging.DistributionPackageImporter) Test(org.junit.Test)

Aggregations

DistributionQueueEntry (org.apache.sling.distribution.queue.DistributionQueueEntry)30 DistributionQueueItem (org.apache.sling.distribution.queue.DistributionQueueItem)20 DistributionQueue (org.apache.sling.distribution.queue.DistributionQueue)18 DistributionQueueItemStatus (org.apache.sling.distribution.queue.DistributionQueueItemStatus)16 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)6 DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)6 HashMap (java.util.HashMap)5 LinkedList (java.util.LinkedList)5 DistributionQueueProvider (org.apache.sling.distribution.queue.DistributionQueueProvider)5 File (java.io.File)4 DistributionException (org.apache.sling.distribution.common.DistributionException)4 Map (java.util.Map)3 CheckForNull (javax.annotation.CheckForNull)3 DistributionAgent (org.apache.sling.distribution.agent.DistributionAgent)3 DistributionPackageInfo (org.apache.sling.distribution.packaging.DistributionPackageInfo)3 SharedDistributionPackage (org.apache.sling.distribution.packaging.impl.SharedDistributionPackage)3 DistributionQueueStatus (org.apache.sling.distribution.queue.DistributionQueueStatus)3 Result (org.apache.sling.hc.api.Result)3 DistributionPackageBuilder (org.apache.sling.distribution.packaging.DistributionPackageBuilder)2