Search in sources :

Example 16 with ApiMessageAndVersion

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

the class TopicImage method write.

public void write(Consumer<List<ApiMessageAndVersion>> out) {
    List<ApiMessageAndVersion> batch = new ArrayList<>();
    batch.add(new ApiMessageAndVersion(new TopicRecord().setName(name).setTopicId(id), TOPIC_RECORD.highestSupportedVersion()));
    for (Entry<Integer, PartitionRegistration> entry : partitions.entrySet()) {
        int partitionId = entry.getKey();
        PartitionRegistration partition = entry.getValue();
        batch.add(partition.toRecord(id, partitionId));
    }
    out.accept(batch);
}
Also used : PartitionRegistration(org.apache.kafka.metadata.PartitionRegistration) TopicRecord(org.apache.kafka.common.metadata.TopicRecord) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) ArrayList(java.util.ArrayList)

Example 17 with ApiMessageAndVersion

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

the class SnapshotFileReader method handleMetadataBatch.

private void handleMetadataBatch(FileChannelRecordBatch batch) {
    List<ApiMessageAndVersion> messages = new ArrayList<>();
    for (Record record : batch) {
        ByteBufferAccessor accessor = new ByteBufferAccessor(record.value());
        try {
            ApiMessageAndVersion messageAndVersion = serde.read(accessor, record.valueSize());
            messages.add(messageAndVersion);
        } catch (Throwable e) {
            log.error("unable to read metadata record at offset {}", record.offset(), e);
        }
    }
    listener.handleCommit(MemoryBatchReader.of(Collections.singletonList(Batch.data(batch.baseOffset(), batch.partitionLeaderEpoch(), batch.maxTimestamp(), batch.sizeInBytes(), messages)), reader -> {
    }));
}
Also used : MemoryBatchReader(org.apache.kafka.raft.internals.MemoryBatchReader) ByteBufferAccessor(org.apache.kafka.common.protocol.ByteBufferAccessor) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) ControlRecordType(org.apache.kafka.common.record.ControlRecordType) OptionalInt(java.util.OptionalInt) Record(org.apache.kafka.common.record.Record) ArrayList(java.util.ArrayList) KafkaEventQueue(org.apache.kafka.queue.KafkaEventQueue) LogContext(org.apache.kafka.common.utils.LogContext) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) FileRecords(org.apache.kafka.common.record.FileRecords) LeaderChangeMessage(org.apache.kafka.common.message.LeaderChangeMessage) MetadataRecordSerde(org.apache.kafka.metadata.MetadataRecordSerde) Logger(org.slf4j.Logger) Time(org.apache.kafka.common.utils.Time) Iterator(java.util.Iterator) FileChannelRecordBatch(org.apache.kafka.common.record.FileLogInputStream.FileChannelRecordBatch) File(java.io.File) Batch(org.apache.kafka.raft.Batch) List(java.util.List) EventQueue(org.apache.kafka.queue.EventQueue) LeaderAndEpoch(org.apache.kafka.raft.LeaderAndEpoch) RaftClient(org.apache.kafka.raft.RaftClient) Collections(java.util.Collections) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) ArrayList(java.util.ArrayList) Record(org.apache.kafka.common.record.Record) ByteBufferAccessor(org.apache.kafka.common.protocol.ByteBufferAccessor)

Example 18 with ApiMessageAndVersion

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

the class AclControlManager method deleteAclsForFilter.

