Search in sources :

Example 6 with DistributionAgent

use of org.apache.sling.distribution.agent.DistributionAgent in project sling by apache.

the class ReverseDistributionAgentMBeanTest method verifyMBeanExposedValues.

@Test
public void verifyMBeanExposedValues() {
    DistributionAgent agent = mock(DistributionAgent.class);
    when(agent.getState()).thenReturn(DistributionAgentState.RUNNING);
    Map<String, Object> osgiConfiguration = new HashMap<String, Object>();
    osgiConfiguration.put("name", "#distributionagent");
    osgiConfiguration.put("title", "Just a test title");
    osgiConfiguration.put("details", "Just test details");
    osgiConfiguration.put("enabled", true);
    osgiConfiguration.put("serviceName", "@distributionagent");
    osgiConfiguration.put("log.level", "error");
    osgiConfiguration.put("queue.processing.enabled", true);
    ReverseDistributionAgentMBean mBean = new ReverseDistributionAgentMBeanImpl(agent, osgiConfiguration);
    assertEquals(osgiConfiguration.get("name"), mBean.getName());
    assertEquals(osgiConfiguration.get("title"), mBean.getTitle());
    assertEquals(osgiConfiguration.get("details"), mBean.getDetails());
    assertEquals(osgiConfiguration.get("enabled"), mBean.isEnabled());
    assertEquals(osgiConfiguration.get("serviceName"), mBean.getServiceName());
    assertEquals(osgiConfiguration.get("log.level"), mBean.getLogLevel());
    assertEquals(osgiConfiguration.get("queue.processing.enabled"), mBean.isQueueProcessingEnabled());
    assertEquals(agent.getState().name().toLowerCase(), mBean.getStatus());
}
Also used : DistributionAgent(org.apache.sling.distribution.agent.DistributionAgent) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 7 with DistributionAgent

use of org.apache.sling.distribution.agent.DistributionAgent in project sling by apache.

the class QueueDistributionAgentMBeanTest method verifyMBeanExposedValues.

@Test
public void verifyMBeanExposedValues() {
    DistributionAgent agent = mock(DistributionAgent.class);
    when(agent.getState()).thenReturn(DistributionAgentState.RUNNING);
    Map<String, Object> osgiConfiguration = new HashMap<String, Object>();
    osgiConfiguration.put("name", "#queueagent");
    osgiConfiguration.put("title", "Just a test title");
    osgiConfiguration.put("details", "Just test details");
    osgiConfiguration.put("enabled", true);
    osgiConfiguration.put("serviceName", "@queueagent");
    osgiConfiguration.put("log.level", "error");
    osgiConfiguration.put("allowed.roots", "admin");
    QueueDistributionAgentMBean mBean = new QueueDistributionAgentMBeanImpl(agent, osgiConfiguration);
    assertEquals(osgiConfiguration.get("name"), mBean.getName());
    assertEquals(osgiConfiguration.get("title"), mBean.getTitle());
    assertEquals(osgiConfiguration.get("details"), mBean.getDetails());
    assertEquals(osgiConfiguration.get("enabled"), mBean.isEnabled());
    assertEquals(osgiConfiguration.get("serviceName"), mBean.getServiceName());
    assertEquals(osgiConfiguration.get("log.level"), mBean.getLogLevel());
    assertEquals(osgiConfiguration.get("allowed.roots"), mBean.getAllowedRoots());
    assertEquals(agent.getState().name().toLowerCase(), mBean.getStatus());
}
Also used : DistributionAgent(org.apache.sling.distribution.agent.DistributionAgent) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 8 with DistributionAgent

use of org.apache.sling.distribution.agent.DistributionAgent in project sling by apache.

the class DistributionQueueHealthCheck method execute.

public Result execute() {
    final FormattingResultLog resultLog = new FormattingResultLog();
    Map<String, Integer> failures = new HashMap<String, Integer>();
    if (distributionAgents.size() > 0) {
        for (DistributionAgent distributionAgent : distributionAgents) {
            for (String queueName : distributionAgent.getQueueNames()) {
                try {
                    DistributionQueue q = distributionAgent.getQueue(queueName);
                    DistributionQueueEntry entry = q.getHead();
                    if (entry != null) {
                        DistributionQueueItemStatus status = entry.getStatus();
                        if (status.getAttempts() <= numberOfRetriesAllowed) {
                            resultLog.debug("Queue: [{}], first item: [{}], number of retries: {}", q.getName(), entry.getId(), status.getAttempts());
                        } else {
                            // the no. of attempts is higher than the configured threshold
                            resultLog.warn("Queue: [{}], first item: [{}], number of retries: {}, expected number of retries <= {}", q.getName(), entry.getId(), status.getAttempts(), numberOfRetriesAllowed);
                            failures.put(q.getName(), status.getAttempts());
                        }
                    } else {
                        resultLog.debug("No items in queue [{}]", q.getName());
                    }
                } catch (Exception e) {
                    resultLog.warn("Exception while inspecting distribution queue [{}]: {}", queueName, e);
                }
            }
        }
    } else {
        resultLog.debug("No distribution queue providers found");
    }
    if (failures.size() > 0) {
        // a specific log entry (using markdown) to provide a recommended user action
        for (Map.Entry<String, Integer> entry : failures.entrySet()) {
            resultLog.warn("Distribution queue {}'s first item in the default queue has been retried {} times (threshold: {})", entry.getKey(), entry.getValue(), numberOfRetriesAllowed);
        }
    }
    return new Result(resultLog);
}
Also used : DistributionAgent(org.apache.sling.distribution.agent.DistributionAgent) DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) HashMap(java.util.HashMap) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) FormattingResultLog(org.apache.sling.hc.util.FormattingResultLog) Result(org.apache.sling.hc.api.Result) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with DistributionAgent

