hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bra...@apache.org
Subject [46/50] [abbrv] hadoop git commit: HDDS-751. Replace usage of Guava Optional with Java Optional.
Date Fri, 02 Nov 2018 09:29:54 GMT
HDDS-751. Replace usage of Guava Optional with Java Optional.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/d16d5f73
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/d16d5f73
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/d16d5f73

Branch: refs/heads/HDFS-13891
Commit: d16d5f730e9d139d3e026805f21ac2c9b0bbb98b
Parents: 8fe85af
Author: Yiqun Lin <yqlin@apache.org>
Authored: Fri Nov 2 10:50:32 2018 +0800
Committer: Yiqun Lin <yqlin@apache.org>
Committed: Fri Nov 2 10:50:32 2018 +0800

----------------------------------------------------------------------
 .../java/org/apache/hadoop/hdds/HddsUtils.java  | 29 +++++++++-----------
 .../apache/hadoop/hdds/scm/HddsServerUtil.java  | 17 ++++++------
 .../hadoop/hdds/server/BaseHttpServer.java      |  9 ++++--
 .../java/org/apache/hadoop/ozone/OmUtils.java   |  8 +++---
 4 files changed, 32 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/d16d5f73/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java
----------------------------------------------------------------------
diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java
index 89edfdd..18637af 100644
--- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java
+++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java
@@ -18,7 +18,6 @@
 
 package org.apache.hadoop.hdds;
 
-import com.google.common.base.Optional;
 import com.google.common.base.Strings;
 import com.google.common.net.HostAndPort;
 import org.apache.hadoop.classification.InterfaceAudience;
@@ -45,6 +44,7 @@ import java.util.Calendar;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Map;
+import java.util.Optional;
 import java.util.TimeZone;
 
 import static org.apache.hadoop.hdfs.DFSConfigKeys
@@ -114,7 +114,7 @@ public final class HddsUtils {
         ScmConfigKeys.OZONE_SCM_CLIENT_ADDRESS_KEY);
 
     return NetUtils.createSocketAddr(host.get() + ":" + port
-        .or(ScmConfigKeys.OZONE_SCM_CLIENT_PORT_DEFAULT));
+        .orElse(ScmConfigKeys.OZONE_SCM_CLIENT_PORT_DEFAULT));
   }
 
   /**
@@ -162,7 +162,7 @@ public final class HddsUtils {
         ScmConfigKeys.OZONE_SCM_BLOCK_CLIENT_ADDRESS_KEY);
 
     return NetUtils.createSocketAddr(host.get() + ":" + port
-        .or(ScmConfigKeys.OZONE_SCM_BLOCK_CLIENT_PORT_DEFAULT));
+        .orElse(ScmConfigKeys.OZONE_SCM_BLOCK_CLIENT_PORT_DEFAULT));
   }
 
   /**
@@ -186,7 +186,7 @@ public final class HddsUtils {
         return hostName;
       }
     }
-    return Optional.absent();
+    return Optional.empty();
   }
 
   /**
@@ -196,7 +196,7 @@ public final class HddsUtils {
    */
   public static Optional<String> getHostName(String value) {
     if ((value == null) || value.isEmpty()) {
-      return Optional.absent();
+      return Optional.empty();
     }
     return Optional.of(HostAndPort.fromString(value).getHostText());
   }
