Search in sources :

Example 11 with SimpleDistributionRequest

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

the class AbstractJcrEventTrigger method addToList.

void addToList(DistributionRequest request, List<DistributionRequest> requestList) {
    DistributionRequest lastRequest = requestList.isEmpty() ? null : requestList.get(requestList.size() - 1);
    log.debug("adding request {} to {}", request, requestList);
    if (lastRequest == null || !lastRequest.getRequestType().equals(request.getRequestType())) {
        requestList.add(request);
    } else if (hasDeepPaths(request) || hasDeepPaths(lastRequest)) {
        requestList.add(request);
    } else {
        Set<String> allPaths = new TreeSet<String>();
        allPaths.addAll(Arrays.asList(lastRequest.getPaths()));
        allPaths.addAll(Arrays.asList(request.getPaths()));
        addMissingPaths(allPaths);
        lastRequest = new SimpleDistributionRequest(lastRequest.getRequestType(), allPaths.toArray(new String[allPaths.size()]));
        requestList.set(requestList.size() - 1, lastRequest);
    }
    log.debug("current requests {}", requestList);
}
Also used : SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set)

Example 12 with SimpleDistributionRequest

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

the class JcrEventDistributionTrigger method processEvent.

@Override
protected DistributionRequest processEvent(Event event) throws RepositoryException {
    DistributionRequest distributionRequest = null;
    String eventPath = event.getPath();
    String replicatingPath = getNodePathFromEvent(event);
    if (!isIgnoredPath(replicatingPath)) {
        if (VltUtils.findParent(replicatingPath, "rep:policy") != null) {
            // distribute all policies
            replicatingPath = VltUtils.findParent(replicatingPath, "rep:policy") + "/rep:policy";
            distributionRequest = new SimpleDistributionRequest(DistributionRequestType.ADD, replicatingPath);
        } else if (VltUtils.findParent(replicatingPath, "rep:membersList") != null || eventPath.endsWith("/rep:members")) {
            // group member list structure is an implementation detail and it is safer to distribute the entire group.
            String groupPath = VltUtils.findParent(replicatingPath, "rep:membersList");
            if (groupPath != null) {
                replicatingPath = groupPath;
            }
            distributionRequest = new SimpleDistributionRequest(DistributionRequestType.ADD, true, replicatingPath);
        } else {
            distributionRequest = new SimpleDistributionRequest(Event.NODE_REMOVED == event.getType() ? DistributionRequestType.DELETE : DistributionRequestType.ADD, deep, replicatingPath);
        }
        log.info("distributing {}", distributionRequest);
    }
    return distributionRequest;
}
Also used : SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest)

Example 13 with SimpleDistributionRequest

use of org.apache.sling.distribution.SimpleDistributionRequest 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()));
}
Also used : SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) SimpleDistributionPackage(org.apache.sling.distribution.packaging.impl.SimpleDistributionPackage) Test(org.junit.Test)

Example 14 with SimpleDistributionRequest

use of org.apache.sling.distribution.SimpleDistributionRequest 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()));
}
Also used : SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) SimpleDistributionPackage(org.apache.sling.distribution.packaging.impl.SimpleDistributionPackage) Test(org.junit.Test)

Example 15 with SimpleDistributionRequest

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

the class AgentDistributionPackageExporterTest method testTestExport.

@Test
public void testTestExport() throws Exception {
    AgentDistributionPackageExporter distributionPackageExporter = new AgentDistributionPackageExporter(null, mock(DistributionAgent.class), mock(DistributionPackageBuilderProvider.class), null);
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    // vargarg doesn't match and causes compiler warning
    String[] args = new String[0];
    DistributionRequest distributionRequest = new SimpleDistributionRequest(DistributionRequestType.TEST, args);
    final List<DistributionPackage> distributionPackages = new ArrayList<DistributionPackage>();
    distributionPackageExporter.exportPackages(resourceResolver, distributionRequest, new DistributionPackageProcessor() {

        @Override
        public void process(DistributionPackage distributionPackage) {
            distributionPackages.add(distributionPackage);
        }

        @Override
        public List<DistributionResponse> getAllResponses() {
            return null;
        }

        @Override
        public int getPackagesCount() {
            return 0;
        }

        @Override
        public long getPackagesSize() {
            return 0;
        }
    });
    assertNotNull(distributionPackages);
    assertEquals(1, distributionPackages.size());
}
Also used : DistributionAgent(org.apache.sling.distribution.agent.DistributionAgent) ArrayList(java.util.ArrayList) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionPackageProcessor(org.apache.sling.distribution.packaging.DistributionPackageProcessor) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) ArrayList(java.util.ArrayList) List(java.util.List) DistributionPackageBuilderProvider(org.apache.sling.distribution.packaging.DistributionPackageBuilderProvider) Test(org.junit.Test)

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