private OzoneManager()

in hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java [499:718]


  private OzoneManager(OzoneConfiguration conf, StartupOption startupOption)
      throws IOException, AuthenticationException {
    super(OzoneVersionInfo.OZONE_VERSION_INFO);
    Preconditions.checkNotNull(conf);
    setConfiguration(conf);
    // Load HA related configurations
    OMHANodeDetails omhaNodeDetails =
        OMHANodeDetails.loadOMHAConfig(configuration);

    this.isSecurityEnabled = OzoneSecurityUtil.isSecurityEnabled(conf);
    this.peerNodesMap = omhaNodeDetails.getPeerNodesMap();
    this.omNodeDetails = omhaNodeDetails.getLocalNodeDetails();
    omStorage = new OMStorage(conf);
    omStorage.validateOrPersistOmNodeId(omNodeDetails.getNodeId());
    omId = omStorage.getOmId();
    reconfigurationHandler =
        new ReconfigurationHandler("OM", conf, this::checkAdminUserPrivilege)
            .register(config)
            .register(OZONE_ADMINISTRATORS, this::reconfOzoneAdmins)
            .register(OZONE_READONLY_ADMINISTRATORS,
                this::reconfOzoneReadOnlyAdmins)
            .register(OZONE_OM_VOLUME_LISTALL_ALLOWED, this::reconfigureAllowListAllVolumes)
            .register(OZONE_KEY_DELETING_LIMIT_PER_TASK,
                this::reconfOzoneKeyDeletingLimitPerTask);

    versionManager = new OMLayoutVersionManager(omStorage.getLayoutVersion());
    upgradeFinalizer = new OMUpgradeFinalizer(versionManager);
    replicationConfigValidator =
        conf.getObject(ReplicationConfigValidator.class);

    exitManager = new ExitManager();

    // In case of single OM Node Service there will be no OM Node ID
    // specified, set it to value from om storage
    if (this.omNodeDetails.getNodeId() == null) {
      this.omNodeDetails = OMHANodeDetails.getOMNodeDetailsForNonHA(conf,
          omNodeDetails.getServiceId(),
          omStorage.getOmId(), omNodeDetails.getRpcAddress(),
          omNodeDetails.getRatisPort());
    }
    this.threadPrefix = omNodeDetails.threadNamePrefix();
    loginOMUserIfSecurityEnabled(conf);
    setInstanceVariablesFromConf();

    if (omStorage.getState() != StorageState.INITIALIZED) {
      throw new OMException("OM not initialized, current OM storage state: "
          + omStorage.getState().name() + ". Please ensure 'ozone om --init' "
          + "command is executed to generate all the required metadata to "
          + omStorage.getStorageDir()
          + " once before starting the OM service.",
          ResultCodes.OM_NOT_INITIALIZED);
    }
    omMetaDir = OMStorage.getOmDbDir(configuration);

    this.isSpnegoEnabled = conf.get(OZONE_OM_HTTP_AUTH_TYPE, "simple")
        .equals("kerberos");
    this.isOmGrpcServerEnabled = conf.getBoolean(
        OZONE_OM_S3_GPRC_SERVER_ENABLED,
        OZONE_OM_S3_GRPC_SERVER_ENABLED_DEFAULT);
    this.scmBlockSize = (long) conf.getStorageSize(OZONE_SCM_BLOCK_SIZE,
        OZONE_SCM_BLOCK_SIZE_DEFAULT, StorageUnit.BYTES);
    this.preallocateBlocksMax = conf.getInt(
        OZONE_KEY_PREALLOCATION_BLOCKS_MAX,
        OZONE_KEY_PREALLOCATION_BLOCKS_MAX_DEFAULT);
    this.grpcBlockTokenEnabled = conf.getBoolean(HDDS_BLOCK_TOKEN_ENABLED,
        HDDS_BLOCK_TOKEN_ENABLED_DEFAULT);
    this.isStrictS3 = conf.getBoolean(
        OZONE_OM_NAMESPACE_STRICT_S3,
        OZONE_OM_NAMESPACE_STRICT_S3_DEFAULT);

    String defaultBucketLayoutString =
        configuration.getTrimmed(OZONE_DEFAULT_BUCKET_LAYOUT,
            OZONE_DEFAULT_BUCKET_LAYOUT_DEFAULT);

    boolean bucketLayoutValid = Arrays.stream(BucketLayout.values())
        .anyMatch(layout -> layout.name().equals(defaultBucketLayoutString));
    if (bucketLayoutValid) {
      this.defaultBucketLayout =
          BucketLayout.fromString(defaultBucketLayoutString);

      if (!defaultBucketLayout.isLegacy() &&
          !versionManager.isAllowed(OMLayoutFeature.BUCKET_LAYOUT_SUPPORT)) {
        LOG.warn("{} configured to non-legacy bucket layout {} when Ozone " +
            "Manager is pre-finalized for bucket layout support. Legacy " +
            "buckets will be created by default until Ozone Manager is " +
            "finalized.", OZONE_DEFAULT_BUCKET_LAYOUT, defaultBucketLayout);
      }
    } else {
      throw new ConfigurationException(defaultBucketLayoutString +
          " is not a valid default bucket layout. Supported values are " +
          Arrays.stream(BucketLayout.values())
              .map(Enum::toString).collect(Collectors.joining(", ")));
    }

    // Validates the default server-side replication configs.
    setReplicationFromConfig();
    InetSocketAddress omNodeRpcAddr = omNodeDetails.getRpcAddress();
    // Honor property 'hadoop.security.token.service.use_ip'
    omRpcAddressTxt = new Text(SecurityUtil.buildTokenService(omNodeRpcAddr));

    final StorageContainerLocationProtocol scmContainerClient = getScmContainerClient(configuration);
    // verifies that the SCM info in the OM Version file is correct.
    final ScmBlockLocationProtocol scmBlockClient = getScmBlockClient(configuration);
    scmTopologyClient = new ScmTopologyClient(scmBlockClient);
    this.scmClient = new ScmClient(scmBlockClient, scmContainerClient,
        configuration);
    this.ozoneLockProvider = new OzoneLockProvider(getKeyPathLockEnabled(),
        getEnableFileSystemPaths());

    // For testing purpose only, not hit scm from om as Hadoop UGI can't login
    // two principals in the same JVM.
    ScmInfo scmInfo;
    if (!testSecureOmFlag) {
      scmInfo = getScmInfo(configuration);
      if (!scmInfo.getClusterId().equals(omStorage.getClusterID())) {
        logVersionMismatch(conf, scmInfo);
        throw new OMException("SCM version info mismatch.",
            ResultCodes.SCM_VERSION_MISMATCH_ERROR);
      }
    } else {
      scmInfo = new ScmInfo.Builder().setScmId("test").build();
    }

    RPC.setProtocolEngine(configuration, OzoneManagerProtocolPB.class,
        ProtobufRpcEngine.class);

    secConfig = new SecurityConfig(configuration);
    // Create the KMS Key Provider
    try {
      kmsProvider = createKeyProviderExt(configuration);
    } catch (IOException ioe) {
      kmsProvider = null;
      LOG.error("Fail to create Key Provider");
    }
    if (secConfig.isSecurityEnabled()) {
      omComponent = OM_DAEMON + "-" + omId;
      HddsProtos.OzoneManagerDetailsProto omInfo =
          getOmDetailsProto(conf, omStorage.getOmId());
      if (omStorage.getOmCertSerialId() == null) {
        throw new RuntimeException("OzoneManager started in secure mode but " +
            "doesn't have SCM signed certificate.");
      }
      SCMSecurityProtocolClientSideTranslatorPB scmSecurityClient =
          getScmSecurityClientWithMaxRetry(configuration, getCurrentUser());
      certClient = new OMCertificateClient(secConfig, scmSecurityClient,
          omStorage, omInfo, "",
          scmInfo == null ? null : scmInfo.getScmId(),
          this::saveNewCertId, this::terminateOM);

      SecretKeyProtocol secretKeyProtocol =
          HddsServerUtil.getSecretKeyClientForOm(conf);
      secretKeyClient = DefaultSecretKeyClient.create(
          conf, secretKeyProtocol, omNodeDetails.threadNamePrefix());
    }
    serviceInfo = new ServiceInfoProvider(secConfig, this, certClient,
        testSecureOmFlag);

    if (secConfig.isBlockTokenEnabled()) {
      blockTokenMgr = createBlockTokenSecretManager();
    }

    // Enable S3 multi-tenancy if config keys are set
    this.isS3MultiTenancyEnabled =
        OMMultiTenantManager.checkAndEnableMultiTenancy(this, conf);

    metrics = OMMetrics.create();
    perfMetrics = OMPerformanceMetrics.register();
    omDeletionMetrics = DeletingServiceMetrics.create();
    // Get admin list
    omStarterUser = UserGroupInformation.getCurrentUser().getShortUserName();
    omAdmins = OzoneAdmins.getOzoneAdmins(omStarterUser, conf);
    LOG.info("OM start with adminUsers: {}", omAdmins.getAdminUsernames());

    // Get read only admin list
    readOnlyAdmins = OzoneAdmins.getReadonlyAdmins(conf);

    s3OzoneAdmins = OzoneAdmins.getS3Admins(conf);
    instantiateServices(false);

    // Create special volume s3v which is required for S3G.
    addS3GVolumeToDB();

    if (startupOption == StartupOption.BOOTSTRAP) {
      isBootstrapping = true;
    } else if (startupOption == StartupOption.FORCE_BOOTSTRAP) {
      isForcedBootstrapping = true;
    }

    initializeRatisDirs(conf);
    initializeRatisServer(isBootstrapping || isForcedBootstrapping);

    omClientProtocolMetrics = ProtocolMessageMetrics
        .create("OmClientProtocol", "Ozone Manager RPC endpoint",
            OzoneManagerProtocolProtos.Type.values());

    // Start Om Rpc Server.
    omRpcServer = getRpcServer(configuration);
    omRpcAddress = updateRPCListenAddress(configuration,
        OZONE_OM_ADDRESS_KEY, omNodeRpcAddr, omRpcServer);

    // Start S3g Om gRPC Server.
    if (isOmGrpcServerEnabled) {
      omS3gGrpcServer = getOmS3gGrpcServer(configuration);
    }

    // init om execution flow for request
    omExecutionFlow = new OMExecutionFlow(this);

    ShutdownHookManager.get().addShutdownHook(this::saveOmMetrics,
        SHUTDOWN_HOOK_PRIORITY);

    if (isBootstrapping || isForcedBootstrapping) {
      omState = State.BOOTSTRAPPING;
    } else {
      omState = State.INITIALIZED;
    }

    bucketUtilizationMetrics = BucketUtilizationMetrics.create(metadataManager);
    omHostName = HddsUtils.getHostName(conf);
  }