use of org.apache.zeppelin.submarine.commons.SubmarineCommand in project zeppelin by apache.
the class SubmarineInterpreter method interpret.
@Override
public InterpreterResult interpret(String script, InterpreterContext context) {
try {
setParagraphConfig(context);
// algorithm & checkpoint path support replaces ${username} with real user name
String algorithmPath = properties.getProperty(SUBMARINE_ALGORITHM_HDFS_PATH, "");
if (algorithmPath.contains(USERNAME_SYMBOL)) {
algorithmPath = algorithmPath.replace(USERNAME_SYMBOL, userName);
properties.setProperty(SUBMARINE_ALGORITHM_HDFS_PATH, algorithmPath);
}
String checkpointPath = properties.getProperty(TF_CHECKPOINT_PATH, "");
if (checkpointPath.contains(USERNAME_SYMBOL)) {
checkpointPath = checkpointPath.replace(USERNAME_SYMBOL, userName);
properties.setProperty(TF_CHECKPOINT_PATH, checkpointPath);
}
SubmarineJob submarineJob = submarineContext.addOrGetSubmarineJob(properties, context);
LOGGER.debug("Run shell command '" + script + "'");
String command = "", operation = "", cleanCheckpoint = "";
String inputPath = "", chkPntPath = "", psLaunchCmd = "", workerLaunchCmd = "";
String noteId = context.getNoteId();
String noteName = context.getNoteName();
if (script.equalsIgnoreCase(COMMAND_CLEAN)) {
// Clean Registry Angular Object
command = CLEAN_RUNTIME_CACHE.getCommand();
} else {
operation = SubmarineUtils.getAgulObjValue(context, OPERATION_TYPE);
if (!StringUtils.isEmpty(operation)) {
SubmarineUtils.removeAgulObjValue(context, OPERATION_TYPE);
command = operation;
} else {
command = SubmarineUtils.getAgulObjValue(context, COMMAND_TYPE);
}
}
String distributed = this.properties.getProperty(MACHINELEARNING_DISTRIBUTED_ENABLE, "false");
SubmarineUtils.setAgulObjValue(context, unifyKey(MACHINELEARNING_DISTRIBUTED_ENABLE), distributed);
inputPath = SubmarineUtils.getAgulObjValue(context, INPUT_PATH);
cleanCheckpoint = SubmarineUtils.getAgulObjValue(context, CLEAN_CHECKPOINT);
chkPntPath = submarineJob.getJobDefaultCheckpointPath();
SubmarineUtils.setAgulObjValue(context, CHECKPOINT_PATH, chkPntPath);
psLaunchCmd = SubmarineUtils.getAgulObjValue(context, PS_LAUNCH_CMD);
workerLaunchCmd = SubmarineUtils.getAgulObjValue(context, WORKER_LAUNCH_CMD);
properties.put(INPUT_PATH, inputPath != null ? inputPath : "");
properties.put(CHECKPOINT_PATH, chkPntPath != null ? chkPntPath : "");
properties.put(PS_LAUNCH_CMD, psLaunchCmd != null ? psLaunchCmd : "");
properties.put(WORKER_LAUNCH_CMD, workerLaunchCmd != null ? workerLaunchCmd : "");
SubmarineCommand submarineCmd = SubmarineCommand.fromCommand(command);
switch(submarineCmd) {
case USAGE:
submarineJob.showUsage();
break;
case JOB_RUN:
if (StringUtils.equals(cleanCheckpoint, "true")) {
submarineJob.cleanJobDefaultCheckpointPath();
}
submarineJob.runJob();
break;
case JOB_STOP:
String jobName = SubmarineUtils.getJobName(userName, noteId);
submarineJob.deleteJob(jobName);
break;
case TENSORBOARD_RUN:
submarineJob.runTensorBoard();
break;
case TENSORBOARD_STOP:
String user = context.getAuthenticationInfo().getUser();
String tensorboardName = SubmarineUtils.getTensorboardName(user);
submarineJob.deleteJob(tensorboardName);
break;
case OLD_UI:
createOldGUI(context);
break;
case CLEAN_RUNTIME_CACHE:
submarineJob.cleanRuntimeCache();
break;
default:
submarineJob.onDashboard();
break;
}
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
return new InterpreterResult(InterpreterResult.Code.ERROR, e.getMessage());
}
return new InterpreterResult(InterpreterResult.Code.SUCCESS);
}
Aggregations