use of org.apache.sling.distribution.packaging.DistributionPackageInfo in project sling by apache.
the class AgentDistributionPackageExporter method getPackage.
public DistributionPackage getPackage(@Nonnull ResourceResolver resourceResolver, @Nonnull String distributionPackageId) {
try {
log.debug("getting package from queue {}", queueName);
DistributionQueue queue = getQueueOrThrow(queueName);
DistributionQueueEntry entry = queue.getItem(distributionPackageId);
DistributionPackage distributionPackage;
if (entry != null) {
DistributionQueueItem queueItem = entry.getItem();
DistributionPackageInfo info = DistributionPackageUtils.fromQueueItem(queueItem);
DistributionPackageBuilder packageBuilder = packageBuilderProvider.getPackageBuilder(info.getType());
if (packageBuilder != null) {
distributionPackage = packageBuilder.getPackage(resourceResolver, queueItem.getPackageId());
distributionPackage.getInfo().putAll(info);
log.debug("item {} fetched from the queue", info);
if (distributionPackage != null) {
return new AgentDistributionPackage(distributionPackage, queue, entry.getId());
}
} else {
log.warn("cannot find package builder with type {}", info.getType());
}
}
} catch (Exception ex) {
log.error("Error exporting package", ex);
}
return null;
}
use of org.apache.sling.distribution.packaging.DistributionPackageInfo in project sling by apache.
the class DistributionAgentQueueServlet method getPackage.
private DistributionPackage getPackage(ResourceResolver resourceResolver, DistributionQueueItem item) {
DistributionPackageInfo info = DistributionPackageUtils.fromQueueItem(item);
String type = info.getType();
DistributionPackageBuilder packageBuilder = packageBuilderProvider.getPackageBuilder(type);
if (packageBuilder != null) {
try {
return packageBuilder.getPackage(resourceResolver, item.getPackageId());
} catch (DistributionException e) {
log.error("cannot get package", e);
}
}
return null;
}
use of org.apache.sling.distribution.packaging.DistributionPackageInfo in project sling by apache.
the class RemoteDistributionPackageImporter method importPackage.
public void importPackage(@Nonnull ResourceResolver resourceResolver, @Nonnull DistributionPackage distributionPackage) throws DistributionException {
DistributionPackageInfo info = distributionPackage.getInfo();
String queueName = DistributionPackageUtils.getQueueName(info);
DistributionTransport distributionTransport = transportHandlers.get(queueName);
if (distributionTransport != null) {
distributionTransport.deliverPackage(resourceResolver, distributionPackage, distributionContext);
} else {
for (DistributionTransport transportHandler : transportHandlers.values()) {
transportHandler.deliverPackage(resourceResolver, distributionPackage, distributionContext);
}
}
}
use of org.apache.sling.distribution.packaging.DistributionPackageInfo in project sling by apache.
the class QueueingDistributionPackageProcessorTest method testProcess.
@Test
public void testProcess() throws Exception {
String callingUser = "mr-who-cares";
String requestId = "id231";
long startTime = System.currentTimeMillis();
DistributionEventFactory eventFactory = mock(DistributionEventFactory.class);
DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
DistributionPackage distributionPackage = mock(DistributionPackage.class);
DistributionQueueDispatchingStrategy scheduleQueueStrategy = mock(DistributionQueueDispatchingStrategy.class);
// assume scheduling works
List<DistributionQueueItemStatus> statuses = new LinkedList<DistributionQueueItemStatus>();
DistributionQueueItemStatus qis = new DistributionQueueItemStatus(DistributionQueueItemState.QUEUED, "queue-1");
statuses.add(qis);
when(scheduleQueueStrategy.add(distributionPackage, queueProvider)).thenReturn(statuses);
DefaultDistributionLog log = mock(DefaultDistributionLog.class);
String agentName = "dummy";
QueueingDistributionPackageProcessor exporterProcessor = new QueueingDistributionPackageProcessor(callingUser, requestId, startTime, eventFactory, scheduleQueueStrategy, queueProvider, log, agentName);
DistributionPackageInfo info = new DistributionPackageInfo("type-a", new HashMap<String, Object>());
when(distributionPackage.getInfo()).thenReturn(info);
exporterProcessor.process(distributionPackage);
}
use of org.apache.sling.distribution.packaging.DistributionPackageInfo in project sling by apache.
the class SimpleDistributionAgentTest method testDistributionWithDisallowedRoot.
@Test
public void testDistributionWithDisallowedRoot() throws Exception {
String name = "sample-agent";
DistributionPackageImporter packageImporter = mock(DistributionPackageImporter.class);
DistributionPackageExporter packageExporter = mock(DistributionPackageExporter.class);
DistributionRequestAuthorizationStrategy packageExporterStrategy = mock(DistributionRequestAuthorizationStrategy.class);
DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
DistributionQueueDispatchingStrategy queueDistributionStrategy = mock(DistributionQueueDispatchingStrategy.class);
DistributionEventFactory distributionEventFactory = mock(DistributionEventFactory.class);
ResourceResolverFactory resolverFactory = mock(ResourceResolverFactory.class);
when(queueDistributionStrategy.add(any(DistributionPackage.class), any(DistributionQueueProvider.class))).thenReturn(Collections.singletonList(new DistributionQueueItemStatus(DistributionQueueItemState.QUEUED, "default")));
SimpleDistributionAgent agent = new SimpleDistributionAgent(name, false, null, "serviceName", packageImporter, packageExporter, packageExporterStrategy, queueProvider, queueDistributionStrategy, null, distributionEventFactory, resolverFactory, mock(SlingRepository.class), mock(DefaultDistributionLog.class), null, new String[] { "/content" }, 0);
DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, "/home");
final DistributionPackage distributionPackage = mock(DistributionPackage.class);
DistributionPackageInfo packageInfo = new DistributionPackageInfo("type");
when(distributionPackage.getInfo()).thenReturn(packageInfo);
ResourceResolver resourceResolver = mock(ResourceResolver.class);
queueDistributionStrategy.add(distributionPackage, queueProvider);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
Object[] args = invocationOnMock.getArguments();
((DistributionPackageProcessor) args[2]).process(distributionPackage);
return null;
}
}).when(packageExporter).exportPackages(any(ResourceResolver.class), any(DistributionRequest.class), any(DistributionPackageProcessor.class));
when(queueProvider.getQueue(DistributionQueueDispatchingStrategy.DEFAULT_QUEUE_NAME)).thenReturn(new SimpleDistributionQueue(name, "name"));
DistributionResponse response = agent.execute(resourceResolver, request);
assertFalse(response.isSuccessful());
}
Aggregations