Search in sources :

Example 1 with SimpleDistributionRequest

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

the class VltUtilsTest method testDeepFilter.

@Test
public void testDeepFilter() throws Exception {
    DistributionRequest request = new SimpleDistributionRequest(ADD, true, "/foo");
    NavigableMap<String, List<String>> nodeFilters = new TreeMap<String, List<String>>();
    nodeFilters.put("/foo", Arrays.asList("/foo/bar", "/foo/bar1"));
    NavigableMap<String, List<String>> propFilters = new TreeMap<String, List<String>>();
    propFilters.put("/", Arrays.asList("^.*/prop1", "^.*/prop2"));
    WorkspaceFilter wsFilter = VltUtils.createFilter(request, nodeFilters, propFilters);
    assertNotNull(wsFilter);
    assertNotNull(wsFilter.getPropertyFilterSets());
    List<PathFilterSet> propFilterSet = wsFilter.getPropertyFilterSets();
    assertEquals(1, propFilterSet.size());
    PathFilterSet propFilter = propFilterSet.get(0);
    assertEquals(2, propFilter.getEntries().size());
    PathFilter filter = propFilter.getEntries().get(0).getFilter();
    assertTrue(filter.matches("/foo/bar/prop1"));
    assertTrue(filter.matches("/foo/prop1"));
}
Also used : SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) PathFilter(org.apache.jackrabbit.vault.fs.api.PathFilter) 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 2 with SimpleDistributionRequest

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

the class SimpleHttpDistributionTransportTest method testRetrievePackagesRemotelyFailing.

@Test
public void testRetrievePackagesRemotelyFailing() throws Exception {
    DistributionTransportSecret secret = mock(DistributionTransportSecret.class);
    Map<String, String> credentialsMap = new HashMap<String, String>();
    credentialsMap.put("username", "foo");
    credentialsMap.put("password", "foo");
    when(secret.asCredentialsMap()).thenReturn(credentialsMap);
    DistributionTransportSecretProvider secretProvider = mock(DistributionTransportSecretProvider.class);
    when(secretProvider.getSecret(any(URI.class))).thenReturn(secret);
    Executor executor = mock(Executor.class);
    Response response = mock(Response.class);
    HttpResponse httpResponse = mock(HttpResponse.class);
    StatusLine statusLine = mock(StatusLine.class);
    when(statusLine.getStatusCode()).thenReturn(404);
    when(httpResponse.getStatusLine()).thenReturn(statusLine);
    when(response.returnResponse()).thenReturn(httpResponse);
    when(executor.execute(any(Request.class))).thenReturn(response);
    DistributionEndpoint endpoint = new DistributionEndpoint("http://127.0.0.1:8080/some/resource");
    DistributionPackageBuilder packageBuilder = mock(DistributionPackageBuilder.class);
    SimpleHttpDistributionTransport simpleHttpDistributionTransport = new SimpleHttpDistributionTransport(mock(DefaultDistributionLog.class), endpoint, packageBuilder, secretProvider, new HttpConfiguration(1000, 1000));
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    DistributionRequest distributionRequest = new SimpleDistributionRequest(DistributionRequestType.ADD, "/");
    RemoteDistributionPackage retrievedPackage = simpleHttpDistributionTransport.retrievePackage(resourceResolver, distributionRequest, new DistributionTransportContext());
    assertNull(retrievedPackage);
}
Also used : HashMap(java.util.HashMap) Request(org.apache.http.client.fluent.Request) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) HttpResponse(org.apache.http.HttpResponse) DistributionTransportSecretProvider(org.apache.sling.distribution.transport.DistributionTransportSecretProvider) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) URI(java.net.URI) HttpResponse(org.apache.http.HttpResponse) Response(org.apache.http.client.fluent.Response) StatusLine(org.apache.http.StatusLine) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionTransportSecret(org.apache.sling.distribution.transport.DistributionTransportSecret) Executor(org.apache.http.client.fluent.Executor) DistributionPackageBuilder(org.apache.sling.distribution.packaging.DistributionPackageBuilder) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Test(org.junit.Test)

Example 3 with SimpleDistributionRequest

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

the class SimpleHttpDistributionTransportTest method testRetrievePackagesRemotelyWorking.

