Search in sources :

Example 21 with DistributionQueue

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

the class JobHandlingDistributionQueueProviderTest method testGetOrCreateNamedQueue.

@Test
public void testGetOrCreateNamedQueue() throws Exception {
    JobManager jobManager = mock(JobManager.class);
    BundleContext context = mock(BundleContext.class);
    JobHandlingDistributionQueueProvider jobHandlingdistributionQueueProvider = new JobHandlingDistributionQueueProvider("dummy-agent", jobManager, context);
    DistributionQueue queue = jobHandlingdistributionQueueProvider.getQueue("default");
    assertNotNull(queue);
}
Also used : DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) JobManager(org.apache.sling.event.jobs.JobManager) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 22 with DistributionQueue

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

the class PriorityQueueDispatchingStrategyTest method testNoMatchingDispatching.

@Test
public void testNoMatchingDispatching() throws Exception {
    PriorityQueueDispatchingStrategy dispatchingStrategy = new PriorityQueueDispatchingStrategy(selectors, queueNames);
    DistributionPackage distributionPackage = mock(SharedDistributionPackage.class);
    DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(DistributionPackageInfo.PROPERTY_REQUEST_PATHS, new String[] { "/content/other" });
    when(distributionPackage.getInfo()).thenReturn(new DistributionPackageInfo("vlt", properties));
    DistributionQueue other1 = mock(DistributionQueue.class);
    when(other1.getName()).thenReturn("publish1");
    when(queueProvider.getQueue("publish1")).thenReturn(other1);
    DistributionQueue other2 = mock(DistributionQueue.class);
    when(other2.getName()).thenReturn("publish2");
    when(queueProvider.getQueue("publish2")).thenReturn(other2);
    dispatchingStrategy.add(distributionPackage, queueProvider);
    verify(queueProvider).getQueue("publish1");
    verify(queueProvider).getQueue("publish2");
    verifyNoMoreInteractions(queueProvider);
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) SharedDistributionPackage(org.apache.sling.distribution.packaging.impl.SharedDistributionPackage) DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) HashMap(java.util.HashMap) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) Test(org.junit.Test)

Example 23 with DistributionQueue

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

the class SingleQueueDistributionStrategyTest method testPackageAdditionWithNotNullItemStateFromTheQueue.

@Test
public void testPackageAdditionWithNotNullItemStateFromTheQueue() throws Exception {
    SingleQueueDispatchingStrategy singleQueueDistributionStrategy = new SingleQueueDispatchingStrategy();
    DistributionPackage distributionPackage = mock(DistributionPackage.class);
    DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
    DistributionQueue queue = mock(DistributionQueue.class);
    when(queueProvider.getQueue(DistributionQueueDispatchingStrategy.DEFAULT_QUEUE_NAME)).thenReturn(queue);
    DistributionQueueItemStatus state = mock(DistributionQueueItemStatus.class);
    when(queue.add(any(DistributionQueueItem.class))).thenReturn(new DistributionQueueEntry(null, null, state));
    Iterable<DistributionQueueItemStatus> returnedStates = singleQueueDistributionStrategy.add(distributionPackage, queueProvider);
    assertNotNull(returnedStates);
    Iterator<DistributionQueueItemStatus> iterator = returnedStates.iterator();
    assertNotNull(iterator);
    assertTrue(iterator.hasNext());
    assertNotNull(iterator.next());
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) Test(org.junit.Test)

Example 24 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 25 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)

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