42
42
import org .apache .hadoop .crypto .key .KeyProviderCryptoExtension ;
43
43
import org .apache .hadoop .fs .CommonConfigurationKeys ;
44
44
import org .apache .hadoop .fs .CommonConfigurationKeysPublic ;
45
- import org .apache .hadoop .conf .Configuration ;
46
45
import org .apache .hadoop .hdds .HddsConfigKeys ;
47
46
import org .apache .hadoop .hdds .HddsUtils ;
48
47
import org .apache .hadoop .hdds .conf .OzoneConfiguration ;
74
73
import org .apache .hadoop .ipc .Server ;
75
74
import org .apache .hadoop .ozone .OzoneAcl ;
76
75
import org .apache .hadoop .ozone .OzoneConfigKeys ;
77
- import org .apache .hadoop .ozone .OzoneIllegalArgumentException ;
78
76
import org .apache .hadoop .ozone .OzoneSecurityUtil ;
79
77
import 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 ;
80
80
import org .apache .hadoop .ozone .om .helpers .OmMultipartUploadList ;
81
81
import org .apache .hadoop .ozone .om .helpers .S3SecretValue ;
82
82
import org .apache .hadoop .ozone .om .protocol .OzoneManagerServerProtocol ;
207
207
import static org .apache .hadoop .ozone .om .OMConfigKeys .OZONE_OM_KERBEROS_PRINCIPAL_KEY ;
208
208
import static org .apache .hadoop .ozone .om .OMConfigKeys .OZONE_OM_METRICS_SAVE_INTERVAL ;
209
209
import 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 ;
214
210
import static org .apache .hadoop .ozone .om .OMConfigKeys .OZONE_OM_USER_MAX_VOLUME ;
215
211
import static org .apache .hadoop .ozone .om .OMConfigKeys .OZONE_OM_USER_MAX_VOLUME_DEFAULT ;
216
212
import static org .apache .hadoop .ozone .om .exceptions .OMException .ResultCodes .INVALID_AUTH_METHOD ;
@@ -310,12 +306,32 @@ private OzoneManager(OzoneConfiguration conf) throws IOException,
310
306
super (OzoneVersionInfo .OZONE_VERSION_INFO );
311
307
Preconditions .checkNotNull (conf );
312
308
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
+
313
330
this .maxUserVolumeCount = conf .getInt (OZONE_OM_USER_MAX_VOLUME ,
314
331
OZONE_OM_USER_MAX_VOLUME_DEFAULT );
315
332
Preconditions .checkArgument (this .maxUserVolumeCount > 0 ,
316
333
OZONE_OM_USER_MAX_VOLUME + " value should be greater than zero" );
317
- omStorage = new OMStorage (conf );
318
- omId = omStorage .getOmId ();
334
+
319
335
if (omStorage .getState () != StorageState .INITIALIZED ) {
320
336
throw new OMException ("OM not initialized." ,
321
337
ResultCodes .OM_NOT_INITIALIZED );
@@ -342,8 +358,7 @@ private OzoneManager(OzoneConfiguration conf) throws IOException,
342
358
OMConfigKeys .OZONE_OM_RATIS_ENABLE_KEY ,
343
359
OMConfigKeys .OZONE_OM_RATIS_ENABLE_DEFAULT );
344
360
345
- // Load HA related configurations
346
- loadOMHAConfigs (configuration );
361
+
347
362
InetSocketAddress omNodeRpcAddr = omNodeDetails .getRpcAddress ();
348
363
omRpcAddressTxt = new Text (omNodeDetails .getRpcAddressString ());
349
364
@@ -420,7 +435,7 @@ private OzoneManager(OzoneConfiguration conf) throws IOException,
420
435
OzoneManagerProtocolProtos .Type .values ());
421
436
422
437
// Start Om Rpc Server.
423
- omRpcServer = getRpcServer (conf );
438
+ omRpcServer = getRpcServer (configuration );
424
439
omRpcAddress = updateRPCListenAddress (configuration ,
425
440
OZONE_OM_ADDRESS_KEY , omNodeRpcAddr , omRpcServer );
426
441
@@ -513,195 +528,6 @@ public boolean isGrpcBlockTokenEnabled() {
513
528
return grpcBlockTokenEnabled ;
514
529
}
515
530
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
-
705
531
private KeyProviderCryptoExtension createKeyProviderExt (
706
532
OzoneConfiguration conf ) throws IOException {
707
533
KeyProvider keyProvider = KMSUtil .createKeyProvider (conf ,
@@ -1024,7 +850,6 @@ private static boolean isOzoneSecurityEnabled() {
1024
850
*/
1025
851
public static OzoneManager createOm (OzoneConfiguration conf )
1026
852
throws IOException , AuthenticationException {
1027
- loginOMUserIfSecurityEnabled (conf );
1028
853
return new OzoneManager (conf );
1029
854
}
1030
855
@@ -1053,6 +878,7 @@ private static void loginOMUserIfSecurityEnabled(OzoneConfiguration conf)
1053
878
@ VisibleForTesting
1054
879
public static boolean omInit (OzoneConfiguration conf ) throws IOException ,
1055
880
AuthenticationException {
881
+ OMHANodeDetails .loadOMHAConfig (conf );
1056
882
loginOMUserIfSecurityEnabled (conf );
1057
883
OMStorage omStorage = new OMStorage (conf );
1058
884
StorageState state = omStorage .getState ();
@@ -1361,7 +1187,7 @@ private RPC.Server getRpcServer(OzoneConfiguration conf) throws IOException {
1361
1187
return omRpcServer ;
1362
1188
}
1363
1189
1364
- InetSocketAddress omNodeRpcAddr = OmUtils .getOmAddress (configuration );
1190
+ InetSocketAddress omNodeRpcAddr = OmUtils .getOmAddress (conf );
1365
1191
1366
1192
final int handlerCount = conf .getInt (OZONE_OM_HANDLER_COUNT_KEY ,
1367
1193
OZONE_OM_HANDLER_COUNT_DEFAULT );
0 commit comments