AclDeleteResult deleteAclsForFilter(AclBindingFilter filter, List<ApiMessageAndVersion> records) {
    List<AclBindingDeleteResult> deleted = new ArrayList<>();
    for (Entry<Uuid, StandardAcl> entry : idToAcl.entrySet()) {
        Uuid id = entry.getKey();
        StandardAcl acl = entry.getValue();
        AclBinding binding = acl.toBinding();
        if (filter.matches(binding)) {
            deleted.add(new AclBindingDeleteResult(binding));
            records.add(new ApiMessageAndVersion(new RemoveAccessControlEntryRecord().setId(id), (short) 0));
        }
    }
    return new AclDeleteResult(deleted);
}
Also used : Uuid(org.apache.kafka.common.Uuid) AclBindingDeleteResult(org.apache.kafka.server.authorizer.AclDeleteResult.AclBindingDeleteResult) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) ArrayList(java.util.ArrayList) AclDeleteResult(org.apache.kafka.server.authorizer.AclDeleteResult) StandardAcl(org.apache.kafka.metadata.authorizer.StandardAcl) AclBinding(org.apache.kafka.common.acl.AclBinding) RemoveAccessControlEntryRecord(org.apache.kafka.common.metadata.RemoveAccessControlEntryRecord)

Example 19 with ApiMessageAndVersion

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

the class AclControlManager method deleteAcls.

ControllerResult<List<AclDeleteResult>> deleteAcls(List<AclBindingFilter> filters) {
    List<AclDeleteResult> results = new ArrayList<>();
    List<ApiMessageAndVersion> records = new ArrayList<>();
    for (AclBindingFilter filter : filters) {
        try {
            validateFilter(filter);
            AclDeleteResult result = deleteAclsForFilter(filter, records);
            results.add(result);
        } catch (Throwable e) {
            results.add(new AclDeleteResult(ApiError.fromThrowable(e).exception()));
        }
    }
    return ControllerResult.atomicOf(records, results);
}
Also used : AclBindingFilter(org.apache.kafka.common.acl.AclBindingFilter) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) ArrayList(java.util.ArrayList) AclDeleteResult(org.apache.kafka.server.authorizer.AclDeleteResult)

Example 20 with ApiMessageAndVersion

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

the class FeatureControlManager method updateFeature.

private ApiError updateFeature(String featureName, VersionRange newRange, boolean downgradeable, Map<Integer, Map<String, VersionRange>> brokerFeatures, List<ApiMessageAndVersion> records) {
    if (newRange.min() <= 0) {
        return new ApiError(Errors.INVALID_UPDATE_VERSION, "The lower value for the new range cannot be less than 1.");
    }
    if (newRange.max() <= 0) {
        return new ApiError(Errors.INVALID_UPDATE_VERSION, "The upper value for the new range cannot be less than 1.");
    }
    VersionRange localRange = supportedFeatures.get(featureName);
    if (localRange == null || !localRange.contains(newRange)) {
        return new ApiError(Errors.INVALID_UPDATE_VERSION, "The controller does not support the given feature range.");
    }
    for (Entry<Integer, Map<String, VersionRange>> brokerEntry : brokerFeatures.entrySet()) {
        VersionRange brokerRange = brokerEntry.getValue().get(featureName);
        if (brokerRange == null || !brokerRange.contains(newRange)) {
            return new ApiError(Errors.INVALID_UPDATE_VERSION, "Broker " + brokerEntry.getKey() + " does not support the given " + "feature range.");
        }
    }
    VersionRange currentRange = finalizedVersions.get(featureName);
    if (currentRange != null && currentRange.max() > newRange.max()) {
        if (!downgradeable) {
            return new ApiError(Errors.INVALID_UPDATE_VERSION, "Can't downgrade the maximum version of this feature without " + "setting downgradable to true.");
        }
    }
    records.add(new ApiMessageAndVersion(new FeatureLevelRecord().setName(featureName).setMinFeatureLevel(newRange.min()).setMaxFeatureLevel(newRange.max()), FEATURE_LEVEL_RECORD.highestSupportedVersion()));
    return ApiError.NONE;
}
Also used : ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) VersionRange(org.apache.kafka.metadata.VersionRange) ApiError(org.apache.kafka.common.requests.ApiError) HashMap(java.util.HashMap) TimelineHashMap(org.apache.kafka.timeline.TimelineHashMap) FeatureMap(org.apache.kafka.metadata.FeatureMap) TreeMap(java.util.TreeMap) Map(java.util.Map) FeatureLevelRecord(org.apache.kafka.common.metadata.FeatureLevelRecord)

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