use of org.apache.sling.distribution.packaging.DistributionPackageBuilder 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"));
}
use of org.apache.sling.distribution.packaging.DistributionPackageBuilder 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);
}
}
use of org.apache.sling.distribution.packaging.DistributionPackageBuilder in project sling by apache.
the class DistributionPackageBuilderFactory method activate.
@Activate
public void activate(BundleContext context, Map<String, Object> config) {
String[] nodeFilters = SettingsUtils.removeEmptyEntries(PropertiesUtil.toStringArray(config.get(PACKAGE_FILTERS), null));
String[] propertyFilters = SettingsUtils.removeEmptyEntries(PropertiesUtil.toStringArray(config.get(PROPERTY_FILTERS), null));
String persistenceType = PropertiesUtil.toString(config.get(PERSISTENCE), null);
String tempFsFolder = SettingsUtils.removeEmptyEntry(PropertiesUtil.toString(config.get(TEMP_FS_FOLDER), null));
String digestAlgorithm = PropertiesUtil.toString(config.get(DIGEST_ALGORITHM), DEFAULT_DIGEST_ALGORITHM);
long cleanupDelay = PropertiesUtil.toLong(config.get(PACKAGE_CLEANUP_DELAY), DEFAULT_PACKAGE_CLEANUP_DELAY);
if (DEFAULT_DIGEST_ALGORITHM.equals(digestAlgorithm)) {
digestAlgorithm = null;
}
DistributionPackageBuilder wrapped;
if ("file".equals(persistenceType)) {
wrapped = new FileDistributionPackageBuilder(contentSerializer.getName(), contentSerializer, tempFsFolder, digestAlgorithm, nodeFilters, propertyFilters);
} else {
final int fileThreshold = PropertiesUtil.toInteger(config.get(FILE_THRESHOLD), DEFAULT_FILE_THRESHOLD_VALUE);
String memoryUnitName = PropertiesUtil.toString(config.get(MEMORY_UNIT), DEFAULT_MEMORY_UNIT);
final MemoryUnit memoryUnit = MemoryUnit.valueOf(memoryUnitName);
final boolean useOffHeapMemory = PropertiesUtil.toBoolean(config.get(USE_OFF_HEAP_MEMORY), DEFAULT_USE_OFF_HEAP_MEMORY);
ResourceDistributionPackageBuilder resourceDistributionPackageBuilder = new ResourceDistributionPackageBuilder(contentSerializer.getName(), contentSerializer, tempFsFolder, fileThreshold, memoryUnit, useOffHeapMemory, digestAlgorithm, nodeFilters, propertyFilters);
Runnable cleanup = new ResourceDistributionPackageCleanup(resolverFactory, resourceDistributionPackageBuilder);
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(Scheduler.PROPERTY_SCHEDULER_CONCURRENT, false);
props.put(Scheduler.PROPERTY_SCHEDULER_PERIOD, cleanupDelay);
packageCleanup = context.registerService(Runnable.class.getName(), cleanup, props);
wrapped = resourceDistributionPackageBuilder;
}
int monitoringQueueSize = PropertiesUtil.toInteger(config.get(MONITORING_QUEUE_SIZE), DEFAULT_MONITORING_QUEUE_SIZE);
packageBuilder = new MonitoringDistributionPackageBuilder(monitoringQueueSize, wrapped, context);
}
use of org.apache.sling.distribution.packaging.DistributionPackageBuilder in project sling by apache.
the class KryoContentSerializerTest method testBuildAndInstallOnSingleShallowPath.
@Test
public void testBuildAndInstallOnSingleShallowPath() throws Exception {
String type = "kryo";
DistributionContentSerializer contentSerializer = new KryoContentSerializer(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"));
}
use of org.apache.sling.distribution.packaging.DistributionPackageBuilder in project sling by apache.
the class KryoContentSerializerTest method testBuildAndInstallOnMultipleShallowPaths.
@Test
public void testBuildAndInstallOnMultipleShallowPaths() throws Exception {
String type = "kryo";
DistributionContentSerializer contentSerializer = new KryoContentSerializer(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"));
}
Aggregations