use of org.apache.hadoop.ozone.om.helpers.OMNodeDetails in project ozone by apache.
the class DecommissionOMSubcommand method call.
@Override
public Void call() throws IOException {
ozoneConf = parent.getParent().getOzoneConf();
user = parent.getParent().getUser();
verifyNodeIdAndHostAddress();
if (!force) {
verifyConfigUpdatedOnAllOMs();
}
// leader.
try (OMAdminProtocolClientSideImpl omAdminProtocolClient = OMAdminProtocolClientSideImpl.createProxyForOMHA(ozoneConf, user, omServiceId)) {
OMNodeDetails decommNodeDetails = new OMNodeDetails.Builder().setOMNodeId(decommNodeId).setHostAddress(hostInetAddress.getHostAddress()).build();
omAdminProtocolClient.decommission(decommNodeDetails);
System.out.println("Successfully decommissioned OM " + decommNodeId);
} catch (IOException e) {
System.out.println("Failed to decommission OM " + decommNodeId);
throw e;
}
return null;
}
use of org.apache.hadoop.ozone.om.helpers.OMNodeDetails in project ozone by apache.
the class OzoneManagerRatisServer method newOMRatisServer.
/**
* Creates an instance of OzoneManagerRatisServer.
*/
public static OzoneManagerRatisServer newOMRatisServer(ConfigurationSource ozoneConf, OzoneManager omProtocol, OMNodeDetails omNodeDetails, Map<String, OMNodeDetails> peerNodes, SecurityConfig secConfig, CertificateClient certClient, boolean isBootstrapping) throws IOException {
// RaftGroupId is the omServiceId
String omServiceId = omNodeDetails.getServiceId();
String omNodeId = omNodeDetails.getNodeId();
RaftPeerId localRaftPeerId = RaftPeerId.getRaftPeerId(omNodeId);
InetSocketAddress ratisAddr = new InetSocketAddress(omNodeDetails.getInetAddress(), omNodeDetails.getRatisPort());
RaftPeer localRaftPeer = RaftPeer.newBuilder().setId(localRaftPeerId).setAddress(ratisAddr).build();
// If OM is started in bootstrap mode, do not add peers to the RaftGroup.
// Raft peers will be added after SetConfiguration transaction is
// committed by leader and propagated to followers.
List<RaftPeer> raftPeers = new ArrayList<>();
if (!isBootstrapping) {
// On regular startup, add all OMs to Ratis ring
raftPeers.add(localRaftPeer);
for (Map.Entry<String, OMNodeDetails> peerInfo : peerNodes.entrySet()) {
String peerNodeId = peerInfo.getKey();
OMNodeDetails peerNode = peerInfo.getValue();
RaftPeerId raftPeerId = RaftPeerId.valueOf(peerNodeId);
RaftPeer raftPeer;
if (peerNode.isHostUnresolved()) {
raftPeer = RaftPeer.newBuilder().setId(raftPeerId).setAddress(peerNode.getRatisHostPortStr()).build();
} else {
InetSocketAddress peerRatisAddr = new InetSocketAddress(peerNode.getInetAddress(), peerNode.getRatisPort());
raftPeer = RaftPeer.newBuilder().setId(raftPeerId).setAddress(peerRatisAddr).build();
}
// Add other OM nodes belonging to the same OM service to the Ratis ring
raftPeers.add(raftPeer);
}
}
return new OzoneManagerRatisServer(ozoneConf, omProtocol, omServiceId, localRaftPeerId, ratisAddr, raftPeers, isBootstrapping, secConfig, certClient);
}
use of org.apache.hadoop.ozone.om.helpers.OMNodeDetails in project ozone by apache.
the class OMHANodeDetails method loadOMHAConfig.
/**
* Inspects and loads OM node configurations.
*
* If {@link OMConfigKeys#OZONE_OM_SERVICE_IDS_KEY} is configured with
* multiple ids and/ or if {@link OMConfigKeys#OZONE_OM_NODE_ID_KEY} is not
* specifically configured , this method determines the omServiceId
* and omNodeId by matching the node's address with the configured
* addresses. When a match is found, it sets the omServicId and omNodeId from
* the corresponding configuration key. This method also finds the OM peers
* nodes belonging to the same OM service.
*
* @param conf
*/
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;
}
}
use of org.apache.hadoop.ozone.om.helpers.OMNodeDetails in project ozone by apache.
the class OMAdminProtocolClientSideImpl method createProxyForOMHA.
/**
* Create OM Admin Protocol Client for contacting the OM ring (failover
* till the current OM leader is reached). Use for admin commands such as
* decommissionOM which should reach the OM leader.
*/
public static OMAdminProtocolClientSideImpl createProxyForOMHA(OzoneConfiguration conf, UserGroupInformation ugi, String omServiceId) throws IOException {
RPC.setProtocolEngine(OzoneConfiguration.of(conf), OMAdminProtocolPB.class, ProtobufRpcEngine.class);
OMFailoverProxyProvider omFailoverProxyProvider = new OMFailoverProxyProvider(conf, ugi, omServiceId, OMAdminProtocolPB.class);
// Multiple the max number of retries with number of OMs to calculate the
// max number of failovers.
int maxFailovers = conf.getInt(OMConfigKeys.OZONE_OM_ADMIN_PROTOCOL_MAX_RETRIES_KEY, OMConfigKeys.OZONE_OM_ADMIN_PROTOCOL_MAX_RETRIES_DEFAULT) * omFailoverProxyProvider.getOMProxies().size();
OMAdminProtocolPB retryProxy = (OMAdminProtocolPB) RetryProxy.create(OMAdminProtocolPB.class, omFailoverProxyProvider, omFailoverProxyProvider.getRetryPolicy(maxFailovers));
List<OMNodeDetails> allOMNodeDetails = OmUtils.getAllOMHAAddresses(conf, omServiceId, false);
return new OMAdminProtocolClientSideImpl(retryProxy, OmUtils.getOMAddressListPrintString(allOMNodeDetails));
}
use of org.apache.hadoop.ozone.om.helpers.OMNodeDetails in project ozone by apache.
the class OMInterServiceProtocolServerSideImpl method bootstrap.
@Override
public BootstrapOMResponse bootstrap(RpcController controller, BootstrapOMRequest request) throws ServiceException {
if (request == null) {
return null;
}
if (!isRatisEnabled) {
return BootstrapOMResponse.newBuilder().setSuccess(false).setErrorCode(ErrorCode.RATIS_NOT_ENABLED).setErrorMsg("New OM node cannot be bootstrapped as Ratis " + "is not enabled on existing OM").build();
}
OzoneManagerRatisUtils.checkLeaderStatus(ozoneManager);
OMNodeDetails newOmNode = new OMNodeDetails.Builder().setOMNodeId(request.getNodeId()).setHostAddress(request.getHostAddress()).setRatisPort(request.getRatisPort()).build();
try {
omRatisServer.addOMToRatisRing(newOmNode);
} catch (IOException ex) {
return BootstrapOMResponse.newBuilder().setSuccess(false).setErrorCode(ErrorCode.RATIS_BOOTSTRAP_ERROR).setErrorMsg(ex.getMessage()).build();
}
return BootstrapOMResponse.newBuilder().setSuccess(true).build();
}
Aggregations