static MetadataCache bootstrap(List<InetSocketAddress> addresses) { List<Node> nodes = new ArrayList<>(); int nodeId = -1; for (InetSocketAddress address : addresses) nodes.add(new Node(nodeId--, address.getHostString(), address.getPort())); return new MetadataCache(null, nodes, Collections.emptyList(), Collections.emptySet(), Collections.emptySet(), Collections.emptySet(), null, Cluster.bootstrap(addresses)); }
private static Cluster mockBootstrapCluster() { return Cluster.bootstrap(ClientUtils.parseAndValidateAddresses( Collections.singletonList("localhost:8121"), ClientDnsLookup.DEFAULT)); }
@Test public void testBootstrap() { String ipAddress = "140.211.11.105"; String hostName = "www.example.com"; Cluster cluster = Cluster.bootstrap(Arrays.asList( new InetSocketAddress(ipAddress, 9002), new InetSocketAddress(hostName, 9002) )); Set<String> expectedHosts = Utils.mkSet(ipAddress, hostName); Set<String> actualHosts = new HashSet<>(); for (Node node : cluster.nodes()) actualHosts.add(node.host()); assertEquals(expectedHosts, actualHosts); }
Cluster fromCluster = Cluster.bootstrap(Collections.singletonList(address)); assertEquals(fromMetadata, fromCluster);
Cluster bootstrapCluster = Cluster.bootstrap(singletonList(new InetSocketAddress("localhost", 9999))); Cluster initializedCluster = mockCluster(0);
@Test public void testUnreachableBootstrapServer() throws Exception { // This tests the scenario in which the bootstrap server is unreachable for a short while, // which prevents AdminClient from being able to send the initial metadata request Cluster cluster = Cluster.bootstrap(Collections.singletonList(new InetSocketAddress("localhost", 8121))); try (final AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(Time.SYSTEM, cluster)) { Cluster discoveredCluster = mockCluster(0); env.kafkaClient().setNodeApiVersions(NodeApiVersions.create()); env.kafkaClient().setUnreachable(cluster.nodes().get(0), 200); env.kafkaClient().prepareResponse(body -> body instanceof MetadataRequest, new MetadataResponse(discoveredCluster.nodes(), discoveredCluster.clusterResource().clusterId(), 1, Collections.emptyList())); env.kafkaClient().prepareResponse(body -> body instanceof CreateTopicsRequest, new CreateTopicsResponse(Collections.singletonMap("myTopic", new ApiError(Errors.NONE, "")))); KafkaFuture<Void> future = env.adminClient().createTopics( Collections.singleton(new NewTopic("myTopic", Collections.singletonMap(0, asList(0, 1, 2)))), new CreateTopicsOptions().timeoutMs(10000)).all(); future.get(); } }
config.getList(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG), config.getString(AdminClientConfig.CLIENT_DNS_LOOKUP_CONFIG)); metadataManager.update(Cluster.bootstrap(addresses), time.milliseconds()); List<MetricsReporter> reporters = config.getConfiguredInstances(AdminClientConfig.METRIC_REPORTER_CLASSES_CONFIG, MetricsReporter.class,
public MetadataClient(KafkaCruiseControlConfig config, Metadata metadata, long metadataTTL, Time time) { _metadataGeneration = new AtomicInteger(0); _metadata = metadata; _refreshMetadataTimeout = config.getLong(KafkaCruiseControlConfig.METADATA_MAX_AGE_CONFIG); _time = time; List<InetSocketAddress> addresses = ClientUtils.parseAndValidateAddresses(config.getList(KafkaCruiseControlConfig.BOOTSTRAP_SERVERS_CONFIG)); _metadata.update(Cluster.bootstrap(addresses), Collections.emptySet(), time.milliseconds()); ChannelBuilder channelBuilder = ClientUtils.createChannelBuilder(config); _networkClient = new NetworkClient( new Selector(config.getLong(KafkaCruiseControlConfig.CONNECTIONS_MAX_IDLE_MS_CONFIG), new Metrics(), time, "load-monitor", channelBuilder), _metadata, config.getString(KafkaCruiseControlConfig.CLIENT_ID_CONFIG), DEFAULT_MAX_IN_FLIGHT_REQUEST, config.getLong(KafkaCruiseControlConfig.RECONNECT_BACKOFF_MS_CONFIG), config.getLong(KafkaCruiseControlConfig.RECONNECT_BACKOFF_MS_CONFIG), config.getInt(KafkaCruiseControlConfig.SEND_BUFFER_CONFIG), config.getInt(KafkaCruiseControlConfig.RECEIVE_BUFFER_CONFIG), config.getInt(KafkaCruiseControlConfig.REQUEST_TIMEOUT_MS_CONFIG), _time, true, new ApiVersions()); _metadataTTL = metadataTTL; // This is a super confusing interface in the Metadata. If we don't set this to false, the metadata.update() // will remove all the topics that are not in the metadata interested topics list. _metadata.addListener((cluster, unavailableTopics) -> _metadata.needMetadataForAllTopics(false)); }
@Test public void testMetadataReady() { // Metadata is not ready on initialization assertFalse(mgr.isReady()); assertEquals(0, mgr.metadataFetchDelayMs(time.milliseconds())); // Metadata is not ready when bootstrap servers are set mgr.update(Cluster.bootstrap(Collections.singletonList(new InetSocketAddress("localhost", 9999))), time.milliseconds()); assertFalse(mgr.isReady()); assertEquals(0, mgr.metadataFetchDelayMs(time.milliseconds())); mgr.update(mockCluster(), time.milliseconds()); assertTrue(mgr.isReady()); assertEquals(metadataExpireMs, mgr.metadataFetchDelayMs(time.milliseconds())); time.sleep(metadataExpireMs); assertEquals(0, mgr.metadataFetchDelayMs(time.milliseconds())); }
@Override public boolean awaitMetadataUpdate(long timeout) { metadata.update(Cluster.bootstrap(addresses),time.milliseconds()); return super.awaitMetadataUpdate(timeout); } };
this.metadata = new Metadata(retryBackoffMs, config.getLong(CommonClientConfigs.METADATA_MAX_AGE_CONFIG)); List<InetSocketAddress> addresses = ClientUtils.parseAndValidateAddresses(config.getList(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG)); this.metadata.update(Cluster.bootstrap(addresses), 0); String metricGrpPrefix = "datalink.worker"; ChannelBuilder channelBuilder = ClientUtils.createChannelBuilder(config.values());
config.getList(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG), config.getString(CommonClientConfigs.CLIENT_DNS_LOOKUP_CONFIG)); this.metadata.update(Cluster.bootstrap(addresses), Collections.<String>emptySet(), 0); String metricGrpPrefix = "connect"; ChannelBuilder channelBuilder = ClientUtils.createChannelBuilder(config);
metricTags); List<InetSocketAddress> addresses = ClientUtils.parseAndValidateAddresses(config.getList(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG)); this.metadata.update(Cluster.bootstrap(addresses), time.milliseconds());