HDDS-502. Exception in OM startup when running unit tests. Contributed by Arpit Agarwal.
This commit is contained in:
parent
c0956ee2a8
commit
15ed74fa24
|
@ -374,7 +374,8 @@ public final class StorageContainerManager extends ServiceRuntimeInfoImpl
|
|||
hParser.printGenericCommandUsage(System.err);
|
||||
System.exit(1);
|
||||
}
|
||||
StorageContainerManager scm = createSCM(hParser.getRemainingArgs(), conf);
|
||||
StorageContainerManager scm = createSCM(
|
||||
hParser.getRemainingArgs(), conf, true);
|
||||
if (scm != null) {
|
||||
scm.start();
|
||||
scm.join();
|
||||
|
@ -389,9 +390,37 @@ public final class StorageContainerManager extends ServiceRuntimeInfoImpl
|
|||
out.println(USAGE + "\n");
|
||||
}
|
||||
|
||||
public static StorageContainerManager createSCM(String[] args,
|
||||
OzoneConfiguration conf)
|
||||
throws IOException {
|
||||
/**
|
||||
* Create an SCM instance based on the supplied command-line arguments.
|
||||
*
|
||||
* This method is intended for unit tests only. It suppresses the
|
||||
* startup/shutdown message and skips registering Unix signal
|
||||
* handlers.
|
||||
*
|
||||
* @param args command line arguments.
|
||||
* @param conf HDDS configuration
|
||||
* @return SCM instance
|
||||
* @throws IOException
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public static StorageContainerManager createSCM(
|
||||
String[] args, OzoneConfiguration conf) throws IOException {
|
||||
return createSCM(args, conf, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an SCM instance based on the supplied command-line arguments.
|
||||
*
|
||||
* @param args command-line arguments.
|
||||
* @param conf HDDS configuration
|
||||
* @param printBanner if true, then log a verbose startup message.
|
||||
* @return SCM instance
|
||||
* @throws IOException
|
||||
*/
|
||||
private static StorageContainerManager createSCM(
|
||||
String[] args,
|
||||
OzoneConfiguration conf,
|
||||
boolean printBanner) throws IOException {
|
||||
String[] argv = (args == null) ? new String[0] : args;
|
||||
if (!HddsUtils.isHddsEnabled(conf)) {
|
||||
System.err.println(
|
||||
|
@ -407,13 +436,17 @@ public final class StorageContainerManager extends ServiceRuntimeInfoImpl
|
|||
}
|
||||
switch (startOpt) {
|
||||
case INIT:
|
||||
StringUtils.startupShutdownMessage(StorageContainerManager.class, argv,
|
||||
LOG);
|
||||
if (printBanner) {
|
||||
StringUtils.startupShutdownMessage(StorageContainerManager.class, argv,
|
||||
LOG);
|
||||
}
|
||||
terminate(scmInit(conf) ? 0 : 1);
|
||||
return null;
|
||||
case GENCLUSTERID:
|
||||
StringUtils.startupShutdownMessage(StorageContainerManager.class, argv,
|
||||
LOG);
|
||||
if (printBanner) {
|
||||
StringUtils.startupShutdownMessage(StorageContainerManager.class, argv,
|
||||
LOG);
|
||||
}
|
||||
System.out.println("Generating new cluster id:");
|
||||
System.out.println(StorageInfo.newClusterID());
|
||||
terminate(0);
|
||||
|
@ -423,8 +456,10 @@ public final class StorageContainerManager extends ServiceRuntimeInfoImpl
|
|||
terminate(0);
|
||||
return null;
|
||||
default:
|
||||
StringUtils.startupShutdownMessage(StorageContainerManager.class, argv,
|
||||
LOG);
|
||||
if (printBanner) {
|
||||
StringUtils.startupShutdownMessage(StorageContainerManager.class, argv,
|
||||
LOG);
|
||||
}
|
||||
return new StorageContainerManager(conf);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -258,7 +258,7 @@ public final class OzoneManager extends ServiceRuntimeInfoImpl
|
|||
hParser.printGenericCommandUsage(System.err);
|
||||
System.exit(1);
|
||||
}
|
||||
OzoneManager om = createOm(hParser.getRemainingArgs(), conf);
|
||||
OzoneManager om = createOm(hParser.getRemainingArgs(), conf, true);
|
||||
if (om != null) {
|
||||
om.start();
|
||||
om.join();
|
||||
|
@ -276,14 +276,33 @@ public final class OzoneManager extends ServiceRuntimeInfoImpl
|
|||
/**
|
||||
* Constructs OM instance based on command line arguments.
|
||||
*
|
||||
* This method is intended for unit tests only. It suppresses the
|
||||
* startup/shutdown message and skips registering Unix signal
|
||||
* handlers.
|
||||
*
|
||||
* @param argv Command line arguments
|
||||
* @param conf OzoneConfiguration
|
||||
* @return OM instance
|
||||
* @throws IOException in case OM instance creation fails.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public static OzoneManager createOm(
|
||||
String[] argv, OzoneConfiguration conf) throws IOException {
|
||||
return createOm(argv, conf, false);
|
||||
}
|
||||
|
||||
public static OzoneManager createOm(String[] argv,
|
||||
OzoneConfiguration conf) throws IOException {
|
||||
|
||||
/**
|
||||
* Constructs OM instance based on command line arguments.
|
||||
*
|
||||
* @param argv Command line arguments
|
||||
* @param conf OzoneConfiguration
|
||||
* @param printBanner if true then log a verbose startup message.
|
||||
* @return OM instance
|
||||
* @throws IOException in case OM instance creation fails.
|
||||
*/
|
||||
private static OzoneManager createOm(String[] argv,
|
||||
OzoneConfiguration conf, boolean printBanner) throws IOException {
|
||||
if (!isHddsEnabled(conf)) {
|
||||
System.err.println("OM cannot be started in secure mode or when " +
|
||||
OZONE_ENABLED + " is set to false");
|
||||
|
@ -297,7 +316,9 @@ public final class OzoneManager extends ServiceRuntimeInfoImpl
|
|||
}
|
||||
switch (startOpt) {
|
||||
case CREATEOBJECTSTORE:
|
||||
StringUtils.startupShutdownMessage(OzoneManager.class, argv, LOG);
|
||||
if (printBanner) {
|
||||
StringUtils.startupShutdownMessage(OzoneManager.class, argv, LOG);
|
||||
}
|
||||
terminate(omInit(conf) ? 0 : 1);
|
||||
return null;
|
||||
case HELP:
|
||||
|
@ -308,7 +329,9 @@ public final class OzoneManager extends ServiceRuntimeInfoImpl
|
|||
if (argv == null) {
|
||||
argv = new String[]{};
|
||||
}
|
||||
StringUtils.startupShutdownMessage(OzoneManager.class, argv, LOG);
|
||||
if (printBanner) {
|
||||
StringUtils.startupShutdownMessage(OzoneManager.class, argv, LOG);
|
||||
}
|
||||
return new OzoneManager(conf);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue