Search in sources :

Example 1 with SupportedFeatureKey

use of org.apache.kafka.common.message.ApiVersionsResponseData.SupportedFeatureKey in project kafka by apache.

the class KafkaAdminClient method describeFeatures.

@Override
public DescribeFeaturesResult describeFeatures(final DescribeFeaturesOptions options) {
    final KafkaFutureImpl<FeatureMetadata> future = new KafkaFutureImpl<>();
    final long now = time.milliseconds();
    final Call call = new Call("describeFeatures", calcDeadlineMs(now, options.timeoutMs()), new LeastLoadedNodeProvider()) {

        private FeatureMetadata createFeatureMetadata(final ApiVersionsResponse response) {
            final Map<String, FinalizedVersionRange> finalizedFeatures = new HashMap<>();
            for (final FinalizedFeatureKey key : response.data().finalizedFeatures().valuesSet()) {
                finalizedFeatures.put(key.name(), new FinalizedVersionRange(key.minVersionLevel(), key.maxVersionLevel()));
            }
            Optional<Long> finalizedFeaturesEpoch;
            if (response.data().finalizedFeaturesEpoch() >= 0L) {
                finalizedFeaturesEpoch = Optional.of(response.data().finalizedFeaturesEpoch());
            } else {
                finalizedFeaturesEpoch = Optional.empty();
            }
            final Map<String, SupportedVersionRange> supportedFeatures = new HashMap<>();
            for (final SupportedFeatureKey key : response.data().supportedFeatures().valuesSet()) {
                supportedFeatures.put(key.name(), new SupportedVersionRange(key.minVersion(), key.maxVersion()));
            }
            return new FeatureMetadata(finalizedFeatures, finalizedFeaturesEpoch, supportedFeatures);
        }

        @Override
        ApiVersionsRequest.Builder createRequest(int timeoutMs) {
            return new ApiVersionsRequest.Builder();
        }

        @Override
        void handleResponse(AbstractResponse response) {
            final ApiVersionsResponse apiVersionsResponse = (ApiVersionsResponse) response;
            if (apiVersionsResponse.data().errorCode() == Errors.NONE.code()) {
                future.complete(createFeatureMetadata(apiVersionsResponse));
            } else {
                future.completeExceptionally(Errors.forCode(apiVersionsResponse.data().errorCode()).exception());
            }
        }

        @Override
        void handleFailure(Throwable throwable) {
            completeAllExceptionally(Collections.singletonList(future), throwable);
        }
    };
    runnable.call(call, now);
    return new DescribeFeaturesResult(future);
}
Also used : ApiVersionsResponse(org.apache.kafka.common.requests.ApiVersionsResponse) SupportedFeatureKey(org.apache.kafka.common.message.ApiVersionsResponseData.SupportedFeatureKey) HashMap(java.util.HashMap) FinalizedFeatureKey(org.apache.kafka.common.message.ApiVersionsResponseData.FinalizedFeatureKey) AbstractResponse(org.apache.kafka.common.requests.AbstractResponse) ChannelBuilder(org.apache.kafka.common.network.ChannelBuilder) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) AtomicLong(java.util.concurrent.atomic.AtomicLong) ApiVersionsRequest(org.apache.kafka.common.requests.ApiVersionsRequest)

Example 2 with SupportedFeatureKey

use of org.apache.kafka.common.message.ApiVersionsResponseData.SupportedFeatureKey in project kafka by apache.

the class ApiVersionsResponse method createSupportedFeatureKeys.

private static SupportedFeatureKeyCollection createSupportedFeatureKeys(Features<SupportedVersionRange> latestSupportedFeatures) {
    SupportedFeatureKeyCollection converted = new SupportedFeatureKeyCollection();
    for (Map.Entry<String, SupportedVersionRange> feature : latestSupportedFeatures.features().entrySet()) {
        final SupportedFeatureKey key = new SupportedFeatureKey();
        final SupportedVersionRange versionRange = feature.getValue();
        key.setName(feature.getKey());
        key.setMinVersion(versionRange.min());
        key.setMaxVersion(versionRange.max());
        converted.add(key);
    }
    return converted;
}
Also used : SupportedVersionRange(org.apache.kafka.common.feature.SupportedVersionRange) SupportedFeatureKey(org.apache.kafka.common.message.ApiVersionsResponseData.SupportedFeatureKey) SupportedFeatureKeyCollection(org.apache.kafka.common.message.ApiVersionsResponseData.SupportedFeatureKeyCollection) Map(java.util.Map)

Aggregations

SupportedFeatureKey (org.apache.kafka.common.message.ApiVersionsResponseData.SupportedFeatureKey)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 SupportedVersionRange (org.apache.kafka.common.feature.SupportedVersionRange)1 KafkaFutureImpl (org.apache.kafka.common.internals.KafkaFutureImpl)1 FinalizedFeatureKey (org.apache.kafka.common.message.ApiVersionsResponseData.FinalizedFeatureKey)1 SupportedFeatureKeyCollection (org.apache.kafka.common.message.ApiVersionsResponseData.SupportedFeatureKeyCollection)1 ChannelBuilder (org.apache.kafka.common.network.ChannelBuilder)1 AbstractResponse (org.apache.kafka.common.requests.AbstractResponse)1 ApiVersionsRequest (org.apache.kafka.common.requests.ApiVersionsRequest)1 ApiVersionsResponse (org.apache.kafka.common.requests.ApiVersionsResponse)1