use of org.apache.sling.distribution.packaging.DistributionPackage 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());
}
use of org.apache.sling.distribution.packaging.DistributionPackage in project sling by apache.
the class AvroContentSerializerTest method testBuildAndInstallOnSingleShallowPath.
@Test
public void testBuildAndInstallOnSingleShallowPath() throws Exception {
String type = "avro";
DistributionContentSerializer contentSerializer = new AvroContentSerializer(type);
String tempFilesFolder = "target";
String[] nodeFilters = new String[0];
String[] propertyFilters = new String[0];
DistributionPackageBuilder packageBuilder = new FileDistributionPackageBuilder(type, contentSerializer, tempFilesFolder, null, nodeFilters, propertyFilters);
DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, "/libs/sub");
DistributionPackage distributionPackage = packageBuilder.createPackage(resourceResolver, request);
Resource resource = resourceResolver.getResource("/libs/sub");
resourceResolver.delete(resource);
resourceResolver.commit();
assertTrue(packageBuilder.installPackage(resourceResolver, distributionPackage));
assertNotNull(resourceResolver.getResource("/libs"));
assertNotNull(resourceResolver.getResource("/libs/sub"));
assertNotNull(resourceResolver.getResource("/libs/sameLevel"));
}
use of org.apache.sling.distribution.packaging.DistributionPackage in project sling by apache.
the class AvroContentSerializerTest method testBuildAndInstallOnMultipleShallowPaths.
@Test
public void testBuildAndInstallOnMultipleShallowPaths() throws Exception {
String type = "avro";
DistributionContentSerializer contentSerializer = new AvroContentSerializer(type);
String tempFilesFolder = "target";
String[] nodeFilters = new String[0];
String[] propertyFilters = new String[0];
DistributionPackageBuilder packageBuilder = new FileDistributionPackageBuilder(type, contentSerializer, tempFilesFolder, null, nodeFilters, propertyFilters);
DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, "/libs/sub", "/libs/sameLevel");
DistributionPackage distributionPackage = packageBuilder.createPackage(resourceResolver, request);
Resource resource = resourceResolver.getResource("/libs/sub");
resourceResolver.delete(resource);
resource = resourceResolver.getResource("/libs/sameLevel");
resourceResolver.delete(resource);
resourceResolver.commit();
assertTrue(packageBuilder.installPackage(resourceResolver, distributionPackage));
assertNotNull(resourceResolver.getResource("/libs"));
assertNotNull(resourceResolver.getResource("/libs/sub"));
assertNotNull(resourceResolver.getResource("/libs/sameLevel"));
}
use of org.apache.sling.distribution.packaging.DistributionPackage in project sling by apache.
the class FileDistributionPackageBuilder method createPackageForAdd.
@Override
protected DistributionPackage createPackageForAdd(@Nonnull ResourceResolver resourceResolver, @Nonnull final DistributionRequest request) throws DistributionException {
DistributionPackage distributionPackage;
OutputStream outputStream = null;
String digestMessage = null;
final File file;
try {
file = File.createTempFile("distrpck-create-" + randomUUID(), "." + getType(), tempDirectory);
if (digestAlgorithm != null) {
outputStream = openDigestOutputStream(new FileOutputStream(file), digestAlgorithm);
} else {
outputStream = new FileOutputStream(file);
}
final DistributionExportFilter filter = distributionContentSerializer.isRequestFiltering() ? null : DistributionExportFilter.createFilter(request, nodeFilters, propertyFilters);
DistributionExportOptions distributionExportOptions = new DistributionExportOptions(request, filter);
distributionContentSerializer.exportToStream(resourceResolver, distributionExportOptions, outputStream);
outputStream.flush();
if (digestAlgorithm != null) {
digestMessage = readDigestMessage((DigestOutputStream) outputStream);
}
distributionPackage = new FileDistributionPackage(file, getType(), digestAlgorithm, digestMessage);
} catch (IOException e) {
throw new DistributionException(e);
} finally {
IOUtils.closeQuietly(outputStream);
}
return distributionPackage;
}
use of org.apache.sling.distribution.packaging.DistributionPackage in project sling by apache.
the class AgentDistributionPackageExporter method exportPackages.
public void exportPackages(@Nonnull ResourceResolver resourceResolver, @Nonnull DistributionRequest distributionRequest, @Nonnull DistributionPackageProcessor packageProcessor) throws DistributionException {
if (DistributionRequestType.TEST.equals(distributionRequest.getRequestType())) {
packageProcessor.process(new SimpleDistributionPackage(distributionRequest, PACKAGE_TYPE));
return;
}
if (!DistributionRequestType.PULL.equals(distributionRequest.getRequestType())) {
throw new DistributionException("request type not supported " + distributionRequest.getRequestType());
}
DistributionPackage distributionPackage = null;
try {
log.debug("getting packages from queue {}", queueName);
DistributionQueue queue = getQueueOrThrow(queueName);
DistributionQueueEntry entry = queue.getHead();
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());
if (distributionPackage != null) {
distributionPackage.getInfo().putAll(info);
log.debug("item {} fetched from the queue", info);
packageProcessor.process(new AgentDistributionPackage(distributionPackage, queue, entry.getId()));
} else {
log.warn("cannot get package {}", info);
}
} else {
log.warn("cannot find package builder with type {}", info.getType());
}
}
} catch (Exception ex) {
log.error("Error exporting package", ex);
} finally {
DistributionPackageUtils.closeSafely(distributionPackage);
}
}
Aggregations