Package org.apache.sling.replication.communication

Examples of org.apache.sling.replication.communication.ReplicationResponse


        ResourceResolver resourceResolver = request.getResourceResolver();

        if (agent != null) {
            try {
                ReplicationResponse replicationResponse = agent.execute(resourceResolver, replicationRequest);
                if (replicationResponse.isSuccessful()) {
                    if (ItemState.SUCCEEDED.toString().equals(replicationResponse.getStatus())) {
                        response.setStatus(200);
                    }
                    if (ItemState.QUEUED.toString().equals(replicationResponse.getStatus())
                            || ItemState.ACTIVE.toString().equals(
                            replicationResponse.getStatus())) {
                        response.setStatus(202);
                    }

                }
                else {
                    if (ItemState.DROPPED.toString().equals(replicationResponse.getStatus())) {
                        response.setStatus(404);
                    } else {
                        response.setStatus(400);
                    }
                }

                response.getWriter().append(replicationResponse.toString());
            } catch (ReplicationAgentException e) {
                response.setStatus(503);
                response.getWriter().append("{\"error\" : \"").append(e.toString()).append("\"}");
            }
        } else {
View Full Code Here


        }
        return replicationResponses.size() == 1 ? replicationResponses.get(0) : new CompositeReplicationResponse(replicationResponses);
    }

    private ReplicationResponse schedule(ReplicationPackage replicationPackage) {
        ReplicationResponse replicationResponse;
        log.info("scheduling replication of package {}", replicationPackage);



        // dispatch the replication package to the queue distribution handler
        try {
            boolean success = queueDistributionStrategy.add(name, replicationPackage, queueProvider);

            Dictionary<Object, Object> properties = new Properties();
            properties.put("replication.package.paths", replicationPackage.getPaths());
            properties.put("replication.agent.name", name);
            replicationEventFactory.generateEvent(ReplicationEventType.PACKAGE_QUEUED, properties);

            replicationResponse = new ReplicationResponse(success? ReplicationQueueItemState.ItemState.QUEUED.toString() :
                    ReplicationQueueItemState.ItemState.ERROR.toString(), success);
        } catch (Exception e) {
            log.error("an error happened during queue processing", e);
            replicationResponse = new ReplicationResponse(e.toString(), false);
        }

        return replicationResponse;
    }
View Full Code Here

        when(replicationPackage.getPaths()).thenReturn(new String[]{"/"});
        when(packageExporter.exportPackages(any(ResourceResolver.class), any(ReplicationRequest.class)))
                .thenReturn(Arrays.asList(replicationPackage));
        when(queueProvider.getDefaultQueue(name)).thenReturn(
                new SimpleReplicationQueue(name, "name"));
        ReplicationResponse response = agent.execute(resourceResolver, request);
        assertNotNull(response);
        assertEquals("ERROR", response.getStatus());
    }
View Full Code Here

        when(distributionHandler.add(any(String.class), any(ReplicationPackage.class), eq(queueProvider))).thenReturn(true);
        when(packageExporter.exportPackages(any(ResourceResolver.class), any(ReplicationRequest.class)))
                .thenReturn(Arrays.asList(replicationPackage));
        when(queueProvider.getDefaultQueue(name)).thenReturn(
                new SimpleReplicationQueue(name, "name"));
        ReplicationResponse response = agent.execute(resourceResolver, request);
        assertNotNull(response);
        assertEquals("QUEUED", response.getStatus());
    }
View Full Code Here

TOP

Related Classes of org.apache.sling.replication.communication.ReplicationResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.