use of org.apache.kafka.common.Endpoint in project kafka by apache.
the class BrokerRegistration method fromRecord.
public static BrokerRegistration fromRecord(RegisterBrokerRecord record) {
Map<String, Endpoint> listeners = new HashMap<>();
for (BrokerEndpoint endpoint : record.endPoints()) {
listeners.put(endpoint.name(), new Endpoint(endpoint.name(), SecurityProtocol.forId(endpoint.securityProtocol()), endpoint.host(), endpoint.port()));
}
Map<String, VersionRange> supportedFeatures = new HashMap<>();
for (BrokerFeature feature : record.features()) {
supportedFeatures.put(feature.name(), new VersionRange(feature.minSupportedVersion(), feature.maxSupportedVersion()));
}
return new BrokerRegistration(record.brokerId(), record.brokerEpoch(), record.incarnationId(), listeners, supportedFeatures, Optional.ofNullable(record.rack()), record.fenced());
}
use of org.apache.kafka.common.Endpoint in project kafka by apache.
the class ClusterControlManagerTest method testUnregister.
@Test
public void testUnregister() throws Exception {
RegisterBrokerRecord brokerRecord = new RegisterBrokerRecord().setBrokerId(1).setBrokerEpoch(100).setIncarnationId(Uuid.fromString("fPZv1VBsRFmnlRvmGcOW9w")).setRack("arack");
brokerRecord.endPoints().add(new BrokerEndpoint().setSecurityProtocol(SecurityProtocol.PLAINTEXT.id).setPort((short) 9092).setName("PLAINTEXT").setHost("example.com"));
SnapshotRegistry snapshotRegistry = new SnapshotRegistry(new LogContext());
ClusterControlManager clusterControl = new ClusterControlManager(new LogContext(), Uuid.randomUuid().toString(), new MockTime(0, 0, 0), snapshotRegistry, 1000, new StripedReplicaPlacer(new Random()), new MockControllerMetrics());
clusterControl.activate();
clusterControl.replay(brokerRecord);
assertEquals(new BrokerRegistration(1, 100, Uuid.fromString("fPZv1VBsRFmnlRvmGcOW9w"), Collections.singletonMap("PLAINTEXT", new Endpoint("PLAINTEXT", SecurityProtocol.PLAINTEXT, "example.com", 9092)), Collections.emptyMap(), Optional.of("arack"), true), clusterControl.brokerRegistrations().get(1));
UnregisterBrokerRecord unregisterRecord = new UnregisterBrokerRecord().setBrokerId(1).setBrokerEpoch(100);
clusterControl.replay(unregisterRecord);
assertFalse(clusterControl.brokerRegistrations().containsKey(1));
}
use of org.apache.kafka.common.Endpoint in project kafka by apache.
the class ClusterControlManager method replay.
public void replay(RegisterBrokerRecord record) {
int brokerId = record.brokerId();
List<Endpoint> listeners = new ArrayList<>();
for (BrokerEndpoint endpoint : record.endPoints()) {
listeners.add(new Endpoint(endpoint.name(), SecurityProtocol.forId(endpoint.securityProtocol()), endpoint.host(), endpoint.port()));
}
Map<String, VersionRange> features = new HashMap<>();
for (BrokerFeature feature : record.features()) {
features.put(feature.name(), new VersionRange(feature.minSupportedVersion(), feature.maxSupportedVersion()));
}
// Update broker registrations.
BrokerRegistration prevRegistration = brokerRegistrations.put(brokerId, new BrokerRegistration(brokerId, record.brokerEpoch(), record.incarnationId(), listeners, features, Optional.ofNullable(record.rack()), record.fenced()));
updateMetrics(prevRegistration, brokerRegistrations.get(brokerId));
if (prevRegistration == null) {
log.info("Registered new broker: {}", record);
} else if (prevRegistration.incarnationId().equals(record.incarnationId())) {
log.info("Re-registered broker incarnation: {}", record);
} else {
log.info("Re-registered broker id {}: {}", brokerId, record);
}
}
use of org.apache.kafka.common.Endpoint in project kafka by apache.
the class BrokerRegistration method toRecord.
public ApiMessageAndVersion toRecord() {
RegisterBrokerRecord registrationRecord = new RegisterBrokerRecord().setBrokerId(id).setRack(rack.orElse(null)).setBrokerEpoch(epoch).setIncarnationId(incarnationId).setFenced(fenced);
for (Entry<String, Endpoint> entry : listeners.entrySet()) {
Endpoint endpoint = entry.getValue();
registrationRecord.endPoints().add(new BrokerEndpoint().setName(entry.getKey()).setHost(endpoint.host()).setPort(endpoint.port()).setSecurityProtocol(endpoint.securityProtocol().id));
}
for (Entry<String, VersionRange> entry : supportedFeatures.entrySet()) {
registrationRecord.features().add(new BrokerFeature().setName(entry.getKey()).setMinSupportedVersion(entry.getValue().min()).setMaxSupportedVersion(entry.getValue().max()));
}
return new ApiMessageAndVersion(registrationRecord, REGISTER_BROKER_RECORD.highestSupportedVersion());
}
Aggregations