Search in sources :

Example 6 with ScmInfo

use of org.apache.hadoop.hdds.scm.ScmInfo in project ozone by apache.

the class OzoneManager method omInit.

/**
 * Initializes the OM instance.
 *
 * @param conf OzoneConfiguration
 * @return true if OM initialization succeeds, false otherwise
 * @throws IOException in case ozone metadata directory path is not
 *                     accessible
 */
@VisibleForTesting
public static boolean omInit(OzoneConfiguration conf) throws IOException, AuthenticationException {
    OMHANodeDetails.loadOMHAConfig(conf);
    loginOMUserIfSecurityEnabled(conf);
    OMStorage omStorage = new OMStorage(conf);
    StorageState state = omStorage.getState();
    if (state != StorageState.INITIALIZED) {
        try {
            ScmInfo scmInfo = getScmInfo(conf);
            String clusterId = scmInfo.getClusterId();
            String scmId = scmInfo.getScmId();
            if (clusterId == null || clusterId.isEmpty()) {
                throw new IOException("Invalid Cluster ID");
            }
            if (scmId == null || scmId.isEmpty()) {
                throw new IOException("Invalid SCM ID");
            }
            omStorage.setClusterId(clusterId);
            if (OzoneSecurityUtil.isSecurityEnabled(conf)) {
                initializeSecurity(conf, omStorage, scmId);
            }
            omStorage.initialize();
            System.out.println("OM initialization succeeded.Current cluster id for sd=" + omStorage.getStorageDir() + ";cid=" + omStorage.getClusterID() + ";layoutVersion=" + omStorage.getLayoutVersion());
            return true;
        } catch (IOException ioe) {
            LOG.error("Could not initialize OM version file", ioe);
            return false;
        }
    } else {
        if (OzoneSecurityUtil.isSecurityEnabled(conf) && omStorage.getOmCertSerialId() == null) {
            ScmInfo scmInfo = HAUtils.getScmInfo(conf);
            String scmId = scmInfo.getScmId();
            if (scmId == null || scmId.isEmpty()) {
                throw new IOException("Invalid SCM ID");
            }
            LOG.info("OM storage is already initialized. Initializing security");
            initializeSecurity(conf, omStorage, scmId);
            omStorage.persistCurrentState();
        }
        System.out.println("OM already initialized.Reusing existing cluster id for sd=" + omStorage.getStorageDir() + ";cid=" + omStorage.getClusterID() + ";layoutVersion=" + omStorage.getLayoutVersion());
        return true;
    }
}
Also used : StorageState(org.apache.hadoop.ozone.common.Storage.StorageState) CertificateSignRequest.getEncodedString(org.apache.hadoop.hdds.security.x509.certificates.utils.CertificateSignRequest.getEncodedString) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) HAUtils.getScmInfo(org.apache.hadoop.hdds.utils.HAUtils.getScmInfo) ScmInfo(org.apache.hadoop.hdds.scm.ScmInfo) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

ScmInfo (org.apache.hadoop.hdds.scm.ScmInfo)6 IOException (java.io.IOException)3 UncheckedIOException (java.io.UncheckedIOException)2 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)2 HddsProtos (org.apache.hadoop.hdds.protocol.proto.HddsProtos)2 StorageState (org.apache.hadoop.ozone.common.Storage.StorageState)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 RpcController (com.google.protobuf.RpcController)1 ServiceException (com.google.protobuf.ServiceException)1 Closeable (java.io.Closeable)1 File (java.io.File)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Consumer (java.util.function.Consumer)1 Pair (org.apache.commons.lang3.tuple.Pair)1