Java Code Examples for org.apache.zeppelin.interpreter.InterpreterContext#getNoteId()

The following examples show how to use org.apache.zeppelin.interpreter.InterpreterContext#getNoteId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PySubmarineInterpreter.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Override
public InterpreterResult interpret(String st, InterpreterContext context)
    throws InterpreterException {
  setParagraphConfig(context);

  // algorithm & checkpoint path support replaces ${username} with real user name
  String algorithmPath = properties.getProperty(
      SubmarineConstants.SUBMARINE_ALGORITHM_HDFS_PATH, "");
  if (algorithmPath.contains(SubmarineConstants.USERNAME_SYMBOL)) {
    algorithmPath = algorithmPath.replace(SubmarineConstants.USERNAME_SYMBOL, userName);
    properties.setProperty(SubmarineConstants.SUBMARINE_ALGORITHM_HDFS_PATH, algorithmPath);
  }
  String checkpointPath = properties.getProperty(
      SubmarineConstants.TF_CHECKPOINT_PATH, "");
  if (checkpointPath.contains(SubmarineConstants.USERNAME_SYMBOL)) {
    checkpointPath = checkpointPath.replace(SubmarineConstants.USERNAME_SYMBOL, userName);
    properties.setProperty(SubmarineConstants.TF_CHECKPOINT_PATH, checkpointPath);
  }

  if (null == submarineInterpreter) {
    submarineInterpreter = getInterpreterInTheSameSessionByClassName(SubmarineInterpreter.class);
    if (null != submarineInterpreter) {
      submarineInterpreter.setPythonWorkDir(context.getNoteId(), getPythonWorkDir());
    }
  }

  SubmarineJob submarineJob = submarineContext.addOrGetSubmarineJob(this.properties, context);
  if (null != submarineJob && null != submarineJob.getHdfsClient()) {
    try {
      String noteId = context.getNoteId();
      List<ParagraphInfo> paragraphInfos = context.getIntpEventClient()
          .getParagraphList(userName, noteId);
      submarineJob.getHdfsClient().saveParagraphToFiles(
          noteId, paragraphInfos, getPythonWorkDir().getAbsolutePath(), properties);
    } catch (Exception e) {
      LOGGER.error(e.getMessage(), e);
    }
  }
  return super.interpret(st, context);
}
 
Example 2
Source File: SubmarineJob.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
public SubmarineJob(InterpreterContext context, Properties properties) {
  this.intpContext = context;
  this.properties = properties;
  this.noteId = context.getNoteId();
  this.noteName = context.getNoteName();
  this.userName = context.getAuthenticationInfo().getUser();
  this.yarnClient = new YarnClient(properties);
  this.hdfsClient = new HdfsClient(properties);
  this.submarineUI = new SubmarineUI(intpContext);

  this.start();
}
 
Example 3
Source File: SubmarineInterpreter.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Override
public void cancel(InterpreterContext context) {
  SubmarineJob submarineJob = submarineContext.addOrGetSubmarineJob(properties, context);
  String userName = context.getAuthenticationInfo().getUser();
  String noteId = context.getNoteId();
  String jobName = SubmarineUtils.getJobName(userName, noteId);
  submarineJob.deleteJob(jobName);
}
 
Example 4
Source File: SubmarineContext.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
public SubmarineJob addOrGetSubmarineJob(Properties properties, InterpreterContext context) {
  SubmarineJob submarineJob = null;
  String noteId = context.getNoteId();
  if (!mapSubmarineJob.containsKey(noteId)) {
    submarineJob = new SubmarineJob(context, properties);
    mapSubmarineJob.put(noteId, submarineJob);
  } else {
    submarineJob = mapSubmarineJob.get(noteId);
  }
  // need update InterpreterContext
  submarineJob.setIntpContext(context);

  return submarineJob;
}
 
Example 5
Source File: RemoteInterpreter.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
private RemoteInterpreterContext convert(InterpreterContext ic) {
  return new RemoteInterpreterContext(ic.getNoteId(), ic.getNoteName(), ic.getParagraphId(),
      ic.getReplName(), ic.getParagraphTitle(), ic.getParagraphText(),
      gson.toJson(ic.getAuthenticationInfo()), gson.toJson(ic.getConfig()), ic.getGui().toJson(),
      gson.toJson(ic.getNoteGui()),
      ic.getLocalProperties());
}
 
Example 6
Source File: Utils.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
public static String buildJobGroupId(InterpreterContext context) {
  String uName = "anonymous";
  if (context.getAuthenticationInfo() != null) {
    uName = getUserName(context.getAuthenticationInfo());
  }
  return "zeppelin|" + uName + "|" + context.getNoteId() + "|" + context.getParagraphId();
}
 
Example 7
Source File: SubmarineInterpreter.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@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);
}