Search in sources :

Example 1 with DistributionLog

use of org.apache.sling.distribution.log.DistributionLog in project sling by apache.

the class ExtendedDistributionServiceResourceProvider method getChildResourceProperties.

@Override
protected Map<String, Object> getChildResourceProperties(DistributionComponent<?> component, String childResourceName) {
    DistributionComponentKind kind = component.getKind();
    if (DistributionComponentKind.AGENT == kind) {
        DistributionAgent agent = (DistributionAgent) component.getService();
        if (agent != null && childResourceName != null) {
            if (childResourceName.startsWith(QUEUES_PATH)) {
                SimplePathInfo queuePathInfo = SimplePathInfo.parsePathInfo(QUEUES_PATH, childResourceName);
                return getQueueProperties(agent, queuePathInfo);
            } else if (childResourceName.startsWith(LOG_PATH)) {
                Map<String, Object> result = new HashMap<String, Object>();
                result.put(SLING_RESOURCE_TYPE, DistributionResourceTypes.LOG_RESOURCE_TYPE);
                DistributionLog distributionLog = agent.getLog();
                result.put(INTERNAL_ADAPTABLE, distributionLog);
                return result;
            } else if (childResourceName.startsWith(STATUS_PATH)) {
                Map<String, Object> result = new HashMap<String, Object>();
                DistributionAgentState agentState = agent.getState();
                result.put("state", agentState.name());
                return result;
            }
        }
    }
    return null;
}
Also used : DistributionAgentState(org.apache.sling.distribution.agent.DistributionAgentState) DistributionAgent(org.apache.sling.distribution.agent.DistributionAgent) DistributionComponentKind(org.apache.sling.distribution.component.impl.DistributionComponentKind) HashMap(java.util.HashMap) SimplePathInfo(org.apache.sling.distribution.resources.impl.common.SimplePathInfo) DistributionLog(org.apache.sling.distribution.log.DistributionLog) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with DistributionLog

use of org.apache.sling.distribution.log.DistributionLog in project sling by apache.

the class DistributionAgentLogServlet method doGet.

@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/plain");
    DistributionRequest distributionRequest = RequestUtils.fromServletRequest(request);
    log.debug("distribution request : {}", distributionRequest);
    DistributionLog distributionLog = request.getResource().adaptTo(DistributionLog.class);
    PrintWriter writer = response.getWriter();
    if (distributionLog != null) {
        for (String line : distributionLog.getLines()) {
            writer.append(line);
            writer.append("\n");
        }
    } else {
        response.setStatus(404);
        writer.append("agent not found");
    }
}
Also used : DistributionRequest(org.apache.sling.distribution.DistributionRequest) DistributionLog(org.apache.sling.distribution.log.DistributionLog) PrintWriter(java.io.PrintWriter)

Aggregations

DistributionLog (org.apache.sling.distribution.log.DistributionLog)2 PrintWriter (java.io.PrintWriter)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 DistributionRequest (org.apache.sling.distribution.DistributionRequest)1 DistributionAgent (org.apache.sling.distribution.agent.DistributionAgent)1 DistributionAgentState (org.apache.sling.distribution.agent.DistributionAgentState)1 DistributionComponentKind (org.apache.sling.distribution.component.impl.DistributionComponentKind)1 SimplePathInfo (org.apache.sling.distribution.resources.impl.common.SimplePathInfo)1