Search in sources :

Example 31 with DistributionPackage

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());
}
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 32 with DistributionPackage

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"));
}
Also used : FileDistributionPackageBuilder(org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) FileDistributionPackageBuilder(org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder) DistributionPackageBuilder(org.apache.sling.distribution.packaging.DistributionPackageBuilder) Resource(org.apache.sling.api.resource.Resource) DistributionContentSerializer(org.apache.sling.distribution.serialization.DistributionContentSerializer) Test(org.junit.Test)

Example 33 with DistributionPackage

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"));
}
Also used : FileDistributionPackageBuilder(org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) FileDistributionPackageBuilder(org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder) DistributionPackageBuilder(org.apache.sling.distribution.packaging.DistributionPackageBuilder) Resource(org.apache.sling.api.resource.Resource) DistributionContentSerializer(org.apache.sling.distribution.serialization.DistributionContentSerializer) Test(org.junit.Test)

Example 34 with DistributionPackage

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;
}
Also used : DistributionExportOptions(org.apache.sling.distribution.serialization.DistributionExportOptions) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DigestUtils.openDigestOutputStream(org.apache.sling.distribution.util.impl.DigestUtils.openDigestOutputStream) DigestOutputStream(java.security.DigestOutputStream) OutputStream(java.io.OutputStream) DigestUtils.openDigestOutputStream(org.apache.sling.distribution.util.impl.DigestUtils.openDigestOutputStream) FileOutputStream(java.io.FileOutputStream) DigestOutputStream(java.security.DigestOutputStream) FileOutputStream(java.io.FileOutputStream) DistributionExportFilter(org.apache.sling.distribution.serialization.DistributionExportFilter) DistributionException(org.apache.sling.distribution.common.DistributionException) IOException(java.io.IOException) File(java.io.File)

Example 35 with 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);
    }
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) SimpleDistributionPackage(org.apache.sling.distribution.packaging.impl.SimpleDistributionPackage) DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) DistributionPackageBuilder(org.apache.sling.distribution.packaging.DistributionPackageBuilder) DistributionException(org.apache.sling.distribution.common.DistributionException) SimpleDistributionPackage(org.apache.sling.distribution.packaging.impl.SimpleDistributionPackage) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) DistributionException(org.apache.sling.distribution.common.DistributionException)

Aggregations

DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)59 Test (org.junit.Test)41 DistributionPackageInfo (org.apache.sling.distribution.packaging.DistributionPackageInfo)25 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)21 DistributionRequest (org.apache.sling.distribution.DistributionRequest)17 SimpleDistributionRequest (org.apache.sling.distribution.SimpleDistributionRequest)17 DistributionPackageBuilder (org.apache.sling.distribution.packaging.DistributionPackageBuilder)16 DefaultDistributionLog (org.apache.sling.distribution.log.impl.DefaultDistributionLog)12 DistributionQueueProvider (org.apache.sling.distribution.queue.DistributionQueueProvider)12 HashMap (java.util.HashMap)11 DistributionQueueItemStatus (org.apache.sling.distribution.queue.DistributionQueueItemStatus)10 DistributionException (org.apache.sling.distribution.common.DistributionException)9 DistributionPackageProcessor (org.apache.sling.distribution.packaging.DistributionPackageProcessor)9 SlingRepository (org.apache.sling.jcr.api.SlingRepository)9 InputStream (java.io.InputStream)8 DistributionEventFactory (org.apache.sling.distribution.event.impl.DistributionEventFactory)8 FileDistributionPackageBuilder (org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder)8 Resource (org.apache.sling.api.resource.Resource)7 DistributionPackageExporter (org.apache.sling.distribution.packaging.DistributionPackageExporter)7 DistributionQueue (org.apache.sling.distribution.queue.DistributionQueue)7