use of org.apache.sling.distribution.agent.DistributionAgent in project sling by apache.

the class DistributionAgentServlet method doPost.

@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
    response.setContentType("application/json");
    DistributionRequest distributionRequest = RequestUtils.fromServletRequest(request);
    log.debug("distribution request : {}", distributionRequest);
    DistributionAgent agent = request.getResource().adaptTo(DistributionAgent.class);
    ResourceResolver resourceResolver = request.getResourceResolver();
    if (agent != null) {
        try {
            DistributionResponse distributionResponse = agent.execute(resourceResolver, distributionRequest);
            ServletJsonUtils.writeJson(response, distributionResponse);
            log.debug("distribution response : {}", distributionResponse);
        } catch (Throwable e) {
            log.error("an unexpected error has occurred", e);
            ServletJsonUtils.writeJson(response, 503, "an unexpected error has occurred", null);
        }
    } else {
        ServletJsonUtils.writeJson(response, 404, "agent not found", null);
    }
}
Also used : DistributionRequest(org.apache.sling.distribution.DistributionRequest) DistributionAgent(org.apache.sling.distribution.agent.DistributionAgent) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) DistributionResponse(org.apache.sling.distribution.DistributionResponse)

Example 10 with DistributionAgent

use of org.apache.sling.distribution.agent.DistributionAgent in project sling by apache.

the class DistributionAgentQueueServlet method doPost.

@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
    String operation = request.getParameter("operation");
    DistributionQueue queue = request.getResource().adaptTo(DistributionQueue.class);
    ResourceResolver resourceResolver = request.getResourceResolver();
    if ("delete".equals(operation)) {
        String limitParam = request.getParameter("limit");
        String[] idParam = request.getParameterValues("id");
        if (idParam != null) {
            deleteItems(resourceResolver, queue, idParam);
        } else {
            int limit = 1;
            try {
                limit = Integer.parseInt(limitParam);
            } catch (NumberFormatException ex) {
                log.warn("limit param malformed : " + limitParam, ex);
            }
            deleteItems(resourceResolver, queue, limit);
        }
    } else if ("copy".equals(operation)) {
        String from = request.getParameter("from");
        String[] idParam = request.getParameterValues("id");
        if (idParam != null && from != null) {
            DistributionAgent agent = request.getResource().getParent().getParent().adaptTo(DistributionAgent.class);
            DistributionQueue sourceQueue = getQueueOrThrow(agent, from);
            addItems(resourceResolver, queue, sourceQueue, idParam);
        }
    } else if ("move".equals(operation)) {
        String from = request.getParameter("from");
        String[] idParam = request.getParameterValues("id");
        if (idParam != null && from != null) {
            DistributionAgent agent = request.getResource().getParent().getParent().adaptTo(DistributionAgent.class);
            DistributionQueue sourceQueue = getQueueOrThrow(agent, from);
            addItems(resourceResolver, queue, sourceQueue, idParam);
            deleteItems(resourceResolver, sourceQueue, idParam);
        }
    }
}
Also used : DistributionAgent(org.apache.sling.distribution.agent.DistributionAgent) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) ResourceResolver(org.apache.sling.api.resource.ResourceResolver)

Aggregations

DistributionAgent (org.apache.sling.distribution.agent.DistributionAgent)15 Test (org.junit.Test)10 HashMap (java.util.HashMap)7 DistributionQueue (org.apache.sling.distribution.queue.DistributionQueue)5 ArrayList (java.util.ArrayList)4 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)4 Result (org.apache.sling.hc.api.Result)4 DistributionRequest (org.apache.sling.distribution.DistributionRequest)3 DistributionQueueEntry (org.apache.sling.distribution.queue.DistributionQueueEntry)3 DistributionQueueItemStatus (org.apache.sling.distribution.queue.DistributionQueueItemStatus)3 Matchers.anyString (org.mockito.Matchers.anyString)3 Map (java.util.Map)2 DistributionComponentKind (org.apache.sling.distribution.component.impl.DistributionComponentKind)2 DefaultDistributionLog (org.apache.sling.distribution.log.impl.DefaultDistributionLog)2 DistributionQueueItem (org.apache.sling.distribution.queue.DistributionQueueItem)2 DistributionResponse (org.apache.sling.distribution.DistributionResponse)1 DistributionAgentState (org.apache.sling.distribution.agent.DistributionAgentState)1 DistributionLog (org.apache.sling.distribution.log.DistributionLog)1 SimplePathInfo (org.apache.sling.distribution.resources.impl.common.SimplePathInfo)1 FormattingResultLog (org.apache.sling.hc.util.FormattingResultLog)1