4242import org .apache .hadoop .crypto .key .KeyProviderCryptoExtension ;
4343import org .apache .hadoop .fs .CommonConfigurationKeys ;
4444import org .apache .hadoop .fs .CommonConfigurationKeysPublic ;
45- import org .apache .hadoop .conf .Configuration ;
4645import org .apache .hadoop .hdds .HddsConfigKeys ;
4746import org .apache .hadoop .hdds .HddsUtils ;
4847import org .apache .hadoop .hdds .conf .OzoneConfiguration ;
7473import org .apache .hadoop .ipc .Server ;
7574import org .apache .hadoop .ozone .OzoneAcl ;
7675import org .apache .hadoop .ozone .OzoneConfigKeys ;
77- import org .apache .hadoop .ozone .OzoneIllegalArgumentException ;
7876import org .apache .hadoop .ozone .OzoneSecurityUtil ;
7977import org .apache .hadoop .ozone .om .ha .OMFailoverProxyProvider ;
78+ import org .apache .hadoop .ozone .om .ha .OMHANodeDetails ;
79+ import org .apache .hadoop .ozone .om .ha .OMNodeDetails ;
8080import org .apache .hadoop .ozone .om .helpers .OmMultipartUploadList ;
8181import org .apache .hadoop .ozone .om .helpers .S3SecretValue ;
8282import org .apache .hadoop .ozone .om .protocol .OzoneManagerServerProtocol ;
207207import static org .apache .hadoop .ozone .om .OMConfigKeys .OZONE_OM_KERBEROS_PRINCIPAL_KEY ;
208208import static org .apache .hadoop .ozone .om .OMConfigKeys .OZONE_OM_METRICS_SAVE_INTERVAL ;
209209import static org .apache .hadoop .ozone .om .OMConfigKeys .OZONE_OM_METRICS_SAVE_INTERVAL_DEFAULT ;
210- import static org .apache .hadoop .ozone .om .OMConfigKeys .OZONE_OM_NODE_ID_KEY ;
211- import static org .apache .hadoop .ozone .om .OMConfigKeys .OZONE_OM_RATIS_PORT_DEFAULT ;
212- import static org .apache .hadoop .ozone .om .OMConfigKeys .OZONE_OM_SERVICE_IDS_KEY ;
213- import static org .apache .hadoop .ozone .om .OMConfigKeys .OZONE_OM_RATIS_PORT_KEY ;
214210import static org .apache .hadoop .ozone .om .OMConfigKeys .OZONE_OM_USER_MAX_VOLUME ;
215211import static org .apache .hadoop .ozone .om .OMConfigKeys .OZONE_OM_USER_MAX_VOLUME_DEFAULT ;
216212import static org .apache .hadoop .ozone .om .exceptions .OMException .ResultCodes .INVALID_AUTH_METHOD ;
@@ -310,12 +306,32 @@ private OzoneManager(OzoneConfiguration conf) throws IOException,
310306 super (OzoneVersionInfo .OZONE_VERSION_INFO );
311307 Preconditions .checkNotNull (conf );
312308 configuration = conf ;
309+ // Load HA related configurations
310+ OMHANodeDetails omhaNodeDetails =
311+ OMHANodeDetails .loadOMHAConfig (configuration );
312+
313+ this .peerNodes = omhaNodeDetails .getPeerNodeDetails ();
314+ this .omNodeDetails = omhaNodeDetails .getLocalNodeDetails ();
315+
316+ omStorage = new OMStorage (conf );
317+ omId = omStorage .getOmId ();
318+
319+ // In case of single OM Node Service there will be no OM Node ID
320+ // specified, set it to value from om storage
321+ if (this .omNodeDetails .getOMNodeId () == null ) {
322+ this .omNodeDetails =
323+ OMHANodeDetails .getOMNodeDetails (conf , omNodeDetails .getOMServiceId (),
324+ omStorage .getOmId (), omNodeDetails .getRpcAddress (),
325+ omNodeDetails .getRatisPort ());
326+ }
327+
328+ loginOMUserIfSecurityEnabled (conf );
329+
313330 this .maxUserVolumeCount = conf .getInt (OZONE_OM_USER_MAX_VOLUME ,
314331 OZONE_OM_USER_MAX_VOLUME_DEFAULT );
315332 Preconditions .checkArgument (this .maxUserVolumeCount > 0 ,
316333 OZONE_OM_USER_MAX_VOLUME + " value should be greater than zero" );
317- omStorage = new OMStorage (conf );
318- omId = omStorage .getOmId ();
334+
319335 if (omStorage .getState () != StorageState .INITIALIZED ) {
320336 throw new OMException ("OM not initialized." ,
321337 ResultCodes .OM_NOT_INITIALIZED );
@@ -342,8 +358,7 @@ private OzoneManager(OzoneConfiguration conf) throws IOException,
342358 OMConfigKeys .OZONE_OM_RATIS_ENABLE_KEY ,
343359 OMConfigKeys .OZONE_OM_RATIS_ENABLE_DEFAULT );
344360
345- // Load HA related configurations
346- loadOMHAConfigs (configuration );
361+
347362 InetSocketAddress omNodeRpcAddr = omNodeDetails .getRpcAddress ();
348363 omRpcAddressTxt = new Text (omNodeDetails .getRpcAddressString ());
349364
@@ -420,7 +435,7 @@ private OzoneManager(OzoneConfiguration conf) throws IOException,
420435 OzoneManagerProtocolProtos .Type .values ());
421436
422437 // Start Om Rpc Server.
423- omRpcServer = getRpcServer (conf );
438+ omRpcServer = getRpcServer (configuration );
424439 omRpcAddress = updateRPCListenAddress (configuration ,
425440 OZONE_OM_ADDRESS_KEY , omNodeRpcAddr , omRpcServer );
426441
@@ -513,195 +528,6 @@ public boolean isGrpcBlockTokenEnabled() {
513528 return grpcBlockTokenEnabled ;
514529 }
515530
516- /**
517- * Inspects and loads OM node configurations.
518- *
519- * If {@link OMConfigKeys#OZONE_OM_SERVICE_IDS_KEY} is configured with
520- * multiple ids and/ or if {@link OMConfigKeys#OZONE_OM_NODE_ID_KEY} is not
521- * specifically configured , this method determines the omServiceId
522- * and omNodeId by matching the node's address with the configured
523- * addresses. When a match is found, it sets the omServicId and omNodeId from
524- * the corresponding configuration key. This method also finds the OM peers
525- * nodes belonging to the same OM service.
526- *
527- * @param conf
528- */
529- private void loadOMHAConfigs (Configuration conf ) {
530- InetSocketAddress localRpcAddress = null ;
531- String localOMServiceId = null ;
532- String localOMNodeId = null ;
533- int localRatisPort = 0 ;
534- Collection <String > omServiceIds = conf .getTrimmedStringCollection (
535- OZONE_OM_SERVICE_IDS_KEY );
536-
537- String knownOMNodeId = conf .get (OZONE_OM_NODE_ID_KEY );
538- int found = 0 ;
539- boolean isOMAddressSet = false ;
540-
541- for (String serviceId : OmUtils .emptyAsSingletonNull (omServiceIds )) {
542- Collection <String > omNodeIds = OmUtils .getOMNodeIds (conf , serviceId );
543-
544- List <OMNodeDetails > peerNodesList = new ArrayList <>();
545- boolean isPeer = false ;
546- for (String nodeId : OmUtils .emptyAsSingletonNull (omNodeIds )) {
547- if (knownOMNodeId != null && !knownOMNodeId .equals (nodeId )) {
548- isPeer = true ;
549- } else {
550- isPeer = false ;
551- }
552- String rpcAddrKey = OmUtils .addKeySuffixes (OZONE_OM_ADDRESS_KEY ,
553- serviceId , nodeId );
554- String rpcAddrStr = OmUtils .getOmRpcAddress (conf , rpcAddrKey );
555- if (rpcAddrStr == null ) {
556- continue ;
557- }
558-
559- // If OM address is set for any node id, we will not fallback to the
560- // default
561- isOMAddressSet = true ;
562-
563- String ratisPortKey = OmUtils .addKeySuffixes (OZONE_OM_RATIS_PORT_KEY ,
564- serviceId , nodeId );
565- int ratisPort = conf .getInt (ratisPortKey , OZONE_OM_RATIS_PORT_DEFAULT );
566-
567- InetSocketAddress addr = null ;
568- try {
569- addr = NetUtils .createSocketAddr (rpcAddrStr );
570- } catch (Exception e ) {
571- LOG .warn ("Exception in creating socket address " + addr , e );
572- continue ;
573- }
574- if (!addr .isUnresolved ()) {
575- if (!isPeer && OmUtils .isAddressLocal (addr )) {
576- localRpcAddress = addr ;
577- localOMServiceId = serviceId ;
578- localOMNodeId = nodeId ;
579- localRatisPort = ratisPort ;
580- found ++;
581- } else {
582- // This OMNode belongs to same OM service as the current OMNode.
583- // Add it to peerNodes list.
584- String httpAddr = OmUtils .getHttpAddressForOMPeerNode (conf ,
585- serviceId , nodeId , addr .getHostName ());
586- String httpsAddr = OmUtils .getHttpsAddressForOMPeerNode (conf ,
587- serviceId , nodeId , addr .getHostName ());
588- OMNodeDetails peerNodeInfo = new OMNodeDetails .Builder ()
589- .setOMServiceId (serviceId )
590- .setOMNodeId (nodeId )
591- .setRpcAddress (addr )
592- .setRatisPort (ratisPort )
593- .setHttpAddress (httpAddr )
594- .setHttpsAddress (httpsAddr )
595- .build ();
596- peerNodesList .add (peerNodeInfo );
597- }
598- }
599- }
600- if (found == 1 ) {
601- LOG .debug ("Found one matching OM address with service ID: {} and node" +
602- " ID: {}" , localOMServiceId , localOMNodeId );
603-
604- setOMNodeDetails (localOMServiceId , localOMNodeId , localRpcAddress ,
605- localRatisPort );
606-
607- this .peerNodes = peerNodesList ;
608-
609- LOG .info ("Found matching OM address with OMServiceId: {}, " +
610- "OMNodeId: {}, RPC Address: {} and Ratis port: {}" ,
611- localOMServiceId , localOMNodeId ,
612- NetUtils .getHostPortString (localRpcAddress ), localRatisPort );
613- return ;
614- } else if (found > 1 ) {
615- String msg = "Configuration has multiple " + OZONE_OM_ADDRESS_KEY +
616- " addresses that match local node's address. Please configure the" +
617- " system with " + OZONE_OM_SERVICE_IDS_KEY + " and " +
618- OZONE_OM_ADDRESS_KEY ;
619- throw new OzoneIllegalArgumentException (msg );
620- }
621- }
622-
623- if (!isOMAddressSet ) {
624- // No OM address is set. Fallback to default
625- InetSocketAddress omAddress = OmUtils .getOmAddress (conf );
626- int ratisPort = conf .getInt (OZONE_OM_RATIS_PORT_KEY ,
627- OZONE_OM_RATIS_PORT_DEFAULT );
628-
629- LOG .info ("Configuration either no {} set. Falling back to the default " +
630- "OM address {}" , OZONE_OM_ADDRESS_KEY , omAddress );
631-
632- setOMNodeDetails (null , null , omAddress , ratisPort );
633-
634- } else {
635- String msg = "Configuration has no " + OZONE_OM_ADDRESS_KEY + " " +
636- "address that matches local node's address. Please configure the " +
637- "system with " + OZONE_OM_ADDRESS_KEY ;
638- LOG .info (msg );
639- throw new OzoneIllegalArgumentException (msg );
640- }
641- }
642-
643- /**
644- * Builds and sets OMNodeDetails object.
645- */
646- private void setOMNodeDetails (String serviceId , String nodeId ,
647- InetSocketAddress rpcAddress , int ratisPort ) {
648-
649- if (serviceId == null ) {
650- // If no serviceId is set, take the default serviceID om-service
651- serviceId = OzoneConsts .OM_SERVICE_ID_DEFAULT ;
652- LOG .info ("OM Service ID is not set. Setting it to the default ID: {}" ,
653- serviceId );
654- }
655- if (nodeId == null ) {
656- // If no nodeId is set, take the omId from omStorage as the nodeID
657- nodeId = omId ;
658- LOG .info ("OM Node ID is not set. Setting it to the OmStorage's " +
659- "OmID: {}" , nodeId );
660- }
661-
662- this .omNodeDetails = new OMNodeDetails .Builder ()
663- .setOMServiceId (serviceId )
664- .setOMNodeId (nodeId )
665- .setRpcAddress (rpcAddress )
666- .setRatisPort (ratisPort )
667- .build ();
668-
669- // Set this nodes OZONE_OM_ADDRESS_KEY to the discovered address.
670- configuration .set (OZONE_OM_ADDRESS_KEY ,
671- NetUtils .getHostPortString (rpcAddress ));
672-
673- // Get and set Http(s) address of local node. If base config keys are
674- // not set, check for keys suffixed with OM serivce ID and node ID.
675- setOMNodeSpecificConfigs (serviceId , nodeId );
676- }
677-
678- /**
679- * Check if any of the following configuration keys have been set using OM
680- * Node ID suffixed to the key. If yes, then set the base key with the
681- * configured valued.
682- * 1. {@link OMConfigKeys#OZONE_OM_HTTP_ADDRESS_KEY}
683- * 2. {@link OMConfigKeys#OZONE_OM_HTTPS_ADDRESS_KEY}
684- * 3. {@link OMConfigKeys#OZONE_OM_HTTP_BIND_HOST_KEY}
685- * 4. {@link OMConfigKeys#OZONE_OM_HTTPS_BIND_HOST_KEY}
686- */
687- private void setOMNodeSpecificConfigs (String omServiceId , String omNodeId ) {
688- String [] confKeys = new String [] {
689- OMConfigKeys .OZONE_OM_HTTP_ADDRESS_KEY ,
690- OMConfigKeys .OZONE_OM_HTTPS_ADDRESS_KEY ,
691- OMConfigKeys .OZONE_OM_HTTP_BIND_HOST_KEY ,
692- OMConfigKeys .OZONE_OM_HTTPS_BIND_HOST_KEY };
693-
694- for (String confKey : confKeys ) {
695- String confValue = OmUtils .getConfSuffixedWithOMNodeId (
696- configuration , confKey , omServiceId , omNodeId );
697- if (confValue != null ) {
698- LOG .info ("Setting configuration key {} with value of key {}: {}" ,
699- confKey , OmUtils .addKeySuffixes (confKey , omNodeId ), confValue );
700- configuration .set (confKey , confValue );
701- }
702- }
703- }
704-
705531 private KeyProviderCryptoExtension createKeyProviderExt (
706532 OzoneConfiguration conf ) throws IOException {
707533 KeyProvider keyProvider = KMSUtil .createKeyProvider (conf ,
@@ -1024,7 +850,6 @@ private static boolean isOzoneSecurityEnabled() {
1024850 */
1025851 public static OzoneManager createOm (OzoneConfiguration conf )
1026852 throws IOException , AuthenticationException {
1027- loginOMUserIfSecurityEnabled (conf );
1028853 return new OzoneManager (conf );
1029854 }
1030855
@@ -1053,6 +878,7 @@ private static void loginOMUserIfSecurityEnabled(OzoneConfiguration conf)
1053878 @ VisibleForTesting
1054879 public static boolean omInit (OzoneConfiguration conf ) throws IOException ,
1055880 AuthenticationException {
881+ OMHANodeDetails .loadOMHAConfig (conf );
1056882 loginOMUserIfSecurityEnabled (conf );
1057883 OMStorage omStorage = new OMStorage (conf );
1058884 StorageState state = omStorage .getState ();
@@ -1361,7 +1187,7 @@ private RPC.Server getRpcServer(OzoneConfiguration conf) throws IOException {
13611187 return omRpcServer ;
13621188 }
13631189
1364- InetSocketAddress omNodeRpcAddr = OmUtils .getOmAddress (configuration );
1190+ InetSocketAddress omNodeRpcAddr = OmUtils .getOmAddress (conf );
13651191
13661192 final int handlerCount = conf .getInt (OZONE_OM_HANDLER_COUNT_KEY ,
13671193 OZONE_OM_HANDLER_COUNT_DEFAULT );
0 commit comments