use of org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerFeature 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.metadata.RegisterBrokerRecord.BrokerFeature 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.metadata.RegisterBrokerRecord.BrokerFeature in project kafka by apache.
the class ClusterControlManager method registerBroker.
/**
* Process an incoming broker registration request.
*/
public ControllerResult<BrokerRegistrationReply> registerBroker(BrokerRegistrationRequestData request, long brokerEpoch, FeatureMapAndEpoch finalizedFeatures) {
if (heartbeatManager == null) {
throw new RuntimeException("ClusterControlManager is not active.");
}
if (!clusterId.equals(request.clusterId())) {
throw new InconsistentClusterIdException("Expected cluster ID " + clusterId + ", but got cluster ID " + request.clusterId());
}
int brokerId = request.brokerId();
BrokerRegistration existing = brokerRegistrations.get(brokerId);
if (existing != null) {
if (heartbeatManager.hasValidSession(brokerId)) {
if (!existing.incarnationId().equals(request.incarnationId())) {
throw new DuplicateBrokerRegistrationException("Another broker is " + "registered with that broker id.");
}
} else {
if (!existing.incarnationId().equals(request.incarnationId())) {
// Remove any existing session for the old broker incarnation.
heartbeatManager.remove(brokerId);
existing = null;
}
}
}
RegisterBrokerRecord record = new RegisterBrokerRecord().setBrokerId(brokerId).setIncarnationId(request.incarnationId()).setBrokerEpoch(brokerEpoch).setRack(request.rack());
for (BrokerRegistrationRequestData.Listener listener : request.listeners()) {
record.endPoints().add(new BrokerEndpoint().setHost(listener.host()).setName(listener.name()).setPort(listener.port()).setSecurityProtocol(listener.securityProtocol()));
}
for (BrokerRegistrationRequestData.Feature feature : request.features()) {
Optional<VersionRange> finalized = finalizedFeatures.map().get(feature.name());
if (finalized.isPresent()) {
if (!finalized.get().contains(new VersionRange(feature.minSupportedVersion(), feature.maxSupportedVersion()))) {
throw new UnsupportedVersionException("Unable to register because " + "the broker has an unsupported version of " + feature.name());
}
}
record.features().add(new BrokerFeature().setName(feature.name()).setMinSupportedVersion(feature.minSupportedVersion()).setMaxSupportedVersion(feature.maxSupportedVersion()));
}
if (existing == null) {
heartbeatManager.touch(brokerId, true, -1);
} else {
heartbeatManager.touch(brokerId, existing.fenced(), -1);
}
List<ApiMessageAndVersion> records = new ArrayList<>();
records.add(new ApiMessageAndVersion(record, REGISTER_BROKER_RECORD.highestSupportedVersion()));
return ControllerResult.atomicOf(records, new BrokerRegistrationReply(brokerEpoch));
}
use of org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerFeature 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