use of org.apache.sling.distribution.queue.DistributionQueueItemStatus 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;
}
use of org.apache.sling.distribution.queue.DistributionQueueItemStatus 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;
}
use of org.apache.sling.distribution.queue.DistributionQueueItemStatus 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;
}
use of org.apache.sling.distribution.queue.DistributionQueueItemStatus in project sling by apache.
the class SimpleDistributionQueueTest method testPackageAdditionRetrievalAndRemoval.
@Test
public void testPackageAdditionRetrievalAndRemoval() throws Exception {
DistributionQueue queue = new SimpleDistributionQueue("agentName", "default");
DistributionQueueItem pkg = mock(DistributionQueueItem.class);
when(pkg.getPackageId()).thenReturn("id");
assertNotNull(queue.add(pkg));
assertFalse(queue.getStatus().isEmpty());
assertEquals(pkg, queue.getHead().getItem());
assertFalse(queue.getStatus().isEmpty());
DistributionQueueItemStatus status = queue.getItem(pkg.getPackageId()).getStatus();
assertNotNull(queue.remove(pkg.getPackageId()));
assertTrue(queue.getStatus().isEmpty());
assertNotNull(status);
assertEquals(1, status.getAttempts());
}
use of org.apache.sling.distribution.queue.DistributionQueueItemStatus 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());
}
Aggregations