Search in sources :

Example 31 with DistributionQueue

use of org.apache.sling.distribution.queue.DistributionQueue in project sling by apache.

the class DistributionQueueHealthCheckTest method testWithNotOkItemInTheQueue.

@Test
public void testWithNotOkItemInTheQueue() throws Exception {
    DistributionQueueHealthCheck distributionQueueHealthCheck = new DistributionQueueHealthCheck();
    distributionQueueHealthCheck.activate(Collections.<String, Object>emptyMap());
    DistributionQueue queue = mock(DistributionQueue.class);
    DistributionQueueItem item = mock(DistributionQueueItem.class);
    DistributionQueueItemStatus status = mock(DistributionQueueItemStatus.class);
    when(status.getAttempts()).thenReturn(10);
    when(queue.getItem(any(String.class))).thenReturn(new DistributionQueueEntry(null, item, status));
    when(queue.getHead()).thenReturn(new DistributionQueueEntry(null, item, status));
    DistributionAgent distributionAgent = mock(DistributionAgent.class);
    List<String> queues = new ArrayList<String>();
    queues.add("queueName");
    when(distributionAgent.getQueueNames()).thenReturn(queues);
    when(distributionAgent.getQueue(anyString())).thenReturn(queue);
    distributionQueueHealthCheck.bindDistributionAgent(distributionAgent);
    Result result = distributionQueueHealthCheck.execute();
    assertNotNull(result);
    assertFalse(result.isOk());
}
Also used : DistributionAgent(org.apache.sling.distribution.agent.DistributionAgent) DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) Result(org.apache.sling.hc.api.Result) Test(org.junit.Test)

Example 32 with DistributionQueue

use of org.apache.sling.distribution.queue.DistributionQueue in project sling by apache.

the class SimpleDistributionAgent method getQueue.

public DistributionQueue getQueue(@Nonnull final String queueName) {
    Set<String> queues = getQueueNames();
    if (!queues.contains(queueName)) {
        return null;
    }
    DistributionQueue queue = null;
    try {
        queue = queueProvider.getQueue(queueName);
    } catch (DistributionException e) {
        log.error("cannot get queue", e);
    }
    if (queue != null) {
        boolean isPausedQueue = !queueProcessingEnabled && (processingQueues != null && processingQueues.contains(queueName));
        queue = new SimpleAgentDistributionQueue(queue, isPausedQueue, name);
    }
    return queue;
}
Also used : SimpleAgentDistributionQueue(org.apache.sling.distribution.queue.impl.SimpleAgentDistributionQueue) SimpleAgentDistributionQueue(org.apache.sling.distribution.queue.impl.SimpleAgentDistributionQueue) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionException(org.apache.sling.distribution.common.DistributionException)

Example 33 with DistributionQueue

use of org.apache.sling.distribution.queue.DistributionQueue in project sling by apache.

the class DistributionQueueHealthCheck method execute.

public Result execute() {
    final FormattingResultLog resultLog = new FormattingResultLog();
    Map<String, Integer> failures = new HashMap<String, Integer>();
    if (distributionAgents.size() > 0) {
        for (DistributionAgent distributionAgent : distributionAgents) {
            for (String queueName : distributionAgent.getQueueNames()) {
                try {
                    DistributionQueue q = distributionAgent.getQueue(queueName);
                    DistributionQueueEntry entry = q.getHead();
                    if (entry != null) {
                        DistributionQueueItemStatus status = entry.getStatus();
                        if (status.getAttempts() <= numberOfRetriesAllowed) {
                            resultLog.debug("Queue: [{}], first item: [{}], number of retries: {}", q.getName(), entry.getId(), status.getAttempts());
                        } else {
                            // the no. of attempts is higher than the configured threshold
                            resultLog.warn("Queue: [{}], first item: [{}], number of retries: {}, expected number of retries <= {}", q.getName(), entry.getId(), status.getAttempts(), numberOfRetriesAllowed);
                            failures.put(q.getName(), status.getAttempts());
                        }
                    } else {
                        resultLog.debug("No items in queue [{}]", q.getName());
                    }
                } catch (Exception e) {
                    resultLog.warn("Exception while inspecting distribution queue [{}]: {}", queueName, e);
                }
            }
        }
    } else {
        resultLog.debug("No distribution queue providers found");
    }
    if (failures.size() > 0) {
        // a specific log entry (using markdown) to provide a recommended user action
        for (Map.Entry<String, Integer> entry : failures.entrySet()) {
            resultLog.warn("Distribution queue {}'s first item in the default queue has been retried {} times (threshold: {})", entry.getKey(), entry.getValue(), numberOfRetriesAllowed);
        }
    }
    return new Result(resultLog);
}
Also used : DistributionAgent(org.apache.sling.distribution.agent.DistributionAgent) DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) HashMap(java.util.HashMap) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) FormattingResultLog(org.apache.sling.hc.util.FormattingResultLog) Result(org.apache.sling.hc.api.Result) HashMap(java.util.HashMap) Map(java.util.Map)

