Search in sources :

Example 26 with DistributionQueueEntry

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

the class SimpleDistributionQueueProviderTest method testEnableQueueProcessingWithCheckpointRecovery.

@Test
public void testEnableQueueProcessingWithCheckpointRecovery() throws Exception {
    File checkpointDirectory = new File("dummy-agent-simple-queues-checkpoints");
    File file = new File(getClass().getResource("/dummy-agent-checkpoint").getFile());
    FileUtils.copyFileToDirectory(file, checkpointDirectory);
    Scheduler scheduler = mock(Scheduler.class);
    ScheduleOptions options = mock(ScheduleOptions.class);
    when(scheduler.NOW(-1, 1)).thenReturn(options);
    when(scheduler.NOW(-1, 15)).thenReturn(options);
    when(options.canRunConcurrently(false)).thenReturn(options);
    when(options.name(any(String.class))).thenReturn(options);
    String name = "dummy-agent";
    try {
        SimpleDistributionQueueProvider simpledistributionQueueProvider = new SimpleDistributionQueueProvider(scheduler, name, true);
        DistributionQueueProcessor processor = mock(DistributionQueueProcessor.class);
        simpledistributionQueueProvider.enableQueueProcessing(processor, name);
        DistributionQueue queue = simpledistributionQueueProvider.getQueue(name);
        assertNotNull(queue);
        assertEquals(1, queue.getStatus().getItemsCount());
        DistributionQueueEntry head = queue.getHead();
        assertNotNull(head);
        DistributionQueueItem item = head.getItem();
        assertNotNull(item);
        String packageId = item.getPackageId();
        assertNotNull(packageId);
        assertEquals("DSTRQ1", item.get("internal.request.id"));
        assertArrayEquals(new String[] { "/foo", "bar" }, (String[]) item.get("request.paths"));
        assertArrayEquals(new String[] { "/foo" }, (String[]) item.get("request.deepPaths"));
        assertEquals("admin", item.get("internal.request.user"));
        assertEquals("ADD", item.get("request.type"));
        assertEquals("default", item.get("package.type"));
        assertEquals("1464090250095", item.get("internal.request.startTime"));
    } finally {
        FileUtils.deleteDirectory(new File(name + "-simple-queues-checkpoints"));
    }
}
Also used : DistributionQueueProcessor(org.apache.sling.distribution.queue.DistributionQueueProcessor) ScheduleOptions(org.apache.sling.commons.scheduler.ScheduleOptions) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) Scheduler(org.apache.sling.commons.scheduler.Scheduler) File(java.io.File) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) Test(org.junit.Test)

Example 27 with DistributionQueueEntry

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

the class SimpleDistributionQueue method getHead.

@CheckForNull
public DistributionQueueEntry getHead() {
    DistributionQueueItem element = queue.peek();
    if (element != null) {
        DistributionQueueItemStatus itemState = statusMap.get(element);
        statusMap.put(element, new DistributionQueueItemStatus(itemState.getEntered(), itemState.getItemState(), itemState.getAttempts() + 1, name));
        return new DistributionQueueEntry(element.getPackageId(), element, itemState);
    }
    return null;
}
Also used : DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) CheckForNull(javax.annotation.CheckForNull)

Example 28 with DistributionQueueEntry

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

the class JobHandlingUtils method getEntry.

@CheckForNull
public static DistributionQueueEntry getEntry(final Job job) {
    DistributionQueueItem item = getItem(job);
    DistributionQueueItemStatus itemStatus = getStatus(job);
    if (item != null && itemStatus != null) {
        return new DistributionQueueEntry(escapeId(job.getId()), item, itemStatus);
    }
    return null;
}
Also used : DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) CheckForNull(javax.annotation.CheckForNull)

Example 29 with DistributionQueueEntry

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

the class SimpleDistributionQueue method add.

public DistributionQueueEntry add(@Nonnull DistributionQueueItem item) {
    DistributionQueueItemState itemState = DistributionQueueItemState.ERROR;
    boolean result = false;
    try {
        result = queue.offer(item);
        itemState = DistributionQueueItemState.QUEUED;
    } catch (Exception e) {
        log.error("cannot add an item to the queue", e);
    } finally {
        statusMap.put(item, new DistributionQueueItemStatus(Calendar.getInstance(), itemState, 0, name));
    }
    if (result) {
        return new DistributionQueueEntry(item.getPackageId(), item, statusMap.get(item));
    }
    return null;
}
Also used : DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) DistributionQueueItemState(org.apache.sling.distribution.queue.DistributionQueueItemState)

Example 30 with DistributionQueueEntry

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

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