Search in sources :

Example 6 with RouteSpec

use of com.yahoo.messagebus.routing.RouteSpec in project vespa by vespa-engine.

the class MessageBusVisitorSessionTestCase method testRoutingTableHasNoStorageClusters.

@Test
public void testRoutingTableHasNoStorageClusters() {
    VisitorParameters visitorParameters = createVisitorParameters("");
    visitorParameters.setRoute(new Route());
    RoutingTableSpec spec = new RoutingTableSpec(DocumentProtocol.NAME);
    spec.addRoute(new RouteSpec("storage/lobster.foo"));
    RoutingTable table = new RoutingTable(spec);
    try {
        createDefaultMock(visitorParameters, table);
        fail("No exception thrown on zero storage clusters");
    } catch (IllegalArgumentException e) {
        assertEquals("No storage cluster found in your application.", e.getMessage());
    }
}
Also used : RoutingTableSpec(com.yahoo.messagebus.routing.RoutingTableSpec) RoutingTable(com.yahoo.messagebus.routing.RoutingTable) RouteSpec(com.yahoo.messagebus.routing.RouteSpec) Route(com.yahoo.messagebus.routing.Route) Test(org.junit.Test)

Example 7 with RouteSpec

use of com.yahoo.messagebus.routing.RouteSpec in project vespa by vespa-engine.

the class MessageBusVisitorSessionTestCase method createDummyRoutingTable.

RoutingTable createDummyRoutingTable() {
    RoutingTableSpec spec = new RoutingTableSpec(DocumentProtocol.NAME);
    spec.addRoute(new RouteSpec("storage/badger.bar"));
    RouteSpec storageCluster = new RouteSpec("storage/cluster.foo");
    storageCluster.addHop("bunnies");
    spec.addRoute(storageCluster);
    spec.addRoute(new RouteSpec("storage/otters.baz"));
    return new RoutingTable(spec);
}
Also used : RoutingTableSpec(com.yahoo.messagebus.routing.RoutingTableSpec) RoutingTable(com.yahoo.messagebus.routing.RoutingTable) RouteSpec(com.yahoo.messagebus.routing.RouteSpec)

Example 8 with RouteSpec

use of com.yahoo.messagebus.routing.RouteSpec in project vespa by vespa-engine.

the class MessageBusVisitorSessionTestCase method testRoutingTableHasMultipleStorageClusters.

@Test
public void testRoutingTableHasMultipleStorageClusters() {
    VisitorParameters visitorParameters = createVisitorParameters("");
    visitorParameters.setRoute(new Route());
    RoutingTableSpec spec = new RoutingTableSpec(DocumentProtocol.NAME);
    spec.addRoute(new RouteSpec("storage/cluster.foo"));
    spec.addRoute(new RouteSpec("storage/cluster.bar"));
    RoutingTable table = new RoutingTable(spec);
    try {
        createDefaultMock(visitorParameters, table);
        fail("No exception thrown on multiple storage clusters");
    } catch (IllegalArgumentException e) {
        assertEquals("There are multiple storage clusters in your application, " + "please specify which one to visit.", e.getMessage());
    }
}
Also used : RoutingTableSpec(com.yahoo.messagebus.routing.RoutingTableSpec) RoutingTable(com.yahoo.messagebus.routing.RoutingTable) RouteSpec(com.yahoo.messagebus.routing.RouteSpec) Route(com.yahoo.messagebus.routing.Route) Test(org.junit.Test)

Example 9 with RouteSpec

use of com.yahoo.messagebus.routing.RouteSpec in project vespa by vespa-engine.

the class DocumentProtocol method addDefaultRoute.

/**
 * Create the "default" route for the Document protocol. This route will be either a route to storage or a route to
 * search. Since we will be supporting recovery from storage, storage takes precedence over search when deciding on
 * the final target of the default route. If there is an unambigous docproc cluster in the application, the default
 * route will pass through this.
 *
 * @param content The content model from {@link com.yahoo.vespa.model.VespaModel}.
 * @param containerClusters a collection of {@link com.yahoo.vespa.model.container.ContainerCluster}s
 * @param table   The routing table to add to.
 */
private static void addDefaultRoute(List<ContentCluster> content, Collection<ContainerCluster> containerClusters, RoutingTableSpec table) {
    List<String> hops = new ArrayList<>();
    if (!content.isEmpty()) {
        boolean found = false;
        for (int i = 0, len = table.getNumHops(); i < len; ++i) {
            if (table.getHop(i).getName().equals("indexing")) {
                found = true;
                break;
            }
        }
        if (found) {
            hops.add("indexing");
        }
    }
    if (!hops.isEmpty()) {
        RouteSpec route = new RouteSpec("default");
        String hop = getContainerClustersDocprocHop(containerClusters);
        if (hop != null) {
            route.addHop(hop);
        }
        int numHops = hops.size();
        if (numHops == 1) {
            route.addHop(hops.get(0));
        } else {
            StringBuilder str = new StringBuilder();
            for (int i = 0; i < numHops; ++i) {
                str.append(hops.get(i)).append(i < numHops - 1 ? " " : "");
            }
            route.addHop("[AND:" + str.toString() + "]");
        }
        table.addRoute(route);
    }
}
Also used : ArrayList(java.util.ArrayList) RouteSpec(com.yahoo.messagebus.routing.RouteSpec)

Aggregations

RouteSpec (com.yahoo.messagebus.routing.RouteSpec)9 RoutingTableSpec (com.yahoo.messagebus.routing.RoutingTableSpec)6 RoutingTable (com.yahoo.messagebus.routing.RoutingTable)3 Test (org.junit.Test)3 Route (com.yahoo.messagebus.routing.Route)2 VespaModel (com.yahoo.vespa.model.VespaModel)2 DocumentProtocol (com.yahoo.vespa.model.routing.DocumentProtocol)2 Routing (com.yahoo.vespa.model.routing.Routing)2 ArrayList (java.util.ArrayList)2 DocumentrouteselectorpolicyConfig (com.yahoo.documentapi.messagebus.protocol.DocumentrouteselectorpolicyConfig)1 MessagebusConfig (com.yahoo.messagebus.MessagebusConfig)1 HopSpec (com.yahoo.messagebus.routing.HopSpec)1 RoutingSpec (com.yahoo.messagebus.routing.RoutingSpec)1 HostResource (com.yahoo.vespa.model.HostResource)1 ContentCluster (com.yahoo.vespa.model.content.cluster.ContentCluster)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1