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