Search in sources :

Example 31 with Route

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());
}
Also used : ManagedRouteMBean(org.apache.camel.api.management.mbean.ManagedRouteMBean) ArrayList(java.util.ArrayList) ManagedProcessorMBean(org.apache.camel.api.management.mbean.ManagedProcessorMBean) List(java.util.List) ArrayList(java.util.ArrayList) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Route(org.apache.camel.Route) MBeanServer(javax.management.MBeanServer)

Example 32 with Route

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;
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Route(org.apache.camel.Route)

Example 33 with Route

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();
    }
}
Also used : Route(org.apache.camel.Route) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Example 34 with Route

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);
}
Also used : CamelContext(org.apache.camel.CamelContext) ArrayList(java.util.ArrayList) Route(org.apache.camel.Route)

Example 35 with Route

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);
            }
        }
    }
}
Also used : RpcRequest(org.opennms.core.rpc.api.RpcRequest) RpcModule(org.opennms.core.rpc.api.RpcModule) RpcResponse(org.opennms.core.rpc.api.RpcResponse) Route(org.apache.camel.Route)

Aggregations

Route (org.apache.camel.Route)90 EventDrivenConsumerRoute (org.apache.camel.impl.EventDrivenConsumerRoute)27 Endpoint (org.apache.camel.Endpoint)24 Channel (org.apache.camel.Channel)17 DeadLetterChannel (org.apache.camel.processor.DeadLetterChannel)15 Processor (org.apache.camel.Processor)13 ArrayList (java.util.ArrayList)12 SendProcessor (org.apache.camel.processor.SendProcessor)11 CamelContext (org.apache.camel.CamelContext)10 ShutdownRoute (org.apache.camel.ShutdownRoute)8 FilterProcessor (org.apache.camel.processor.FilterProcessor)7 RoutePolicy (org.apache.camel.spi.RoutePolicy)6 HashMap (java.util.HashMap)5 Service (org.apache.camel.Service)5 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)4 DelegateProcessor (org.apache.camel.DelegateProcessor)4 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)4 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)4