use of com.yahoo.messagebus.routing.RouteSpec in project vespa by vespa-engine.
the class DocumentProtocol method addContentRouting.
/**
* Create hops to all configured storage nodes for the Document protocol. The "Distributor" policy resolves its
* recipients using slobrok lookups, so it requires no configured recipients.
*
* @param content The storage model from {@link com.yahoo.vespa.model.VespaModel}.
* @param table The routing table to add to.
*/
private static void addContentRouting(List<ContentCluster> content, RoutingTableSpec table) {
for (ContentCluster cluster : content) {
RouteSpec spec = new RouteSpec(cluster.getConfigId());
if (cluster.getSearch().hasIndexedCluster()) {
table.addRoute(spec.addHop("[MessageType:" + cluster.getConfigId() + "]"));
table.addRoute(new RouteSpec(getIndexedRouteName(cluster.getConfigId())).addHop(cluster.getSearch().getIndexed().getIndexingServiceName()).addHop("[Content:cluster=" + cluster.getName() + "]"));
table.addRoute(new RouteSpec(getDirectRouteName(cluster.getConfigId())).addHop("[Content:cluster=" + cluster.getName() + "]"));
} else {
table.addRoute(spec.addHop("[Content:cluster=" + cluster.getName() + "]"));
}
table.addRoute(new RouteSpec("storage/cluster." + cluster.getName()).addHop("route:" + cluster.getConfigId()));
}
}
use of com.yahoo.messagebus.routing.RouteSpec in project vespa by vespa-engine.
the class DocumentProtocol method simplifyRouteNames.
/**
* Attempts to simplify all route names by removing prefixing plugin name and whatever comes before the dot (.) in
* the second naming element. This can only be done to those routes that do not share primary name elements with
* other routes (e.g. a search clusters with the same name as a storage cluster).
*
* @param table The routing table whose route names are to be simplified.
*/
private static void simplifyRouteNames(RoutingTableSpec table) {
if (table == null || !table.hasRoutes()) {
return;
}
// Pass 1: Determine which simplifications are in conflict.
Map<String, Set<String>> simple = new TreeMap<>();
List<String> broken = new ArrayList<>();
for (int i = 0, len = table.getNumRoutes(); i < len; ++i) {
String before = table.getRoute(i).getName();
String after = simplifyRouteName(before);
if (simple.containsKey(after)) {
Set<String> l = simple.get(after);
l.add(before);
if (!(l.contains("content/" + after) && l.contains("storage/cluster." + after) && (l.size() == 2))) {
broken.add(after);
}
} else {
Set<String> l = new HashSet<>();
l.add(before);
simple.put(after, l);
}
}
// Pass 2: Simplify all non-conflicting route names by alias.
Set<RouteSpec> alias = new HashSet<>();
Set<String> unique = new HashSet<>();
for (int i = 0; i < table.getNumRoutes(); ) {
RouteSpec route = table.getRoute(i);
String before = route.getName();
String after = simplifyRouteName(before);
if (!before.equals(after)) {
if (!broken.contains(after)) {
if (route.getNumHops() == 1 && route.getHop(0).equals(route.getName())) {
// full route name is redundant
alias.add(new RouteSpec(after).addHop(route.getHop(0)));
unique.add(after);
table.removeRoute(i);
// do not increment i
continue;
} else {
if (!unique.contains(after)) {
alias.add(new RouteSpec(after).addHop("route:" + before));
unique.add(after);
}
}
}
}
++i;
}
for (RouteSpec rs : alias) {
table.addRoute(rs);
}
}
use of com.yahoo.messagebus.routing.RouteSpec in project vespa by vespa-engine.
the class StorageContentTest method doTestRouting.
public void doTestRouting(String cluster1docs, String cluster2docs, String expectedRoutes) throws Exception {
VespaModel model = getStorageVespaModel(cluster1docs, cluster2docs);
if (expectedRoutes == null) {
return;
}
Routing routing = model.getRouting();
assertNotNull(routing);
assertEquals(0, routing.getErrors().size());
assertEquals(1, routing.getProtocols().size());
DocumentProtocol protocol = (DocumentProtocol) routing.getProtocols().get(0);
RoutingTableSpec spec = protocol.getRoutingTableSpec();
assertEquals(1, spec.getNumHops());
assertEquals("indexing", spec.getHop(0).getName());
assertEquals("[DocumentRouteSelector]", spec.getHop(0).getSelector());
Map<String, RouteSpec> routes = new TreeMap<>();
for (int i = 0; i < spec.getNumRoutes(); ++i) {
RouteSpec r = spec.getRoute(i);
routes.put(r.getName(), r);
}
{
RouteSpec r = routes.get("default");
assertEquals(1, r.getNumHops());
assertEquals("indexing", r.getHop(0));
}
Set<String> configuredRoutes = new TreeSet<>();
DocumentrouteselectorpolicyConfig.Builder builder = new DocumentrouteselectorpolicyConfig.Builder();
protocol.getConfig(builder);
DocumentrouteselectorpolicyConfig config = new DocumentrouteselectorpolicyConfig(builder);
for (DocumentrouteselectorpolicyConfig.Route r : config.route()) {
configuredRoutes.add(r.name() + " : " + r.selector());
}
StringBuilder routeStr = new StringBuilder();
for (String r : configuredRoutes) {
routeStr.append(r).append('\n');
}
assertEquals(expectedRoutes, routeStr.toString());
}
use of com.yahoo.messagebus.routing.RouteSpec in project vespa by vespa-engine.
the class IndexedTest method requireIndexedOnlyServices.
@Test
public void requireIndexedOnlyServices() {
VespaModel model = getIndexedVespaModel();
HostResource h = model.getHostSystem().getHosts().get(0);
String[] expectedServices = { "logserver", "configserver", "adminserver", "slobrok", "logd", "configproxy", "config-sentinel", "qrserver", "fleetcontroller", "topleveldispatch", "docprocservice", "storagenode", "searchnode", "distributor", "transactionlogserver" };
// TODO DomContentBuilderTest.assertServices(h, expectedServices);
Routing routing = model.getRouting();
assertNotNull(routing);
assertEquals("[]", routing.getErrors().toString());
assertEquals(1, routing.getProtocols().size());
DocumentProtocol protocol = (DocumentProtocol) routing.getProtocols().get(0);
RoutingTableSpec spec = protocol.getRoutingTableSpec();
assertEquals(2, spec.getNumHops());
assertEquals("docproc/cluster.test.indexing/chain.indexing", spec.getHop(0).getName());
assertEquals("indexing", spec.getHop(1).getName());
RouteSpec r;
r = spec.getRoute(0);
assertEquals("default", r.getName());
assertEquals(1, r.getNumHops());
assertEquals("indexing", r.getHop(0));
r = spec.getRoute(1);
assertEquals("storage/cluster.test", r.getName());
assertEquals(1, r.getNumHops());
assertEquals("route:test", r.getHop(0));
r = spec.getRoute(2);
assertEquals("test", r.getName());
assertEquals(1, r.getNumHops());
assertEquals("[MessageType:test]", r.getHop(0));
r = spec.getRoute(3);
assertEquals("test-direct", r.getName());
assertEquals(1, r.getNumHops());
assertEquals("[Content:cluster=test]", r.getHop(0));
r = spec.getRoute(4);
assertEquals("test-index", r.getName());
assertEquals(2, r.getNumHops());
assertEquals("docproc/cluster.test.indexing/chain.indexing", r.getHop(0));
assertEquals("[Content:cluster=test]", r.getHop(1));
}
use of com.yahoo.messagebus.routing.RouteSpec in project vespa by vespa-engine.
the class ConfigAgent method configure.
@Override
public void configure(MessagebusConfig config) {
RoutingSpec routing = new RoutingSpec();
for (int table = 0; table < config.routingtable().size(); table++) {
MessagebusConfig.Routingtable tableConfig = config.routingtable(table);
RoutingTableSpec tableSpec = new RoutingTableSpec(tableConfig.protocol());
for (int hop = 0; hop < tableConfig.hop().size(); hop++) {
MessagebusConfig.Routingtable.Hop hopConfig = tableConfig.hop(hop);
HopSpec hopSpec = new HopSpec(hopConfig.name(), hopConfig.selector());
for (int recipient = 0; recipient < hopConfig.recipient().size(); recipient++) {
hopSpec.addRecipient(hopConfig.recipient(recipient));
}
hopSpec.setIgnoreResult(hopConfig.ignoreresult());
tableSpec.addHop(hopSpec);
}
for (int route = 0; route < tableConfig.route().size(); route++) {
MessagebusConfig.Routingtable.Route routeConfig = tableConfig.route(route);
RouteSpec routeSpec = new RouteSpec(routeConfig.name());
for (int hop = 0; hop < routeConfig.hop().size(); hop++) {
routeSpec.addHop(routeConfig.hop(hop));
}
tableSpec.addRoute(routeSpec);
}
routing.addTable(tableSpec);
}
handler.setupRouting(routing);
}
Aggregations