Search in sources :

Example 1 with BrokerServer

use of kafka.server.BrokerServer in project kafka by apache.

the class KafkaClusterTestKit method clientProperties.

public Properties clientProperties() {
    Properties properties = new Properties();
    if (!brokers.isEmpty()) {
        StringBuilder bld = new StringBuilder();
        String prefix = "";
        for (Entry<Integer, BrokerServer> entry : brokers.entrySet()) {
            int brokerId = entry.getKey();
            BrokerServer broker = entry.getValue();
            ListenerName listenerName = nodes.externalListenerName();
            int port = broker.boundPort(listenerName);
            if (port <= 0) {
                throw new RuntimeException("Broker " + brokerId + " does not yet " + "have a bound port for " + listenerName + ".  Did you start " + "the cluster yet?");
            }
            bld.append(prefix).append("localhost:").append(port);
            prefix = ",";
        }
        properties.setProperty(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, bld.toString());
    }
    return properties;
}
Also used : BrokerServer(kafka.server.BrokerServer) MetaProperties(kafka.server.MetaProperties) Properties(java.util.Properties) ListenerName(org.apache.kafka.common.network.ListenerName)

Example 2 with BrokerServer

use of kafka.server.BrokerServer in project kafka by apache.

the class KafkaClusterTestKit method close.

@Override
public void close() throws Exception {
    List<Entry<String, Future<?>>> futureEntries = new ArrayList<>();
    try {
        controllerQuorumVotersFutureManager.close();
        for (Entry<Integer, BrokerServer> entry : brokers.entrySet()) {
            int brokerId = entry.getKey();
            BrokerServer broker = entry.getValue();
            futureEntries.add(new SimpleImmutableEntry<>("broker" + brokerId, executorService.submit(broker::shutdown)));
        }
        waitForAllFutures(futureEntries);
        futureEntries.clear();
        for (Entry<Integer, ControllerServer> entry : controllers.entrySet()) {
            int controllerId = entry.getKey();
            ControllerServer controller = entry.getValue();
            futureEntries.add(new SimpleImmutableEntry<>("controller" + controllerId, executorService.submit(controller::shutdown)));
        }
        waitForAllFutures(futureEntries);
        futureEntries.clear();
        for (Entry<Integer, KafkaRaftManager<ApiMessageAndVersion>> entry : raftManagers.entrySet()) {
            int raftManagerId = entry.getKey();
            KafkaRaftManager<ApiMessageAndVersion> raftManager = entry.getValue();
            futureEntries.add(new SimpleImmutableEntry<>("raftManager" + raftManagerId, executorService.submit(raftManager::shutdown)));
        }
        waitForAllFutures(futureEntries);
        futureEntries.clear();
        Utils.delete(baseDirectory);
    } catch (Exception e) {
        for (Entry<String, Future<?>> entry : futureEntries) {
            entry.getValue().cancel(true);
        }
        throw e;
    } finally {
        executorService.shutdownNow();
        executorService.awaitTermination(5, TimeUnit.MINUTES);
    }
}
Also used : ControllerServer(kafka.server.ControllerServer) BrokerServer(kafka.server.BrokerServer) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Entry(java.util.Map.Entry) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) KafkaRaftManager(kafka.raft.KafkaRaftManager)

Example 3 with BrokerServer

use of kafka.server.BrokerServer in project kafka by apache.

the class KafkaClusterTestKit method format.

public void format() throws Exception {
    List<Future<?>> futures = new ArrayList<>();
    try {
        for (Entry<Integer, ControllerServer> entry : controllers.entrySet()) {
            int nodeId = entry.getKey();
            ControllerServer controller = entry.getValue();
            formatNodeAndLog(nodes.controllerProperties(nodeId), controller.config().metadataLogDir(), controller, futures::add);
        }
        for (Entry<Integer, BrokerServer> entry : brokers.entrySet()) {
            int nodeId = entry.getKey();
            BrokerServer broker = entry.getValue();
            formatNodeAndLog(nodes.brokerProperties(nodeId), broker.config().metadataLogDir(), broker, futures::add);
        }
        for (Future<?> future : futures) {
            future.get();
        }
    } catch (Exception e) {
        for (Future<?> future : futures) {
            future.cancel(true);
        }
        throw e;
    }
}
Also used : ControllerServer(kafka.server.ControllerServer) BrokerServer(kafka.server.BrokerServer) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) CompletableFuture(java.util.concurrent.CompletableFuture) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

BrokerServer (kafka.server.BrokerServer)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ExecutionException (java.util.concurrent.ExecutionException)2 ControllerServer (kafka.server.ControllerServer)2 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)1 Entry (java.util.Map.Entry)1 Properties (java.util.Properties)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Future (java.util.concurrent.Future)1 KafkaRaftManager (kafka.raft.KafkaRaftManager)1 MetaProperties (kafka.server.MetaProperties)1 ListenerName (org.apache.kafka.common.network.ListenerName)1 ApiMessageAndVersion (org.apache.kafka.server.common.ApiMessageAndVersion)1