use of kafka.server.ControllerServer in project kafka by apache.
the class KafkaClusterTestKit method waitForReadyBrokers.
/**
* Wait for a controller to mark all the brokers as ready (registered and unfenced).
*/
public void waitForReadyBrokers() throws ExecutionException, InterruptedException {
// We can choose any controller, not just the active controller.
// If we choose a standby controller, we will wait slightly longer.
ControllerServer controllerServer = controllers.values().iterator().next();
Controller controller = controllerServer.controller();
controller.waitForReadyBrokers(brokers.size()).get();
}
use of kafka.server.ControllerServer 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);
}
}
use of kafka.server.ControllerServer 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;
}
}
Aggregations