Search in sources :

Example 1 with MessagebusConfig

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

the class RoutingTestCase method assertApplication.

/**
 * Tests whether or not the given application produces the expected output. When creating new tests, create an
 * application directory containing the necessary setup files, and call this method with a TRUE create flag.
 *
 * @param application The application directory.
 */
private static void assertApplication(File application) throws IOException {
    assertTrue(application.isDirectory());
    String applicationName = application.getName();
    Map<String, File> files = new HashMap<>();
    for (File file : application.listFiles(new ContentFilter())) {
        files.put(file.getName(), file);
    }
    String path = null;
    try {
        path = application.getCanonicalPath();
    } catch (IOException e) {
        fail("Could not resolve path for application '" + applicationName + "'.");
    }
    VespaModelCreatorWithFilePkg creator = new VespaModelCreatorWithFilePkg(path);
    VespaModel model = creator.create();
    List<String> errors = model.getRouting().getErrors();
    if (errors.isEmpty()) {
        if (files.containsKey("errors.txt")) {
            if (WRITE_FILES) {
                files.remove("errors.txt").delete();
            } else {
                fail("Route verification did not fail.");
            }
        }
        MessagebusConfig.Builder mBusB = new MessagebusConfig.Builder();
        model.getConfig(mBusB, "");
        MessagebusConfig mBus = new MessagebusConfig(mBusB);
        assertConfigFileContains(application, files, "messagebus.cfg", mBus);
        DocumentrouteselectorpolicyConfig.Builder drB = new DocumentrouteselectorpolicyConfig.Builder();
        model.getConfig(drB, "");
        DocumentrouteselectorpolicyConfig dr = new DocumentrouteselectorpolicyConfig(drB);
        assertConfigFileContains(application, files, "documentrouteselectorpolicy.cfg", dr);
    } else {
        StringBuilder msg = new StringBuilder();
        for (String error : errors) {
            msg.append(error).append("\n");
        }
        assertFileContains(application, files, "errors.txt", msg.toString());
    }
}
Also used : VespaModelCreatorWithFilePkg(com.yahoo.vespa.model.test.utils.VespaModelCreatorWithFilePkg) HashMap(java.util.HashMap) DocumentrouteselectorpolicyConfig(com.yahoo.documentapi.messagebus.protocol.DocumentrouteselectorpolicyConfig) MessagebusConfig(com.yahoo.messagebus.MessagebusConfig) VespaModel(com.yahoo.vespa.model.VespaModel)

Example 2 with MessagebusConfig

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

the class VespaModelTestCase method testCreateFromReaders.

@Test
public void testCreateFromReaders() throws SAXException, IOException {
    VespaModel model = CommonVespaModelSetup.createVespaModelWithMusic(simpleHosts, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" + "<services  version=\"1.0\">" + "<admin  version=\"2.0\">" + "  <adminserver hostalias=\"node0\" />" + "</admin>" + "<container version=\"1.0\">" + "   <nodes>" + "      <node hostalias=\"node0\" />" + "   </nodes>" + "   <search/>" + "   <document-api/>" + "</container>" + "<content id=\"music\" version=\"1.0\">" + "   <redundancy>1</redundancy>" + "   <nodes>" + "      <node hostalias=\"node0\" distribution-key=\"0\"/>" + "   </nodes>" + "   <documents>" + "     <document type=\"music\" mode=\"index\"/>" + "   </documents>" + "</content>" + "</services>");
    MessagebusConfig.Builder mBusB = new MessagebusConfig.Builder();
    model.getConfig(mBusB, "client");
    MessagebusConfig mBus = new MessagebusConfig(mBusB);
    assertEquals(mBus.routingtable().size(), 1);
}
Also used : MessagebusConfig(com.yahoo.messagebus.MessagebusConfig) VespaModel(com.yahoo.vespa.model.VespaModel) Test(org.junit.Test)

Example 3 with MessagebusConfig

use of com.yahoo.messagebus.MessagebusConfig 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);
}
Also used : RoutingTableSpec(com.yahoo.messagebus.routing.RoutingTableSpec) MessagebusConfig(com.yahoo.messagebus.MessagebusConfig) HopSpec(com.yahoo.messagebus.routing.HopSpec) RouteSpec(com.yahoo.messagebus.routing.RouteSpec) RoutingSpec(com.yahoo.messagebus.routing.RoutingSpec)

Aggregations

MessagebusConfig (com.yahoo.messagebus.MessagebusConfig)3 VespaModel (com.yahoo.vespa.model.VespaModel)2 DocumentrouteselectorpolicyConfig (com.yahoo.documentapi.messagebus.protocol.DocumentrouteselectorpolicyConfig)1 HopSpec (com.yahoo.messagebus.routing.HopSpec)1 RouteSpec (com.yahoo.messagebus.routing.RouteSpec)1 RoutingSpec (com.yahoo.messagebus.routing.RoutingSpec)1 RoutingTableSpec (com.yahoo.messagebus.routing.RoutingTableSpec)1 VespaModelCreatorWithFilePkg (com.yahoo.vespa.model.test.utils.VespaModelCreatorWithFilePkg)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1