cmccabe commented on a change in pull request #11649:
URL: https://github.com/apache/kafka/pull/11649#discussion_r802177256



##########
File path: 
metadata/src/main/java/org/apache/kafka/controller/AclControlManager.java
##########
@@ -0,0 +1,232 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.controller;
+
+import org.apache.kafka.common.Uuid;
+import org.apache.kafka.common.acl.AclBinding;
+import org.apache.kafka.common.acl.AclBindingFilter;
+import org.apache.kafka.common.errors.ApiException;
+import org.apache.kafka.common.errors.InvalidRequestException;
+import org.apache.kafka.common.errors.UnknownServerException;
+import org.apache.kafka.common.metadata.AccessControlEntryRecord;
+import org.apache.kafka.common.metadata.RemoveAccessControlEntryRecord;
+import org.apache.kafka.common.requests.ApiError;
+import org.apache.kafka.metadata.authorizer.ClusterMetadataAuthorizer;
+import org.apache.kafka.metadata.authorizer.StandardAcl;
+import org.apache.kafka.metadata.authorizer.StandardAclRecordIterator;
+import org.apache.kafka.metadata.authorizer.StandardAclWithId;
+import org.apache.kafka.raft.OffsetAndEpoch;
+import org.apache.kafka.server.authorizer.AclCreateResult;
+import org.apache.kafka.server.authorizer.AclDeleteResult;
+import 
org.apache.kafka.server.authorizer.AclDeleteResult.AclBindingDeleteResult;
+import org.apache.kafka.server.common.ApiMessageAndVersion;
+import org.apache.kafka.timeline.SnapshotRegistry;
+import org.apache.kafka.timeline.TimelineHashMap;
+import org.apache.kafka.timeline.TimelineHashSet;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+
+
+/**
+ * The AclControlManager manages any ACLs that are stored in the 
__cluster_metadata topic.
+ * If the ACLs are stored externally (such as in ZooKeeper) then there will be 
nothing for
+ * this manager to do, and the authorizer field will always be Optional.empty.
+ *
+ * Because the Authorizer is being concurrently used by other threads, we need 
to be
+ * careful about snapshots. We don't want the Authorizer to act based on 
partial state
+ * during the loading process. Therefore, unlike most of the other managers,
+ * AclControlManager needs to receive callbacks when we start loading a 
snapshot and when
+ * we finish. The prepareForSnapshotLoad callback clears the authorizer field, 
preventing
+ * any changes from affecting the authorizer until completeSnapshotLoad is 
called.
+ * Note that the Authorizer's start() method will block until the first 
snapshot load has
+ * completed, which is another reason the prepare / complete callbacks are 
needed.
+ */
+public class AclControlManager {
+    private final TimelineHashMap<Uuid, StandardAcl> idToAcl;
+    private final TimelineHashSet<StandardAcl> existingAcls;
+    private final Optional<ClusterMetadataAuthorizer> authorizer;
+
+    AclControlManager(SnapshotRegistry snapshotRegistry,
+                      Optional<ClusterMetadataAuthorizer> authorizer) {
+        this.idToAcl = new TimelineHashMap<>(snapshotRegistry, 0);
+        this.existingAcls = new TimelineHashSet<>(snapshotRegistry, 0);
+        this.authorizer = authorizer;
+    }
+
+    ControllerResult<List<AclCreateResult>> createAcls(List<AclBinding> acls) {
+        List<AclCreateResult> results = new ArrayList<>(acls.size());
+        List<ApiMessageAndVersion> records = new ArrayList<>(acls.size());
+        for (AclBinding acl : acls) {
+            try {
+                validateNewAcl(acl);

Review comment:
       I think it would make sense to pull them up eventually in a follow-up PR.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to