http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterProcessListener.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterProcessListener.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterProcessListener.java index 56fb516..ac7fa1e 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterProcessListener.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterProcessListener.java @@ -16,30 +16,24 @@ */ package org.apache.zeppelin.interpreter.remote; +import org.apache.zeppelin.interpreter.InterpreterResult; + import java.io.IOException; import java.util.List; import java.util.Map; -import org.apache.zeppelin.interpreter.InterpreterResult; -/** Event from remoteInterpreterProcess */ +/** + * Event from remoteInterpreterProcess + */ public interface RemoteInterpreterProcessListener { public void onOutputAppend(String noteId, String paragraphId, int index, String output); - public void onOutputUpdated( String noteId, String paragraphId, int index, InterpreterResult.Type type, String output); - public void onOutputClear(String noteId, String paragraphId); - - void runParagraphs( - String noteId, - List<Integer> paragraphIndices, - List<String> paragraphIds, - String curParagraphId) + void runParagraphs(String noteId, List<Integer> paragraphIndices, List<String> paragraphIds, + String curParagraphId) throws IOException; - public void onParaInfosReceived( - String noteId, - String paragraphId, - String interpreterSettingId, - Map<String, String> metaInfos); + public void onParaInfosReceived(String noteId, String paragraphId, + String interpreterSettingId, Map<String, String> metaInfos); }
http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterRunningProcess.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterRunningProcess.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterRunningProcess.java index b012eab..69daa6f 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterRunningProcess.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterRunningProcess.java @@ -16,11 +16,14 @@ */ package org.apache.zeppelin.interpreter.remote; +import org.apache.zeppelin.helium.ApplicationEventListener; import org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** This class connects to existing process */ +/** + * This class connects to existing process + */ public class RemoteInterpreterRunningProcess extends RemoteInterpreterProcess { private final Logger logger = LoggerFactory.getLogger(RemoteInterpreterRunningProcess.class); private final String host; @@ -28,7 +31,11 @@ public class RemoteInterpreterRunningProcess extends RemoteInterpreterProcess { private final String interpreterSettingName; public RemoteInterpreterRunningProcess( - String interpreterSettingName, int connectTimeout, String host, int port) { + String interpreterSettingName, + int connectTimeout, + String host, + int port + ) { super(connectTimeout); this.interpreterSettingName = interpreterSettingName; this.host = host; @@ -63,14 +70,13 @@ public class RemoteInterpreterRunningProcess extends RemoteInterpreterProcess { if (isRunning()) { logger.info("Kill interpreter process"); try { - callRemoteFunction( - new RemoteFunction<Void>() { - @Override - public Void call(RemoteInterpreterService.Client client) throws Exception { - client.shutdown(); - return null; - } - }); + callRemoteFunction(new RemoteFunction<Void>() { + @Override + public Void call(RemoteInterpreterService.Client client) throws Exception { + client.shutdown(); + return null; + } + }); } catch (Exception e) { logger.warn("ignore the exception when shutting down interpreter process.", e); } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/ApplicationState.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/ApplicationState.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/ApplicationState.java index 9f56f96..bc71d89 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/ApplicationState.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/ApplicationState.java @@ -18,10 +18,14 @@ package org.apache.zeppelin.notebook; import org.apache.zeppelin.helium.HeliumPackage; -/** Current state of application */ +/** + * Current state of application + */ public class ApplicationState { - /** Status of Application */ + /** + * Status of Application + */ public static enum Status { LOADING, LOADED, @@ -32,7 +36,7 @@ public class ApplicationState { Status status = Status.UNLOADED; - String id; // unique id for this instance. Similar to note id or paragraph id + String id; // unique id for this instance. Similar to note id or paragraph id HeliumPackage pkg; String output; @@ -42,8 +46,9 @@ public class ApplicationState { } /** - * After ApplicationState is restored from NotebookRepo, such as after Zeppelin daemon starts or - * Notebook import, Application status need to be reset. + * After ApplicationState is restored from NotebookRepo, + * such as after Zeppelin daemon starts or Notebook import, + * Application status need to be reset. */ public void resetStatus() { if (status != Status.ERROR) { @@ -51,6 +56,7 @@ public class ApplicationState { } } + @Override public boolean equals(Object o) { String compareName; http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/FileSystemStorage.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/FileSystemStorage.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/FileSystemStorage.java index e7ed568..4670e20 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/FileSystemStorage.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/FileSystemStorage.java @@ -1,14 +1,5 @@ package org.apache.zeppelin.notebook; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.net.URISyntaxException; -import java.security.PrivilegedExceptionAction; -import java.util.ArrayList; -import java.util.List; import org.apache.commons.lang.StringUtils; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileStatus; @@ -21,7 +12,20 @@ import org.apache.zeppelin.conf.ZeppelinConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** Hadoop FileSystem wrapper. Support both secure and no-secure mode */ +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URISyntaxException; +import java.security.PrivilegedExceptionAction; +import java.util.ArrayList; +import java.util.List; + + +/** + * Hadoop FileSystem wrapper. Support both secure and no-secure mode + */ public class FileSystemStorage { private static Logger LOGGER = LoggerFactory.getLogger(FileSystemStorage.class); @@ -31,22 +35,19 @@ public class FileSystemStorage { static { if (UserGroupInformation.isSecurityEnabled()) { ZeppelinConfiguration zConf = ZeppelinConfiguration.create(); - String keytab = - zConf.getString(ZeppelinConfiguration.ConfVars.ZEPPELIN_SERVER_KERBEROS_KEYTAB); - String principal = - zConf.getString(ZeppelinConfiguration.ConfVars.ZEPPELIN_SERVER_KERBEROS_PRINCIPAL); + String keytab = zConf.getString( + ZeppelinConfiguration.ConfVars.ZEPPELIN_SERVER_KERBEROS_KEYTAB); + String principal = zConf.getString( + ZeppelinConfiguration.ConfVars.ZEPPELIN_SERVER_KERBEROS_PRINCIPAL); if (StringUtils.isBlank(keytab) || StringUtils.isBlank(principal)) { - throw new RuntimeException( - "keytab and principal can not be empty, keytab: " - + keytab - + ", principal: " - + principal); + throw new RuntimeException("keytab and principal can not be empty, keytab: " + keytab + + ", principal: " + principal); } try { UserGroupInformation.loginUserFromKeytab(principal, keytab); } catch (IOException e) { - throw new RuntimeException( - "Fail to login via keytab:" + keytab + ", principal:" + principal, e); + throw new RuntimeException("Fail to login via keytab:" + keytab + + ", principal:" + principal, e); } } } @@ -80,93 +81,82 @@ public class FileSystemStorage { } public boolean exists(final Path path) throws IOException { - return callHdfsOperation( - new HdfsOperation<Boolean>() { + return callHdfsOperation(new HdfsOperation<Boolean>() { - @Override - public Boolean call() throws IOException { - return fs.exists(path); - } - }); + @Override + public Boolean call() throws IOException { + return fs.exists(path); + } + }); } public void tryMkDir(final Path dir) throws IOException { - callHdfsOperation( - new HdfsOperation<Void>() { - @Override - public Void call() throws IOException { - if (!fs.exists(dir)) { - fs.mkdirs(dir); - LOGGER.info("Create dir {} in hdfs", dir.toString()); - } - if (fs.isFile(dir)) { - throw new IOException( - dir.toString() - + " is file instead of directory, please remove " - + "it or specify another directory"); - } - fs.mkdirs(dir); - return null; - } - }); + callHdfsOperation(new HdfsOperation<Void>() { + @Override + public Void call() throws IOException { + if (!fs.exists(dir)) { + fs.mkdirs(dir); + LOGGER.info("Create dir {} in hdfs", dir.toString()); + } + if (fs.isFile(dir)) { + throw new IOException(dir.toString() + " is file instead of directory, please remove " + + "it or specify another directory"); + } + fs.mkdirs(dir); + return null; + } + }); } public List<Path> list(final Path path) throws IOException { - return callHdfsOperation( - new HdfsOperation<List<Path>>() { - @Override - public List<Path> call() throws IOException { - List<Path> paths = new ArrayList<>(); - for (FileStatus status : fs.globStatus(path)) { - paths.add(status.getPath()); - } - return paths; - } - }); + return callHdfsOperation(new HdfsOperation<List<Path>>() { + @Override + public List<Path> call() throws IOException { + List<Path> paths = new ArrayList<>(); + for (FileStatus status : fs.globStatus(path)) { + paths.add(status.getPath()); + } + return paths; + } + }); } public boolean delete(final Path path) throws IOException { - return callHdfsOperation( - new HdfsOperation<Boolean>() { - @Override - public Boolean call() throws IOException { - return fs.delete(path, true); - } - }); + return callHdfsOperation(new HdfsOperation<Boolean>() { + @Override + public Boolean call() throws IOException { + return fs.delete(path, true); + } + }); } public String readFile(final Path file) throws IOException { - return callHdfsOperation( - new HdfsOperation<String>() { - @Override - public String call() throws IOException { - LOGGER.debug("Read from file: " + file); - ByteArrayOutputStream noteBytes = new ByteArrayOutputStream(); - IOUtils.copyBytes(fs.open(file), noteBytes, hadoopConf); - return new String( - noteBytes.toString( - zConf.getString(ZeppelinConfiguration.ConfVars.ZEPPELIN_ENCODING))); - } - }); + return callHdfsOperation(new HdfsOperation<String>() { + @Override + public String call() throws IOException { + LOGGER.debug("Read from file: " + file); + ByteArrayOutputStream noteBytes = new ByteArrayOutputStream(); + IOUtils.copyBytes(fs.open(file), noteBytes, hadoopConf); + return new String(noteBytes.toString( + zConf.getString(ZeppelinConfiguration.ConfVars.ZEPPELIN_ENCODING))); + } + }); } public void writeFile(final String content, final Path file, boolean writeTempFileFirst) throws IOException { - callHdfsOperation( - new HdfsOperation<Void>() { - @Override - public Void call() throws IOException { - InputStream in = - new ByteArrayInputStream( - content.getBytes( - zConf.getString(ZeppelinConfiguration.ConfVars.ZEPPELIN_ENCODING))); - Path tmpFile = new Path(file.toString() + ".tmp"); - IOUtils.copyBytes(in, fs.create(tmpFile), hadoopConf); - fs.delete(file, true); - fs.rename(tmpFile, file); - return null; - } - }); + callHdfsOperation(new HdfsOperation<Void>() { + @Override + public Void call() throws IOException { + InputStream in = new ByteArrayInputStream(content.getBytes( + zConf.getString(ZeppelinConfiguration.ConfVars.ZEPPELIN_ENCODING))); + Path tmpFile = new Path(file.toString() + ".tmp"); + IOUtils.copyBytes(in, fs.create(tmpFile), hadoopConf); + fs.delete(file, true); + fs.rename(tmpFile, file); + return null; + } + }); } private interface HdfsOperation<T> { @@ -176,14 +166,12 @@ public class FileSystemStorage { public synchronized <T> T callHdfsOperation(final HdfsOperation<T> func) throws IOException { if (isSecurityEnabled) { try { - return UserGroupInformation.getCurrentUser() - .doAs( - new PrivilegedExceptionAction<T>() { - @Override - public T run() throws Exception { - return func.call(); - } - }); + return UserGroupInformation.getCurrentUser().doAs(new PrivilegedExceptionAction<T>() { + @Override + public T run() throws Exception { + return func.call(); + } + }); } catch (InterruptedException e) { throw new IOException(e); } @@ -191,4 +179,5 @@ public class FileSystemStorage { return func.call(); } } + } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Folder.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Folder.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Folder.java index d3709c2..afd5229 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Folder.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Folder.java @@ -18,14 +18,16 @@ package org.apache.zeppelin.notebook; import com.google.common.collect.Sets; -import java.util.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.*; + /** - * Represents a folder of Notebook. ID of the folder is a normalized path of it. 'normalized path' - * means the path that removed '/' from the beginning and the end of the path. e.g. "a/b/c", but not - * "/a/b/c", "a/b/c/" or "/a/b/c/". One exception can be the root folder, which is '/'. + * Represents a folder of Notebook. ID of the folder is a normalized path of it. + * 'normalized path' means the path that removed '/' from the beginning and the end of the path. + * e.g. "a/b/c", but not "/a/b/c", "a/b/c/" or "/a/b/c/". + * One exception can be the root folder, which is '/'. */ public class Folder { public static final String ROOT_FOLDER_ID = "/"; @@ -53,12 +55,13 @@ public class Folder { } public String getName() { - if (isRoot()) return ROOT_FOLDER_ID; + if (isRoot()) + return ROOT_FOLDER_ID; String path = getId(); int lastSlashIndex = path.lastIndexOf("/"); - if (lastSlashIndex < 0) { // This folder is under the root + if (lastSlashIndex < 0) { // This folder is under the root return path; } @@ -66,7 +69,8 @@ public class Folder { } public String getParentFolderId() { - if (isRoot()) return ROOT_FOLDER_ID; + if (isRoot()) + return ROOT_FOLDER_ID; int lastSlashIndex = getId().lastIndexOf("/"); // The root folder @@ -105,8 +109,8 @@ public class Folder { * @param newId */ public void rename(String newId) { - if (isRoot()) // root folder cannot be renamed - return; + if (isRoot()) // root folder cannot be renamed + return; String oldId = getId(); id = normalizeFolderId(newId); @@ -168,7 +172,7 @@ public class Folder { public void addChild(Folder child) { if (child == this) // prevent the root folder from setting itself as child - return; + return; children.put(child.getId(), child); } @@ -213,8 +217,8 @@ public class Folder { return notes; } - public List<Note> getNotesRecursively( - Set<String> userAndRoles, NotebookAuthorization notebookAuthorization) { + public List<Note> getNotesRecursively(Set<String> userAndRoles, + NotebookAuthorization notebookAuthorization) { final Set<String> entities = Sets.newHashSet(); if (userAndRoles != null) { entities.addAll(userAndRoles); @@ -245,7 +249,8 @@ public class Folder { } public boolean isTrash() { - if (isRoot()) return false; + if (isRoot()) + return false; return getId().split("/")[0].equals(TRASH_FOLDER_ID); } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/FolderListener.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/FolderListener.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/FolderListener.java index 0b7e0fb..efc2f72 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/FolderListener.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/FolderListener.java @@ -16,7 +16,9 @@ */ package org.apache.zeppelin.notebook; -/** Folder listener used by FolderView */ +/** + * Folder listener used by FolderView + */ public interface FolderListener { void onFolderRenamed(Folder folder, String oldFolderId); } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/FolderView.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/FolderView.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/FolderView.java index c111193..7d3f001 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/FolderView.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/FolderView.java @@ -17,13 +17,15 @@ package org.apache.zeppelin.notebook; -import java.util.LinkedHashMap; -import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.LinkedHashMap; +import java.util.Map; + /** - * Folder view of notes of Notebook. FolderView allows you to see notes from perspective of folders. + * Folder view of notes of Notebook. + * FolderView allows you to see notes from perspective of folders. */ public class FolderView implements NoteNameListener, FolderListener { // key: folderId @@ -43,20 +45,22 @@ public class FolderView implements NoteNameListener, FolderListener { * * @param oldFolderId folderId to rename * @param newFolderId newFolderId - * @return `null` if folder not exists, else old Folder in order to know which notes and child - * folders are renamed + * @return `null` if folder not exists, else old Folder + * in order to know which notes and child folders are renamed */ public Folder renameFolder(String oldFolderId, String newFolderId) { String normOldFolderId = Folder.normalizeFolderId(oldFolderId); String normNewFolderId = Folder.normalizeFolderId(newFolderId); - if (!hasFolder(normOldFolderId)) return null; + if (!hasFolder(normOldFolderId)) + return null; - if (oldFolderId.equals(Folder.ROOT_FOLDER_ID)) // cannot rename the root folder - return null; + if (oldFolderId.equals(Folder.ROOT_FOLDER_ID)) // cannot rename the root folder + return null; // check whether oldFolderId and newFolderId are same or not - if (normOldFolderId.equals(normNewFolderId)) return getFolder(normOldFolderId); + if (normOldFolderId.equals(normNewFolderId)) + return getFolder(normOldFolderId); logger.info("Rename {} to {}", normOldFolderId, normNewFolderId); @@ -88,7 +92,8 @@ public class FolderView implements NoteNameListener, FolderListener { } private Folder getOrCreateFolder(String folderId) { - if (folders.containsKey(folderId)) return folders.get(folderId); + if (folders.containsKey(folderId)) + return folders.get(folderId); return createFolder(folderId); } @@ -129,7 +134,8 @@ public class FolderView implements NoteNameListener, FolderListener { } private void removeFolderIfEmpty(String folderId) { - if (!hasFolder(folderId)) return; + if (!hasFolder(folderId)) + return; Folder folder = getFolder(folderId); if (folder.countNotes() == 0 && !folder.hasChild()) { @@ -185,8 +191,8 @@ public class FolderView implements NoteNameListener, FolderListener { } /** - * Fired after a note's setName() run. When the note's name changed, FolderView should check if - * the note is in the right folder. + * Fired after a note's setName() run. + * When the note's name changed, FolderView should check if the note is in the right folder. * * @param note * @param oldName @@ -216,11 +222,12 @@ public class FolderView implements NoteNameListener, FolderListener { @Override public void onFolderRenamed(Folder folder, String oldFolderId) { - if (getFolder(folder.getId()) == folder) // the folder is at the right place - return; + if (getFolder(folder.getId()) == folder) // the folder is at the right place + return; logger.info("folder renamed: {} -> {}", oldFolderId, folder.getId()); - if (getFolder(oldFolderId) == folder) folders.remove(oldFolderId); + if (getFolder(oldFolderId) == folder) + folders.remove(oldFolderId); Folder newFolder = getOrCreateFolder(folder.getId()); newFolder.merge(folder); http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java index a845ec1..61a36ab 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Note.java @@ -17,38 +17,29 @@ package org.apache.zeppelin.notebook; -import static java.lang.String.format; - import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import java.io.IOException; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.ScheduledThreadPoolExecutor; -import java.util.concurrent.TimeUnit; import org.apache.commons.lang.StringUtils; import org.apache.zeppelin.common.JsonSerializable; +import org.apache.zeppelin.completer.CompletionType; import org.apache.zeppelin.conf.ZeppelinConfiguration; import org.apache.zeppelin.display.AngularObject; import org.apache.zeppelin.display.AngularObjectRegistry; import org.apache.zeppelin.display.Input; import org.apache.zeppelin.interpreter.InterpreterFactory; import org.apache.zeppelin.interpreter.InterpreterGroup; +import org.apache.zeppelin.interpreter.InterpreterInfo; import org.apache.zeppelin.interpreter.InterpreterResult; +import org.apache.zeppelin.interpreter.InterpreterResultMessage; import org.apache.zeppelin.interpreter.InterpreterSetting; import org.apache.zeppelin.interpreter.InterpreterSettingManager; import org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry; import org.apache.zeppelin.interpreter.thrift.InterpreterCompletion; import org.apache.zeppelin.notebook.repo.NotebookRepo; import org.apache.zeppelin.notebook.utility.IdHashes; +import org.apache.zeppelin.scheduler.Job; import org.apache.zeppelin.scheduler.Job.Status; import org.apache.zeppelin.search.SearchService; import org.apache.zeppelin.user.AuthenticationInfo; @@ -56,17 +47,32 @@ import org.apache.zeppelin.user.Credentials; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** Binded interpreters for a note */ +import java.io.IOException; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +import static java.lang.String.format; + +/** + * Binded interpreters for a note + */ public class Note implements JsonSerializable { private static final Logger logger = LoggerFactory.getLogger(Note.class); private static final long serialVersionUID = 7920699076577612429L; - private static Gson gson = - new GsonBuilder() - .setPrettyPrinting() - .setDateFormat("yyyy-MM-dd HH:mm:ss.SSS") - .registerTypeAdapter(Date.class, new NotebookImportDeserializer()) - .registerTypeAdapterFactory(Input.TypeAdapterFactory) - .create(); + private static Gson gson = new GsonBuilder() + .setPrettyPrinting() + .setDateFormat("yyyy-MM-dd HH:mm:ss.SSS") + .registerTypeAdapter(Date.class, new NotebookImportDeserializer()) + .registerTypeAdapterFactory(Input.TypeAdapterFactory) + .create(); // threadpool for delayed persist of note private static final ScheduledThreadPoolExecutor delayedPersistThreadPool = @@ -108,20 +114,14 @@ public class Note implements JsonSerializable { */ private Map<String, Object> info = new HashMap<>(); + public Note() { generateId(); } - public Note( - String name, - String defaultInterpreterGroup, - NotebookRepo repo, - InterpreterFactory factory, - InterpreterSettingManager interpreterSettingManager, - ParagraphJobListener paragraphJobListener, - SearchService noteIndex, - Credentials credentials, - NoteEventListener noteEventListener) { + public Note(String name, String defaultInterpreterGroup, NotebookRepo repo, InterpreterFactory factory, + InterpreterSettingManager interpreterSettingManager, ParagraphJobListener paragraphJobListener, + SearchService noteIndex, Credentials credentials, NoteEventListener noteEventListener) { this.name = name; this.defaultInterpreterGroup = defaultInterpreterGroup; this.repo = repo; @@ -214,12 +214,15 @@ public class Note implements JsonSerializable { return notePath.substring(lastSlashIndex + 1); } - /** @return normalized folder path, which is folderId */ + /** + * @return normalized folder path, which is folderId + */ public String getFolderId() { String notePath = getName(); // Ignore first '/' - if (notePath.charAt(0) == '/') notePath = notePath.substring(1); + if (notePath.charAt(0) == '/') + notePath = notePath.substring(1); int lastSlashIndex = notePath.lastIndexOf("/"); // The root folder @@ -283,9 +286,8 @@ public class Note implements JsonSerializable { final Note paragraphNote = paragraph.getNote(); if (!paragraphNote.getId().equals(this.getId())) { throw new IllegalArgumentException( - format( - "The paragraph %s from note %s " + "does not belong to note %s", - paragraph.getId(), paragraphNote.getId(), this.getId())); + format("The paragraph %s from note %s " + "does not belong to note %s", paragraph.getId(), + paragraphNote.getId(), this.getId())); } boolean foundParagraph = false; @@ -298,9 +300,8 @@ public class Note implements JsonSerializable { if (!foundParagraph) { throw new IllegalArgumentException( - format( - "Cannot find paragraph %s " + "from note %s", - paragraph.getId(), paragraphNote.getId())); + format("Cannot find paragraph %s " + "from note %s", paragraph.getId(), + paragraphNote.getId())); } } @@ -345,11 +346,14 @@ public class Note implements JsonSerializable { this.credentials = credentials; } + Map<String, List<AngularObject>> getAngularObjects() { return angularObjects; } - /** Create a new paragraph and add it to the end of the note. */ + /** + * Create a new paragraph and add it to the end of the note. + */ public Paragraph addNewParagraph(AuthenticationInfo authenticationInfo) { return insertNewParagraph(paragraphs.size(), authenticationInfo); } @@ -362,24 +366,25 @@ public class Note implements JsonSerializable { void addCloneParagraph(Paragraph srcParagraph, AuthenticationInfo subject) { // Keep paragraph original ID - final Paragraph newParagraph = - new Paragraph(srcParagraph.getId(), this, paragraphJobListener, factory); + final Paragraph newParagraph = new Paragraph(srcParagraph.getId(), this, + paragraphJobListener, factory); Map<String, Object> config = new HashMap<>(srcParagraph.getConfig()); Map<String, Object> param = srcParagraph.settings.getParams(); Map<String, Input> form = srcParagraph.settings.getForms(); logger.debug("srcParagraph user: " + srcParagraph.getUser()); - + newParagraph.setAuthenticationInfo(subject); newParagraph.setConfig(config); newParagraph.settings.setParams(param); newParagraph.settings.setForms(form); newParagraph.setText(srcParagraph.getText()); newParagraph.setTitle(srcParagraph.getTitle()); - + logger.debug("newParagraph user: " + newParagraph.getUser()); + try { Gson gson = new Gson(); String resultJson = gson.toJson(srcParagraph.getReturn()); @@ -497,7 +502,9 @@ public class Note implements JsonSerializable { return null; } - /** Clear all paragraph output of note */ + /** + * Clear all paragraph output of note + */ public void clearAllParagraphOutput() { synchronized (paragraphs) { for (Paragraph p : paragraphs) { @@ -510,7 +517,7 @@ public class Note implements JsonSerializable { * Move paragraph into the new index (order from 0 ~ n-1). * * @param paragraphId ID of paragraph - * @param index new index + * @param index new index */ public void moveParagraph(String paragraphId, int index) { moveParagraph(paragraphId, index, false); @@ -519,10 +526,10 @@ public class Note implements JsonSerializable { /** * Move paragraph into the new index (order from 0 ~ n-1). * - * @param paragraphId ID of paragraph - * @param index new index - * @param throwWhenIndexIsOutOfBound whether throw IndexOutOfBoundException when index is out of - * bound + * @param paragraphId ID of paragraph + * @param index new index + * @param throwWhenIndexIsOutOfBound whether throw IndexOutOfBoundException + * when index is out of bound */ public void moveParagraph(String paragraphId, int index, boolean throwWhenIndexIsOutOfBound) { synchronized (paragraphs) { @@ -646,18 +653,19 @@ public class Note implements JsonSerializable { } } - /** Run all paragraphs sequentially. Only used for CronJob */ + /** + * Run all paragraphs sequentially. Only used for CronJob + */ public synchronized void runAll() { String cronExecutingUser = (String) getConfig().get("cronExecutingUser"); String cronExecutingRoles = (String) getConfig().get("cronExecutingRoles"); if (null == cronExecutingUser) { cronExecutingUser = "anonymous"; } - AuthenticationInfo authenticationInfo = - new AuthenticationInfo( - cronExecutingUser, - StringUtils.isEmpty(cronExecutingRoles) ? null : cronExecutingRoles, - null); + AuthenticationInfo authenticationInfo = new AuthenticationInfo( + cronExecutingUser, + StringUtils.isEmpty(cronExecutingRoles) ? null : cronExecutingRoles, + null); runAll(authenticationInfo, true); } @@ -689,7 +697,9 @@ public class Note implements JsonSerializable { return p.execute(blocking); } - /** Return true if there is a running or pending paragraph */ + /** + * Return true if there is a running or pending paragraph + */ boolean isRunningOrPending() { synchronized (paragraphs) { for (Paragraph p : paragraphs) { @@ -731,7 +741,7 @@ public class Note implements JsonSerializable { if (settings == null || settings.size() == 0) { return; } - + for (InterpreterSetting setting : settings) { InterpreterGroup intpGroup = setting.getInterpreterGroup(user, id); if (intpGroup != null) { @@ -790,7 +800,9 @@ public class Note implements JsonSerializable { repo.save(this, subject); } - /** Persist this note with maximum delay. */ + /** + * Persist this note with maximum delay. + */ public void persist(int maxDelaySec, AuthenticationInfo subject) { startDelayedPersistTimer(maxDelaySec, subject); } @@ -799,6 +811,7 @@ public class Note implements JsonSerializable { repo.remove(getId(), subject); } + /** * Return new note for specific user. this inserts and replaces user paragraph which doesn't * exists in original paragraph @@ -831,21 +844,17 @@ public class Note implements JsonSerializable { return; } - delayedPersist = - delayedPersistThreadPool.schedule( - new Runnable() { + delayedPersist = delayedPersistThreadPool.schedule(new Runnable() { - @Override - public void run() { - try { - persist(subject); - } catch (IOException e) { - logger.error(e.getMessage(), e); - } - } - }, - maxDelaySec, - TimeUnit.SECONDS); + @Override + public void run() { + try { + persist(subject); + } catch (IOException e) { + logger.error(e.getMessage(), e); + } + } + }, maxDelaySec, TimeUnit.SECONDS); } } @@ -935,22 +944,21 @@ public class Note implements JsonSerializable { if (paragraphs != null ? !paragraphs.equals(note.paragraphs) : note.paragraphs != null) { return false; } - // TODO(zjffdu) exclude name because FolderView.index use Note as key and consider different - // name - // as same note + //TODO(zjffdu) exclude name because FolderView.index use Note as key and consider different name + //as same note // if (name != null ? !name.equals(note.name) : note.name != null) return false; if (id != null ? !id.equals(note.id) : note.id != null) { return false; } - if (angularObjects != null - ? !angularObjects.equals(note.angularObjects) - : note.angularObjects != null) { + if (angularObjects != null ? + !angularObjects.equals(note.angularObjects) : note.angularObjects != null) { return false; } if (config != null ? !config.equals(note.config) : note.config != null) { return false; } return info != null ? info.equals(note.info) : note.info == null; + } @Override http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteEventListener.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteEventListener.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteEventListener.java index 83f311d..5f98f70 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteEventListener.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteEventListener.java @@ -18,11 +18,11 @@ package org.apache.zeppelin.notebook; import org.apache.zeppelin.scheduler.Job; -/** NoteEventListener */ +/** + * NoteEventListener + */ public interface NoteEventListener { public void onParagraphRemove(Paragraph p); - public void onParagraphCreate(Paragraph p); - public void onParagraphStatusChange(Paragraph p, Job.Status status); } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteInfo.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteInfo.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteInfo.java index 281744f..d316dfb 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteInfo.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteInfo.java @@ -20,7 +20,9 @@ package org.apache.zeppelin.notebook; import java.util.HashMap; import java.util.Map; -/** */ +/** + * + */ public class NoteInfo { String id; String name; @@ -62,4 +64,5 @@ public class NoteInfo { public void setConfig(Map<String, Object> config) { this.config = config; } + } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteNameListener.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteNameListener.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteNameListener.java index 2d5175e..28b53fb 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteNameListener.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteNameListener.java @@ -17,11 +17,12 @@ package org.apache.zeppelin.notebook; -/** NoteNameListener. It's used by FolderView. */ +/** + * NoteNameListener. It's used by FolderView. + */ public interface NoteNameListener { /** * Fired after note name changed - * * @param note * @param oldName */ http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java index fbccd80..b7dcdc3 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java @@ -69,19 +69,21 @@ import org.quartz.impl.StdSchedulerFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** Collection of Notes. */ +/** + * Collection of Notes. + */ public class Notebook implements NoteEventListener { private static final Logger logger = LoggerFactory.getLogger(Notebook.class); - @SuppressWarnings("unused") - @Deprecated // TODO(bzz): remove unused + @SuppressWarnings("unused") @Deprecated //TODO(bzz): remove unused private SchedulerFactory schedulerFactory; private InterpreterFactory replFactory; private InterpreterSettingManager interpreterSettingManager; - /** Keep the order. */ + /** + * Keep the order. + */ private final Map<String, Note> notes = new LinkedHashMap<>(); - private final FolderView folders = new FolderView(); private ZeppelinConfiguration conf; private StdSchedulerFactory quertzSchedFact; @@ -97,21 +99,15 @@ public class Notebook implements NoteEventListener { /** * Main constructor \w manual Dependency Injection * - * @param noteSearchService - (nullable) for indexing all notebooks on creating. + * @param noteSearchService - (nullable) for indexing all notebooks on creating. * @throws IOException * @throws SchedulerException */ - public Notebook( - ZeppelinConfiguration conf, - NotebookRepo notebookRepo, - SchedulerFactory schedulerFactory, - InterpreterFactory replFactory, - InterpreterSettingManager interpreterSettingManager, - ParagraphJobListener paragraphJobListener, - SearchService noteSearchService, - NotebookAuthorization notebookAuthorization, - Credentials credentials) - throws IOException, SchedulerException { + public Notebook(ZeppelinConfiguration conf, NotebookRepo notebookRepo, + SchedulerFactory schedulerFactory, InterpreterFactory replFactory, + InterpreterSettingManager interpreterSettingManager, ParagraphJobListener paragraphJobListener, + SearchService noteSearchService, NotebookAuthorization notebookAuthorization, + Credentials credentials) throws IOException, SchedulerException { this.conf = conf; this.notebookRepo = notebookRepo; this.schedulerFactory = schedulerFactory; @@ -132,9 +128,7 @@ public class Notebook implements NoteEventListener { long start = System.nanoTime(); logger.info("Notebook indexing started..."); noteSearchService.addIndexDocs(notes.values()); - logger.info( - "Notebook indexing finished: {} indexed in {}s", - notes.size(), + logger.info("Notebook indexing finished: {} indexed in {}s", notes.size(), TimeUnit.NANOSECONDS.toSeconds(start - System.nanoTime())); } } @@ -145,8 +139,7 @@ public class Notebook implements NoteEventListener { * @throws IOException */ public Note createNote(AuthenticationInfo subject) throws IOException { - return createNote( - "", interpreterSettingManager.getDefaultInterpreterSetting().getName(), subject); + return createNote("", interpreterSettingManager.getDefaultInterpreterSetting().getName(), subject); } /** @@ -157,16 +150,8 @@ public class Notebook implements NoteEventListener { public Note createNote(String name, String defaultInterpreterGroup, AuthenticationInfo subject) throws IOException { Note note = - new Note( - name, - defaultInterpreterGroup, - notebookRepo, - replFactory, - interpreterSettingManager, - paragraphJobListener, - noteSearchService, - credentials, - this); + new Note(name, defaultInterpreterGroup, notebookRepo, replFactory, interpreterSettingManager, + paragraphJobListener, noteSearchService, credentials, this); note.setNoteNameListener(folders); synchronized (notes) { @@ -198,7 +183,7 @@ public class Notebook implements NoteEventListener { * import JSON as a new note. * * @param sourceJson - the note JSON to import - * @param noteName - the name of the new note + * @param noteName - the name of the new note * @return note ID * @throws IOException */ @@ -233,7 +218,7 @@ public class Notebook implements NoteEventListener { * Clone existing note. * * @param sourceNoteId - the note ID to clone - * @param newNoteName - the name of the new note + * @param newNoteName - the name of the new note * @return noteId * @throws IOException, CloneNotSupportedException, IllegalArgumentException */ @@ -269,8 +254,8 @@ public class Notebook implements NoteEventListener { for (Paragraph p : note.getParagraphs()) { try { Interpreter intp = p.getBindedInterpreter(); - settings.add( - ((ManagedInterpreterGroup) intp.getInterpreterGroup()).getInterpreterSetting()); + settings.add(( + (ManagedInterpreterGroup) intp.getInterpreterGroup()).getInterpreterSetting()); } catch (InterpreterNotFoundException e) { // ignore this } @@ -306,11 +291,11 @@ public class Notebook implements NoteEventListener { } public void moveNoteToTrash(String noteId) { - // try { - //// interpreterSettingManager.setInterpreterBinding("", noteId, new ArrayList<String>()); - // } catch (IOException e) { - // e.printStackTrace(); - // } +// try { +//// interpreterSettingManager.setInterpreterBinding("", noteId, new ArrayList<String>()); +// } catch (IOException e) { +// e.printStackTrace(); +// } } public void removeNote(String id, AuthenticationInfo subject) { @@ -377,13 +362,14 @@ public class Notebook implements NoteEventListener { } } - public Revision checkpointNote( - String noteId, String checkpointMessage, AuthenticationInfo subject) throws IOException { + public Revision checkpointNote(String noteId, String checkpointMessage, + AuthenticationInfo subject) throws IOException { if (((NotebookRepoSync) notebookRepo).isRevisionSupportedInDefaultRepo()) { return ((NotebookRepoWithVersionControl) notebookRepo) .checkpoint(noteId, checkpointMessage, subject); } else { return null; + } } @@ -426,7 +412,7 @@ public class Notebook implements NoteEventListener { return null; } - // Manually inject ALL dependencies, as DI constructor was NOT used + //Manually inject ALL dependencies, as DI constructor was NOT used note.setIndex(this.noteSearchService); note.setCredentials(this.credentials); @@ -461,8 +447,7 @@ public class Notebook implements NoteEventListener { for (AngularObject object : objectList) { SnapshotAngularObject snapshot = angularObjectSnapshot.get(object.getName()); if (snapshot == null || snapshot.getLastUpdate().before(lastUpdatedDate)) { - angularObjectSnapshot.put( - object.getName(), + angularObjectSnapshot.put(object.getName(), new SnapshotAngularObject(intpGroupName, object, lastUpdatedDate)); } } @@ -509,8 +494,8 @@ public class Notebook implements NoteEventListener { } /** - * Reload all notes from repository after clearing `notes` and `folders` to reflect the changes of - * added/deleted/modified notes on file system level. + * Reload all notes from repository after clearing `notes` and `folders` + * to reflect the changes of added/deleted/modified notes on file system level. * * @throws IOException */ @@ -573,29 +558,28 @@ public class Notebook implements NoteEventListener { return folders.getFolder(folderId).getNotesRecursively(); } - public List<Note> getNotesUnderFolder(String folderId, Set<String> userAndRoles) { + public List<Note> getNotesUnderFolder(String folderId, + Set<String> userAndRoles) { return folders.getFolder(folderId).getNotesRecursively(userAndRoles, notebookAuthorization); } public List<Note> getAllNotes() { synchronized (notes) { List<Note> noteList = new ArrayList<>(notes.values()); - Collections.sort( - noteList, - new Comparator<Note>() { - @Override - public int compare(Note note1, Note note2) { - String name1 = note1.getId(); - if (note1.getName() != null) { - name1 = note1.getName(); - } - String name2 = note2.getId(); - if (note2.getName() != null) { - name2 = note2.getName(); - } - return name1.compareTo(name2); - } - }); + Collections.sort(noteList, new Comparator<Note>() { + @Override + public int compare(Note note1, Note note2) { + String name1 = note1.getId(); + if (note1.getName() != null) { + name1 = note1.getName(); + } + String name2 = note2.getId(); + if (note2.getName() != null) { + name2 = note2.getName(); + } + return name1.compareTo(name2); + } + }); return noteList; } } @@ -607,33 +591,31 @@ public class Notebook implements NoteEventListener { } synchronized (notes) { - return FluentIterable.from(notes.values()) - .filter( - new Predicate<Note>() { - @Override - public boolean apply(Note input) { - return input != null && notebookAuthorization.isReader(input.getId(), entities); - } - }) - .toSortedList( - new Comparator<Note>() { - @Override - public int compare(Note note1, Note note2) { - String name1 = note1.getId(); - if (note1.getName() != null) { - name1 = note1.getName(); - } - String name2 = note2.getId(); - if (note2.getName() != null) { - name2 = note2.getName(); - } - return name1.compareTo(name2); - } - }); - } - } - - /** Cron task for the note. */ + return FluentIterable.from(notes.values()).filter(new Predicate<Note>() { + @Override + public boolean apply(Note input) { + return input != null && notebookAuthorization.isReader(input.getId(), entities); + } + }).toSortedList(new Comparator<Note>() { + @Override + public int compare(Note note1, Note note2) { + String name1 = note1.getId(); + if (note1.getName() != null) { + name1 = note1.getName(); + } + String name2 = note2.getId(); + if (note2.getName() != null) { + name2 = note2.getName(); + } + return name1.compareTo(name2); + } + }); + } + } + + /** + * Cron task for the note. + */ public static class CronJob implements org.quartz.Job { public static Notebook notebook; @@ -644,16 +626,13 @@ public class Notebook implements NoteEventListener { Note note = notebook.getNote(noteId); if (note.isRunningOrPending()) { - logger.warn( - "execution of the cron job is skipped because there is a running or pending " - + "paragraph (note id: {})", - noteId); + logger.warn("execution of the cron job is skipped because there is a running or pending " + + "paragraph (note id: {})", noteId); return; } if (!note.isCronSupported(notebook.getConf())) { - logger.warn( - "execution of the cron job is skipped cron is not enabled from Zeppelin server"); + logger.warn("execution of the cron job is skipped cron is not enabled from Zeppelin server"); return; } @@ -673,14 +652,10 @@ public class Notebook implements NoteEventListener { logger.error(e.getMessage(), e); } if (releaseResource) { - for (InterpreterSetting setting : - notebook.getInterpreterSettingManager().getInterpreterSettings(note.getId())) { + for (InterpreterSetting setting : notebook.getInterpreterSettingManager() + .getInterpreterSettings(note.getId())) { try { - notebook - .getInterpreterSettingManager() - .restart( - setting.getId(), - noteId, + notebook.getInterpreterSettingManager().restart(setting.getId(), noteId, cronExecutingUser != null ? cronExecutingUser : "anonymous"); } catch (InterpreterException e) { logger.error("Fail to restart interpreter: " + setting.getId(), e); @@ -693,6 +668,7 @@ public class Notebook implements NoteEventListener { public void refreshCron(String id) { removeCron(id); synchronized (notes) { + Note note = notes.get(id); if (note == null) { return; @@ -703,8 +679,7 @@ public class Notebook implements NoteEventListener { } if (!note.isCronSupported(getConf())) { - logger.warn( - "execution of the cron job is skipped cron is not enabled from Zeppelin server"); + logger.warn("execution of the cron job is skipped cron is not enabled from Zeppelin server"); return; } @@ -713,10 +688,9 @@ public class Notebook implements NoteEventListener { return; } + JobDetail newJob = - JobBuilder.newJob(CronJob.class) - .withIdentity(id, "note") - .usingJobData("noteId", id) + JobBuilder.newJob(CronJob.class).withIdentity(id, "note").usingJobData("noteId", id) .build(); Map<String, Object> info = note.getInfo(); @@ -724,17 +698,14 @@ public class Notebook implements NoteEventListener { CronTrigger trigger = null; try { - trigger = - TriggerBuilder.newTrigger() - .withIdentity("trigger_" + id, "note") - .withSchedule(CronScheduleBuilder.cronSchedule(cronExpr)) - .forJob(id, "note") - .build(); + trigger = TriggerBuilder.newTrigger().withIdentity("trigger_" + id, "note") + .withSchedule(CronScheduleBuilder.cronSchedule(cronExpr)).forJob(id, "note").build(); } catch (Exception e) { logger.error("Error", e); info.put("cron", e.getMessage()); } + try { if (trigger != null) { quartzSched.scheduleJob(newJob, trigger); http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NotebookAuthorization.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NotebookAuthorization.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NotebookAuthorization.java index f0b5ac1..137af65 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NotebookAuthorization.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NotebookAuthorization.java @@ -17,10 +17,13 @@ package org.apache.zeppelin.notebook; -import com.google.common.base.Predicate; -import com.google.common.collect.FluentIterable; -import com.google.common.collect.Sets; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; @@ -28,6 +31,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; + import org.apache.commons.lang.StringUtils; import org.apache.zeppelin.conf.ZeppelinConfiguration; import org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars; @@ -36,7 +40,15 @@ import org.apache.zeppelin.user.AuthenticationInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** Contains authorization information for notes */ +import com.google.common.base.Predicate; +import com.google.common.collect.FluentIterable; +import com.google.common.collect.Sets; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +/** + * Contains authorization information for notes + */ public class NotebookAuthorization { private static final Logger LOG = LoggerFactory.getLogger(NotebookAuthorization.class); private static NotebookAuthorization instance = null; @@ -71,9 +83,8 @@ public class NotebookAuthorization { public static NotebookAuthorization getInstance() { if (instance == null) { - LOG.warn( - "Notebook authorization module was called without initialization," - + " initializing with default configuration"); + LOG.warn("Notebook authorization module was called without initialization," + + " initializing with default configuration"); init(ZeppelinConfiguration.create()); } return instance; @@ -85,7 +96,7 @@ public class NotebookAuthorization { authInfo = info.authInfo; } } - + public void setRoles(String user, Set<String> roles) { if (StringUtils.isBlank(user)) { LOG.warn("Setting roles for empty user"); @@ -94,7 +105,7 @@ public class NotebookAuthorization { roles = validateUser(roles); userRoles.put(user, roles); } - + public Set<String> getRoles(String user) { Set<String> roles = Sets.newHashSet(); if (userRoles.containsKey(user)) { @@ -102,7 +113,7 @@ public class NotebookAuthorization { } return roles; } - + private void saveToFile() { synchronized (authInfo) { NotebookAuthorizationInfoSaving info = new NotebookAuthorizationInfoSaving(); @@ -114,7 +125,7 @@ public class NotebookAuthorization { } } } - + public boolean isPublic() { return conf.isNotebookPublic(); } @@ -177,6 +188,7 @@ public class NotebookAuthorization { saveToFile(); } + public void setWriters(String noteId, Set<String> entities) { Map<String, Set<String>> noteAuthInfo = authInfo.get(noteId); entities = validateUser(entities); @@ -194,8 +206,8 @@ public class NotebookAuthorization { } /* - * If case conversion is enforced, then change entity names to lower case - */ + * If case conversion is enforced, then change entity names to lower case + */ private Set<String> checkCaseAndConvert(Set<String> entities) { if (conf.isUsernameForceLowerCase()) { Set<String> set2 = new HashSet<String>(); @@ -277,24 +289,24 @@ public class NotebookAuthorization { } public boolean isWriter(String noteId, Set<String> entities) { - return isMember(entities, getWriters(noteId)) - || isMember(entities, getOwners(noteId)) - || isAdmin(entities); + return isMember(entities, getWriters(noteId)) || + isMember(entities, getOwners(noteId)) || + isAdmin(entities); } public boolean isReader(String noteId, Set<String> entities) { - return isMember(entities, getReaders(noteId)) - || isMember(entities, getOwners(noteId)) - || isMember(entities, getWriters(noteId)) - || isMember(entities, getRunners(noteId)) - || isAdmin(entities); + return isMember(entities, getReaders(noteId)) || + isMember(entities, getOwners(noteId)) || + isMember(entities, getWriters(noteId)) || + isMember(entities, getRunners(noteId)) || + isAdmin(entities); } public boolean isRunner(String noteId, Set<String> entities) { - return isMember(entities, getRunners(noteId)) - || isMember(entities, getWriters(noteId)) - || isMember(entities, getOwners(noteId)) - || isAdmin(entities); + return isMember(entities, getRunners(noteId)) || + isMember(entities, getWriters(noteId)) || + isMember(entities, getOwners(noteId)) || + isAdmin(entities); } private boolean isAdmin(Set<String> entities) { @@ -322,7 +334,7 @@ public class NotebookAuthorization { } return isOwner(noteId, userAndRoles); } - + public boolean hasWriteAuthorization(Set<String> userAndRoles, String noteId) { if (conf.isAnonymousAllowed()) { LOG.debug("Zeppelin runs in anonymous mode, everybody is writer"); @@ -333,7 +345,7 @@ public class NotebookAuthorization { } return isWriter(noteId, userAndRoles); } - + public boolean hasReadAuthorization(Set<String> userAndRoles, String noteId) { if (conf.isAnonymousAllowed()) { LOG.debug("Zeppelin runs in anonymous mode, everybody is reader"); @@ -366,17 +378,14 @@ public class NotebookAuthorization { if (subject != null) { entities.add(subject.getUser()); } - return FluentIterable.from(notes) - .filter( - new Predicate<NoteInfo>() { - @Override - public boolean apply(NoteInfo input) { - return input != null && isReader(input.getId(), entities); - } - }) - .toList(); + return FluentIterable.from(notes).filter(new Predicate<NoteInfo>() { + @Override + public boolean apply(NoteInfo input) { + return input != null && isReader(input.getId(), entities); + } + }).toList(); } - + public void setNewNotePermissions(String noteId, AuthenticationInfo subject) { if (!AuthenticationInfo.isAnonymous(subject)) { if (isPublic()) { http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NotebookAuthorizationInfoSaving.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NotebookAuthorizationInfoSaving.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NotebookAuthorizationInfoSaving.java index 2227842..629e400 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NotebookAuthorizationInfoSaving.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NotebookAuthorizationInfoSaving.java @@ -18,11 +18,14 @@ package org.apache.zeppelin.notebook; import com.google.gson.Gson; +import org.apache.zeppelin.common.JsonSerializable; + import java.util.Map; import java.util.Set; -import org.apache.zeppelin.common.JsonSerializable; -/** Only used for saving NotebookAuthorization info */ +/** + * Only used for saving NotebookAuthorization info + */ public class NotebookAuthorizationInfoSaving implements JsonSerializable { private static final Gson gson = new Gson(); http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NotebookEventListener.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NotebookEventListener.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NotebookEventListener.java index f5a62c4..01ebec6 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NotebookEventListener.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NotebookEventListener.java @@ -16,9 +16,12 @@ */ package org.apache.zeppelin.notebook; -/** Notebook event */ +import org.apache.zeppelin.interpreter.InterpreterSetting; + +/** + * Notebook event + */ public interface NotebookEventListener extends NoteEventListener { public void onNoteRemove(Note note); - public void onNoteCreate(Note note); } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NotebookImportDeserializer.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NotebookImportDeserializer.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NotebookImportDeserializer.java index bd34f80..0b8eed8 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NotebookImportDeserializer.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NotebookImportDeserializer.java @@ -21,6 +21,7 @@ import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonParseException; + import java.lang.reflect.Type; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -28,29 +29,27 @@ import java.util.Arrays; import java.util.Date; import java.util.Locale; -/** importNote date format deserializer */ +/** + * importNote date format deserializer + */ public class NotebookImportDeserializer implements JsonDeserializer<Date> { - private static final String[] DATE_FORMATS = - new String[] { - "yyyy-MM-dd'T'HH:mm:ssZ", - "MMM d, yyyy h:mm:ss a", - "MMM dd, yyyy HH:mm:ss", - "yyyy-MM-dd HH:mm:ss.SSS" - }; + private static final String[] DATE_FORMATS = new String[] { + "yyyy-MM-dd'T'HH:mm:ssZ", + "MMM d, yyyy h:mm:ss a", + "MMM dd, yyyy HH:mm:ss", + "yyyy-MM-dd HH:mm:ss.SSS" + }; @Override - public Date deserialize(JsonElement jsonElement, Type typeOF, JsonDeserializationContext context) - throws JsonParseException { + public Date deserialize(JsonElement jsonElement, Type typeOF, + JsonDeserializationContext context) throws JsonParseException { for (String format : DATE_FORMATS) { try { return new SimpleDateFormat(format, Locale.US).parse(jsonElement.getAsString()); } catch (ParseException e) { } } - throw new JsonParseException( - "Unparsable date: \"" - + jsonElement.getAsString() - + "\". Supported formats: " - + Arrays.toString(DATE_FORMATS)); + throw new JsonParseException("Unparsable date: \"" + jsonElement.getAsString() + + "\". Supported formats: " + Arrays.toString(DATE_FORMATS)); } } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java index 37bc77c..87dc5fd 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Paragraph.java @@ -17,9 +17,6 @@ package org.apache.zeppelin.notebook; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Strings; -import com.google.common.collect.Maps; import java.io.IOException; import java.security.SecureRandom; import java.util.ArrayList; @@ -33,6 +30,7 @@ import java.util.Map; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; + import org.apache.commons.lang.StringUtils; import org.apache.zeppelin.common.JsonSerializable; import org.apache.zeppelin.display.AngularObject; @@ -46,6 +44,7 @@ import org.apache.zeppelin.interpreter.InterpreterContext; import org.apache.zeppelin.interpreter.InterpreterException; import org.apache.zeppelin.interpreter.InterpreterFactory; import org.apache.zeppelin.interpreter.InterpreterNotFoundException; +import org.apache.zeppelin.interpreter.InterpreterOption; import org.apache.zeppelin.interpreter.InterpreterOutput; import org.apache.zeppelin.interpreter.InterpreterOutputListener; import org.apache.zeppelin.interpreter.InterpreterResult; @@ -66,9 +65,15 @@ import org.apache.zeppelin.user.UserCredentials; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** Paragraph is a representation of an execution unit. */ -public class Paragraph extends JobWithProgressPoller<InterpreterResult> - implements Cloneable, JsonSerializable { +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Strings; +import com.google.common.collect.Maps; + +/** + * Paragraph is a representation of an execution unit. + */ +public class Paragraph extends JobWithProgressPoller<InterpreterResult> implements Cloneable, + JsonSerializable { private static Logger LOGGER = LoggerFactory.getLogger(Paragraph.class); private static Pattern REPL_PATTERN = @@ -87,9 +92,8 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> // Application states in this paragraph private final List<ApplicationState> apps = new LinkedList<>(); - /** ************ Transient fields which are not serializabled into note json ************* */ + /************** Transient fields which are not serializabled into note json **************/ private transient String intpText; - private transient String scriptText; private transient InterpreterFactory interpreterFactory; private transient Interpreter interpreter; @@ -100,13 +104,14 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> private transient Map<String, String> localProperties = new HashMap<>(); private transient Map<String, ParagraphRuntimeInfo> runtimeInfos = new HashMap<>(); + @VisibleForTesting Paragraph() { super(generateId(), null); } - public Paragraph( - String paragraphId, Note note, JobListener listener, InterpreterFactory interpreterFactory) { + public Paragraph(String paragraphId, Note note, JobListener listener, + InterpreterFactory interpreterFactory) { super(paragraphId, generateId(), listener); this.note = note; this.interpreterFactory = interpreterFactory; @@ -193,8 +198,8 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> if (matcher.groupCount() == 3 && matcher.group(3) != null) { String localPropertiesText = matcher.group(3); - String[] splits = - localPropertiesText.substring(1, localPropertiesText.length() - 1).split(","); + String[] splits = localPropertiesText.substring(1, localPropertiesText.length() -1) + .split(","); for (String split : splits) { String[] kv = split.split("="); if (StringUtils.isBlank(split) || kv.length == 0) { @@ -209,14 +214,10 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> localProperties.put(kv[0].trim(), kv[1].trim()); } } - this.scriptText = - this.text - .substring( - headingSpace.length() + intpText.length() + localPropertiesText.length() + 1) - .trim(); + this.scriptText = this.text.substring(headingSpace.length() + intpText.length() + + localPropertiesText.length() + 1).trim(); } else { - this.scriptText = - this.text.substring(headingSpace.length() + intpText.length() + 1).trim(); + this.scriptText = this.text.substring(headingSpace.length() + intpText.length() + 1).trim(); } } else { this.intpText = ""; @@ -270,8 +271,8 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> } public Interpreter getBindedInterpreter() throws InterpreterNotFoundException { - return this.interpreterFactory.getInterpreter( - user, note.getId(), intpText, note.getDefaultInterpreterGroup()); + return this.interpreterFactory.getInterpreter(user, note.getId(), intpText, + note.getDefaultInterpreterGroup()); } public void setInterpreter(Interpreter interpreter) { @@ -368,7 +369,8 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> return true; } } catch (InterpreterNotFoundException e) { - InterpreterResult intpResult = new InterpreterResult(InterpreterResult.Code.ERROR); + InterpreterResult intpResult = + new InterpreterResult(InterpreterResult.Code.ERROR); setReturn(intpResult, e); setStatus(Job.Status.ERROR); throw new RuntimeException(e); @@ -377,20 +379,16 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> @Override protected InterpreterResult jobRun() throws Throwable { - LOGGER.info( - "Run paragraph [paragraph_id: {}, interpreter: {}, note_id: {}, user: {}]", - getId(), - intpText, - note.getId(), - subject.getUser()); + LOGGER.info("Run paragraph [paragraph_id: {}, interpreter: {}, note_id: {}, user: {}]", + getId(), intpText, note.getId(), subject.getUser()); this.runtimeInfos.clear(); this.interpreter = getBindedInterpreter(); if (this.interpreter == null) { LOGGER.error("Can not find interpreter name " + intpText); throw new RuntimeException("Can not find interpreter for " + intpText); } - InterpreterSetting interpreterSetting = - ((ManagedInterpreterGroup) interpreter.getInterpreterGroup()).getInterpreterSetting(); + InterpreterSetting interpreterSetting = ((ManagedInterpreterGroup) + interpreter.getInterpreterGroup()).getInterpreterSetting(); if (interpreterSetting != null) { interpreterSetting.waitForReady(); } @@ -421,7 +419,7 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> settings.setForms(inputs); if (!noteInputs.isEmpty()) { if (!note.getNoteForms().isEmpty()) { - Map<String, Input> currentNoteForms = note.getNoteForms(); + Map<String, Input> currentNoteForms = note.getNoteForms(); for (String s : noteInputs.keySet()) { if (!currentNoteForms.containsKey(s)) { currentNoteForms.put(s, noteInputs.get(s)); @@ -491,42 +489,40 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> private InterpreterContext getInterpreterContext() { final Paragraph self = this; - return getInterpreterContext( - new InterpreterOutput( - new InterpreterOutputListener() { - @Override - public void onAppend(int index, InterpreterResultMessageOutput out, byte[] line) { - ((ParagraphJobListener) getListener()) - .onOutputAppend(self, index, new String(line)); - } - - @Override - public void onUpdate(int index, InterpreterResultMessageOutput out) { - try { - ((ParagraphJobListener) getListener()) - .onOutputUpdate(self, index, out.toInterpreterResultMessage()); - } catch (IOException e) { - LOGGER.error(e.getMessage(), e); - } - } - - @Override - public void onUpdateAll(InterpreterOutput out) { - try { - List<InterpreterResultMessage> messages = out.toInterpreterResultMessage(); - ((ParagraphJobListener) getListener()).onOutputUpdateAll(self, messages); - updateParagraphResult(messages); - } catch (IOException e) { - LOGGER.error(e.getMessage(), e); - } - } - - private void updateParagraphResult(List<InterpreterResultMessage> msgs) { - // update paragraph results - InterpreterResult result = new InterpreterResult(Code.SUCCESS, msgs); - setReturn(result, null); - } - })); + return getInterpreterContext(new InterpreterOutput(new InterpreterOutputListener() { + @Override + public void onAppend(int index, InterpreterResultMessageOutput out, byte[] line) { + ((ParagraphJobListener) getListener()).onOutputAppend(self, index, new String(line)); + } + + @Override + public void onUpdate(int index, InterpreterResultMessageOutput out) { + try { + ((ParagraphJobListener) getListener()) + .onOutputUpdate(self, index, out.toInterpreterResultMessage()); + } catch (IOException e) { + LOGGER.error(e.getMessage(), e); + } + } + + @Override + public void onUpdateAll(InterpreterOutput out) { + try { + List<InterpreterResultMessage> messages = out.toInterpreterResultMessage(); + ((ParagraphJobListener) getListener()).onOutputUpdateAll(self, messages); + updateParagraphResult(messages); + } catch (IOException e) { + LOGGER.error(e.getMessage(), e); + } + + } + + private void updateParagraphResult(List<InterpreterResultMessage> msgs) { + // update paragraph results + InterpreterResult result = new InterpreterResult(Code.SUCCESS, msgs); + setReturn(result, null); + } + })); } private InterpreterContext getInterpreterContext(InterpreterOutput output) { @@ -540,7 +536,8 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> Credentials credentials = note.getCredentials(); if (subject != null) { - UserCredentials userCredentials = credentials.getUserCredentials(subject.getUser()); + UserCredentials userCredentials = + credentials.getUserCredentials(subject.getUser()); subject.setUserCredentials(userCredentials); } @@ -603,6 +600,7 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> } } + public ApplicationState getApplicationState(String appId) { synchronized (apps) { for (ApplicationState as : apps) { @@ -621,8 +619,8 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> } } - String extractVariablesFromAngularRegistry( - String scriptBody, Map<String, Input> inputs, AngularObjectRegistry angularRegistry) { + String extractVariablesFromAngularRegistry(String scriptBody, Map<String, Input> inputs, + AngularObjectRegistry angularRegistry) { final String noteId = this.getNote().getId(); final String paragraphId = this.getId(); @@ -644,16 +642,15 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> public boolean isValidInterpreter(String replName) { try { - return interpreterFactory.getInterpreter( - user, note.getId(), replName, note.getDefaultInterpreterGroup()) - != null; + return interpreterFactory.getInterpreter(user, note.getId(), replName, + note.getDefaultInterpreterGroup()) != null; } catch (InterpreterNotFoundException e) { return false; } } - public void updateRuntimeInfos( - String label, String tooltip, Map<String, String> infos, String group, String intpSettingId) { + public void updateRuntimeInfos(String label, String tooltip, Map<String, String> infos, + String group, String intpSettingId) { if (this.runtimeInfos == null) { this.runtimeInfos = new HashMap<>(); } @@ -708,9 +705,8 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> if (user != null ? !user.equals(paragraph.user) : paragraph.user != null) { return false; } - if (dateUpdated != null - ? !dateUpdated.equals(paragraph.dateUpdated) - : paragraph.dateUpdated != null) { + if (dateUpdated != null ? + !dateUpdated.equals(paragraph.dateUpdated) : paragraph.dateUpdated != null) { return false; } if (config != null ? !config.equals(paragraph.config) : paragraph.config != null) { @@ -720,7 +716,9 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> return false; } - return results != null ? results.equals(paragraph.results) : paragraph.results == null; + return results != null ? + results.equals(paragraph.results) : paragraph.results == null; + } @Override @@ -744,4 +742,5 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> public static Paragraph fromJson(String json) { return Note.getGson().fromJson(json, Paragraph.class); } + } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/ParagraphJobListener.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/ParagraphJobListener.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/ParagraphJobListener.java index a721b03..8743fb7 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/ParagraphJobListener.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/ParagraphJobListener.java @@ -17,15 +17,18 @@ package org.apache.zeppelin.notebook; -import java.util.List; +import org.apache.zeppelin.interpreter.InterpreterOutput; import org.apache.zeppelin.interpreter.InterpreterResultMessage; +import org.apache.zeppelin.interpreter.InterpreterResultMessageOutput; import org.apache.zeppelin.scheduler.JobListener; -/** Listen paragraph update */ +import java.util.List; + +/** + * Listen paragraph update + */ public interface ParagraphJobListener extends JobListener<Paragraph> { void onOutputAppend(Paragraph paragraph, int idx, String output); - void onOutputUpdate(Paragraph paragraph, int idx, InterpreterResultMessage msg); - void onOutputUpdateAll(Paragraph paragraph, List<InterpreterResultMessage> msgs); } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/ParagraphRuntimeInfo.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/ParagraphRuntimeInfo.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/ParagraphRuntimeInfo.java index eb1f872..0042023 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/ParagraphRuntimeInfo.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/ParagraphRuntimeInfo.java @@ -3,18 +3,21 @@ package org.apache.zeppelin.notebook; import java.util.ArrayList; import java.util.List; -/** Store runtime infos of each para */ +/** + * Store runtime infos of each para + * + */ public class ParagraphRuntimeInfo { - private String propertyName; // Name of the property - private String label; // Label to be used in UI - private String tooltip; // Tooltip text toshow in UI - private String group; // The interpretergroup from which the info was derived - private List<String> values; // values for the property + private String propertyName; // Name of the property + private String label; // Label to be used in UI + private String tooltip; // Tooltip text toshow in UI + private String group; // The interpretergroup from which the info was derived + private List<String> values; // values for the property private String interpreterSettingId; - - public ParagraphRuntimeInfo( - String propertyName, String label, String tooltip, String group, String intpSettingId) { + + public ParagraphRuntimeInfo(String propertyName, String label, + String tooltip, String group, String intpSettingId) { if (intpSettingId == null) { throw new IllegalArgumentException("Interpreter setting Id cannot be null"); } @@ -29,7 +32,7 @@ public class ParagraphRuntimeInfo { public void addValue(String value) { values.add(value); } - + public String getInterpreterSettingId() { return interpreterSettingId; } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/0d746fa2/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/ParagraphWithRuntimeInfo.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/ParagraphWithRuntimeInfo.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/ParagraphWithRuntimeInfo.java index 78c58cc..33dce22 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/ParagraphWithRuntimeInfo.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/ParagraphWithRuntimeInfo.java @@ -20,8 +20,8 @@ package org.apache.zeppelin.notebook; import java.util.Map; /** - * This class is used for broadcast Paragrapah to frontend. runtimeInfos will also been prapagated - * to frontend. + * This class is used for broadcast Paragrapah to frontend. + * runtimeInfos will also been prapagated to frontend. */ public class ParagraphWithRuntimeInfo extends Paragraph { @@ -31,4 +31,5 @@ public class ParagraphWithRuntimeInfo extends Paragraph { super(p); this.runtimeInfos = p.getRuntimeInfos(); } + }
