Search in sources :

Example 11 with DistributionQueueItemStatus

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

the class SingleQueueDistributionStrategyTest method testPackageAdditionWithFailingItemDelivery.

@Test
public void testPackageAdditionWithFailingItemDelivery() throws Exception {
    SingleQueueDispatchingStrategy singleQueueDistributionStrategy = new SingleQueueDispatchingStrategy();
    DistributionPackage distributionPackage = mock(DistributionPackage.class);
    DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
    DistributionQueue queue = mock(DistributionQueue.class);
    DistributionQueueItem queueItem = mock(DistributionQueueItem.class);
    when(queueProvider.getQueue(DistributionQueueDispatchingStrategy.DEFAULT_QUEUE_NAME)).thenReturn(queue);
    DistributionQueueItemStatus state = mock(DistributionQueueItemStatus.class);
    when(queue.add(queueItem)).thenReturn(new DistributionQueueEntry(null, queueItem, 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 12 with DistributionQueueItemStatus

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

the class SingleQueueDistributionStrategyTest method testPackageAdditionWithSucceedingItemDelivery.

@Test
public void testPackageAdditionWithSucceedingItemDelivery() 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 13 with DistributionQueueItemStatus

use of org.apache.sling.distribution.queue.DistributionQueueItemStatus 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 14 with DistributionQueueItemStatus

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

the class QueueingDistributionPackageProcessor method scheduleImportPackage.

private Collection<SimpleDistributionResponse> scheduleImportPackage(DistributionPackage distributionPackage, String callingUser, String requestId, long startTime) {
    Collection<SimpleDistributionResponse> distributionResponses = new LinkedList<SimpleDistributionResponse>();
    // dispatch the distribution package to one or more queues
    try {
        // add metadata to the package
        distributionPackage.getInfo().put(DistributionPackageUtils.PACKAGE_INFO_PROPERTY_REQUEST_USER, callingUser);
        distributionPackage.getInfo().put(DistributionPackageUtils.PACKAGE_INFO_PROPERTY_REQUEST_ID, requestId);
        distributionPackage.getInfo().put(DistributionPackageUtils.PACKAGE_INFO_PROPERTY_REQUEST_START_TIME, startTime);
        // put the package in the queue
        Iterable<DistributionQueueItemStatus> states = scheduleQueueStrategy.add(distributionPackage, queueProvider);
        for (DistributionQueueItemStatus state : states) {
            DistributionRequestState requestState = getRequestStateFromQueueState(state.getItemState());
            distributionResponses.add(new SimpleDistributionResponse(requestState, state.getItemState().toString()));
        }
        distributionEventFactory.generatePackageEvent(DistributionEventTopics.AGENT_PACKAGE_QUEUED, DistributionComponentKind.AGENT, agentName, distributionPackage.getInfo());
    } catch (DistributionException e) {
        log.error("an error happened during dispatching items to the queue(s)", e);
        distributionResponses.add(new SimpleDistributionResponse(DistributionRequestState.DROPPED, e.toString()));
    }
    return distributionResponses;
}
Also used : DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) SimpleDistributionResponse(org.apache.sling.distribution.impl.SimpleDistributionResponse) DistributionRequestState(org.apache.sling.distribution.DistributionRequestState) DistributionException(org.apache.sling.distribution.common.DistributionException) LinkedList(java.util.LinkedList)

Example 15 with DistributionQueueItemStatus

use of org.apache.sling.distribution.queue.DistributionQueueItemStatus 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

DistributionQueueItemStatus (org.apache.sling.distribution.queue.DistributionQueueItemStatus)30 DistributionQueueItem (org.apache.sling.distribution.queue.DistributionQueueItem)20 Test (org.junit.Test)18 DistributionQueueEntry (org.apache.sling.distribution.queue.DistributionQueueEntry)16 DistributionQueue (org.apache.sling.distribution.queue.DistributionQueue)14 DistributionQueueProvider (org.apache.sling.distribution.queue.DistributionQueueProvider)12 DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)11 DistributionPackageInfo (org.apache.sling.distribution.packaging.DistributionPackageInfo)9 DistributionEventFactory (org.apache.sling.distribution.event.impl.DistributionEventFactory)8 DefaultDistributionLog (org.apache.sling.distribution.log.impl.DefaultDistributionLog)8 DistributionPackageExporter (org.apache.sling.distribution.packaging.DistributionPackageExporter)7 DistributionPackageImporter (org.apache.sling.distribution.packaging.DistributionPackageImporter)7 DistributionQueueDispatchingStrategy (org.apache.sling.distribution.queue.impl.DistributionQueueDispatchingStrategy)7 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)6 ResourceResolverFactory (org.apache.sling.api.resource.ResourceResolverFactory)6 SlingRepository (org.apache.sling.jcr.api.SlingRepository)6 HashMap (java.util.HashMap)5 DistributionRequest (org.apache.sling.distribution.DistributionRequest)5 SimpleDistributionRequest (org.apache.sling.distribution.SimpleDistributionRequest)5 DistributionPackageProcessor (org.apache.sling.distribution.packaging.DistributionPackageProcessor)5