Search in sources :

Example 1 with DistributionAgent

use of org.apache.sling.distribution.agent.DistributionAgent 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 DistributionAgent

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

the class ExtendedDistributionServiceResourceProvider method getChildResourceChildren.

@Override
protected Iterable<String> getChildResourceChildren(DistributionComponent<?> component, String childResourceName) {
    DistributionComponentKind kind = component.getKind();
    if (DistributionComponentKind.AGENT == kind) {
        DistributionAgent agent = (DistributionAgent) component.getService();
        if (agent != null) {
            if (childResourceName == null) {
                List<String> nameList = new ArrayList<String>();
                nameList.add(QUEUES_PATH);
                nameList.add(LOG_PATH);
                nameList.add(STATUS_PATH);
                return nameList;
            }
        }
    }
    return null;
}
Also used : DistributionAgent(org.apache.sling.distribution.agent.DistributionAgent) DistributionComponentKind(org.apache.sling.distribution.component.impl.DistributionComponentKind) ArrayList(java.util.ArrayList)

Example 3 with DistributionAgent

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

the class TriggerAgentRequestHandlerTest method testHandlePassive.

@Test
public void testHandlePassive() throws Exception {
    DistributionAgent agent = mock(DistributionAgent.class);
    SimpleDistributionAgentAuthenticationInfo authenticationInfo = mock(SimpleDistributionAgentAuthenticationInfo.class);
    DefaultDistributionLog log = mock(DefaultDistributionLog.class);
    TriggerAgentRequestHandler triggerAgentRequestHandler = new TriggerAgentRequestHandler(agent, authenticationInfo, log, false);
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    DistributionRequest request = mock(DistributionRequest.class);
    triggerAgentRequestHandler.handle(resourceResolver, request);
}
Also used : DistributionAgent(org.apache.sling.distribution.agent.DistributionAgent) DistributionRequest(org.apache.sling.distribution.DistributionRequest) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) Test(org.junit.Test)

Example 4 with DistributionAgent

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

the class DistributionQueueHealthCheckTest method testWithNoItemInTheQueue.

@Test
public void testWithNoItemInTheQueue() throws Exception {
    DistributionQueueHealthCheck distributionQueueHealthCheck = new DistributionQueueHealthCheck();
    distributionQueueHealthCheck.activate(Collections.<String, Object>emptyMap());
    DistributionQueue queue = mock(DistributionQueue.class);
    when(queue.getHead()).thenReturn(null);
    DistributionAgent distributionAgent = mock(DistributionAgent.class);
    List<String> queues = new ArrayList<String>();
    queues.add("queueName");
    when(distributionAgent.getQueueNames()).thenReturn(queues);
    when(distributionAgent.getQueue(anyString())).thenReturn(queue);
    distributionQueueHealthCheck.bindDistributionAgent(distributionAgent);
    Result result = distributionQueueHealthCheck.execute();
    assertNotNull(result);
    assertTrue(result.isOk());
}
Also used : DistributionAgent(org.apache.sling.distribution.agent.DistributionAgent) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Result(org.apache.sling.hc.api.Result) Test(org.junit.Test)

Example 5 with DistributionAgent

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

the class DistributionQueueHealthCheckTest method testWithOneOkItemInTheQueue.

@Test
public void testWithOneOkItemInTheQueue() throws Exception {
    DistributionQueueHealthCheck distributionQueueHealthCheck = new DistributionQueueHealthCheck();
    distributionQueueHealthCheck.activate(Collections.<String, Object>emptyMap());
    DistributionQueue queue = mock(DistributionQueue.class);
    DistributionQueueItem item = mock(DistributionQueueItem.class);
    DistributionQueueItemStatus status = mock(DistributionQueueItemStatus.class);
    when(status.getAttempts()).thenReturn(1);
    when(queue.getItem(any(String.class))).thenReturn(new DistributionQueueEntry(null, item, status));
    when(queue.getHead()).thenReturn(new DistributionQueueEntry(null, item, status));
    DistributionAgent distributionAgent = mock(DistributionAgent.class);
    List<String> queues = new ArrayList<String>();
    queues.add("queueName");
    when(distributionAgent.getQueueNames()).thenReturn(queues);
    when(distributionAgent.getQueue(anyString())).thenReturn(queue);
    distributionQueueHealthCheck.bindDistributionAgent(distributionAgent);
    Result result = distributionQueueHealthCheck.execute();
    assertNotNull(result);
    assertTrue(result.isOk());
}
Also used : DistributionAgent(org.apache.sling.distribution.agent.DistributionAgent) DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) Result(org.apache.sling.hc.api.Result) Test(org.junit.Test)

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