Search in sources :

Example 6 with FileDistributionPackageBuilder

use of org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder 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);
}
Also used : ResourceDistributionPackageCleanup(org.apache.sling.distribution.packaging.impl.ResourceDistributionPackageCleanup) FileDistributionPackageBuilder(org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder) MemoryUnit(org.apache.sling.distribution.util.impl.FileBackedMemoryOutputStream.MemoryUnit) ResourceDistributionPackageBuilder(org.apache.sling.distribution.packaging.impl.ResourceDistributionPackageBuilder) Hashtable(java.util.Hashtable) MonitoringDistributionPackageBuilder(org.apache.sling.distribution.monitor.impl.MonitoringDistributionPackageBuilder) FileDistributionPackageBuilder(org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder) DistributionPackageBuilder(org.apache.sling.distribution.packaging.DistributionPackageBuilder) ResourceDistributionPackageBuilder(org.apache.sling.distribution.packaging.impl.ResourceDistributionPackageBuilder) MonitoringDistributionPackageBuilder(org.apache.sling.distribution.monitor.impl.MonitoringDistributionPackageBuilder) Activate(org.apache.felix.scr.annotations.Activate)

Example 7 with FileDistributionPackageBuilder

use of org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder 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"));
}
Also used : FileDistributionPackageBuilder(org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) FileDistributionPackageBuilder(org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder) DistributionPackageBuilder(org.apache.sling.distribution.packaging.DistributionPackageBuilder) Resource(org.apache.sling.api.resource.Resource) DistributionContentSerializer(org.apache.sling.distribution.serialization.DistributionContentSerializer) Test(org.junit.Test)

Example 8 with FileDistributionPackageBuilder

use of org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder 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"));
}
Also used : FileDistributionPackageBuilder(org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) FileDistributionPackageBuilder(org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder) DistributionPackageBuilder(org.apache.sling.distribution.packaging.DistributionPackageBuilder) Resource(org.apache.sling.api.resource.Resource) DistributionContentSerializer(org.apache.sling.distribution.serialization.DistributionContentSerializer) Test(org.junit.Test)

Example 9 with FileDistributionPackageBuilder

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

the class LocalDistributionPackageImporterTest method importPackageWithLargeHeader.

@Test
public void importPackageWithLargeHeader() throws Exception {
    DistributionPackageBuilder packageBuilder = mock(DistributionPackageBuilder.class);
    DistributionEventFactory distributionEventFactory = mock(DistributionEventFactory.class);
    LocalDistributionPackageImporter localdistributionPackageImporter = new LocalDistributionPackageImporter("mockImporter", distributionEventFactory, packageBuilder);
    FileVaultContentSerializer vaultSerializer = new FileVaultContentSerializer("importPackageWithLargeHeader", new PackagingImpl(), ImportMode.UPDATE, AccessControlHandling.IGNORE, new String[0], new String[0], new String[0], false, -1);
    DistributionPackageBuilder builder = new FileDistributionPackageBuilder(DistributionRequestType.ADD.name(), vaultSerializer, null, null, null, null);
    ResourceResolver resourceResolver = slingContext.resourceResolver();
    String[] paths = createPaths(resourceResolver, 1000, "/content/company/de/press-releases/2016/11/04/message");
    DistributionPackage pkg = builder.createPackage(resourceResolver, new SimpleDistributionRequest(DistributionRequestType.ADD, paths));
    InputStream streamWithHeader = DistributionPackageUtils.createStreamWithHeader(pkg);
    localdistributionPackageImporter.importStream(resourceResolver, streamWithHeader);
}
Also used : FileDistributionPackageBuilder(org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) InputStream(java.io.InputStream) FileDistributionPackageBuilder(org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder) DistributionPackageBuilder(org.apache.sling.distribution.packaging.DistributionPackageBuilder) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) DistributionEventFactory(org.apache.sling.distribution.event.impl.DistributionEventFactory) PackagingImpl(org.apache.jackrabbit.vault.packaging.impl.PackagingImpl) FileVaultContentSerializer(org.apache.sling.distribution.serialization.impl.vlt.FileVaultContentSerializer) Test(org.junit.Test)

Aggregations

DistributionPackageBuilder (org.apache.sling.distribution.packaging.DistributionPackageBuilder)9 FileDistributionPackageBuilder (org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder)9 SimpleDistributionRequest (org.apache.sling.distribution.SimpleDistributionRequest)7 DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)7 DistributionContentSerializer (org.apache.sling.distribution.serialization.DistributionContentSerializer)7 Test (org.junit.Test)7 Resource (org.apache.sling.api.resource.Resource)6 DistributionRequest (org.apache.sling.distribution.DistributionRequest)6 Hashtable (java.util.Hashtable)2 MonitoringDistributionPackageBuilder (org.apache.sling.distribution.monitor.impl.MonitoringDistributionPackageBuilder)2 ResourceDistributionPackageBuilder (org.apache.sling.distribution.packaging.impl.ResourceDistributionPackageBuilder)2 ResourceDistributionPackageCleanup (org.apache.sling.distribution.packaging.impl.ResourceDistributionPackageCleanup)2 MemoryUnit (org.apache.sling.distribution.util.impl.FileBackedMemoryOutputStream.MemoryUnit)2 InputStream (java.io.InputStream)1 Activate (org.apache.felix.scr.annotations.Activate)1 ImportMode (org.apache.jackrabbit.vault.fs.api.ImportMode)1 AccessControlHandling (org.apache.jackrabbit.vault.fs.io.AccessControlHandling)1 PackagingImpl (org.apache.jackrabbit.vault.packaging.impl.PackagingImpl)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1 DistributionEventFactory (org.apache.sling.distribution.event.impl.DistributionEventFactory)1