HDDS-502. Exception in OM startup when running unit tests. Contributed by Arpit Agarwal.

This commit is contained in:
Nanda kumar 2018-09-19 19:46:25 +05:30
parent c0956ee2a8
commit 15ed74fa24
2 changed files with 73 additions and 15 deletions

View File

@ -374,7 +374,8 @@ public static void main(String[] argv) throws IOException {
hParser.printGenericCommandUsage(System.err); hParser.printGenericCommandUsage(System.err);
System.exit(1); System.exit(1);
} }
StorageContainerManager scm = createSCM(hParser.getRemainingArgs(), conf); StorageContainerManager scm = createSCM(
hParser.getRemainingArgs(), conf, true);
if (scm != null) { if (scm != null) {
scm.start(); scm.start();
scm.join(); scm.join();
@ -389,9 +390,37 @@ private static void printUsage(PrintStream out) {
out.println(USAGE + "\n"); out.println(USAGE + "\n");
} }
public static StorageContainerManager createSCM(String[] args, /**
OzoneConfiguration conf) * Create an SCM instance based on the supplied command-line arguments.
throws IOException { *
* 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; String[] argv = (args == null) ? new String[0] : args;
if (!HddsUtils.isHddsEnabled(conf)) { if (!HddsUtils.isHddsEnabled(conf)) {
System.err.println( System.err.println(
@ -407,13 +436,17 @@ public static StorageContainerManager createSCM(String[] args,
} }
switch (startOpt) { switch (startOpt) {
case INIT: case INIT:
StringUtils.startupShutdownMessage(StorageContainerManager.class, argv, if (printBanner) {
LOG); StringUtils.startupShutdownMessage(StorageContainerManager.class, argv,
LOG);
}
terminate(scmInit(conf) ? 0 : 1); terminate(scmInit(conf) ? 0 : 1);
return null; return null;
case GENCLUSTERID: case GENCLUSTERID:
StringUtils.startupShutdownMessage(StorageContainerManager.class, argv, if (printBanner) {
LOG); StringUtils.startupShutdownMessage(StorageContainerManager.class, argv,
LOG);
}
System.out.println("Generating new cluster id:"); System.out.println("Generating new cluster id:");
System.out.println(StorageInfo.newClusterID()); System.out.println(StorageInfo.newClusterID());
terminate(0); terminate(0);
@ -423,8 +456,10 @@ public static StorageContainerManager createSCM(String[] args,
terminate(0); terminate(0);
return null; return null;
default: default:
StringUtils.startupShutdownMessage(StorageContainerManager.class, argv, if (printBanner) {
LOG); StringUtils.startupShutdownMessage(StorageContainerManager.class, argv,
LOG);
}
return new StorageContainerManager(conf); return new StorageContainerManager(conf);
} }
} }

View File

@ -258,7 +258,7 @@ public static void main(String[] argv) throws IOException {
hParser.printGenericCommandUsage(System.err); hParser.printGenericCommandUsage(System.err);
System.exit(1); System.exit(1);
} }
OzoneManager om = createOm(hParser.getRemainingArgs(), conf); OzoneManager om = createOm(hParser.getRemainingArgs(), conf, true);
if (om != null) { if (om != null) {
om.start(); om.start();
om.join(); om.join();
@ -276,14 +276,33 @@ private static void printUsage(PrintStream out) {
/** /**
* Constructs OM instance based on command line arguments. * 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 argv Command line arguments
* @param conf OzoneConfiguration * @param conf OzoneConfiguration
* @return OM instance * @return OM instance
* @throws IOException in case OM instance creation fails. * @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)) { if (!isHddsEnabled(conf)) {
System.err.println("OM cannot be started in secure mode or when " + System.err.println("OM cannot be started in secure mode or when " +
OZONE_ENABLED + " is set to false"); OZONE_ENABLED + " is set to false");
@ -297,7 +316,9 @@ public static OzoneManager createOm(String[] argv,
} }
switch (startOpt) { switch (startOpt) {
case CREATEOBJECTSTORE: case CREATEOBJECTSTORE:
StringUtils.startupShutdownMessage(OzoneManager.class, argv, LOG); if (printBanner) {
StringUtils.startupShutdownMessage(OzoneManager.class, argv, LOG);
}
terminate(omInit(conf) ? 0 : 1); terminate(omInit(conf) ? 0 : 1);
return null; return null;
case HELP: case HELP:
@ -308,7 +329,9 @@ public static OzoneManager createOm(String[] argv,
if (argv == null) { if (argv == null) {
argv = new String[]{}; argv = new String[]{};
} }
StringUtils.startupShutdownMessage(OzoneManager.class, argv, LOG); if (printBanner) {
StringUtils.startupShutdownMessage(OzoneManager.class, argv, LOG);
}
return new OzoneManager(conf); return new OzoneManager(conf);
} }
} }