This is an automated email from the ASF dual-hosted git repository.
adoroszlai 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 7ce75794f4 HDDS-9582. OM transport factory configuration mismatch
(#5834)
7ce75794f4 is described below
commit 7ce75794f476fa20cf78e7fba06a1642829d683e
Author: Duong Nguyen <[email protected]>
AuthorDate: Thu Dec 21 01:57:19 2023 -0800
HDDS-9582. OM transport factory configuration mismatch (#5834)
---
.../ozone/om/protocolPB/OmTransportFactory.java | 33 ++++---
.../om/protocolPB/TestOmTransportFactory.java | 101 +++++++++++++++++++++
...e.hadoop.ozone.om.protocolPB.OmTransportFactory | 15 ---
...e.hadoop.ozone.om.protocolPB.OmTransportFactory | 15 ---
4 files changed, 117 insertions(+), 47 deletions(-)
diff --git
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/OmTransportFactory.java
b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/OmTransportFactory.java
index 2ba8536e18..a4fac2be50 100644
---
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/OmTransportFactory.java
+++
b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/protocolPB/OmTransportFactory.java
@@ -23,6 +23,8 @@ import java.util.ServiceLoader;
import org.apache.hadoop.hdds.conf.ConfigurationSource;
import org.apache.hadoop.security.UserGroupInformation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_TRANSPORT_CLASS;
import static
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_TRANSPORT_CLASS_DEFAULT;
@@ -31,6 +33,7 @@ import static
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_TRANSPORT_CLASS_D
* Factory pattern to create object for RPC communication with OM.
*/
public interface OmTransportFactory {
+ Logger LOG = LoggerFactory.getLogger(OmTransportFactory.class);
OmTransport createOmTransport(ConfigurationSource source,
UserGroupInformation ugi, String omServiceId) throws IOException;
@@ -45,28 +48,24 @@ public interface OmTransportFactory {
static OmTransportFactory createFactory(ConfigurationSource conf)
throws IOException {
try {
- // if configured transport class is different than the default
- // OmTransportFactory (Hadoop3OmTransportFactory), then
- // check service loader for transport class and instantiate it
- if (conf
- .get(OZONE_OM_TRANSPORT_CLASS,
- OZONE_OM_TRANSPORT_CLASS_DEFAULT) !=
- OZONE_OM_TRANSPORT_CLASS_DEFAULT) {
- ServiceLoader<OmTransportFactory> transportFactoryServiceLoader =
- ServiceLoader.load(OmTransportFactory.class);
- Iterator<OmTransportFactory> iterator =
- transportFactoryServiceLoader.iterator();
- if (iterator.hasNext()) {
- return iterator.next();
- }
+ // if a transport implementation is found via ServiceLoader, use it.
+ ServiceLoader<OmTransportFactory> transportFactoryServiceLoader =
ServiceLoader.load(OmTransportFactory.class);
+ Iterator<OmTransportFactory> iterator =
transportFactoryServiceLoader.iterator();
+ if (iterator.hasNext()) {
+ OmTransportFactory next = iterator.next();
+ LOG.info("Found OM transport implementation {} from service loader.",
next.getClass().getName());
+ return next;
}
+
+ // Otherwise, load the transport implementation specified by
configuration.
+ String transportClassName = conf.get(OZONE_OM_TRANSPORT_CLASS,
OZONE_OM_TRANSPORT_CLASS_DEFAULT);
+ LOG.info("Loading OM transport implementation {} as specified by
configuration.", transportClassName);
return OmTransportFactory.class.getClassLoader()
- .loadClass(OZONE_OM_TRANSPORT_CLASS_DEFAULT)
+ .loadClass(transportClassName)
.asSubclass(OmTransportFactory.class)
.newInstance();
} catch (Exception ex) {
- throw new IOException(
- "Can't create the default OmTransport implementation", ex);
+ throw new IOException("Can't create the default OmTransport
implementation", ex);
}
}
diff --git
a/hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/protocolPB/TestOmTransportFactory.java
b/hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/protocolPB/TestOmTransportFactory.java
new file mode 100644
index 0000000000..fdc1239585
--- /dev/null
+++
b/hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/protocolPB/TestOmTransportFactory.java
@@ -0,0 +1,101 @@
+/**
+ * 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.om.protocolPB;
+
+
+import org.apache.hadoop.hdds.conf.ConfigurationSource;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.MockedStatic;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.ServiceLoader;
+
+import static java.util.Collections.singletonList;
+import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_TRANSPORT_CLASS;
+import static
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_TRANSPORT_CLASS_DEFAULT;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.when;
+
+/**
+ * Test OmTransportFactory.
+ */
+public class TestOmTransportFactory {
+ private OzoneConfiguration conf;
+
+ @BeforeEach
+ void setUp() {
+ conf = new OzoneConfiguration();
+ }
+
+ @Test
+ public void testCreateFactoryFromServiceLoader() throws IOException {
+ OmTransportFactory dummyImpl = mock(OmTransportFactory.class);
+ ServiceLoader<OmTransportFactory> serviceLoader =
mock(ServiceLoader.class);
+
when(serviceLoader.iterator()).thenReturn(singletonList(dummyImpl).iterator());
+
+ try (MockedStatic mocked = mockStatic(ServiceLoader.class)) {
+ mocked.when(() ->
ServiceLoader.load(OmTransportFactory.class)).thenReturn(serviceLoader);
+
+ OmTransportFactory factory = OmTransportFactory.createFactory(conf);
+ assertEquals(dummyImpl, factory);
+ }
+ }
+
+ @Test
+ public void testCreateFactoryFromConfig() throws IOException {
+ ServiceLoader<OmTransportFactory> emptyLoader = mock(ServiceLoader.class);
+ when(emptyLoader.iterator()).thenReturn(Collections.emptyIterator());
+
+ try (MockedStatic mocked = mockStatic(ServiceLoader.class)) {
+ mocked.when(() -> ServiceLoader.load(OmTransportFactory.class))
+ .thenReturn(emptyLoader);
+
+ // Without anything in config, the default transport is returned.
+ OmTransportFactory factory = OmTransportFactory.createFactory(conf);
+ assertEquals(OZONE_OM_TRANSPORT_CLASS_DEFAULT,
factory.getClass().getName());
+
+ // With concrete class name indicated in config.
+ conf.set(OZONE_OM_TRANSPORT_CLASS, MyDummyTransport.class.getName());
+ OmTransportFactory factory2 = OmTransportFactory.createFactory(conf);
+ assertEquals(MyDummyTransport.class, factory2.getClass());
+
+ // With non-existing class name in the config, exception is expected.
+ conf.set(OZONE_OM_TRANSPORT_CLASS, "com.MyMadeUpClass");
+ assertThrows(IOException.class, () -> {
+ OmTransportFactory.createFactory(conf);
+ });
+ }
+ }
+
+ static class MyDummyTransport implements OmTransportFactory {
+
+ @Override
+ public OmTransport createOmTransport(ConfigurationSource source,
+ UserGroupInformation ugi, String omServiceId) throws IOException {
+ return null;
+ }
+ }
+}
diff --git
a/hadoop-ozone/s3gateway/src/main/resources/META-INF/services/org.apache.hadoop.ozone.om.protocolPB.OmTransportFactory
b/hadoop-ozone/s3gateway/src/main/resources/META-INF/services/org.apache.hadoop.ozone.om.protocolPB.OmTransportFactory
deleted file mode 100644
index 254933bc82..0000000000
---
a/hadoop-ozone/s3gateway/src/main/resources/META-INF/services/org.apache.hadoop.ozone.om.protocolPB.OmTransportFactory
+++ /dev/null
@@ -1,15 +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.
-org.apache.hadoop.ozone.om.protocolPB.GrpcOmTransportFactory
diff --git
a/hadoop-ozone/tools/src/main/resources/META-INF/services/org.apache.hadoop.ozone.om.protocolPB.OmTransportFactory
b/hadoop-ozone/tools/src/main/resources/META-INF/services/org.apache.hadoop.ozone.om.protocolPB.OmTransportFactory
deleted file mode 100644
index 21669f5982..0000000000
---
a/hadoop-ozone/tools/src/main/resources/META-INF/services/org.apache.hadoop.ozone.om.protocolPB.OmTransportFactory
+++ /dev/null
@@ -1,15 +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.
-org.apache.hadoop.ozone.om.protocolPB.Hadoop3OmTransportFactory
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]