Search in sources :

Example 1 with Endpoint

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());
}
Also used : BrokerFeature(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerFeature) Endpoint(org.apache.kafka.common.Endpoint) BrokerEndpoint(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint) HashMap(java.util.HashMap) BrokerEndpoint(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint)

Example 2 with Endpoint

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));
}
Also used : SnapshotRegistry(org.apache.kafka.timeline.SnapshotRegistry) Random(java.util.Random) Endpoint(org.apache.kafka.common.Endpoint) BrokerEndpoint(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint) RegisterBrokerRecord(org.apache.kafka.common.metadata.RegisterBrokerRecord) UnregisterBrokerRecord(org.apache.kafka.common.metadata.UnregisterBrokerRecord) BrokerEndpoint(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint) LogContext(org.apache.kafka.common.utils.LogContext) BrokerRegistration(org.apache.kafka.metadata.BrokerRegistration) MockTime(org.apache.kafka.common.utils.MockTime) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with Endpoint

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);
    }
}
Also used : BrokerFeature(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerFeature) Endpoint(org.apache.kafka.common.Endpoint) BrokerEndpoint(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint) TimelineHashMap(org.apache.kafka.timeline.TimelineHashMap) HashMap(java.util.HashMap) BrokerEndpoint(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint) ArrayList(java.util.ArrayList) VersionRange(org.apache.kafka.metadata.VersionRange) BrokerRegistration(org.apache.kafka.metadata.BrokerRegistration) Endpoint(org.apache.kafka.common.Endpoint) BrokerEndpoint(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint)

Example 4 with Endpoint

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());
}
Also used : BrokerFeature(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerFeature) Endpoint(org.apache.kafka.common.Endpoint) BrokerEndpoint(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint) RegisterBrokerRecord(org.apache.kafka.common.metadata.RegisterBrokerRecord) BrokerEndpoint(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion)

Aggregations

Endpoint (org.apache.kafka.common.Endpoint)4 BrokerEndpoint (org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint)4 BrokerFeature (org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerFeature)3 HashMap (java.util.HashMap)2 RegisterBrokerRecord (org.apache.kafka.common.metadata.RegisterBrokerRecord)2 BrokerRegistration (org.apache.kafka.metadata.BrokerRegistration)2 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 UnregisterBrokerRecord (org.apache.kafka.common.metadata.UnregisterBrokerRecord)1 LogContext (org.apache.kafka.common.utils.LogContext)1 MockTime (org.apache.kafka.common.utils.MockTime)1 VersionRange (org.apache.kafka.metadata.VersionRange)1 ApiMessageAndVersion (org.apache.kafka.server.common.ApiMessageAndVersion)1 SnapshotRegistry (org.apache.kafka.timeline.SnapshotRegistry)1 TimelineHashMap (org.apache.kafka.timeline.TimelineHashMap)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1