Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: action → actions

...

This policy will be configured via a new configuration key, topic.actionactions.policy.class.name.

The existing policy interfaces CreateTopicPolicy and AlterConfigPolicy will be deprecated, but will continue to be applied where they are currently applied until they are removed.

Proposed Changes

Add

...

TopicActionsPolicy

The following policy interface will be added

Code Block
languagejava
linenumberstrue
/**
 * A policy that is enforced on actions affecting topics.
 * An implementation of this policy can be configured on a broker via the
 * {@code topic.actionactions.policy.class.name} broker config. 
 * When this is configured the named class will be instantiated reflectively 
 * using its nullary constructor and will then pass the broker configs to 
 * its <code>configure()</code> method. During broker shutdown, the 
 * <code>close()</code> method will be invoked so that resources can be 
 * released (if necessary).
 */
interface TopicActionPolicyTopicActionsPolicy extends Configurable, AutoCloseable {
    /** Enumerates possible actions on topics. */
    static enum Action {
        /** The creation of a topic. */
        CREATE,

        /** The modification of a topic. */
        MODIFY,

        /** The deletion of a topic. */
        DELETE
    }

    /**
     * Represents the state of a topic either before, or as a result of, an administrative request affecting the topic.
     */
    static interface TopicState {
        /**
         * The number of partitions of the topic.
         */
        public abstract int numPartitions();

        /**
         * The replication factor of the topic.
         */
        public abstract Short replicationFactor();

        /**
         * The replica assignments of the topic.
         */
        public abstract Map<Integer, List<Integer>> replicasAssignments()

        /**
         * The topic config.
         */
        public abstract Map<String,String> configs();
    }

    /**
     * Parameters for a request to perform an {@linkplain #action} on a {@linkplain #topic}
     * @see #validate(RequestMetadata)
     */
    static interface RequestMetadata {

        /**
         * The {@linkplain Action action} being performed on the topic.
         */
        public abstract Action action();

        /**
         * The topic the {@linkplain #action() action} is being performed upon.
         */
        public abstract String topic();

        /**
         * The authenticated principal making the request, or null if the session is not authenticated.
         */
        Principal principal();

         /**
          * The state the topic has before the request.
          * <ul>
          * <li>For {@link Action#CREATE} this will be null.</li>
          * <li>For {@link Action#MODIFY} this will be the state the topic currently has (before the modification).</li>
          * <li>For {@link Action#DELETE} this will be the state of the topic which is going to be deleted.</li>
          * </ul>
          */
        public abstract TopicState preRequestState();

        /**
         * The state the topic will have after the request.
         * <ul>
         * <li>For {@link Action#CREATE} this will be the requested state of the topic to be created.</li>
         * <li>For {@link Action#MODIFY} this will be the state the topic will have after the modification.</li>
         * <li>For {@link Action#DELETE} this will be null.</li>
         * </ul>
         */
        public abstract TopicState postRequestState();


        public abstract String toString();
    }

    /**
     * Validate the request parameters and throw a <code>PolicyViolationException</code> with a suitable error
     * message if the request parameters for the provided topic do not satisfy this policy.
     *
     * Clients will receive the POLICY_VIOLATION error code along with the exception's message. Note that validation
     * failure only affects the relevant topic, other topics in the request will still be processed.
     *
     * @param requestMetadata the request parameters for the provided topic.
     * @throws PolicyViolationException if the request parameters do not satisfy this policy.
     */
    void validate(RequestMetadata requestMetadata) throws PolicyViolationException;
}

...

This will be configurable via the topic.actionactions.policy.class.name broker config.

...

It will be a configuration time error if both create.topic.policy.class.name and topic.actionactions.policy.class.name are used at the same time, or both alter.config.policy.class.name and topic.actionactions.policy.class.name are used at the same time.

Internally, an adapter implementation of TopicActionPolicy TopicActionsPolicy will be used when CreateTopicPolicy and AlterConfigPolicy are configured, so policy use sites won't be unnecessarily complicated.

...

Existing users will have to reimplement their policies in terms of the new TopicActionPolicy TopicActionsPolicy interface, and reconfigure their brokers accordingly. Since the TopicActionPolicy TopicActionsPolicy contains a superset of the existing information used by the deprecated policies such reimplementation should be trivial.

...

  • incurs ongoing maintenance and testing costs on the project for not overall benefit
  • If two policies were in force it would be more confusing to users when a request was rejected (which policy rejected it?) possibly exacerbated if users didn't know two policies were in force.
  • If it were possible to have two policies in force administrators have not been relieved of the burden of maintaining two policies in sync.

The proposed TopicActionPolicy TopicActionsPolicy doesn't have to cover the topic deletion case: That could still be handled by a separate policy, but it is desirable to have a single policy to cover the whole lifecycle of a topic, and for the same information to be made available about a topic being deleted as about a topic being modified.

The proposed TopicActionPolicy TopicActionsPolicy doesn't cover the use case of records being deleted from a topic. This is not the same as the modification of a topic, and would require a different policy interface. It might be appropriate to use the same topic state in such a policy interface, however.