Search in sources :

Example 1 with ScmInfo

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

the class ScmBlockLocationProtocolClientSideTranslatorPB method getScmInfo.

/**
 * Gets the cluster Id and Scm Id from SCM.
 * @return ScmInfo
 * @throws IOException
 */
@Override
public ScmInfo getScmInfo() throws IOException {
    HddsProtos.GetScmInfoRequestProto request = HddsProtos.GetScmInfoRequestProto.getDefaultInstance();
    HddsProtos.GetScmInfoResponseProto resp;
    SCMBlockLocationRequest wrapper = createSCMBlockRequest(Type.GetScmInfo).setGetScmInfoRequest(request).build();
    final SCMBlockLocationResponse wrappedResponse = handleError(submitRequest(wrapper));
    resp = wrappedResponse.getGetScmInfoResponse();
    ScmInfo.Builder builder = new ScmInfo.Builder().setClusterId(resp.getClusterId()).setScmId(resp.getScmId());
    return builder.build();
}
Also used : SCMBlockLocationRequest(org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.SCMBlockLocationRequest) HddsProtos(org.apache.hadoop.hdds.protocol.proto.HddsProtos) SCMBlockLocationResponse(org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.SCMBlockLocationResponse) ScmInfo(org.apache.hadoop.hdds.scm.ScmInfo)

Example 2 with ScmInfo

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

the class StorageContainerLocationProtocolClientSideTranslatorPB method getScmInfo.

