Skip to content

Commit

Permalink
Address style comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dhutchis committed Aug 22, 2016
1 parent c59c2c0 commit f17ed57
Showing 1 changed file with 49 additions and 39 deletions.
88 changes: 49 additions & 39 deletions src/edu/washington/escience/myria/daemon/MyriaDriverLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public final class MyriaDriverLauncher {
* @throws Exception if the Driver can't start.
*/
public static void main(final String[] args) throws Exception {
LauncherStatus run = run(args);
LOGGER.info("Exit with status " + run);
LauncherStatus status = run(args);
LOGGER.info("Exit with status " + status);
}

private final REEF reef;
Expand All @@ -80,7 +80,7 @@ private MyriaDriverLauncher(final REEF reef) {
this.reef = reef;
}

private final static Configuration getRuntimeConf(final String runtimeClassName)
private static Configuration getRuntimeConf(final String runtimeClassName)
throws ClassNotFoundException, IllegalArgumentException, IllegalAccessException,
NoSuchFieldException, SecurityException {
final Class<?> runtimeClass = Class.forName(runtimeClassName);
Expand All @@ -92,7 +92,7 @@ private final static Configuration getRuntimeConf(final String runtimeClassName)
return cm.build();
}

private final static Configuration getClientConf() {
private static Configuration getClientConf() {
return ClientConfiguration.CONF
.set(ClientConfiguration.ON_JOB_RUNNING, RunningJobHandler.class)
.set(ClientConfiguration.ON_JOB_MESSAGE, JobMessageHandler.class)
Expand All @@ -104,9 +104,8 @@ private final static Configuration getClientConf() {

/**
* @return The Driver configuration.
* @throws IOException
*/
private final static Configuration getDriverConf(
private static Configuration getDriverConf(
@Nullable final String driverJobSubmissionDirectory,
final String driverHostName,
final int driverMemoryMB,
Expand Down Expand Up @@ -217,7 +216,7 @@ private static int getDriverMemory(final Configuration conf) throws InjectionExc
* Prints the expected configuration, compared to the actual configuration given.
* Used for logging command line arguments.
*/
private static void logStartupMessage(Class<? extends Name<?>>[] classes, Injector inj) {
private static String genStartupMessage(Class<? extends Name<?>>[] classes, Injector inj) {
final StringBuilder sb = new StringBuilder("MyriaDriverLauncher configuration:\n");
for (int i = 0; i < classes.length; i++) {
final Class<? extends Name<?>> c = classes[i];
Expand All @@ -229,55 +228,60 @@ private static void logStartupMessage(Class<? extends Name<?>>[] classes, Inject
final String doc = annotation.doc();
final String defaultVal;
{
if (!annotation.default_value().equals(NamedParameter.REEF_UNINITIALIZED_VALUE))
if (!annotation.default_value().equals(NamedParameter.REEF_UNINITIALIZED_VALUE)) {
defaultVal = annotation.default_value();
else if (!annotation.default_class().equals(Void.class))
} else if (!annotation.default_class().equals(Void.class)) {
defaultVal = annotation.default_class().getSimpleName();
else if (annotation.default_values().length > 0)
} else if (annotation.default_values().length > 0) {
defaultVal = Arrays.toString(annotation.default_values());
else if (annotation.default_classes().length > 0) {
Class<?>[] default_classes = annotation.default_classes();
String[] sss = new String[default_classes.length];
for (int i1 = 0; i1 < default_classes.length; i1++) {
sss[i1] = default_classes[i1].getSimpleName();
} else if (annotation.default_classes().length > 0) {
StringBuilder b = new StringBuilder("[");
Class<?>[] cls = annotation.default_classes();
for (int j = 0; ; j++) {

b.append(cls[j].getSimpleName());
if (j == cls.length - 1) {
b.append(']');
break;
}
b.append(", ");
}
defaultVal = Arrays.toString(sss);
defaultVal = b.toString();
} else defaultVal = "";
}

if (i > 0) sb.append('\n');
if (i > 0) {
sb.append('\n');
}
sb.append(simpleName);
if (!shortName.isEmpty()) sb.append(" [-").append(shortName).append("]");
if (!shortName.isEmpty()) {
sb.append(" [-").append(shortName).append("]");
}

// sb.append(" (").append(expectedParameter.getSimpleArgName()).append("): ")
// If desired, the type of the parameter can be obtained from
// commandLineConf.getNamedParameters() --> .getSimpleArgName()
sb.append(": ").append(doc).append("\n -> ");

boolean ok;
try {
if ((ok = inj.isParameterSet(fullName))) sb.append(inj.getInstance(fullName).toString());
ok = inj.isParameterSet(fullName);
if (ok) {
sb.append(inj.getInstance(fullName).toString());
}
} catch (InjectionException e) {
ok = false;
}
if (!ok)
if (!defaultVal.isEmpty()) sb.append("[cannot parse; using default] ").append(defaultVal);
else sb.append("[cannot parse; no default]");
}
LOGGER.info(sb.toString());
return sb.toString();
}

/**
* Launch the Myria driver.
*
* @param args Command line arguments.
* @throws InjectionException
* @throws java.io.IOException
* @throws ParseException
* @throws ConfigFileException
* @throws SecurityException
* @throws NoSuchFieldException
* @throws IllegalAccessException
* @throws IllegalArgumentException
* @throws ClassNotFoundException
*/
@SuppressWarnings("unchecked")
public static LauncherStatus run(final String[] args)
Expand All @@ -297,12 +301,17 @@ public static LauncherStatus run(final String[] args)
final Configuration commandLineConf =
CommandLine.parseToConfiguration(args, commandLineClasses);
final Injector commandLineInjector = tang.newInjector(commandLineConf);
logStartupMessage(commandLineClasses, commandLineInjector);
LOGGER.info(genStartupMessage(commandLineClasses, commandLineInjector));
final String runtimeClassName = commandLineInjector.getNamedInstance(RuntimeClassName.class);
final String driverJobSubmissionDirectory =
commandLineInjector.isParameterSet(DriverJobSubmissionDirectory.class)
? commandLineInjector.getNamedInstance(DriverJobSubmissionDirectory.class)
: null;
final String driverJobSubmissionDirectory;
{
if (commandLineInjector.isParameterSet(DriverJobSubmissionDirectory.class)) {
driverJobSubmissionDirectory =
commandLineInjector.getNamedInstance(DriverJobSubmissionDirectory.class);
} else {
driverJobSubmissionDirectory = null;
}
}
final String configPath = commandLineInjector.getNamedInstance(ConfigPath.class);
final String javaLibPath = commandLineInjector.getNamedInstance(JavaLibPath.class);
final String nativeLibPath = commandLineInjector.getNamedInstance(NativeLibPath.class);
Expand All @@ -313,8 +322,8 @@ public static LauncherStatus run(final String[] args)
tang.newConfigurationBuilder()
.bindNamedParameter(SerializedGlobalConf.class, serializedGlobalConf)
.build();
String driverHostName = getMasterHost(globalConf);
int driverMemoryMB = getDriverMemory(globalConf);
final String driverHostName = getMasterHost(globalConf);
final int driverMemoryMB = getDriverMemory(globalConf);
final Configuration driverConf =
Configurations.merge(
getDriverConf(
Expand All @@ -329,7 +338,7 @@ public static LauncherStatus run(final String[] args)
.getInstance(MyriaDriverLauncher.class)
.run(driverConf);
} catch (ParseException | InjectionException e) {
LOGGER.error("Problem with command line options", e);
LOGGER.error("Problem with command line options (see previous log message)", e);
return LauncherStatus.FAILED;
}
}
Expand Down Expand Up @@ -384,7 +393,8 @@ public synchronized void close() {
public static final class RuntimeClassName implements Name<String> {}

/**
* Command line parameter: runtime configuration class to use (defaults to local runtime).
* Command line parameter: path of driver job submission directory;
* must be visible to the driver launcher and the driver
*/
@NamedParameter(
doc =
Expand Down

0 comments on commit f17ed57

Please sign in to comment.