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;
}
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");
}
}
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;
}
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;
}
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++;
}
}
}
Aggregations