@@ -208,11 +208,11 @@ public final class HddsUtils {
    */
   public static Optional<Integer> getHostPort(String value) {
     if ((value == null) || value.isEmpty()) {
-      return Optional.absent();
+      return Optional.empty();
     }
     int port = HostAndPort.fromString(value).getPortOrDefault(NO_PORT);
     if (port == NO_PORT) {
-      return Optional.absent();
+      return Optional.empty();
     } else {
       return Optional.of(port);
     }
@@ -239,7 +239,7 @@ public final class HddsUtils {
         return hostPort;
       }
     }
-    return Optional.absent();
+    return Optional.empty();
   }
 
   /**
@@ -261,20 +261,17 @@ public final class HddsUtils {
           + " Null or empty address list found.");
     }
 
-    final com.google.common.base.Optional<Integer>
-        defaultPort =  com.google.common.base.Optional.of(ScmConfigKeys
-        .OZONE_SCM_DEFAULT_PORT);
+    final Optional<Integer> defaultPort = Optional
+        .of(ScmConfigKeys.OZONE_SCM_DEFAULT_PORT);
     for (String address : names) {
-      com.google.common.base.Optional<String> hostname =
-          getHostName(address);
+      Optional<String> hostname = getHostName(address);
       if (!hostname.isPresent()) {
         throw new IllegalArgumentException("Invalid hostname for SCM: "
             + hostname);
       }
-      com.google.common.base.Optional<Integer> port =
-          getHostPort(address);
+      Optional<Integer> port = getHostPort(address);
       InetSocketAddress addr = NetUtils.createSocketAddr(hostname.get(),
-          port.or(defaultPort.get()));
+          port.orElse(defaultPort.get()));
       addresses.add(addr);
     }
     return addresses;

http://git-wip-us.apache.org/repos/asf/hadoop/blob/d16d5f73/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/hdds/scm/HddsServerUtil.java
----------------------------------------------------------------------
diff --git a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/hdds/scm/HddsServerUtil.java
b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/hdds/scm/HddsServerUtil.java
index 738a2ef..40b3d7a 100644
--- a/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/hdds/scm/HddsServerUtil.java
+++ b/hadoop-hdds/container-service/src/main/java/org/apache/hadoop/hdds/scm/HddsServerUtil.java
@@ -17,7 +17,6 @@
 
 package org.apache.hadoop.hdds.scm;
 
-import com.google.common.base.Optional;
 import com.google.common.base.Strings;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hdds.HddsConfigKeys;
@@ -32,6 +31,7 @@ import java.net.InetSocketAddress;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Optional;
 import java.util.concurrent.TimeUnit;
 
 import static org.apache.hadoop.hdds.HddsConfigKeys
@@ -114,7 +114,7 @@ public final class HddsServerUtil {
         ScmConfigKeys.OZONE_SCM_DATANODE_ADDRESS_KEY);
 
     InetSocketAddress addr = NetUtils.createSocketAddr(host.get() + ":" +
-        port.or(ScmConfigKeys.OZONE_SCM_DATANODE_PORT_DEFAULT));
+        port.orElse(ScmConfigKeys.OZONE_SCM_DATANODE_PORT_DEFAULT));
 
     return addr;
   }
@@ -135,8 +135,8 @@ public final class HddsServerUtil {
         ScmConfigKeys.OZONE_SCM_CLIENT_ADDRESS_KEY);
 
     return NetUtils.createSocketAddr(
-        host.or(ScmConfigKeys.OZONE_SCM_CLIENT_BIND_HOST_DEFAULT) + ":" +
-            port.or(ScmConfigKeys.OZONE_SCM_CLIENT_PORT_DEFAULT));
+        host.orElse(ScmConfigKeys.OZONE_SCM_CLIENT_BIND_HOST_DEFAULT) + ":" +
+            port.orElse(ScmConfigKeys.OZONE_SCM_CLIENT_PORT_DEFAULT));
   }
 
   /**
@@ -155,8 +155,9 @@ public final class HddsServerUtil {
         ScmConfigKeys.OZONE_SCM_BLOCK_CLIENT_ADDRESS_KEY);
 
     return NetUtils.createSocketAddr(
-        host.or(ScmConfigKeys.OZONE_SCM_BLOCK_CLIENT_BIND_HOST_DEFAULT) +
-            ":" + port.or(ScmConfigKeys.OZONE_SCM_BLOCK_CLIENT_PORT_DEFAULT));
+        host.orElse(ScmConfigKeys.OZONE_SCM_BLOCK_CLIENT_BIND_HOST_DEFAULT)
+            + ":"
+            + port.orElse(ScmConfigKeys.OZONE_SCM_BLOCK_CLIENT_PORT_DEFAULT));
   }
 
   /**
@@ -176,8 +177,8 @@ public final class HddsServerUtil {
         ScmConfigKeys.OZONE_SCM_DATANODE_ADDRESS_KEY);
 
     return NetUtils.createSocketAddr(
-        host.or(ScmConfigKeys.OZONE_SCM_DATANODE_BIND_HOST_DEFAULT) + ":" +
-            port.or(ScmConfigKeys.OZONE_SCM_DATANODE_PORT_DEFAULT));
+        host.orElse(ScmConfigKeys.OZONE_SCM_DATANODE_BIND_HOST_DEFAULT) + ":" +
+            port.orElse(ScmConfigKeys.OZONE_SCM_DATANODE_PORT_DEFAULT));
   }
 
 

http://git-wip-us.apache.org/repos/asf/hadoop/blob/d16d5f73/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/BaseHttpServer.java
----------------------------------------------------------------------
diff --git a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/BaseHttpServer.java
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/BaseHttpServer.java
index da5d8da..2726fc3 100644
--- a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/BaseHttpServer.java
+++ b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/server/BaseHttpServer.java
@@ -17,7 +17,6 @@
 
 package org.apache.hadoop.hdds.server;
 
-import com.google.common.base.Optional;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hdfs.DFSConfigKeys;
 import org.apache.hadoop.hdfs.DFSUtil;
@@ -32,6 +31,7 @@ import org.slf4j.LoggerFactory;
 import javax.servlet.http.HttpServlet;
 import java.io.IOException;
 import java.net.InetSocketAddress;
+import java.util.Optional;
 
 import static org.apache.hadoop.hdds.HddsUtils.getHostNameFromConfigKeys;
 import static org.apache.hadoop.hdds.HddsUtils.getPortNumberFromConfigKeys;
@@ -118,10 +118,13 @@ public abstract class BaseHttpServer {
     final Optional<String> addresHost =
         getHostNameFromConfigKeys(conf, addressKey);
 
-    String hostName = bindHost.or(addresHost).or(bindHostDefault);
+    String hostName = bindHost.orElse(addresHost.get());
+    if (hostName == null || hostName.isEmpty()) {
+      hostName = bindHostDefault;
+    }
 
     return NetUtils.createSocketAddr(
-        hostName + ":" + addressPort.or(bindPortdefault));
+        hostName + ":" + addressPort.orElse(bindPortdefault));
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/hadoop/blob/d16d5f73/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/OmUtils.java
----------------------------------------------------------------------
diff --git a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/OmUtils.java b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/OmUtils.java
index d8608be..9280648 100644
--- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/OmUtils.java
+++ b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/OmUtils.java
@@ -20,13 +20,13 @@ package org.apache.hadoop.ozone;
 import java.io.File;
 import java.net.InetSocketAddress;
 import java.util.Collection;
+import java.util.Optional;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hdds.HddsConfigKeys;
 import org.apache.hadoop.hdds.server.ServerUtils;
 import org.apache.hadoop.net.NetUtils;
 
-import com.google.common.base.Optional;
 import org.apache.hadoop.ozone.om.OMConfigKeys;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -60,7 +60,7 @@ public final class OmUtils {
         OZONE_OM_ADDRESS_KEY);
 
     return NetUtils.createSocketAddr(
-        host.or(OZONE_OM_BIND_HOST_DEFAULT) + ":" +
+        host.orElse(OZONE_OM_BIND_HOST_DEFAULT) + ":" +
             getOmRpcPort(conf));
   }
 
@@ -90,7 +90,7 @@ public final class OmUtils {
     // If no port number is specified then we'll just try the defaultBindPort.
     final Optional<Integer> port = getPortNumberFromConfigKeys(conf,
         OZONE_OM_ADDRESS_KEY);
-    return port.or(OZONE_OM_PORT_DEFAULT);
+    return port.orElse(OZONE_OM_PORT_DEFAULT);
   }
 
   public static int getOmRestPort(Configuration conf) {
@@ -98,7 +98,7 @@ public final class OmUtils {
     // HTTP BindPort.
     final Optional<Integer> port =
         getPortNumberFromConfigKeys(conf, OZONE_OM_HTTP_ADDRESS_KEY);
-    return port.or(OZONE_OM_HTTP_BIND_PORT_DEFAULT);
+    return port.orElse(OZONE_OM_HTTP_BIND_PORT_DEFAULT);
   }
 
   /**


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message