use of org.apache.kafka.common.message.UpdateFeaturesRequestData in project kafka by apache.
the class RequestResponseTest method createUpdateFeaturesRequest.
private UpdateFeaturesRequest createUpdateFeaturesRequest(short version) {
UpdateFeaturesRequestData.FeatureUpdateKeyCollection features = new UpdateFeaturesRequestData.FeatureUpdateKeyCollection();
features.add(new UpdateFeaturesRequestData.FeatureUpdateKey().setFeature("feature1").setAllowDowngrade(false).setMaxVersionLevel((short) 1));
UpdateFeaturesRequestData data = new UpdateFeaturesRequestData().setFeatureUpdates(features).setTimeoutMs(123);
return new UpdateFeaturesRequest.Builder(data).build(version);
}
use of org.apache.kafka.common.message.UpdateFeaturesRequestData in project kafka by apache.
the class UpdateFeaturesRequestTest method testGetErrorResponse.
@Test
public void testGetErrorResponse() {
UpdateFeaturesRequestData.FeatureUpdateKeyCollection features = new UpdateFeaturesRequestData.FeatureUpdateKeyCollection();
features.add(new UpdateFeaturesRequestData.FeatureUpdateKey().setFeature("foo").setMaxVersionLevel((short) 2));
features.add(new UpdateFeaturesRequestData.FeatureUpdateKey().setFeature("bar").setMaxVersionLevel((short) 3));
UpdateFeaturesRequest request = new UpdateFeaturesRequest(new UpdateFeaturesRequestData().setFeatureUpdates(features), UpdateFeaturesRequestData.HIGHEST_SUPPORTED_VERSION);
UpdateFeaturesResponse response = request.getErrorResponse(0, new UnknownServerException());
assertEquals(Errors.UNKNOWN_SERVER_ERROR, response.topLevelError().error());
assertEquals(0, response.data().results().size());
assertEquals(Collections.singletonMap(Errors.UNKNOWN_SERVER_ERROR, 1), response.errorCounts());
}
use of org.apache.kafka.common.message.UpdateFeaturesRequestData 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));
}
Aggregations