You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ozone.apache.org by bh...@apache.org on 2021/12/10 22:41:34 UTC
[ozone] branch master updated: HDDS-6066. Cleanup OmService injection. (#2896)
This is an automated email from the ASF dual-hosted git repository.
bharat pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new 5dd1144 HDDS-6066. Cleanup OmService injection. (#2896)
5dd1144 is described below
commit 5dd11441f202b992013d9d9e1388eefe91154b44
Author: Bharat Viswanadham <bh...@apache.org>
AuthorDate: Fri Dec 10 14:41:16 2021 -0800
HDDS-6066. Cleanup OmService injection. (#2896)
---
.../hadoop/ozone/s3/OzoneClientProducer.java | 4 -
.../hadoop/ozone/s3/OzoneServiceProvider.java | 25 +---
.../apache/hadoop/ozone/s3/util/OzoneS3Util.java | 81 ------------
.../hadoop/ozone/s3/util/TestOzoneS3Util.java | 136 ---------------------
4 files changed, 4 insertions(+), 242 deletions(-)
diff --git a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/OzoneClientProducer.java b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/OzoneClientProducer.java
index ff8b36e..1f6e52d 100644
--- a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/OzoneClientProducer.java
+++ b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/OzoneClientProducer.java
@@ -28,7 +28,6 @@ import java.io.IOException;
import com.google.common.annotations.VisibleForTesting;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
-import org.apache.hadoop.io.Text;
import org.apache.hadoop.ozone.client.OzoneClient;
import org.apache.hadoop.ozone.client.OzoneClientFactory;
import org.apache.hadoop.ozone.om.protocol.S3Auth;
@@ -64,9 +63,6 @@ public class OzoneClientProducer {
private OzoneConfiguration ozoneConfiguration;
@Inject
- private Text omService;
-
- @Inject
private String omServiceID;
@Context
diff --git a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/OzoneServiceProvider.java b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/OzoneServiceProvider.java
index b98426c..0530fa6 100644
--- a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/OzoneServiceProvider.java
+++ b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/OzoneServiceProvider.java
@@ -18,10 +18,7 @@
package org.apache.hadoop.ozone.s3;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
-import org.apache.hadoop.io.Text;
import org.apache.hadoop.ozone.OmUtils;
-import org.apache.hadoop.ozone.s3.util.OzoneS3Util;
-import org.apache.hadoop.security.SecurityUtil;
import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
@@ -40,9 +37,7 @@ import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_SERVICE_IDS_KEY;
@ApplicationScoped
public class OzoneServiceProvider {
- private Text omServiceAddr;
-
- private String omserviceID;
+ private String omServiceID;
@Inject
private OzoneConfiguration conf;
@@ -51,11 +46,7 @@ public class OzoneServiceProvider {
public void init() {
Collection<String> serviceIdList =
conf.getTrimmedStringCollection(OZONE_OM_SERVICE_IDS_KEY);
- if (serviceIdList.size() == 0) {
- // Non-HA cluster
- omServiceAddr = SecurityUtil.buildTokenService(OmUtils.
- getOmAddressForClients(conf));
- } else {
+ if (!serviceIdList.isEmpty()) {
// HA cluster.
//For now if multiple service id's are configured we throw exception.
// As if multiple service id's are configured, S3Gateway will not be
@@ -73,22 +64,14 @@ public class OzoneServiceProvider {
throw new IllegalArgumentException(OZONE_OM_NODES_KEY
+ "." + serviceId + " is not defined");
}
- omServiceAddr = new Text(OzoneS3Util.buildServiceNameForToken(conf,
- serviceId, omNodeIds));
- omserviceID = serviceId;
+ omServiceID = serviceId;
}
}
}
-
- @Produces
- public Text getService() {
- return omServiceAddr;
- }
-
@Produces
public String getOmServiceID() {
- return omserviceID;
+ return omServiceID;
}
}
diff --git a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/OzoneS3Util.java b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/OzoneS3Util.java
deleted file mode 100644
index 28ab6fe..0000000
--- a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/OzoneS3Util.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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.hadoop.ozone.s3.util;
-
-import org.apache.commons.codec.digest.DigestUtils;
-import org.apache.hadoop.hdds.conf.OzoneConfiguration;
-import org.apache.hadoop.net.NetUtils;
-import org.apache.hadoop.ozone.OmUtils;
-import org.apache.hadoop.ozone.ha.ConfUtils;
-import org.apache.hadoop.security.SecurityUtil;
-
-import javax.annotation.Nonnull;
-import java.util.Collection;
-import java.util.Objects;
-
-import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_ADDRESS_KEY;
-
-/**
- * Ozone util for S3 related operations.
- */
-public final class OzoneS3Util {
-
- private OzoneS3Util() {
- }
-
- public static String getS3Username(String userName) {
- Objects.requireNonNull(userName);
- return DigestUtils.md5Hex(userName.toLowerCase());
- }
-
- /**
- * Generate service Name for token.
- * @param configuration
- * @param serviceId - ozone manager service ID
- * @param omNodeIds - list of node ids for the given OM service.
- * @return service Name.
- */
- public static String buildServiceNameForToken(
- @Nonnull OzoneConfiguration configuration, @Nonnull String serviceId,
- @Nonnull Collection<String> omNodeIds) {
- StringBuilder rpcAddress = new StringBuilder();
-
- int nodesLength = omNodeIds.size();
- int counter = 0;
- for (String nodeId : omNodeIds) {
- counter++;
- String rpcAddrKey = ConfUtils.addKeySuffixes(OZONE_OM_ADDRESS_KEY,
- serviceId, nodeId);
- String rpcAddrStr = OmUtils.getOmRpcAddress(configuration, rpcAddrKey);
- if (rpcAddrStr == null || rpcAddrStr.isEmpty()) {
- throw new IllegalArgumentException("Could not find rpcAddress for " +
- OZONE_OM_ADDRESS_KEY + "." + serviceId + "." + nodeId);
- }
-
- if (counter != nodesLength) {
- rpcAddress.append(SecurityUtil.buildTokenService(
- NetUtils.createSocketAddr(rpcAddrStr)) + ",");
- } else {
- rpcAddress.append(SecurityUtil.buildTokenService(
- NetUtils.createSocketAddr(rpcAddrStr)));
- }
- }
- return rpcAddress.toString();
- }
-}
diff --git a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/util/TestOzoneS3Util.java b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/util/TestOzoneS3Util.java
deleted file mode 100644
index 1444791..0000000
--- a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/util/TestOzoneS3Util.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/**
- * 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.ozone.s3.util;
-
-import org.apache.hadoop.hdds.conf.OzoneConfiguration;
-import org.apache.hadoop.ozone.OmUtils;
-import org.apache.hadoop.ozone.ha.ConfUtils;
-import org.apache.hadoop.ozone.om.OMConfigKeys;
-import org.apache.hadoop.security.SecurityUtil;
-import org.apache.ozone.test.GenericTestUtils;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.Collection;
-
-import static org.apache.hadoop.fs.CommonConfigurationKeys.HADOOP_SECURITY_TOKEN_SERVICE_USE_IP;
-import static org.junit.Assert.fail;
-
-/**
- * Class used to test OzoneS3Util.
- */
-public class TestOzoneS3Util {
-
-
- private OzoneConfiguration configuration;
- private String serviceID = "omService";
-
- @Before
- public void setConf() {
- configuration = new OzoneConfiguration();
-
- String nodeIDs = "om1,om2,om3";
- configuration.set(OMConfigKeys.OZONE_OM_SERVICE_IDS_KEY, serviceID);
- configuration.set(OMConfigKeys.OZONE_OM_NODES_KEY + "." + serviceID,
- nodeIDs);
- configuration.setBoolean(HADOOP_SECURITY_TOKEN_SERVICE_USE_IP, false);
- }
-
- @Test
- public void testBuildServiceNameForToken() {
-
- Collection<String> nodeIDList = OmUtils.getOMNodeIds(configuration,
- serviceID);
-
- configuration.set(
- ConfUtils.addKeySuffixes(OMConfigKeys.OZONE_OM_ADDRESS_KEY,
- serviceID, "om1"), "om1:9862");
- configuration.set(
- ConfUtils.addKeySuffixes(OMConfigKeys.OZONE_OM_ADDRESS_KEY,
- serviceID, "om2"), "om2:9862");
- configuration.set(
- ConfUtils.addKeySuffixes(OMConfigKeys.OZONE_OM_ADDRESS_KEY,
- serviceID, "om3"), "om3:9862");
-
- String expectedOmServiceAddress = buildServiceAddress(nodeIDList);
-
- SecurityUtil.setConfiguration(configuration);
- String omserviceAddr = OzoneS3Util.buildServiceNameForToken(configuration,
- serviceID, nodeIDList);
-
- Assert.assertEquals(expectedOmServiceAddress, omserviceAddr);
- }
-
-
- @Test
- public void testBuildServiceNameForTokenIncorrectConfig() {
-
- Collection<String> nodeIDList = OmUtils.getOMNodeIds(configuration,
- serviceID);
-
- // Don't set om3 node rpc address. Here we are skipping setting of one of
- // the OM address. So buildServiceNameForToken will fail.
- configuration.set(
- ConfUtils.addKeySuffixes(OMConfigKeys.OZONE_OM_ADDRESS_KEY,
- serviceID, "om1"), "om1:9862");
- configuration.set(
- ConfUtils.addKeySuffixes(OMConfigKeys.OZONE_OM_ADDRESS_KEY,
- serviceID, "om2"), "om2:9862");
-
-
- SecurityUtil.setConfiguration(configuration);
-
- try {
- OzoneS3Util.buildServiceNameForToken(configuration,
- serviceID, nodeIDList);
- fail("testBuildServiceNameForTokenIncorrectConfig failed");
- } catch (IllegalArgumentException ex) {
- GenericTestUtils.assertExceptionContains("Could not find rpcAddress " +
- "for", ex);
- }
-
-
- }
-
- /**
- * Build serviceName from list of node ids.
- * @param nodeIDList
- * @return service name for token.
- */
- private String buildServiceAddress(Collection<String> nodeIDList) {
- StringBuilder omServiceAddrBuilder = new StringBuilder();
- int nodesLength = nodeIDList.size();
- int counter = 0;
- for (String nodeID : nodeIDList) {
- counter++;
- String addr = configuration.get(ConfUtils.addKeySuffixes(
- OMConfigKeys.OZONE_OM_ADDRESS_KEY, serviceID, nodeID));
-
- if (counter != nodesLength) {
- omServiceAddrBuilder.append(addr + ",");
- } else {
- omServiceAddrBuilder.append(addr);
- }
- }
-
- return omServiceAddrBuilder.toString();
- }
-
-}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@ozone.apache.org
For additional commands, e-mail: commits-help@ozone.apache.org