HDDS-751. Replace usage of Guava Optional with Java Optional.
This commit is contained in:
parent
8fe85af63b
commit
d16d5f730e
@ -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.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 static InetSocketAddress getScmAddressForClients(Configuration conf) {
|
||||
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 static InetSocketAddress getScmAddressForBlockClients(
|
||||
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 static Optional<String> getHostNameFromConfigKeys(Configuration conf,
|
||||
return hostName;
|
||||
}
|
||||
}
|
||||
return Optional.absent();
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -196,7 +196,7 @@ public static Optional<String> getHostNameFromConfigKeys(Configuration conf,
|
||||
*/
|
||||
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 static Optional<String> getHostName(String value) {
|
||||
*/
|
||||
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 static Optional<Integer> getPortNumberFromConfigKeys(
|
||||
return hostPort;
|
||||
}
|
||||
}
|
||||
return Optional.absent();
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -261,20 +261,17 @@ public static Collection<InetSocketAddress> getSCMAddresses(
|
||||
+ " 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;
|
||||
|
@ -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.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 static InetSocketAddress getScmAddressForDataNodes(
|
||||
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 static InetSocketAddress getScmClientBindAddress(
|
||||
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 static InetSocketAddress getScmBlockClientBindAddress(
|
||||
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 static InetSocketAddress getScmDataNodeBindAddress(
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 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 @@ protected InetSocketAddress getBindAddress(String bindHostKey,
|
||||
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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,13 +20,13 @@
|
||||
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 static InetSocketAddress getOmAddress(
|
||||
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 static int getOmRpcPort(Configuration conf) {
|
||||
// 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 static int getOmRestPort(Configuration conf) {
|
||||
// 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user