@Test
public void testRetrievePackagesRemotelyWorking() throws Exception {
    DistributionTransportSecret secret = mock(DistributionTransportSecret.class);
    Map<String, String> credentialsMap = new HashMap<String, String>();
    credentialsMap.put("username", "foo");
    credentialsMap.put("password", "foo");
    when(secret.asCredentialsMap()).thenReturn(credentialsMap);
    DistributionTransportSecretProvider secretProvider = mock(DistributionTransportSecretProvider.class);
    when(secretProvider.getSecret(any(URI.class))).thenReturn(secret);
    Executor executor = mock(Executor.class);
    Response response = mock(Response.class);
    HttpResponse httpResponse = mock(HttpResponse.class);
    StatusLine statusLine = mock(StatusLine.class);
    when(statusLine.getStatusCode()).thenReturn(200);
    when(httpResponse.getStatusLine()).thenReturn(statusLine);
    HttpEntity entity = mock(HttpEntity.class);
    InputStream stream = new ByteArrayInputStream("package binary stuff".getBytes("UTF-8"));
    when(entity.getContent()).thenReturn(stream);
    when(httpResponse.getEntity()).thenReturn(entity);
    when(response.returnResponse()).thenReturn(httpResponse);
    when(executor.execute(any(Request.class))).thenReturn(response);
    DistributionEndpoint endpoint = new DistributionEndpoint("http://127.0.0.1:8080/some/resource");
    DistributionPackageBuilder packageBuilder = mock(DistributionPackageBuilder.class);
    DistributionPackage distributionPackage = mock(DistributionPackage.class);
    when(distributionPackage.getInfo()).thenReturn(new DistributionPackageInfo("type"));
    when(packageBuilder.readPackage(any(ResourceResolver.class), any(InputStream.class))).thenReturn(distributionPackage);
    SimpleHttpDistributionTransport simpleHttpDistributionTransport = new SimpleHttpDistributionTransport(mock(DefaultDistributionLog.class), endpoint, packageBuilder, secretProvider, new HttpConfiguration(1000, 1000));
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    DistributionRequest distributionRequest = new SimpleDistributionRequest(DistributionRequestType.ADD, "/");
    DistributionTransportContext distributionContext = mock(DistributionTransportContext.class);
    when(distributionContext.get(any(String.class), same(Executor.class))).thenReturn(executor);
    when(distributionContext.containsKey(any(String.class))).thenReturn(true);
    RemoteDistributionPackage retrievedPackage = simpleHttpDistributionTransport.retrievePackage(resourceResolver, distributionRequest, distributionContext);
    assertNotNull(retrievedPackage);
}
Also used : DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) HttpEntity(org.apache.http.HttpEntity) HashMap(java.util.HashMap) DistributionTransportSecretProvider(org.apache.sling.distribution.transport.DistributionTransportSecretProvider) URI(java.net.URI) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DistributionTransportSecret(org.apache.sling.distribution.transport.DistributionTransportSecret) Executor(org.apache.http.client.fluent.Executor) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Request(org.apache.http.client.fluent.Request) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) HttpResponse(org.apache.http.HttpResponse) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) HttpResponse(org.apache.http.HttpResponse) Response(org.apache.http.client.fluent.Response) StatusLine(org.apache.http.StatusLine) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) DistributionPackageBuilder(org.apache.sling.distribution.packaging.DistributionPackageBuilder) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Test(org.junit.Test)

Example 4 with SimpleDistributionRequest

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

the class AbstractJcrEventTriggerTest method addToListTest.

//"SLING-6054"
@Test
public void addToListTest() throws Exception {
    SlingRepository repository = mock(SlingRepository.class);
    Scheduler scheduler = mock(Scheduler.class);
    String path = "/";
    String serviceUser = "service-user";
    AbstractJcrEventTrigger trigger = new AbstractJcrEventTrigger(repository, scheduler, rrf, path, serviceUser) {

        @Override
        protected DistributionRequest processEvent(Event event) throws RepositoryException {
            return null;
        }
    };
    String descendant = "/a/b/c/d/e/f/h";
    String ancestor = "/a/b/c/d";
    List<DistributionRequest> requests = new LinkedList<DistributionRequest>();
    requests.add(new SimpleDistributionRequest(DistributionRequestType.ADD, descendant));
    DistributionRequest newRequest = new SimpleDistributionRequest(DistributionRequestType.ADD, ancestor);
    trigger.addToList(newRequest, requests);
    assertEquals(1, requests.size());
    assertEquals(3, requests.get(0).getPaths().length);
    String[] paths = requests.get(0).getPaths();
    assertEquals(ancestor, paths[0]);
    // the missing path is added
    assertEquals("/a/b/c/d/e/f/g", paths[1]);
    assertEquals(descendant, paths[2]);
    // invert order of requests
    requests = new LinkedList<DistributionRequest>();
    requests.add(new SimpleDistributionRequest(DistributionRequestType.ADD, ancestor));
    newRequest = new SimpleDistributionRequest(DistributionRequestType.ADD, descendant);
    trigger.addToList(newRequest, requests);
    assertEquals(1, requests.size());
    assertEquals(3, requests.get(0).getPaths().length);
    paths = requests.get(0).getPaths();
    assertEquals(ancestor, paths[0]);
    // the missing path is added
    assertEquals("/a/b/c/d/e/f/g", paths[1]);
    assertEquals(descendant, paths[2]);
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) Scheduler(org.apache.sling.commons.scheduler.Scheduler) Event(javax.jcr.observation.Event) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 5 with SimpleDistributionRequest

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

the class DistributorServlet method doPost.

@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
    String action = request.getParameter("action");
    String agentName = request.getParameter("agent");
    String[] paths = request.getParameterValues("path");
    if (agentName == null) {
        response.getWriter().print("agent is required");
        return;
    }
    DistributionRequest distributionRequest = new SimpleDistributionRequest(DistributionRequestType.fromName(action), paths);
    DistributionResponse distributionResponse = distributor.distribute(agentName, request.getResourceResolver(), distributionRequest);
    if (distributionResponse.isSuccessful()) {
        response.setStatus(200);
    } else {
        response.setStatus(400);
    }
}
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