ConfigserverCluster extends AbstractConfigProducer implements
        ZookeeperServerConfig.Producer,
        ConfigserverConfig.Producer,
        StatisticsConfig.Producer,
        HealthMonitorConfig.Producer,
        VipStatusConfig.Producer { @Override public void getConfig(ZookeeperServerConfig.Builder builder) { ConfigServer[] configServers = getConfigServers(); int[] zookeeperIds = getConfigServerZookeeperIds(); if (configServers.length != zookeeperIds.length) { throw new IllegalArgumentException(String.format("Number of provided config server hosts (%d) must be the " + "same as number of provided config server zookeeper ids (%d)", configServers.length, zookeeperIds.length)); } String myhostname = HostName.getLocalhost(); for (int i = 0; i < configServers.length; i++) { if (zookeeperIds[i] < 0) { throw new IllegalArgumentException(String.format("Zookeeper ids cannot be negative, was %d for %s", zookeeperIds[i], configServers[i].hostName)); } if (configServers[i].hostName.equals(myhostname)) { builder.myid(zookeeperIds[i]); } builder.server(getZkServer(configServers[i], zookeeperIds[i])); } if (options.zookeeperClientPort().isPresent()) { builder.clientPort(options.zookeeperClientPort().get()); } } ConfigserverCluster(AbstractConfigProducer parent, String subId, CloudConfigOptions options); void setContainerCluster(ContainerCluster containerCluster); @Override void getConfig(ZookeeperServerConfig.Builder builder); @Override void getConfig(ConfigserverConfig.Builder builder); @Override void getConfig(StatisticsConfig.Builder builder); @Override void getConfig(HealthMonitorConfig.Builder builder); @Override void getConfig(VipStatusConfig.Builder builder);  }
@Test public void zookeeperConfig_default() { ZookeeperServerConfig config = getConfig(ZookeeperServerConfig.class); assertZookeeperServerProperty(config.server(), ZookeeperServerConfig.Server::hostname, "localhost"); assertZookeeperServerProperty(config.server(), ZookeeperServerConfig.Server::id, 0); assertEquals(0, config.myid()); }
@Test public void zookeeperConfig_only_config_servers_set() { TestOptions testOptions = createTestOptions(Arrays.asList("cfg1", "localhost", "cfg3"), Collections.emptyList()); ZookeeperServerConfig config = getConfig(ZookeeperServerConfig.class, testOptions); assertZookeeperServerProperty(config.server(), ZookeeperServerConfig.Server::hostname, "cfg1", "localhost", "cfg3"); assertZookeeperServerProperty(config.server(), ZookeeperServerConfig.Server::id, 0, 1, 2); assertEquals(1, config.myid()); }
@Test public void zookeeperConfig_with_config_servers_and_zk_ids() { TestOptions testOptions = createTestOptions(Arrays.asList("cfg1", "localhost", "cfg3"), Arrays.asList(4, 2, 3)); ZookeeperServerConfig config = getConfig(ZookeeperServerConfig.class, testOptions); assertZookeeperServerProperty(config.server(), ZookeeperServerConfig.Server::hostname, "cfg1", "localhost", "cfg3"); assertZookeeperServerProperty(config.server(), ZookeeperServerConfig.Server::id, 4, 2, 3); assertEquals(2, config.myid()); }
@Test public void zookeeperConfig_self_hosted() { final boolean hostedVespa = false; TestOptions testOptions = createTestOptions(Arrays.asList("cfg1", "localhost", "cfg3"), Arrays.asList(4, 2, 3), hostedVespa); ZookeeperServerConfig config = getConfig(ZookeeperServerConfig.class, testOptions); assertZookeeperServerProperty(config.server(), ZookeeperServerConfig.Server::hostname, "cfg1", "localhost", "cfg3"); assertZookeeperServerProperty(config.server(), ZookeeperServerConfig.Server::id, 4, 2, 3); assertEquals(2, config.myid()); }
@Test(expected = IllegalArgumentException.class) public void zookeeperConfig_uneven_number_of_config_servers_and_zk_ids() { TestOptions testOptions = createTestOptions(Arrays.asList("cfg1", "localhost", "cfg3"), Collections.singletonList(1)); getConfig(ZookeeperServerConfig.class, testOptions); }
@Test(expected = IllegalArgumentException.class) public void zookeeperConfig_negative_zk_id() { TestOptions testOptions = createTestOptions(Arrays.asList("cfg1", "localhost", "cfg3"), Arrays.asList(1, 2, -1)); getConfig(ZookeeperServerConfig.class, testOptions); }
@Test public void testStatisticsConfig() { StatisticsConfig config = getConfig(StatisticsConfig.class); assertThat((int) config.collectionintervalsec(), is(60)); assertThat((int) config.loggingintervalsec(), is(60)); }
@Test public void testHealthMonitorConfig() { HealthMonitorConfig config = getConfig(HealthMonitorConfig.class); assertThat(((int) config.snapshot_interval()), is(60)); }
@Test public void testConfigserverConfig() { ConfigserverConfig config = getConfig(ConfigserverConfig.class); assertThat(config.configModelPluginDir().size(), is(1)); assertThat(config.configModelPluginDir().get(0), is(Defaults.getDefaults().underVespaHome("lib/jars/config-models"))); assertThat(config.rpcport(), is(12345)); assertThat(config.httpport(), is(1337)); assertThat(config.serverId(), is(HostName.getLocalhost())); assertTrue(config.useVespaVersionInRequest()); assertThat(config.numParallelTenantLoaders(), is(4)); assertFalse(config.multitenant()); assertTrue(config.hostedVespa()); assertThat(config.environment(), is("test")); assertThat(config.region(), is("bar")); }