Apache Zeppelin系列教程第三篇——Note的持久化管理

简介: Apache Zeppelin系列教程第三篇——Note的持久化管理

Note CURD分别提供http接口和websocket 接口

http接口:

zeppelin-server\src\main\java\org\apache\zeppelin\rest\NotebookRestApi.java

websocket接口:

zeppelin-server\src\main\java\org\apache\zeppelin\socket\NotebookServer.java

creatNote 时序图(SequenceDiagram生成):

NotebookRepo类图

/**
 * Notebook repository (persistence layer) abstraction.
 */
public interface NotebookRepo {
  void init(ZeppelinConfiguration zConf) throws IOException;
  /**
   * Lists notebook information about all notebooks in storage. This method should only read
   * the note file name, rather than reading all note content which usually takes long time.
   *
   * @param subject contains user information.
   * @return Map of noteId -> NoteInfo
   * @throws IOException
   */
  @ZeppelinApi
  Map<String, NoteInfo> list(AuthenticationInfo subject) throws IOException;
  /**
   * Get the notebook with the given noteId and given notePath.
   *
   * @param noteId   is note id.
   * @param notePath is note path
   * @param subject  contains user information.
   * @return
   * @throws IOException
   */
  @ZeppelinApi
  Note get(String noteId, String notePath, AuthenticationInfo subject) throws IOException;
  /**
   * Save given note in storage
   *
   * @param note    is the note itself.
   * @param subject contains user information.
   * @throws IOException
   */
  @ZeppelinApi
  void save(Note note, AuthenticationInfo subject) throws IOException;
  /**
   *
   * Move given note to another path
   *
   * @param noteId
   * @param notePath
   * @param newNotePath
   * @throws IOException
   */
  @ZeppelinApi
  void move(String noteId, String notePath, String newNotePath,
            AuthenticationInfo subject) throws IOException;
  /**
   * Move folder to another path
   *
   * @param folderPath
   * @param newFolderPath
   * @param subject
   * @throws IOException
   */
  void move(String folderPath, String newFolderPath,
            AuthenticationInfo subject) throws IOException;
  /**
   * Remove note with given id and notePath
   *
   * @param noteId   is note id.
   * @param notePath is note path
   * @param subject  contains user information.
   * @throws IOException
   */
  @ZeppelinApi
  void remove(String noteId, String notePath, AuthenticationInfo subject) throws IOException;
  /**
   * Remove folder
   *
   * @param folderPath
   * @param subject
   * @throws IOException
   */
  @ZeppelinApi
  void remove(String folderPath, AuthenticationInfo subject) throws IOException;
  /**
   * Release any underlying resources
   */
  @ZeppelinApi
  void close();
  /**
   * Get NotebookRepo settings got the given user.
   *
   * @param subject
   * @return
   */
  @ZeppelinApi
  List<NotebookRepoSettingsInfo> getSettings(AuthenticationInfo subject);
  /**
   * update notebook repo settings.
   *
   * @param settings
   * @param subject
   */
  @ZeppelinApi
  void updateSettings(Map<String, String> settings, AuthenticationInfo subject);
  default String buildNoteFileName(String noteId, String notePath) throws IOException {
    if (!notePath.startsWith("/")) {
      throw new IOException("Invalid notePath: " + notePath);
    }
    return (notePath + "_" + noteId + ".zpln").substring(1);
  }
  default String buildNoteFileName(Note note) throws IOException {
    return buildNoteFileName(note.getId(), note.getPath());
  }
  default String buildNoteTempFileName(Note note) {
    return (note.getPath() + "_" + note.getId() + ".tmp").substring(1);
  }
  default String getNoteId(String noteFileName) throws IOException {
    int separatorIndex = noteFileName.lastIndexOf("_");
    if (separatorIndex == -1) {
      throw new IOException(
          "Invalid note name, no '_' in note name: " + noteFileName);
    }
    try {
      int dotIndex = noteFileName.lastIndexOf(".");
      return noteFileName.substring(separatorIndex + 1, dotIndex);
    } catch (StringIndexOutOfBoundsException e) {
      throw new IOException("Invalid note name: " + noteFileName);
    }
  }
  default String getNotePath(String rootNoteFolder, String noteFileName)
      throws IOException {
    int index = noteFileName.lastIndexOf("_");
    if (index == -1) {
      throw new IOException(
          "Invalid note name, no '_' in note name: " + noteFileName);
    }
    try {
      return noteFileName.substring(rootNoteFolder.length(), index);
    } catch (StringIndexOutOfBoundsException e) {
      throw new IOException("Invalid note name: " + noteFileName);
    }
  }
}

参考:

Apache Commons VFS——让java访问资源效率超级加倍 -


相关文章
|
5月前
|
算法 Java Go
Apache Zeppelin 番外篇——参与开源的得与失
Apache Zeppelin 番外篇——参与开源的得与失
39 0
|
5月前
|
前端开发 Java Apache
Apache Zeppelin系列教程第七篇——运行paragraph的整个流程分析
Apache Zeppelin系列教程第七篇——运行paragraph的整个流程分析
35 0
|
5月前
|
SQL Java 数据库连接
Apache Zeppelin系列教程第十篇——SQL Debug In Zeppelin
Apache Zeppelin系列教程第十篇——SQL Debug In Zeppelin
51 0
|
5月前
|
算法 NoSQL Java
Apache Zeppelin系列教程第八篇——LRU算法在Apache Zeppelin中的应用
Apache Zeppelin系列教程第八篇——LRU算法在Apache Zeppelin中的应用
32 0
|
2月前
|
Shell Linux 网络安全
【Shell 命令集合 网络通讯 】Linux 管理Apache HTTP服务器 httpd命令 使用指南
【Shell 命令集合 网络通讯 】Linux 管理Apache HTTP服务器 httpd命令 使用指南
32 0
|
2月前
|
Shell Linux Apache
【Shell 命令集合 网络通讯 】Linux 管理Apache HTTP服务器 apachectl命令 使用教程
【Shell 命令集合 网络通讯 】Linux 管理Apache HTTP服务器 apachectl命令 使用教程
163 1
|
2月前
|
SQL 分布式计算 Apache
生态 | Apache Hudi集成Apache Zeppelin
生态 | Apache Hudi集成Apache Zeppelin
33 0
|
5月前
|
SQL 关系型数据库 MySQL
Apache StreamPark系列教程第二篇——项目打包和开发
Apache StreamPark系列教程第二篇——项目打包和开发
83 0
|
5月前
|
SQL Apache 流计算
Apache StreamPark系列教程第一篇——安装和体验
Apache StreamPark系列教程第一篇——安装和体验
209 0
|
5月前
|
SQL 缓存 分布式计算
Apache Zeppelin系列教程第九篇——Zeppelin NoteBook数据缓存
Apache Zeppelin系列教程第九篇——Zeppelin NoteBook数据缓存
104 0

推荐镜像

更多