You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zeppelin.apache.org by GitBox <gi...@apache.org> on 2019/03/24 06:08:32 UTC

[GitHub] [zeppelin] zjffdu commented on a change in pull request #3340: [ZEPPELIN-4068] Implement MongoNotebookRepo

zjffdu commented on a change in pull request #3340: [ZEPPELIN-4068] Implement MongoNotebookRepo
URL: https://github.com/apache/zeppelin/pull/3340#discussion_r268419595
 
 

 ##########
 File path: zeppelin-plugins/notebookrepo/mongo/src/main/java/org/apache/zeppelin/notebook/repo/MongoNotebookRepo.java
 ##########
 @@ -0,0 +1,390 @@
+package org.apache.zeppelin.notebook.repo;
+
+import static com.mongodb.client.model.Filters.and;
+import static com.mongodb.client.model.Filters.eq;
+import com.google.common.collect.Lists;
+import org.apache.commons.lang.ArrayUtils;
+import org.bson.Document;
+import org.bson.conversions.Bson;
+import org.bson.types.ObjectId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import com.mongodb.MongoClient;
+import com.mongodb.MongoClientURI;
+import com.mongodb.client.AggregateIterable;
+import com.mongodb.client.FindIterable;
+import com.mongodb.client.MongoCollection;
+import com.mongodb.client.MongoDatabase;
+import com.mongodb.client.model.UpdateOptions;
+import com.mongodb.client.model.Updates;
+import org.apache.zeppelin.conf.ZeppelinConfiguration;
+import org.apache.zeppelin.notebook.Note;
+import org.apache.zeppelin.notebook.NoteInfo;
+import org.apache.zeppelin.user.AuthenticationInfo;
+
+/**
+ * Backend for storing Notebook on MongoDB.
+ */
+public class MongoNotebookRepo implements NotebookRepo {
+
+  private static final Logger LOG = LoggerFactory.getLogger(MongoNotebookRepo.class);
+
+  private ZeppelinConfiguration conf;
+
+  private MongoClient client;
+
+  private MongoDatabase db;
+
+  private MongoCollection<Document> notes;
+
+  private MongoCollection<Document> folders;
+
+  private String folderName;
+
+  public MongoNotebookRepo() {
+  }
+
+  @Override
+  public void init(ZeppelinConfiguration zConf) throws IOException {
+    this.conf = zConf;
+    client = new MongoClient(new MongoClientURI(conf.getMongoUri()));
+    db = client.getDatabase(conf.getMongoDatabase());
+    notes = db.getCollection(conf.getMongoCollection());
+    folderName = conf.getMongoFolder();
+    folders = db.getCollection(folderName);
+
+    if (conf.getMongoAutoimport()) {
+      // import local notes into MongoDB
+      insertFileSystemNotes();
 
 Review comment:
   Would this cause notes in mongo to be overwritten ? e.g. In the first time I start zeppelin server, it would import notes in local fs to mongodb. Then I did some updates on notes via zeppelin, and then restart zeppelin server. Would the the updated notes in mongodb to be overwritten by the old notes in local fs if user didn't change the auto import configuration in zeppelin-site.xml ?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services