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();
}
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();
}
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());
}
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;
}
}
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;
}
Aggregations