Search in sources :

Example 6 with DistributionPackage

use of org.apache.sling.distribution.packaging.DistributionPackage in project sling by apache.

the class AbstractDistributionPackageBuilder method getPackage.

@CheckForNull
public DistributionPackage getPackage(@Nonnull ResourceResolver resourceResolver, @Nonnull String id) {
    DistributionPackage distributionPackage = SimpleDistributionPackage.fromIdString(id, type);
    // not a simple package
    if (distributionPackage == null) {
        if (id.startsWith("reference")) {
            String localId = id.substring("reference-".length());
            distributionPackage = new ReferencePackage(getPackageInternal(resourceResolver, localId));
        } else {
            distributionPackage = getPackageInternal(resourceResolver, id);
        }
    }
    return distributionPackage;
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) CheckForNull(javax.annotation.CheckForNull)

Example 7 with DistributionPackage

use of org.apache.sling.distribution.packaging.DistributionPackage in project sling by apache.

the class AbstractDistributionPackageBuilder method installPackage.

@Nonnull
@Override
public DistributionPackageInfo installPackage(@Nonnull ResourceResolver resourceResolver, @Nonnull InputStream stream) throws DistributionException {
    if (!stream.markSupported()) {
        stream = new BufferedInputStream(stream);
    }
    DistributionPackageInfo packageInfo = new DistributionPackageInfo(type);
    DistributionPackageUtils.readInfo(stream, packageInfo);
    DistributionPackage distributionPackage = SimpleDistributionPackage.fromStream(stream, type);
    boolean installed;
    // not a simple package
    if (distributionPackage == null) {
        installed = installPackageInternal(resourceResolver, stream);
    } else {
        installed = installPackage(resourceResolver, distributionPackage);
        packageInfo.putAll(distributionPackage.getInfo());
    }
    if (installed) {
        return packageInfo;
    } else {
        throw new DistributionException("could not install package from stream");
    }
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) BufferedInputStream(java.io.BufferedInputStream) DistributionException(org.apache.sling.distribution.common.DistributionException) Nonnull(javax.annotation.Nonnull)

Example 8 with DistributionPackage

use of org.apache.sling.distribution.packaging.DistributionPackage in project sling by apache.

the class MonitoringDistributionPackageBuilder method createPackage.

@Nonnull
@Override
public DistributionPackage createPackage(@Nonnull ResourceResolver resourceResolver, @Nonnull DistributionRequest request) throws DistributionException {
    long start = System.currentTimeMillis();
    DistributionPackage distributionPackage = wrapped.createPackage(resourceResolver, request);
    if (queueCapacity > 0) {
        registerDistributionPackageMBean(start, distributionPackage);
    }
    return distributionPackage;
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) Nonnull(javax.annotation.Nonnull)

Example 9 with DistributionPackage

use of org.apache.sling.distribution.packaging.DistributionPackage 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;
}
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) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) DistributionException(org.apache.sling.distribution.common.DistributionException)

Example 10 with DistributionPackage

use of org.apache.sling.distribution.packaging.DistributionPackage in project sling by apache.

the class RemoteDistributionPackageExporter method exportPackages.

public void exportPackages(@Nonnull ResourceResolver resourceResolver, @Nonnull DistributionRequest distributionRequest, @Nonnull DistributionPackageProcessor packageProcessor) throws DistributionException {
    int maxNumberOfPackages = DistributionRequestType.PULL.equals(distributionRequest.getRequestType()) ? maxPullItems : 1;
    for (DistributionTransport distributionTransport : transportHandlers) {
        int noPackages = 0;
        RemoteDistributionPackage retrievedPackage;
        while (noPackages < maxNumberOfPackages && ((retrievedPackage = distributionTransport.retrievePackage(resourceResolver, distributionRequest, distributionContext)) != null)) {
            DistributionPackage distributionPackage = retrievedPackage.getPackage();
            try {
                packageProcessor.process(distributionPackage);
                retrievedPackage.deleteRemotePackage();
            } finally {
                DistributionPackageUtils.closeSafely(distributionPackage);
            }
            noPackages++;
        }
    }
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage)

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