Search in sources :

Example 1 with SimpleDistributionPackage

use of org.apache.sling.distribution.packaging.impl.SimpleDistributionPackage in project sling by apache.

the class SimpleDistributionPackageTest method testSimplePackageFromTest.

@Test
public void testSimplePackageFromTest() throws Exception {
    DistributionRequest distributionRequest = new SimpleDistributionRequest(DistributionRequestType.TEST);
    SimpleDistributionPackage createdPackage = new SimpleDistributionPackage(distributionRequest, "VOID");
    SimpleDistributionPackage readPackage = SimpleDistributionPackage.fromStream(new ByteArrayInputStream(("DSTRPCK:TEST|").getBytes()), "VOID");
    assertNotNull(readPackage);
    assertEquals(createdPackage.getType(), readPackage.getType());
    assertEquals(createdPackage.getInfo().getRequestType(), readPackage.getInfo().getRequestType());
    assertEquals(Arrays.toString(createdPackage.getInfo().getPaths()), Arrays.toString(readPackage.getInfo().getPaths()));
    assertEquals(createdPackage.getId(), readPackage.getId());
    assertTrue(IOUtils.contentEquals(createdPackage.createInputStream(), readPackage.createInputStream()));
}
Also used : SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) SimpleDistributionPackage(org.apache.sling.distribution.packaging.impl.SimpleDistributionPackage) Test(org.junit.Test)

Example 2 with SimpleDistributionPackage

use of org.apache.sling.distribution.packaging.impl.SimpleDistributionPackage in project sling by apache.

the class SimpleDistributionPackageTest method testCreatedAndReadPackagesEquality.

@Test
public void testCreatedAndReadPackagesEquality() throws Exception {
    DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.DELETE, "/abc");
    SimpleDistributionPackage createdPackage = new SimpleDistributionPackage(request, "VOID");
    SimpleDistributionPackage readPackage = SimpleDistributionPackage.fromStream(new ByteArrayInputStream(("DSTRPCK:DELETE|/abc").getBytes()), "VOID");
    assertNotNull(readPackage);
    assertEquals(createdPackage.getType(), readPackage.getType());
    assertEquals(createdPackage.getInfo().getRequestType(), readPackage.getInfo().getRequestType());
    assertEquals(Arrays.toString(createdPackage.getInfo().getPaths()), Arrays.toString(readPackage.getInfo().getPaths()));
    assertEquals(createdPackage.getId(), readPackage.getId());
    assertTrue(IOUtils.contentEquals(createdPackage.createInputStream(), readPackage.createInputStream()));
}
Also used : SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) SimpleDistributionPackage(org.apache.sling.distribution.packaging.impl.SimpleDistributionPackage) Test(org.junit.Test)

Example 3 with SimpleDistributionPackage

use of org.apache.sling.distribution.packaging.impl.SimpleDistributionPackage 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

SimpleDistributionPackage (org.apache.sling.distribution.packaging.impl.SimpleDistributionPackage)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DistributionRequest (org.apache.sling.distribution.DistributionRequest)2 SimpleDistributionRequest (org.apache.sling.distribution.SimpleDistributionRequest)2 Test (org.junit.Test)2 DistributionException (org.apache.sling.distribution.common.DistributionException)1 DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)1 DistributionPackageBuilder (org.apache.sling.distribution.packaging.DistributionPackageBuilder)1 DistributionPackageInfo (org.apache.sling.distribution.packaging.DistributionPackageInfo)1 DistributionQueue (org.apache.sling.distribution.queue.DistributionQueue)1 DistributionQueueEntry (org.apache.sling.distribution.queue.DistributionQueueEntry)1 DistributionQueueItem (org.apache.sling.distribution.queue.DistributionQueueItem)1