use of org.apache.camel.Route in project camel by apache.
the class CamelTestSupport method logCoverageSummary.
/**
* Logs route coverage summary:
* - which routes are uncovered
* - what is the coverage of each processor in each route
*/
private void logCoverageSummary(ManagedCamelContextMBean managedCamelContext) throws Exception {
StringBuilder builder = new StringBuilder("\nCoverage summary\n");
int routes = managedCamelContext.getTotalRoutes();
long contextExchangesTotal = managedCamelContext.getExchangesTotal();
List<String> uncoveredRoutes = new ArrayList<>();
StringBuilder routesSummary = new StringBuilder();
routesSummary.append("\tProcessor coverage\n");
MBeanServer server = context.getManagementStrategy().getManagementAgent().getMBeanServer();
Map<String, List<ManagedProcessorMBean>> processorsForRoute = findProcessorsForEachRoute(server);
// log processor coverage for each route
for (Route route : context.getRoutes()) {
ManagedRouteMBean managedRoute = context.getManagedRoute(route.getId(), ManagedRouteMBean.class);
if (managedRoute.getExchangesTotal() == 0) {
uncoveredRoutes.add(route.getId());
}
long routeCoveragePercentage = Math.round((double) managedRoute.getExchangesTotal() / contextExchangesTotal * 100);
routesSummary.append("\t\tRoute ").append(route.getId()).append(" total: ").append(managedRoute.getExchangesTotal()).append(" (").append(routeCoveragePercentage).append("%)\n");
if (server != null) {
for (ManagedProcessorMBean managedProcessor : processorsForRoute.get(route.getId())) {
String processorId = managedProcessor.getProcessorId();
long processorExchangesTotal = managedProcessor.getExchangesTotal();
long processorCoveragePercentage = Math.round((double) processorExchangesTotal / contextExchangesTotal * 100);
routesSummary.append("\t\t\tProcessor ").append(processorId).append(" total: ").append(processorExchangesTotal).append(" (").append(processorCoveragePercentage).append("%)\n");
}
}
}
int used = routes - uncoveredRoutes.size();
long contextPercentage = Math.round((double) used / routes * 100);
builder.append("\tRoute coverage: ").append(used).append(" out of ").append(routes).append(" routes used (").append(contextPercentage).append("%)\n");
builder.append("\t\tCamelContext (").append(managedCamelContext.getCamelId()).append(") total: ").append(contextExchangesTotal).append("\n");
if (uncoveredRoutes.size() > 0) {
builder.append("\t\tUncovered routes: ").append(uncoveredRoutes.stream().collect(Collectors.joining(", "))).append("\n");
}
builder.append(routesSummary);
log.info(builder.toString());
}
use of org.apache.camel.Route in project camel by apache.
the class TestSupport method getRouteList.
/**
* A helper method to create a list of Route objects for a given route builder
*/
public static List<Route> getRouteList(RouteBuilder builder) throws Exception {
CamelContext context = new DefaultCamelContext();
context.addRoutes(builder);
context.start();
List<Route> answer = context.getRoutes();
context.stop();
return answer;
}
use of org.apache.camel.Route in project camel by apache.
the class CuratorMultiMasterLeaderRoutePolicy method startAllStoppedRoutes.
private void startAllStoppedRoutes() {
try {
lock.lock();
if (!suspendedRoutes.isEmpty()) {
if (log.isDebugEnabled()) {
log.info("{} route(s) have been stopped previously by policy, restarting.", suspendedRoutes.size());
}
for (Route suspended : suspendedRoutes) {
DefaultCamelContext ctx = (DefaultCamelContext) suspended.getRouteContext().getCamelContext();
while (!ctx.isStarted()) {
log.info("Context {} is not started yet. Sleeping for a bit.", ctx.getName());
Thread.sleep(5000);
}
log.info("Starting route [{}] defined in context [{}].", suspended.getId(), ctx.getName());
startRoute(suspended);
}
suspendedRoutes.clear();
}
} catch (Exception e) {
handleException(e);
} finally {
lock.unlock();
}
}
use of org.apache.camel.Route in project camel by apache.
the class CamelCommandsFacade method getCamelContextForRoute.
private String getCamelContextForRoute(String routeId) throws Exception {
ArrayList<String> contextNames = new ArrayList<String>();
for (CamelContext camelContext : camelController.getLocalCamelContexts()) {
for (Route route : camelContext.getRoutes()) {
if (routeId.equals(route.getId())) {
contextNames.add(camelContext.getName());
break;
}
}
}
if (contextNames.size() != 1) {
StringBuffer error = new StringBuffer();
error.append("Cannot infer CamelContext. Please provide manually.");
if (contextNames.size() > 1) {
error.append(" Contexts : " + contextNames.toString());
}
throw new org.crsh.cli.impl.SyntaxException(error.toString());
}
return contextNames.get(0);
}
use of org.apache.camel.Route in project opennms by OpenNMS.
the class CamelRpcServerRouteManager method bind.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void bind(RpcModule module) throws Exception {
if (module != null) {
final RpcModule<RpcRequest, RpcResponse> rpcModule = (RpcModule<RpcRequest, RpcResponse>) module;
final String routeId = getRouteId(rpcModule);
final Route existingRoute = context.getRoute(routeId);
if (routeIdsByModule.containsKey(rpcModule)) {
if (existingRoute == null) {
LOG.error("RpcModule {} ({}) was marked as registered but its route {} cannot be found in the Camel context", rpcModule.getId(), Integer.toHexString(rpcModule.hashCode()), routeId);
} else {
LOG.warn("RpcModule {} ({}) was already registered on route {}: {}", rpcModule.getId(), Integer.toHexString(rpcModule.hashCode()), routeId, existingRoute);
}
} else {
if (existingRoute == null) {
final DynamicRpcRouteBuilder routeBuilder = new DynamicRpcRouteBuilder(context, identity, rpcModule);
context.addRoutes(routeBuilder);
routeIdsByModule.put(rpcModule, routeId);
LOG.info("Registered RpcModule {} ({}) on route {} with queue {}", rpcModule.getId(), Integer.toHexString(rpcModule.hashCode()), routeId, routeBuilder.getQueueName());
} else {
LOG.warn("RpcModule {} ({}) cannot be registered, route {} is already present: {}", rpcModule.getId(), Integer.toHexString(rpcModule.hashCode()), routeId, existingRoute);
}
}
}
}
Aggregations