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());
}
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());
}
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);
}
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);
}
}
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);
}
}
}
Aggregations