Example 34 with DistributionQueue

use of org.apache.sling.distribution.queue.DistributionQueue in project sling by apache.

the class AsyncDeliveryDispatchingStrategy method add.

@Override
public Iterable<DistributionQueueItemStatus> add(@Nonnull DistributionPackage distributionPackage, @Nonnull DistributionQueueProvider queueProvider) throws DistributionException {
    if (!(distributionPackage instanceof SharedDistributionPackage) && deliveryMappings.size() > 1) {
        throw new DistributionException("distribution package must be a shared package to be added in multiple queues");
    }
    String distributionPackageId = distributionPackage.getId();
    List<DistributionQueueItemStatus> result = new LinkedList<DistributionQueueItemStatus>();
    for (String referenceQueueName : deliveryMappings.keySet()) {
        DistributionQueue queue = queueProvider.getQueue(referenceQueueName);
        int MAX_QUEUE_ITEMS_THRESHOLD = 100;
        if (queue.getStatus().getItemsCount() > MAX_QUEUE_ITEMS_THRESHOLD) {
            // too many items in the queue, let's send actual packages and references separately
            distributionPackage.getInfo().put("reference-required", true);
            DistributionQueueItem item = getItem(distributionPackage);
            // create and acquire reference package
            ReferencePackage referencePackage = new ReferencePackage(distributionPackage);
            DistributionPackageUtils.acquire(referencePackage, referenceQueueName);
            // acquire actual package
            String deliveryQueueName = deliveryMappings.get(referenceQueueName);
            DistributionPackageUtils.acquire(distributionPackage, deliveryQueueName);
            // add the actual package to the delivery queue
            DistributionQueue deliveryQueue = queueProvider.getQueue(deliveryQueueName);
            DistributionQueueEntry deliveryQueueEntry = deliveryQueue.add(item);
            if (deliveryQueueEntry != null) {
                DistributionQueueItemStatus status = deliveryQueueEntry.getStatus();
                log.debug("item {} added to delivery queue: {}", item, status);
                result.add(status);
            } else {
                DistributionPackageUtils.release(distributionPackage, deliveryQueueName);
                log.error("cannot add package {} to delivery queue {}", distributionPackageId, deliveryQueueName);
                result.add(new DistributionQueueItemStatus(DistributionQueueItemState.ERROR, deliveryQueue.getName()));
            }
            // add the reference package to the reference queue
            DistributionQueue referenceQueue = queueProvider.getQueue(referenceQueueName);
            DistributionQueueItem referenceQueueItem = getItem(referencePackage);
            DistributionQueueEntry referenceQueueEntry = referenceQueue.add(referenceQueueItem);
            if (referenceQueueEntry != null) {
                DistributionQueueItemStatus status = referenceQueueEntry.getStatus();
                log.debug("item {} added to reference queue: {}", referenceQueueItem, status);
            } else {
                DistributionPackageUtils.release(referencePackage, referenceQueueName);
                log.error("cannot add package {} to reference queue {}", distributionPackageId, referenceQueueName);
                result.add(new DistributionQueueItemStatus(DistributionQueueItemState.ERROR, referenceQueue.getName()));
            }
        } else {
            // normal queueing
            DistributionQueueItem item = getItem(distributionPackage);
            DistributionQueueItemStatus status = new DistributionQueueItemStatus(DistributionQueueItemState.ERROR, queue.getName());
            DistributionPackageUtils.acquire(distributionPackage, referenceQueueName);
            DistributionQueueEntry queueEntry = queue.add(item);
            if (queueEntry != null) {
                status = queueEntry.getStatus();
                log.debug("item {} added to queue: {}", item, status);
            } else {
                DistributionPackageUtils.release(distributionPackage, referenceQueueName);
                log.error("cannot add package {} to queue {}", distributionPackageId, referenceQueueName);
            }
            result.add(status);
        }
    }
    return result;
}
Also used : ReferencePackage(org.apache.sling.distribution.packaging.impl.ReferencePackage) DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) SharedDistributionPackage(org.apache.sling.distribution.packaging.impl.SharedDistributionPackage) DistributionException(org.apache.sling.distribution.common.DistributionException) LinkedList(java.util.LinkedList) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem)

