Search in sources :

Example 1 with UpdatableFeatureResult

use of org.apache.kafka.common.message.UpdateFeaturesResponseData.UpdatableFeatureResult in project kafka by apache.

the class UpdateFeaturesResponse method errorCounts.

@Override
public Map<Errors, Integer> errorCounts() {
    Map<Errors, Integer> errorCounts = new HashMap<>();
    updateErrorCounts(errorCounts, Errors.forCode(data.errorCode()));
    for (UpdatableFeatureResult result : data.results()) {
        updateErrorCounts(errorCounts, Errors.forCode(result.errorCode()));
    }
    return errorCounts;
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) HashMap(java.util.HashMap) UpdatableFeatureResult(org.apache.kafka.common.message.UpdateFeaturesResponseData.UpdatableFeatureResult)

Example 2 with UpdatableFeatureResult

use of org.apache.kafka.common.message.UpdateFeaturesResponseData.UpdatableFeatureResult in project kafka by apache.

the class UpdateFeaturesResponse method createWithErrors.

public static UpdateFeaturesResponse createWithErrors(ApiError topLevelError, Map<String, ApiError> updateErrors, int throttleTimeMs) {
    final UpdatableFeatureResultCollection results = new UpdatableFeatureResultCollection();
    for (final Map.Entry<String, ApiError> updateError : updateErrors.entrySet()) {
        final String feature = updateError.getKey();
        final ApiError error = updateError.getValue();
        final UpdatableFeatureResult result = new UpdatableFeatureResult();
        result.setFeature(feature).setErrorCode(error.error().code()).setErrorMessage(error.message());
        results.add(result);
    }
    final UpdateFeaturesResponseData responseData = new UpdateFeaturesResponseData().setThrottleTimeMs(throttleTimeMs).setErrorCode(topLevelError.error().code()).setErrorMessage(topLevelError.message()).setResults(results).setThrottleTimeMs(throttleTimeMs);
    return new UpdateFeaturesResponse(responseData);
}
Also used : UpdateFeaturesResponseData(org.apache.kafka.common.message.UpdateFeaturesResponseData) UpdatableFeatureResultCollection(org.apache.kafka.common.message.UpdateFeaturesResponseData.UpdatableFeatureResultCollection) UpdatableFeatureResult(org.apache.kafka.common.message.UpdateFeaturesResponseData.UpdatableFeatureResult) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with UpdatableFeatureResult

use of org.apache.kafka.common.message.UpdateFeaturesResponseData.UpdatableFeatureResult in project kafka by apache.

the class KafkaAdminClient method updateFeatures.

