Search in sources :

Example 81 with ApiMessageAndVersion

use of org.apache.kafka.server.common.ApiMessageAndVersion in project kafka by apache.

the class ClusterImage method write.

public void write(Consumer<List<ApiMessageAndVersion>> out) {
    List<ApiMessageAndVersion> batch = new ArrayList<>();
    for (BrokerRegistration broker : brokers.values()) {
        batch.add(broker.toRecord());
    }
    out.accept(batch);
}
Also used : ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) ArrayList(java.util.ArrayList) BrokerRegistration(org.apache.kafka.metadata.BrokerRegistration)

Example 82 with ApiMessageAndVersion

use of org.apache.kafka.server.common.ApiMessageAndVersion in project kafka by apache.

the class StandardAclRecordIterator method next.

@Override
public List<ApiMessageAndVersion> next() {
    if (!hasNext())
        throw new NoSuchElementException();
    List<ApiMessageAndVersion> result = new ArrayList<>(10);
    for (int i = 0; i < maxRecordsInBatch; i++) {
        if (!iterator.hasNext())
            break;
        StandardAclWithId aclWithId = iterator.next();
        result.add(new ApiMessageAndVersion(aclWithId.toRecord(), (short) 0));
    }
    return result;
}
Also used : ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) ArrayList(java.util.ArrayList) NoSuchElementException(java.util.NoSuchElementException)

Example 83 with ApiMessageAndVersion

use of org.apache.kafka.server.common.ApiMessageAndVersion 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)

Example 84 with ApiMessageAndVersion

use of org.apache.kafka.server.common.ApiMessageAndVersion in project kafka by apache.

the class RemoteLogMetadataSerde method serialize.

public byte[] serialize(RemoteLogMetadata remoteLogMetadata) {
    Short apiKey = remoteLogStorageClassToApiKey.get(remoteLogMetadata.getClass().getName());
    if (apiKey == null) {
        throw new IllegalArgumentException("ApiKey for given RemoteStorageMetadata class: " + remoteLogMetadata.getClass() + " does not exist.");
    }
    @SuppressWarnings("unchecked") ApiMessageAndVersion apiMessageAndVersion = remoteLogMetadataTransform(apiKey).toApiMessageAndVersion(remoteLogMetadata);
    return bytesApiMessageSerde.serialize(apiMessageAndVersion);
}
Also used : ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion)

Aggregations

ApiMessageAndVersion (org.apache.kafka.server.common.ApiMessageAndVersion)84 ArrayList (java.util.ArrayList)38 Test (org.junit.jupiter.api.Test)35 Uuid (org.apache.kafka.common.Uuid)23 ApiError (org.apache.kafka.common.requests.ApiError)20 LogContext (org.apache.kafka.common.utils.LogContext)17 HashMap (java.util.HashMap)16 SnapshotRegistry (org.apache.kafka.timeline.SnapshotRegistry)15 List (java.util.List)12 Map (java.util.Map)12 PartitionChangeRecord (org.apache.kafka.common.metadata.PartitionChangeRecord)12 PartitionRegistration (org.apache.kafka.metadata.PartitionRegistration)11 TopicRecord (org.apache.kafka.common.metadata.TopicRecord)8 UnknownTopicOrPartitionException (org.apache.kafka.common.errors.UnknownTopicOrPartitionException)7 AlterIsrRequestData (org.apache.kafka.common.message.AlterIsrRequestData)7 Collections (java.util.Collections)6 Iterator (java.util.Iterator)6 Entry (java.util.Map.Entry)6 NoSuchElementException (java.util.NoSuchElementException)6 Optional (java.util.Optional)6