in hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/ha/OMHANodeDetails.java [102:237]
public static OMHANodeDetails loadOMHAConfig(OzoneConfiguration conf) {
InetSocketAddress localRpcAddress = null;
String localOMServiceId = null;
String localOMNodeId = null;
int localRatisPort = 0;
Collection<String> omServiceIds;
localOMServiceId = conf.getTrimmed(OZONE_OM_INTERNAL_SERVICE_ID);
if (localOMServiceId == null) {
// There is no internal om service id is being set, fall back to ozone
// .om.service.ids.
LOG.info("{} is not defined, falling back to {} to find serviceID for "
+ "OzoneManager if it is HA enabled cluster",
OZONE_OM_INTERNAL_SERVICE_ID, OZONE_OM_SERVICE_IDS_KEY);
omServiceIds = conf.getTrimmedStringCollection(
OZONE_OM_SERVICE_IDS_KEY);
} else {
LOG.info("ServiceID for OzoneManager is {}", localOMServiceId);
omServiceIds = Collections.singletonList(localOMServiceId);
}
String knownOMNodeId = conf.get(OZONE_OM_NODE_ID_KEY);
int found = 0;
boolean isOMAddressSet = false;
for (String serviceId : omServiceIds) {
Collection<String> omNodeIds = OmUtils.getActiveOMNodeIds(conf,
serviceId);
if (omNodeIds.size() == 0) {
throwConfException("Configuration does not have any value set for %s " +
"for the service %s. List of OM Node ID's should be specified " +
"for an OM service", OZONE_OM_NODES_KEY, serviceId);
return null;
}
List<OMNodeDetails> peerNodesList = new ArrayList<>();
boolean isPeer;
for (String nodeId : omNodeIds) {
if (knownOMNodeId != null && !knownOMNodeId.equals(nodeId)) {
isPeer = true;
} else {
isPeer = false;
}
String rpcAddrKey = ConfUtils.addKeySuffixes(OZONE_OM_ADDRESS_KEY,
serviceId, nodeId);
String rpcAddrStr = OmUtils.getOmRpcAddress(conf, rpcAddrKey);
if (rpcAddrStr == null || rpcAddrStr.isEmpty()) {
throwConfException("Configuration does not have any value set for " +
"%s. OM RPC Address should be set for all nodes in an OM " +
"service.", rpcAddrKey);
return null;
}
// If OM address is set for any node id, we will not fallback to the
// default
isOMAddressSet = true;
String ratisPortKey = ConfUtils.addKeySuffixes(OZONE_OM_RATIS_PORT_KEY,
serviceId, nodeId);
int ratisPort = conf.getInt(ratisPortKey, OZONE_OM_RATIS_PORT_DEFAULT);
InetSocketAddress addr = null;
try {
addr = NetUtils.createSocketAddr(rpcAddrStr);
} catch (Exception e) {
LOG.error("Couldn't create socket address for OM {} : {}", nodeId,
rpcAddrStr, e);
throw e;
}
boolean flexibleFqdnResolutionEnabled = conf.getBoolean(
OZONE_FLEXIBLE_FQDN_RESOLUTION_ENABLED,
OZONE_FLEXIBLE_FQDN_RESOLUTION_ENABLED_DEFAULT);
if (OzoneNetUtils.isUnresolved(flexibleFqdnResolutionEnabled, addr)) {
LOG.error("Address for OM {} : {} couldn't be resolved. Proceeding " +
"with unresolved host to create Ratis ring.", nodeId,
rpcAddrStr);
}
if (!isPeer
&& OzoneNetUtils
.isAddressLocal(flexibleFqdnResolutionEnabled, addr)) {
localRpcAddress = addr;
localOMServiceId = serviceId;
localOMNodeId = nodeId;
localRatisPort = ratisPort;
found++;
} else {
// This OMNode belongs to same OM service as the current OMNode.
// Add it to peerNodes list.
peerNodesList.add(getHAOMNodeDetails(conf, serviceId,
nodeId, addr, ratisPort));
}
}
if (found == 1) {
LOG.info("Found matching OM address with OMServiceId: {}, " +
"OMNodeId: {}, RPC Address: {} and Ratis port: {}",
localOMServiceId, localOMNodeId,
NetUtils.getHostPortString(localRpcAddress), localRatisPort);
ConfUtils.setNodeSpecificConfigs(genericConfigKeys, conf,
localOMServiceId, localOMNodeId, LOG);
return new OMHANodeDetails(getHAOMNodeDetails(conf, localOMServiceId,
localOMNodeId, localRpcAddress, localRatisPort), peerNodesList);
} else if (found > 1) {
throwConfException("Configuration has multiple %s addresses that " +
"match local node's address. Please configure the system with %s " +
"and %s", OZONE_OM_ADDRESS_KEY, OZONE_OM_SERVICE_IDS_KEY,
OZONE_OM_ADDRESS_KEY);
return null;
}
}
if (!isOMAddressSet) {
// No OM address is set. Fallback to default
InetSocketAddress omAddress = OmUtils.getOmAddress(conf);
int ratisPort = conf.getInt(OZONE_OM_RATIS_PORT_KEY,
OZONE_OM_RATIS_PORT_DEFAULT);
LOG.info("Configuration does not have {} set. Falling back to the " +
"default OM address {}", OZONE_OM_ADDRESS_KEY, omAddress);
return new OMHANodeDetails(getOMNodeDetailsForNonHA(conf, null,
null, omAddress, ratisPort), new ArrayList<>());
} else {
throwConfException("Configuration has no %s address that matches local " +
"node's address.", OZONE_OM_ADDRESS_KEY);
return null;
}
}