@Override
public ScmInfo getScmInfo() throws IOException {
    HddsProtos.GetScmInfoRequestProto request = HddsProtos.GetScmInfoRequestProto.newBuilder().setTraceID(TracingUtil.exportCurrentSpan()).build();
    GetScmInfoResponseProto resp = submitRequest(Type.GetScmInfo, builder -> builder.setGetScmInfoRequest(request)).getGetScmInfoResponse();
    ScmInfo.Builder builder = new ScmInfo.Builder().setClusterId(resp.getClusterId()).setScmId(resp.getScmId()).setRatisPeerRoles(resp.getPeerRolesList());
    return builder.build();
}
Also used : DatanodeAdminErrorResponseProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.DatanodeAdminErrorResponseProto) GetContainerWithPipelineRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.GetContainerWithPipelineRequestProto) HddsProtos(org.apache.hadoop.hdds.protocol.proto.HddsProtos) RecommissionNodesRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.RecommissionNodesRequestProto) StartReplicationManagerRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.StartReplicationManagerRequestProto) UpgradeFinalizer(org.apache.hadoop.ozone.upgrade.UpgradeFinalizer) SCMContainerLocationFailoverProxyProvider(org.apache.hadoop.hdds.scm.proxy.SCMContainerLocationFailoverProxyProvider) ServiceException(com.google.protobuf.ServiceException) SCMListContainerRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.SCMListContainerRequestProto) StopContainerBalancerRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.StopContainerBalancerRequestProto) GetContainerWithPipelineBatchRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.GetContainerWithPipelineBatchRequestProto) ScmContainerLocationResponse(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.ScmContainerLocationResponse) Pair(org.apache.commons.lang3.tuple.Pair) ProtocolTranslator(org.apache.hadoop.ipc.ProtocolTranslator) ProtobufHelper(org.apache.hadoop.ipc.ProtobufHelper) StartMaintenanceNodesRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.StartMaintenanceNodesRequestProto) Map(java.util.Map) StatusAndMessages(org.apache.hadoop.ozone.upgrade.UpgradeFinalizer.StatusAndMessages) ScmInfo(org.apache.hadoop.hdds.scm.ScmInfo) RecommissionNodesResponseProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.RecommissionNodesResponseProto) SCMListContainerResponseProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.SCMListContainerResponseProto) NodeQueryRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.NodeQueryRequestProto) ForceExitSafeModeRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.ForceExitSafeModeRequestProto) PipelineRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.PipelineRequestProto) Builder(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.ScmContainerLocationRequest.Builder) StartContainerBalancerRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.StartContainerBalancerRequestProto) ActivatePipelineRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.ActivatePipelineRequestProto) RpcController(com.google.protobuf.RpcController) FinalizeScmUpgradeResponseProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.FinalizeScmUpgradeResponseProto) SCMCloseContainerRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.SCMCloseContainerRequestProto) SCMDeleteContainerRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.SCMDeleteContainerRequestProto) Type(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.Type) ClosePipelineRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.ClosePipelineRequestProto) ContainerResponseProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.ContainerResponseProto) DeactivatePipelineRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.DeactivatePipelineRequestProto) List(java.util.List) GetContainerReplicasRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.GetContainerReplicasRequestProto) ListPipelineRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.ListPipelineRequestProto) QueryUpgradeFinalizationProgressRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.QueryUpgradeFinalizationProgressRequestProto) QueryUpgradeFinalizationProgressResponseProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.QueryUpgradeFinalizationProgressResponseProto) ContainerRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.ContainerRequestProto) ReplicationManagerReportResponseProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.ReplicationManagerReportResponseProto) GetContainerCountResponseProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.GetContainerCountResponseProto) StopReplicationManagerRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.StopReplicationManagerRequestProto) RPC(org.apache.hadoop.ipc.RPC) Optional(java.util.Optional) ReplicationManagerReport(org.apache.hadoop.hdds.scm.container.ReplicationManagerReport) GetContainerCountRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.GetContainerCountRequestProto) ContainerInfo(org.apache.hadoop.hdds.scm.container.ContainerInfo) GetScmInfoResponseProto(org.apache.hadoop.hdds.protocol.proto.HddsProtos.GetScmInfoResponseProto) CURRENT_VERSION(org.apache.hadoop.ozone.ClientVersions.CURRENT_VERSION) StorageContainerLocationProtocolProtos(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos) InSafeModeRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.InSafeModeRequestProto) HashMap(java.util.HashMap) GetSafeModeRuleStatusesRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.GetSafeModeRuleStatusesRequestProto) UpgradeFinalizationStatus(org.apache.hadoop.hdds.protocol.proto.HddsProtos.UpgradeFinalizationStatus) GetContainerTokenResponseProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.GetContainerTokenResponseProto) ArrayList(java.util.ArrayList) FinalizeScmUpgradeRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.FinalizeScmUpgradeRequestProto) DatanodeUsageInfoRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.DatanodeUsageInfoRequestProto) GetContainerRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.GetContainerRequestProto) ReplicationManagerStatusRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.ReplicationManagerStatusRequestProto) NodeQueryResponseProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.NodeQueryResponseProto) ScmContainerLocationRequest(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.ScmContainerLocationRequest) GetPipelineResponseProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.GetPipelineResponseProto) DecommissionNodesRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.DecommissionNodesRequestProto) ContainerBalancerStatusRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.ContainerBalancerStatusRequestProto) ReplicationManagerStatusResponseProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.ReplicationManagerStatusResponseProto) GetExistContainerWithPipelinesInBatchRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.GetExistContainerWithPipelinesInBatchRequestProto) GetPipelineRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.GetPipelineRequestProto) DatanodeUsageInfoResponseProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.DatanodeUsageInfoResponseProto) StartMaintenanceNodesResponseProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.StartMaintenanceNodesResponseProto) DatanodeAdminError(org.apache.hadoop.hdds.scm.DatanodeAdminError) ForceExitSafeModeResponseProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.ForceExitSafeModeResponseProto) ContainerBalancerStatusResponseProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.ContainerBalancerStatusResponseProto) ContainerWithPipeline(org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline) ContainerID(org.apache.hadoop.hdds.scm.container.ContainerID) Pipeline(org.apache.hadoop.hdds.scm.pipeline.Pipeline) IOException(java.io.IOException) Token(org.apache.hadoop.security.token.Token) PipelineResponseProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.PipelineResponseProto) Consumer(java.util.function.Consumer) GetSafeModeRuleStatusesResponseProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.GetSafeModeRuleStatusesResponseProto) DecommissionNodesResponseProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.DecommissionNodesResponseProto) ListPipelineResponseProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.ListPipelineResponseProto) InterfaceAudience(org.apache.hadoop.hdds.annotation.InterfaceAudience) SafeModeRuleStatusProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.SafeModeRuleStatusProto) TracingUtil(org.apache.hadoop.hdds.tracing.TracingUtil) StorageContainerLocationProtocol(org.apache.hadoop.hdds.scm.protocol.StorageContainerLocationProtocol) Closeable(java.io.Closeable) GetContainerTokenRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.GetContainerTokenRequestProto) Preconditions(com.google.common.base.Preconditions) ReplicationManagerReportRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.ReplicationManagerReportRequestProto) RetryProxy(org.apache.hadoop.io.retry.RetryProxy) StartContainerBalancerResponseProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerLocationProtocolProtos.StartContainerBalancerResponseProto) HddsProtos(org.apache.hadoop.hdds.protocol.proto.HddsProtos) ScmInfo(org.apache.hadoop.hdds.scm.ScmInfo) GetScmInfoResponseProto(org.apache.hadoop.hdds.protocol.proto.HddsProtos.GetScmInfoResponseProto)

Example 3 with ScmInfo

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

the class TestSecureOzoneCluster method testSecureScmStartupSuccess.

@Test
public void testSecureScmStartupSuccess() throws Exception {
    initSCM();
    scm = HddsTestUtils.getScmSimple(conf);
    // Reads the SCM Info from SCM instance
    ScmInfo scmInfo = scm.getClientProtocolServer().getScmInfo();
    assertEquals(clusterId, scmInfo.getClusterId());
    assertEquals(scmId, scmInfo.getScmId());
}
Also used : ScmInfo(org.apache.hadoop.hdds.scm.ScmInfo) Test(org.junit.Test)

