SubmarineInterpreter extends Interpreter { @Override public InterpreterResult interpret(String script, InterpreterContext context) { try { setParagraphConfig(context); 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)) { 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); } SubmarineInterpreter(Properties properties); @Override void open(); @Override void close(); @Override InterpreterResult interpret(String script, InterpreterContext context); @Override void cancel(InterpreterContext context); @Override FormType getFormType(); @Override int getProgress(InterpreterContext context); @Override Scheduler getScheduler(); @Override List<InterpreterCompletion> completion(
      String buf, int cursor, InterpreterContext intpContext); void setPythonWorkDir(String noteId, File pythonWorkDir); @VisibleForTesting SubmarineContext getSubmarineContext();  }
@Test public void testDashboard() throws InterpreterException { String script = "dashboard"; InterpreterContext intpContext = getIntpContext(); InterpreterResult interpreterResult = submarineIntp.interpret(script, intpContext); String message = interpreterResult.toJson(); LOGGER.info(message); assertEquals(interpreterResult.code(), InterpreterResult.Code.SUCCESS); assertTrue(intpContext.out().size() >= 2); String dashboardTemplate = intpContext.out().getOutputAt(0).toString(); LOGGER.info(dashboardTemplate); assertTrue("Did not generate template!", (dashboardTemplate.length() > 500)); }