ivanzlenko commented on code in PR #7268:
URL: https://github.com/apache/ozone/pull/7268#discussion_r1814289863
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/OzoneAdmins.java:
##########
@@ -186,4 +191,85 @@ public static Collection<String>
getOzoneReadOnlyAdminsGroupsFromConfig(
return conf.getTrimmedStringCollection(
OZONE_READONLY_ADMINISTRATORS_GROUPS);
}
+
+ /**
+ * Get the list of S3 administrators from Ozone config.
+ *
+ * @param conf An instance of {@link OzoneConfiguration} being used
+ * @return A {@link Collection} of the S3 administrator users
+ *
+ * If ozone.s3.administrators value is empty string or unset,
+ * defaults to ozone.administrators value.
+ */
+ public static Collection<String> getS3AdminsFromConfig(OzoneConfiguration
conf) throws IOException {
+ Collection<String> ozoneAdmins =
conf.getTrimmedStringCollection(OZONE_S3_ADMINISTRATORS);
+
+ if (ozoneAdmins == null || ozoneAdmins.isEmpty()) {
+ ozoneAdmins = conf.getTrimmedStringCollection(OZONE_ADMINISTRATORS);
+ }
+ String omSPN = UserGroupInformation.getCurrentUser().getShortUserName();
+ if (!ozoneAdmins.contains(omSPN)) {
+ ozoneAdmins.add(omSPN);
+ }
+
+ return ozoneAdmins;
+ }
+
+ /**
+ * Get the list of the groups that are a part S3 administrators from Ozone
config.
+ *
+ * @param conf An instance of {@link OzoneConfiguration} being used
+ * @return A {@link Collection} of the S3 administrator groups
+ *
+ * If ozone.s3.administrators.groups value is empty or unset,
+ * defaults to the ozone.administrators.groups value
+ */
+ public static Collection<String>
getS3AdminsGroupsFromConfig(OzoneConfiguration conf) {
Review Comment:
```suggestion
public static Set<String> getS3AdminsGroupsFromConfig(OzoneConfiguration
conf) {
```
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/OzoneAdmins.java:
##########
@@ -186,4 +191,85 @@ public static Collection<String>
getOzoneReadOnlyAdminsGroupsFromConfig(
return conf.getTrimmedStringCollection(
OZONE_READONLY_ADMINISTRATORS_GROUPS);
}
+
+ /**
+ * Get the list of S3 administrators from Ozone config.
+ *
+ * @param conf An instance of {@link OzoneConfiguration} being used
+ * @return A {@link Collection} of the S3 administrator users
+ *
+ * If ozone.s3.administrators value is empty string or unset,
+ * defaults to ozone.administrators value.
+ */
+ public static Collection<String> getS3AdminsFromConfig(OzoneConfiguration
conf) throws IOException {
Review Comment:
```suggestion
public static Set<String> getS3AdminsFromConfig(OzoneConfiguration conf)
throws IOException {
```
##########
hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/server/TestOzoneAdmins.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.hdds.server;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.ozone.OzoneConfigKeys;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * This class is to test the utilities present in the OzoneAdmins class.
+ */
+class TestOzoneAdmins {
Review Comment:
Let's move configuration set up into BeforeEach method and use
ParameterizedTest to verify any possible scenarios, so we will reduce amount of
similar methods in the test class.
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/OzoneAdmins.java:
##########
@@ -186,4 +191,85 @@ public static Collection<String>
getOzoneReadOnlyAdminsGroupsFromConfig(
return conf.getTrimmedStringCollection(
OZONE_READONLY_ADMINISTRATORS_GROUPS);
}
+
+ /**
+ * Get the list of S3 administrators from Ozone config.
+ *
+ * @param conf An instance of {@link OzoneConfiguration} being used
+ * @return A {@link Collection} of the S3 administrator users
+ *
+ * If ozone.s3.administrators value is empty string or unset,
+ * defaults to ozone.administrators value.
+ */
+ public static Collection<String> getS3AdminsFromConfig(OzoneConfiguration
conf) throws IOException {
+ Collection<String> ozoneAdmins =
conf.getTrimmedStringCollection(OZONE_S3_ADMINISTRATORS);
+
+ if (ozoneAdmins == null || ozoneAdmins.isEmpty()) {
+ ozoneAdmins = conf.getTrimmedStringCollection(OZONE_ADMINISTRATORS);
+ }
+ String omSPN = UserGroupInformation.getCurrentUser().getShortUserName();
+ if (!ozoneAdmins.contains(omSPN)) {
+ ozoneAdmins.add(omSPN);
+ }
+
+ return ozoneAdmins;
+ }
+
+ /**
+ * Get the list of the groups that are a part S3 administrators from Ozone
config.
+ *
+ * @param conf An instance of {@link OzoneConfiguration} being used
+ * @return A {@link Collection} of the S3 administrator groups
+ *
+ * If ozone.s3.administrators.groups value is empty or unset,
+ * defaults to the ozone.administrators.groups value
+ */
+ public static Collection<String>
getS3AdminsGroupsFromConfig(OzoneConfiguration conf) {
+ Collection<String> s3AdminsGroup =
conf.getTrimmedStringCollection(OZONE_S3_ADMINISTRATORS_GROUPS);
+
+ if (s3AdminsGroup.isEmpty() &&
conf.getTrimmedStringCollection(OZONE_S3_ADMINISTRATORS).isEmpty()) {
+ s3AdminsGroup =
conf.getTrimmedStringCollection(OZONE_ADMINISTRATORS_GROUPS);
+ }
+
+ return s3AdminsGroup;
+ }
+
+ /**
+ * Get the users and groups that are a part of S3 administrators.
+ * @param conf Stores an instance of {@link OzoneConfiguration} being used
+ * @return an instance of {@link OzoneAdmins} containing the S3 admin users
and groups
+ */
+ public static OzoneAdmins getS3Admins(OzoneConfiguration conf) {
+ Collection<String> s3Admins;
Review Comment:
```suggestion
Set<String> s3Admins;
```
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/OzoneAdmins.java:
##########
@@ -186,4 +191,85 @@ public static Collection<String>
getOzoneReadOnlyAdminsGroupsFromConfig(
return conf.getTrimmedStringCollection(
OZONE_READONLY_ADMINISTRATORS_GROUPS);
}
+
+ /**
+ * Get the list of S3 administrators from Ozone config.
Review Comment:
I think it is worth adding this information to the JavaDoc.
At least in that way we could prevent some potential issues.
##########
hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/server/TestOzoneAdmins.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.hdds.server;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.ozone.OzoneConfigKeys;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * This class is to test the utilities present in the OzoneAdmins class.
+ */
+class TestOzoneAdmins {
+ // The following set of tests are to validate the S3 based utilities present
in OzoneAdmins
+ @Test
+ void testS3AdminExtraction() throws IOException {
+ OzoneConfiguration configuration = new OzoneConfiguration();
+ configuration.set(OzoneConfigKeys.OZONE_S3_ADMINISTRATORS, "alice,bob");
+
+ assertThat(OzoneAdmins.getS3AdminsFromConfig(configuration))
+ .containsAll(Arrays.asList("alice", "bob"));
+ }
+
+ @Test
+ void testS3AdminExtractionWithFallback() throws IOException {
+ OzoneConfiguration configuration = new OzoneConfiguration();
+ configuration.set(OzoneConfigKeys.OZONE_ADMINISTRATORS, "alice,bob");
+
+ assertThat(OzoneAdmins.getS3AdminsFromConfig(configuration))
+ .containsAll(Arrays.asList("alice", "bob"));
+ }
+
+ @Test
+ void testS3AdminGroupExtraction() {
+ OzoneConfiguration configuration = new OzoneConfiguration();
+ configuration.set(OzoneConfigKeys.OZONE_S3_ADMINISTRATORS_GROUPS,
+ "test1, test2");
Review Comment:
```suggestion
configuration.set(OzoneConfigKeys.OZONE_S3_ADMINISTRATORS_GROUPS,
"test1, test2");
```
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/OzoneAdmins.java:
##########
@@ -186,4 +191,85 @@ public static Collection<String>
getOzoneReadOnlyAdminsGroupsFromConfig(
return conf.getTrimmedStringCollection(
OZONE_READONLY_ADMINISTRATORS_GROUPS);
}
+
+ /**
+ * Get the list of S3 administrators from Ozone config.
+ *
+ * @param conf An instance of {@link OzoneConfiguration} being used
+ * @return A {@link Collection} of the S3 administrator users
+ *
+ * If ozone.s3.administrators value is empty string or unset,
+ * defaults to ozone.administrators value.
+ */
+ public static Collection<String> getS3AdminsFromConfig(OzoneConfiguration
conf) throws IOException {
+ Collection<String> ozoneAdmins =
conf.getTrimmedStringCollection(OZONE_S3_ADMINISTRATORS);
+
+ if (ozoneAdmins == null || ozoneAdmins.isEmpty()) {
+ ozoneAdmins = conf.getTrimmedStringCollection(OZONE_ADMINISTRATORS);
+ }
+ String omSPN = UserGroupInformation.getCurrentUser().getShortUserName();
+ if (!ozoneAdmins.contains(omSPN)) {
+ ozoneAdmins.add(omSPN);
+ }
+
+ return ozoneAdmins;
+ }
+
+ /**
+ * Get the list of the groups that are a part S3 administrators from Ozone
config.
Review Comment:
```suggestion
* Get the list of the groups that are a part of S3 administrators from
Ozone config.
```
##########
hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/server/TestOzoneAdmins.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.hdds.server;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.ozone.OzoneConfigKeys;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * This class is to test the utilities present in the OzoneAdmins class.
+ */
+class TestOzoneAdmins {
+ // The following set of tests are to validate the S3 based utilities present
in OzoneAdmins
+ @Test
+ void testS3AdminExtraction() throws IOException {
+ OzoneConfiguration configuration = new OzoneConfiguration();
+ configuration.set(OzoneConfigKeys.OZONE_S3_ADMINISTRATORS, "alice,bob");
+
+ assertThat(OzoneAdmins.getS3AdminsFromConfig(configuration))
+ .containsAll(Arrays.asList("alice", "bob"));
+ }
+
+ @Test
+ void testS3AdminExtractionWithFallback() throws IOException {
+ OzoneConfiguration configuration = new OzoneConfiguration();
+ configuration.set(OzoneConfigKeys.OZONE_ADMINISTRATORS, "alice,bob");
+
+ assertThat(OzoneAdmins.getS3AdminsFromConfig(configuration))
+ .containsAll(Arrays.asList("alice", "bob"));
+ }
+
+ @Test
+ void testS3AdminGroupExtraction() {
+ OzoneConfiguration configuration = new OzoneConfiguration();
+ configuration.set(OzoneConfigKeys.OZONE_S3_ADMINISTRATORS_GROUPS,
+ "test1, test2");
+
+ assertThat(OzoneAdmins.getS3AdminsGroupsFromConfig(configuration))
+ .containsAll(Arrays.asList("test1", "test2"));
+ }
+
+ @Test
+ void testS3AdminGroupExtractionWithFallback() {
+ OzoneConfiguration configuration = new OzoneConfiguration();
+ configuration.set(OzoneConfigKeys.OZONE_ADMINISTRATORS_GROUPS,
+ "test1, test2");
Review Comment:
```suggestion
configuration.set(OzoneConfigKeys.OZONE_ADMINISTRATORS_GROUPS, "test1,
test2");
```
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/OzoneAdmins.java:
##########
@@ -186,4 +191,85 @@ public static Collection<String>
getOzoneReadOnlyAdminsGroupsFromConfig(
return conf.getTrimmedStringCollection(
OZONE_READONLY_ADMINISTRATORS_GROUPS);
}
+
+ /**
+ * Get the list of S3 administrators from Ozone config.
Review Comment:
```suggestion
* Get the list of S3 administrators from Ozone config.
* <p>
* Note: If the current is not a part of the administration group,
* {@link UserGroupInformation#getCurrentUser()} will be added to the
resulting list.
```
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/OzoneAdmins.java:
##########
@@ -186,4 +191,85 @@ public static Collection<String>
getOzoneReadOnlyAdminsGroupsFromConfig(
return conf.getTrimmedStringCollection(
OZONE_READONLY_ADMINISTRATORS_GROUPS);
}
+
+ /**
+ * Get the list of S3 administrators from Ozone config.
+ *
+ * @param conf An instance of {@link OzoneConfiguration} being used
+ * @return A {@link Collection} of the S3 administrator users
+ *
+ * If ozone.s3.administrators value is empty string or unset,
+ * defaults to ozone.administrators value.
+ */
+ public static Collection<String> getS3AdminsFromConfig(OzoneConfiguration
conf) throws IOException {
+ Collection<String> ozoneAdmins =
conf.getTrimmedStringCollection(OZONE_S3_ADMINISTRATORS);
+
+ if (ozoneAdmins == null || ozoneAdmins.isEmpty()) {
+ ozoneAdmins = conf.getTrimmedStringCollection(OZONE_ADMINISTRATORS);
+ }
+ String omSPN = UserGroupInformation.getCurrentUser().getShortUserName();
+ if (!ozoneAdmins.contains(omSPN)) {
+ ozoneAdmins.add(omSPN);
+ }
+
+ return ozoneAdmins;
+ }
+
+ /**
+ * Get the list of the groups that are a part S3 administrators from Ozone
config.
+ *
+ * @param conf An instance of {@link OzoneConfiguration} being used
+ * @return A {@link Collection} of the S3 administrator groups
+ *
+ * If ozone.s3.administrators.groups value is empty or unset,
+ * defaults to the ozone.administrators.groups value
+ */
+ public static Collection<String>
getS3AdminsGroupsFromConfig(OzoneConfiguration conf) {
+ Collection<String> s3AdminsGroup =
conf.getTrimmedStringCollection(OZONE_S3_ADMINISTRATORS_GROUPS);
+
+ if (s3AdminsGroup.isEmpty() &&
conf.getTrimmedStringCollection(OZONE_S3_ADMINISTRATORS).isEmpty()) {
+ s3AdminsGroup =
conf.getTrimmedStringCollection(OZONE_ADMINISTRATORS_GROUPS);
+ }
+
+ return s3AdminsGroup;
+ }
+
+ /**
+ * Get the users and groups that are a part of S3 administrators.
+ * @param conf Stores an instance of {@link OzoneConfiguration} being used
+ * @return an instance of {@link OzoneAdmins} containing the S3 admin users
and groups
+ */
+ public static OzoneAdmins getS3Admins(OzoneConfiguration conf) {
+ Collection<String> s3Admins;
+ try {
+ s3Admins = getS3AdminsFromConfig(conf);
+ } catch (IOException ie) {
+ s3Admins = null;
Review Comment:
```suggestion
s3Admins = Collections.emptySet();
```
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/OzoneAdmins.java:
##########
@@ -186,4 +191,85 @@ public static Collection<String>
getOzoneReadOnlyAdminsGroupsFromConfig(
return conf.getTrimmedStringCollection(
OZONE_READONLY_ADMINISTRATORS_GROUPS);
}
+
+ /**
+ * Get the list of S3 administrators from Ozone config.
Review Comment:
P.S. I've made this suggestion via web ui so worth checking check style
before pushing this changes :)
##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/ha/GrpcOMFailoverProxyProvider.java:
##########
@@ -59,10 +57,12 @@ public class GrpcOMFailoverProxyProvider<T> extends
public static final Logger LOG =
LoggerFactory.getLogger(GrpcOMFailoverProxyProvider.class);
+
Review Comment:
```suggestion
```
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]