Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Config name tweak and add back `Configurable` and `AutoCloseable` that were removed by mistake.

...

A user can define a policy manager similar to the pluggable Authorizer by setting create.topicstopic.policy.class.name in server.properties and implementing the the CreateTopicPolicy interface. The interface will live in the clients jar under the org.apache.kafka.server.policy package. It implements Configurable so that implementations can act on broker configurations and AutoCloseable so that resources can be released on shutdown.

Code Block
languagejava
package org.apache.kafka.server.policy;

public interface CreateTopicPolicy extends Configurable, AutoCloseable {

    class RequestMetadata {
        private final String topic;
        private final int numPartitions;
        private final short replicationFactor;
        private final Map<Integer, List<Integer>> replicasAssignments;
        private final Map<String, String> configs;

        public RequestMetadata(String topic, int numPartitions, short replicationFactor,
                               Map<Integer, List<Integer>> replicasAssignments, Map<String, String> configs) {
			...
        }

        public String topic() {
            return topic;
        }

        public int numPartitions() {
            return numPartitions;
        }

        public Map<Integer, List<Integer>> replicasAssignments() {
            return replicasAssignments;
        }

        public Map<String, String> configs() {
            return configs;
        }

    }

    void validate(RequestMetadata requestMetadata) throws PolicyViolationException;
}
 
package org.apache.kafka.common.errors;

public class PolicyViolationException extends ApiException {

    public PolicyViolationException(String message) {
        super(message);
    }

    public PolicyViolationException(String message, Throwable cause) {
        super(message, cause);
    }
}

...

During broker start-up, AdminManager will create a CreateTopicPolicy instance if create.topicstopic.policy.class.name is defined. It will then pass the broker configs to the configure method.

...