Example 35 with DistributionQueue

use of org.apache.sling.distribution.queue.DistributionQueue in project sling by apache.

the class ErrorQueueDispatchingStrategy method add.

@Override
public Iterable<DistributionQueueItemStatus> add(@Nonnull DistributionPackage distributionPackage, @Nonnull DistributionQueueProvider queueProvider) throws DistributionException {
    List<DistributionQueueItemStatus> result = new ArrayList<DistributionQueueItemStatus>();
    String originQueue = DistributionPackageUtils.getQueueName(distributionPackage.getInfo());
    if (!queueNames.contains(originQueue)) {
        return result;
    }
    String errorQueueName = ERROR_PREFIX + originQueue;
    DistributionQueue errorQueue = queueProvider.getQueue(errorQueueName);
    DistributionQueueItemStatus status = new DistributionQueueItemStatus(DistributionQueueItemState.ERROR, errorQueueName);
    DistributionQueueItem queueItem = DistributionPackageUtils.toQueueItem(distributionPackage);
    DistributionPackageUtils.acquire(distributionPackage, errorQueueName);
    DistributionQueueEntry queueEntry = errorQueue.add(queueItem);
    if (queueEntry != null) {
        status = queueEntry.getStatus();
    } else {
        DistributionPackageUtils.releaseOrDelete(distributionPackage, errorQueueName);
        log.error("cannot add package {} to queue {}", distributionPackage.getId(), errorQueueName);
    }
    result.add(status);
    return result;
}
Also used : DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) ArrayList(java.util.ArrayList) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem)

Aggregations

DistributionQueue (org.apache.sling.distribution.queue.DistributionQueue)40 Test (org.junit.Test)25 DistributionQueueItem (org.apache.sling.distribution.queue.DistributionQueueItem)20 DistributionQueueEntry (org.apache.sling.distribution.queue.DistributionQueueEntry)18 DistributionQueueItemStatus (org.apache.sling.distribution.queue.DistributionQueueItemStatus)14 HashMap (java.util.HashMap)8 DistributionQueueProvider (org.apache.sling.distribution.queue.DistributionQueueProvider)8 DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)7 DistributionPackageInfo (org.apache.sling.distribution.packaging.DistributionPackageInfo)7 ArrayList (java.util.ArrayList)6 File (java.io.File)5 Map (java.util.Map)5 DistributionAgent (org.apache.sling.distribution.agent.DistributionAgent)5 Matchers.anyString (org.mockito.Matchers.anyString)5 DistributionException (org.apache.sling.distribution.common.DistributionException)4 SharedDistributionPackage (org.apache.sling.distribution.packaging.impl.SharedDistributionPackage)4 DistributionQueueStatus (org.apache.sling.distribution.queue.DistributionQueueStatus)4 Result (org.apache.sling.hc.api.Result)4 LinkedList (java.util.LinkedList)3 Scheduler (org.apache.sling.commons.scheduler.Scheduler)3