Search in sources :

Example 26 with SimpleDistributionRequest

use of org.apache.sling.distribution.SimpleDistributionRequest in project sling by apache.

the class KryoContentSerializerTest method testExtract.

@Test
public void testExtract() throws Exception {
    KryoContentSerializer kryoContentSerializer = new KryoContentSerializer("kryo");
    DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, "/libs");
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    NavigableMap<String, List<String>> nodeFilters = new TreeMap<String, List<String>>();
    NavigableMap<String, List<String>> propertyFilters = new TreeMap<String, List<String>>();
    try {
        DistributionExportFilter filter = DistributionExportFilter.createFilter(request, nodeFilters, propertyFilters);
        kryoContentSerializer.exportToStream(resourceResolver, new DistributionExportOptions(request, filter), outputStream);
        byte[] bytes = outputStream.toByteArray();
        assertNotNull(bytes);
        assertTrue(bytes.length > 0);
    } finally {
        outputStream.close();
    }
}
Also used : DistributionExportOptions(org.apache.sling.distribution.serialization.DistributionExportOptions) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) List(java.util.List) DistributionExportFilter(org.apache.sling.distribution.serialization.DistributionExportFilter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 27 with SimpleDistributionRequest

use of org.apache.sling.distribution.SimpleDistributionRequest in project sling by apache.

the class VltUtils method sanitizeRequest.

public static DistributionRequest sanitizeRequest(DistributionRequest request) {
    DistributionRequestType requestType = request.getRequestType();
    if (!DistributionRequestType.ADD.equals(requestType) && !DistributionRequestType.DELETE.equals(requestType)) {
        return request;
    }
    Set<String> deepPaths = new HashSet<String>();
    List<String> paths = new ArrayList<String>();
    Map<String, String[]> filters = new HashMap<String, String[]>();
    for (String path : request.getPaths()) {
        if (VltUtils.findParent(path, "rep:policy") != null) {
            if (DistributionRequestType.DELETE.equals(requestType)) {
                // vlt cannot properly install delete of rep:policy subnodes
                throw new IllegalArgumentException("cannot distribute DELETE node " + path);
            } else if (DistributionRequestType.ADD.equals(requestType)) {
                String newPath = VltUtils.findParent(path, "rep:policy") + "/rep:policy";
                paths.add(newPath);
                deepPaths.add(newPath);
                log.debug("changed distribution path {} to deep path {}", path, newPath);
            }
        } else if (request.isDeep(path)) {
            paths.add(path);
            deepPaths.add(path);
        } else {
            paths.add(path);
        }
        filters.put(path, request.getFilters(path));
    }
    return new SimpleDistributionRequest(requestType, paths.toArray(new String[paths.size()]), deepPaths, filters);
}
Also used : SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequestType(org.apache.sling.distribution.DistributionRequestType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 28 with SimpleDistributionRequest

use of org.apache.sling.distribution.SimpleDistributionRequest 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 29 with SimpleDistributionRequest

use of org.apache.sling.distribution.SimpleDistributionRequest in project sling by apache.

the class VltUtilsTest method testEmptyFilter.

@Test
public void testEmptyFilter() throws Exception {
    DistributionRequest request = new SimpleDistributionRequest(ADD, true, "/foo");
    NavigableMap<String, List<String>> nodeFilters = new TreeMap<String, List<String>>();
    NavigableMap<String, List<String>> propFilters = new TreeMap<String, List<String>>();
    WorkspaceFilter filter = VltUtils.createFilter(request, nodeFilters, propFilters);
    assertNotNull(filter);
    assertNotNull(filter.getPropertyFilterSets());
    List<PathFilterSet> propFilterSet = filter.getPropertyFilterSets();
    assertEquals(1, propFilterSet.size());
    PathFilterSet propFilter = propFilterSet.get(0);
    assertTrue(propFilter.getEntries().isEmpty());
    assertEquals("/", propFilter.getRoot());
    assertNotNull(filter.getFilterSets());
    List<PathFilterSet> nodeFilterSet = filter.getFilterSets();
    assertEquals(1, nodeFilterSet.size());
    PathFilterSet nodeFilter = nodeFilterSet.get(0);
    assertTrue(nodeFilter.getEntries().isEmpty());
    assertEquals("/foo", nodeFilter.getRoot());
}
Also used : SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) PathFilterSet(org.apache.jackrabbit.vault.fs.api.PathFilterSet) List(java.util.List) WorkspaceFilter(org.apache.jackrabbit.vault.fs.api.WorkspaceFilter) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 30 with SimpleDistributionRequest

use of org.apache.sling.distribution.SimpleDistributionRequest in project sling by apache.

the class PlumberImpl method persist.

/**
     * Persists pipe change if big enough, or ended, and eventually distribute changes
     * @param resolver
     * @param pipe
     * @param paths
     * @param currentResource if running, null if ended
     * @throws PersistenceException
     */
protected void persist(ResourceResolver resolver, Pipe pipe, Set<String> paths, Resource currentResource) throws Exception {
    if (pipe.modifiesContent() && resolver.hasChanges() && !pipe.isDryRun()) {
        if (currentResource == null || paths.size() % bufferSize == 0) {
            log.info("[{}] saving changes...", pipe.getName());
            writeStatus(pipe, currentResource == null ? STATUS_FINISHED : currentResource.getPath());
            resolver.commit();
        }
        if (currentResource == null && distributor != null && StringUtils.isNotBlank(pipe.getDistributionAgent())) {
            log.info("a distribution agent is configured, will try to distribute the changes");
            DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, true, paths.toArray(new String[paths.size()]));
            DistributionResponse response = distributor.distribute(pipe.getDistributionAgent(), resolver, request);
            log.info("distribution response : {}", response);
        }
    }
}
Also used : SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionResponse(org.apache.sling.distribution.DistributionResponse)

Aggregations

SimpleDistributionRequest (org.apache.sling.distribution.SimpleDistributionRequest)33 DistributionRequest (org.apache.sling.distribution.DistributionRequest)31 Test (org.junit.Test)26 DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)16 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)11 DistributionPackageBuilder (org.apache.sling.distribution.packaging.DistributionPackageBuilder)11 List (java.util.List)9 DefaultDistributionLog (org.apache.sling.distribution.log.impl.DefaultDistributionLog)8 DistributionPackageProcessor (org.apache.sling.distribution.packaging.DistributionPackageProcessor)8 FileDistributionPackageBuilder (org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder)7 TreeMap (java.util.TreeMap)6 Resource (org.apache.sling.api.resource.Resource)6 DistributionResponse (org.apache.sling.distribution.DistributionResponse)6 DistributionEventFactory (org.apache.sling.distribution.event.impl.DistributionEventFactory)6 DistributionPackageInfo (org.apache.sling.distribution.packaging.DistributionPackageInfo)6 DistributionContentSerializer (org.apache.sling.distribution.serialization.DistributionContentSerializer)6 SlingRepository (org.apache.sling.jcr.api.SlingRepository)6 ArrayList (java.util.ArrayList)5 ResourceResolverFactory (org.apache.sling.api.resource.ResourceResolverFactory)5 DistributionPackageExporter (org.apache.sling.distribution.packaging.DistributionPackageExporter)5