Example 4 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)

Example 5 with ScmInfo

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

the class StorageContainerManager method scmBootstrap.

/**
 * Routine to bootstrap the StorageContainerManager. This will connect to a
 * running SCM instance which has valid cluster id and fetch the cluster id
 * from there.
 *
 * TODO: once SCM HA security is enabled, CSR cerificates will be fetched from
 * running scm leader instance as well.
 *
 * @param conf OzoneConfiguration
 * @return true if SCM bootstrap is successful, false otherwise.
 * @throws IOException if init fails due to I/O error
 */
public static boolean scmBootstrap(OzoneConfiguration conf) throws AuthenticationException, IOException {
    if (!SCMHAUtils.isSCMHAEnabled(conf)) {
        LOG.error("Bootstrap is not supported without SCM HA.");
        return false;
    }
    String primordialSCM = SCMHAUtils.getPrimordialSCM(conf);
    SCMHANodeDetails scmhaNodeDetails = SCMHANodeDetails.loadSCMHAConfig(conf);
    String selfNodeId = scmhaNodeDetails.getLocalNodeDetails().getNodeId();
    final String selfHostName = scmhaNodeDetails.getLocalNodeDetails().getHostName();
    if (primordialSCM != null && SCMHAUtils.isSCMHAEnabled(conf) && SCMHAUtils.isPrimordialSCM(conf, selfNodeId, selfHostName)) {
        LOG.info("SCM bootstrap command can only be executed in non-Primordial SCM " + "{}, self id {} " + "Ignoring it.", primordialSCM, selfNodeId);
        return true;
    }
    SCMStorageConfig scmStorageConfig = new SCMStorageConfig(conf);
    final String persistedClusterId = scmStorageConfig.getClusterID();
    StorageState state = scmStorageConfig.getState();
    if (state == StorageState.INITIALIZED && conf.getBoolean(ScmConfigKeys.OZONE_SCM_SKIP_BOOTSTRAP_VALIDATION_KEY, ScmConfigKeys.OZONE_SCM_SKIP_BOOTSTRAP_VALIDATION_DEFAULT)) {
        LOG.info("Skipping clusterId validation during bootstrap command.  " + "ClusterId id {}, SCM id {}", persistedClusterId, scmStorageConfig.getScmId());
        // Initialize security if security is enabled later.
        initializeSecurityIfNeeded(conf, scmhaNodeDetails, scmStorageConfig);
        return true;
    }
    loginAsSCMUserIfSecurityEnabled(scmhaNodeDetails, conf);
    // The node here will try to fetch the cluster id from any of existing
    // running SCM instances.
    OzoneConfiguration config = SCMHAUtils.removeSelfId(conf, scmhaNodeDetails.getLocalNodeDetails().getNodeId());
    final ScmInfo scmInfo = HAUtils.getScmInfo(config);
    final String fetchedId = scmInfo.getClusterId();
    Preconditions.checkNotNull(fetchedId);
    if (state == StorageState.INITIALIZED) {
        Preconditions.checkNotNull(scmStorageConfig.getScmId());
        if (!fetchedId.equals(persistedClusterId)) {
            LOG.error("Could not bootstrap as SCM is already initialized with cluster " + "id {} but cluster id for existing leader SCM instance " + "is {}", persistedClusterId, fetchedId);
            return false;
        }
        // Initialize security if security is enabled later.
        initializeSecurityIfNeeded(conf, scmhaNodeDetails, scmStorageConfig);
    } else {
        try {
            scmStorageConfig.setClusterId(fetchedId);
            if (OzoneSecurityUtil.isSecurityEnabled(conf)) {
                HASecurityUtils.initializeSecurity(scmStorageConfig, config, getScmAddress(scmhaNodeDetails, conf), false);
            }
            scmStorageConfig.setPrimaryScmNodeId(scmInfo.getScmId());
            scmStorageConfig.setSCMHAFlag(true);
            scmStorageConfig.initialize();
            LOG.info("SCM BootStrap  is successful for ClusterID {}, SCMID {}", scmInfo.getClusterId(), scmStorageConfig.getScmId());
            LOG.info("Primary SCM Node ID {}", scmStorageConfig.getPrimaryScmNodeId());
        } catch (IOException ioe) {
            LOG.error("Could not initialize SCM version file", ioe);
            return false;
        }
    }
    return true;
}
Also used : SCMHANodeDetails(org.apache.hadoop.hdds.scm.ha.SCMHANodeDetails) StorageState(org.apache.hadoop.ozone.common.Storage.StorageState) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ScmInfo(org.apache.hadoop.hdds.scm.ScmInfo)

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