@Override
public UpdateFeaturesResult updateFeatures(final Map<String, FeatureUpdate> featureUpdates, final UpdateFeaturesOptions options) {
    if (featureUpdates.isEmpty()) {
        throw new IllegalArgumentException("Feature updates can not be null or empty.");
    }
    final Map<String, KafkaFutureImpl<Void>> updateFutures = new HashMap<>();
    for (final Map.Entry<String, FeatureUpdate> entry : featureUpdates.entrySet()) {
        final String feature = entry.getKey();
        if (Utils.isBlank(feature)) {
            throw new IllegalArgumentException("Provided feature can not be empty.");
        }
        updateFutures.put(entry.getKey(), new KafkaFutureImpl<>());
    }
    final long now = time.milliseconds();
    final Call call = new Call("updateFeatures", calcDeadlineMs(now, options.timeoutMs()), new ControllerNodeProvider()) {

        @Override
        UpdateFeaturesRequest.Builder createRequest(int timeoutMs) {
            final UpdateFeaturesRequestData.FeatureUpdateKeyCollection featureUpdatesRequestData = new UpdateFeaturesRequestData.FeatureUpdateKeyCollection();
            for (Map.Entry<String, FeatureUpdate> entry : featureUpdates.entrySet()) {
                final String feature = entry.getKey();
                final FeatureUpdate update = entry.getValue();
                final UpdateFeaturesRequestData.FeatureUpdateKey requestItem = new UpdateFeaturesRequestData.FeatureUpdateKey();
                requestItem.setFeature(feature);
                requestItem.setMaxVersionLevel(update.maxVersionLevel());
                requestItem.setAllowDowngrade(update.allowDowngrade());
                featureUpdatesRequestData.add(requestItem);
            }
            return new UpdateFeaturesRequest.Builder(new UpdateFeaturesRequestData().setTimeoutMs(timeoutMs).setFeatureUpdates(featureUpdatesRequestData));
        }

        @Override
        void handleResponse(AbstractResponse abstractResponse) {
            final UpdateFeaturesResponse response = (UpdateFeaturesResponse) abstractResponse;
            ApiError topLevelError = response.topLevelError();
            switch(topLevelError.error()) {
                case NONE:
                    for (final UpdatableFeatureResult result : response.data().results()) {
                        final KafkaFutureImpl<Void> future = updateFutures.get(result.feature());
                        if (future == null) {
                            log.warn("Server response mentioned unknown feature {}", result.feature());
                        } else {
                            final Errors error = Errors.forCode(result.errorCode());
                            if (error == Errors.NONE) {
                                future.complete(null);
                            } else {
                                future.completeExceptionally(error.exception(result.errorMessage()));
                            }
                        }
                    }
                    // The server should send back a response for every feature, but we do a sanity check anyway.
                    completeUnrealizedFutures(updateFutures.entrySet().stream(), feature -> "The controller response did not contain a result for feature " + feature);
                    break;
                case NOT_CONTROLLER:
                    handleNotControllerError(topLevelError.error());
                    break;
                default:
                    for (final Map.Entry<String, KafkaFutureImpl<Void>> entry : updateFutures.entrySet()) {
                        entry.getValue().completeExceptionally(topLevelError.exception());
                    }
                    break;
            }
        }

        @Override
        void handleFailure(Throwable throwable) {
            completeAllExceptionally(updateFutures.values(), throwable);
        }
    };
    runnable.call(call, now);
    return new UpdateFeaturesResult(new HashMap<>(updateFutures));
}
Also used : UpdateFeaturesResponse(org.apache.kafka.common.requests.UpdateFeaturesResponse) HashMap(java.util.HashMap) ChannelBuilder(org.apache.kafka.common.network.ChannelBuilder) UpdateFeaturesRequest(org.apache.kafka.common.requests.UpdateFeaturesRequest) UpdatableFeatureResult(org.apache.kafka.common.message.UpdateFeaturesResponseData.UpdatableFeatureResult) AbstractResponse(org.apache.kafka.common.requests.AbstractResponse) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) Errors(org.apache.kafka.common.protocol.Errors) UpdateFeaturesRequestData(org.apache.kafka.common.message.UpdateFeaturesRequestData) ApiError(org.apache.kafka.common.requests.ApiError) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap)

Aggregations

HashMap (java.util.HashMap)3 UpdatableFeatureResult (org.apache.kafka.common.message.UpdateFeaturesResponseData.UpdatableFeatureResult)3 Map (java.util.Map)2 Errors (org.apache.kafka.common.protocol.Errors)2 TreeMap (java.util.TreeMap)1 KafkaFutureImpl (org.apache.kafka.common.internals.KafkaFutureImpl)1 UpdateFeaturesRequestData (org.apache.kafka.common.message.UpdateFeaturesRequestData)1 UpdateFeaturesResponseData (org.apache.kafka.common.message.UpdateFeaturesResponseData)1 UpdatableFeatureResultCollection (org.apache.kafka.common.message.UpdateFeaturesResponseData.UpdatableFeatureResultCollection)1 ChannelBuilder (org.apache.kafka.common.network.ChannelBuilder)1 AbstractResponse (org.apache.kafka.common.requests.AbstractResponse)1 ApiError (org.apache.kafka.common.requests.ApiError)1 UpdateFeaturesRequest (org.apache.kafka.common.requests.UpdateFeaturesRequest)1 UpdateFeaturesResponse (org.apache.kafka.common.requests.UpdateFeaturesResponse)1