lasdf1234 commented on code in PR #12288: URL: https://github.com/apache/gravitino/pull/12288#discussion_r3689203163
########## core/src/main/java/org/apache/gravitino/bulk/BulkManager.java: ########## @@ -0,0 +1,136 @@ +/* + * 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.gravitino.bulk; + +import java.util.List; +import java.util.Optional; +import org.apache.gravitino.Config; +import org.apache.gravitino.Configs; +import org.apache.gravitino.MetadataObject; +import org.apache.gravitino.MetadataObjects; +import org.apache.gravitino.authorization.AccessControlDispatcher; +import org.apache.gravitino.authorization.Owner; +import org.apache.gravitino.authorization.OwnerDispatcher; +import org.apache.gravitino.authorization.User; +import org.apache.gravitino.dto.responses.BulkError; +import org.apache.gravitino.dto.responses.ErrorConstants; +import org.apache.gravitino.exceptions.AlreadyExistsException; +import org.apache.gravitino.exceptions.ForbiddenException; +import org.apache.gravitino.exceptions.NotFoundException; +import org.apache.gravitino.exceptions.NotInUseException; +import org.apache.gravitino.metalake.MetalakeManager; + +/** Manages best-effort bulk operations. */ +public class BulkManager { + + private final AccessControlDispatcher accessControlDispatcher; + private final OwnerDispatcher ownerDispatcher; + private final int bulkMaxItems; + + /** + * Creates a new {@link BulkManager}. + * + * @param config The Gravitino configuration. + * @param accessControlDispatcher The access-control dispatcher. + * @param ownerDispatcher The owner dispatcher. + */ + public BulkManager( + Config config, + AccessControlDispatcher accessControlDispatcher, + OwnerDispatcher ownerDispatcher) { + this.accessControlDispatcher = accessControlDispatcher; + this.ownerDispatcher = ownerDispatcher; + this.bulkMaxItems = + config == null + ? Configs.BULK_MAX_ITEMS.getDefaultValue() + : config.get(Configs.BULK_MAX_ITEMS); + } + + /** + * Adds users in bulk. + * + * @param metalake The metalake name. + * @param users The users to add. + * @return The item-level results. + */ + public List<BulkItemResult<User>> addUsers(String metalake, List<UserAdd> users) { + checkBulkSize("users", users.size()); Review Comment: This method seems unnecessary. ########## core/src/main/java/org/apache/gravitino/bulk/BulkManager.java: ########## @@ -0,0 +1,136 @@ +/* + * 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.gravitino.bulk; + +import java.util.List; +import java.util.Optional; +import org.apache.gravitino.Config; +import org.apache.gravitino.Configs; +import org.apache.gravitino.MetadataObject; +import org.apache.gravitino.MetadataObjects; +import org.apache.gravitino.authorization.AccessControlDispatcher; +import org.apache.gravitino.authorization.Owner; +import org.apache.gravitino.authorization.OwnerDispatcher; +import org.apache.gravitino.authorization.User; +import org.apache.gravitino.dto.responses.BulkError; +import org.apache.gravitino.dto.responses.ErrorConstants; +import org.apache.gravitino.exceptions.AlreadyExistsException; +import org.apache.gravitino.exceptions.ForbiddenException; +import org.apache.gravitino.exceptions.NotFoundException; +import org.apache.gravitino.exceptions.NotInUseException; +import org.apache.gravitino.metalake.MetalakeManager; + +/** Manages best-effort bulk operations. */ +public class BulkManager { + + private final AccessControlDispatcher accessControlDispatcher; + private final OwnerDispatcher ownerDispatcher; + private final int bulkMaxItems; + + /** + * Creates a new {@link BulkManager}. + * + * @param config The Gravitino configuration. + * @param accessControlDispatcher The access-control dispatcher. + * @param ownerDispatcher The owner dispatcher. + */ + public BulkManager( + Config config, + AccessControlDispatcher accessControlDispatcher, + OwnerDispatcher ownerDispatcher) { + this.accessControlDispatcher = accessControlDispatcher; + this.ownerDispatcher = ownerDispatcher; + this.bulkMaxItems = + config == null + ? Configs.BULK_MAX_ITEMS.getDefaultValue() + : config.get(Configs.BULK_MAX_ITEMS); + } + + /** + * Adds users in bulk. + * + * @param metalake The metalake name. + * @param users The users to add. + * @return The item-level results. + */ + public List<BulkItemResult<User>> addUsers(String metalake, List<UserAdd> users) { + checkBulkSize("users", users.size()); + MetalakeManager.checkMetalakeInUse(metalake); + return accessControlDispatcher.addUsers(metalake, users); + } + + /** + * Removes users in bulk. + * + * @param metalake The metalake name. + * @param users The user names to remove. + * @return The item-level results. + */ + public List<BulkItemResult<String>> removeUsers(String metalake, List<String> users) { + checkBulkSize("names", users.size()); Review Comment: This method seems unnecessary. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
