|
@@ -30,7 +30,6 @@ import org.apache.hadoop.net.NetUtils;
|
|
|
import org.apache.hadoop.ozone.OmUtils;
|
|
|
import org.apache.hadoop.ozone.OzoneConsts;
|
|
|
import org.apache.hadoop.ozone.om.protocolPB.OzoneManagerProtocolPB;
|
|
|
-import org.apache.hadoop.security.SecurityUtil;
|
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -59,7 +58,8 @@ public class OMFailoverProxyProvider implements
|
|
|
LoggerFactory.getLogger(OMFailoverProxyProvider.class);
|
|
|
|
|
|
// Map of OMNodeID to its proxy
|
|
|
- private Map<String, OMProxyInfo> omProxies;
|
|
|
+ private Map<String, ProxyInfo<OzoneManagerProtocolPB>> omProxies;
|
|
|
+ private Map<String, OMProxyInfo> omProxyInfos;
|
|
|
private List<String> omNodeIDList;
|
|
|
|
|
|
private String currentProxyOMNodeId;
|
|
@@ -80,33 +80,9 @@ public class OMFailoverProxyProvider implements
|
|
|
currentProxyOMNodeId = omNodeIDList.get(currentProxyIndex);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Class to store proxy information.
|
|
|
- */
|
|
|
- public class OMProxyInfo
|
|
|
- extends FailoverProxyProvider.ProxyInfo<OzoneManagerProtocolPB> {
|
|
|
- private InetSocketAddress address;
|
|
|
- private Text dtService;
|
|
|
-
|
|
|
- OMProxyInfo(OzoneManagerProtocolPB proxy, String proxyInfoStr,
|
|
|
- Text dtService,
|
|
|
- InetSocketAddress addr) {
|
|
|
- super(proxy, proxyInfoStr);
|
|
|
- this.address = addr;
|
|
|
- this.dtService = dtService;
|
|
|
- }
|
|
|
-
|
|
|
- public InetSocketAddress getAddress() {
|
|
|
- return address;
|
|
|
- }
|
|
|
-
|
|
|
- public Text getDelegationTokenService() {
|
|
|
- return dtService;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
private void loadOMClientConfigs(Configuration config) throws IOException {
|
|
|
this.omProxies = new HashMap<>();
|
|
|
+ this.omProxyInfos = new HashMap<>();
|
|
|
this.omNodeIDList = new ArrayList<>();
|
|
|
|
|
|
Collection<String> omServiceIds = config.getTrimmedStringCollection(
|
|
@@ -130,25 +106,21 @@ public class OMFailoverProxyProvider implements
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- InetSocketAddress addr = NetUtils.createSocketAddr(rpcAddrStr);
|
|
|
+ OMProxyInfo omProxyInfo = new OMProxyInfo(nodeId, rpcAddrStr);
|
|
|
+
|
|
|
+ if (omProxyInfo.getAddress() != null) {
|
|
|
|
|
|
- // Add the OM client proxy info to list of proxies
|
|
|
- if (addr != null) {
|
|
|
- Text dtService = SecurityUtil.buildTokenService(addr);
|
|
|
- StringBuilder proxyInfo = new StringBuilder()
|
|
|
- .append(nodeId).append("(")
|
|
|
- .append(NetUtils.getHostPortString(addr)).append(")");
|
|
|
- OMProxyInfo omProxyInfo = new OMProxyInfo(null,
|
|
|
- proxyInfo.toString(), dtService, addr);
|
|
|
+ ProxyInfo<OzoneManagerProtocolPB> proxyInfo =
|
|
|
+ new ProxyInfo(null, omProxyInfo.toString());
|
|
|
|
|
|
// For a non-HA OM setup, nodeId might be null. If so, we assign it
|
|
|
// a dummy value
|
|
|
if (nodeId == null) {
|
|
|
nodeId = OzoneConsts.OM_NODE_ID_DUMMY;
|
|
|
}
|
|
|
- omProxies.put(nodeId, omProxyInfo);
|
|
|
+ omProxies.put(nodeId, proxyInfo);
|
|
|
+ omProxyInfos.put(nodeId, omProxyInfo);
|
|
|
omNodeIDList.add(nodeId);
|
|
|
-
|
|
|
} else {
|
|
|
LOG.error("Failed to create OM proxy for {} at address {}",
|
|
|
nodeId, rpcAddrStr);
|
|
@@ -183,26 +155,31 @@ public class OMFailoverProxyProvider implements
|
|
|
* @return the OM proxy object to invoke methods upon
|
|
|
*/
|
|
|
@Override
|
|
|
- public synchronized OMProxyInfo getProxy() {
|
|
|
- OMProxyInfo currentOMProxyInfo = omProxies.get(currentProxyOMNodeId);
|
|
|
- createOMProxyIfNeeded(currentOMProxyInfo);
|
|
|
- return currentOMProxyInfo;
|
|
|
+ public synchronized ProxyInfo getProxy() {
|
|
|
+ ProxyInfo currentProxyInfo = omProxies.get(currentProxyOMNodeId);
|
|
|
+ createOMProxyIfNeeded(currentProxyInfo, currentProxyOMNodeId);
|
|
|
+ return currentProxyInfo;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Creates OM proxy object if it does not already exist.
|
|
|
+ * Creates proxy object if it does not already exist.
|
|
|
*/
|
|
|
- private OMProxyInfo createOMProxyIfNeeded(OMProxyInfo proxyInfo) {
|
|
|
+ private void createOMProxyIfNeeded(ProxyInfo proxyInfo,
|
|
|
+ String nodeId) {
|
|
|
if (proxyInfo.proxy == null) {
|
|
|
+ InetSocketAddress address = omProxyInfos.get(nodeId).getAddress();
|
|
|
try {
|
|
|
- proxyInfo.proxy = createOMProxy(proxyInfo.address);
|
|
|
+ proxyInfo.proxy = createOMProxy(address);
|
|
|
} catch (IOException ioe) {
|
|
|
LOG.error("{} Failed to create RPC proxy to OM at {}",
|
|
|
- this.getClass().getSimpleName(), proxyInfo.address, ioe);
|
|
|
+ this.getClass().getSimpleName(), address, ioe);
|
|
|
throw new RuntimeException(ioe);
|
|
|
}
|
|
|
}
|
|
|
- return proxyInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ public synchronized Text getCurrentProxyDelegationToken() {
|
|
|
+ return omProxyInfos.get(currentProxyOMNodeId).getDelegationTokenService();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -269,7 +246,7 @@ public class OMFailoverProxyProvider implements
|
|
|
*/
|
|
|
@Override
|
|
|
public synchronized void close() throws IOException {
|
|
|
- for (OMProxyInfo proxy : omProxies.values()) {
|
|
|
+ for (ProxyInfo<OzoneManagerProtocolPB> proxy : omProxies.values()) {
|
|
|
OzoneManagerProtocolPB omProxy = proxy.proxy;
|
|
|
if (omProxy != null) {
|
|
|
RPC.stopProxy(omProxy);
|
|
@@ -278,8 +255,13 @@ public class OMFailoverProxyProvider implements
|
|
|
}
|
|
|
|
|
|
@VisibleForTesting
|
|
|
- public List<OMProxyInfo> getOMProxies() {
|
|
|
- return new ArrayList<>(omProxies.values());
|
|
|
+ public List<ProxyInfo> getOMProxies() {
|
|
|
+ return new ArrayList<ProxyInfo>(omProxies.values());
|
|
|
+ }
|
|
|
+
|
|
|
+ @VisibleForTesting
|
|
|
+ public List<OMProxyInfo> getOMProxyInfos() {
|
|
|
+ return new ArrayList<OMProxyInfo>(omProxyInfos.values());
|
|
|
}
|
|
|
}
|
|
|
|