http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/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 ac7fa1e..56fb516 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,24 +16,30 @@ */ 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/55f6c91c/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 69daa6f..b012eab 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,14 +16,11 @@ */ 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; @@ -31,11 +28,7 @@ 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; @@ -70,13 +63,14 @@ 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/55f6c91c/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 bc71d89..9f56f96 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,14 +18,10 @@ 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, @@ -36,7 +32,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; @@ -46,9 +42,8 @@ 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) { @@ -56,7 +51,6 @@ public class ApplicationState { } } - @Override public boolean equals(Object o) { String compareName; http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/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 4670e20..e7ed568 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,5 +1,14 @@ 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; @@ -12,20 +21,7 @@ import org.apache.zeppelin.conf.ZeppelinConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -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 - */ +/** Hadoop FileSystem wrapper. Support both secure and no-secure mode */ public class FileSystemStorage { private static Logger LOGGER = LoggerFactory.getLogger(FileSystemStorage.class); @@ -35,19 +31,22 @@ 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); } } } @@ -81,82 +80,93 @@ 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> { @@ -166,12 +176,14 @@ 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); } @@ -179,5 +191,4 @@ public class FileSystemStorage { return func.call(); } } - } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/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 afd5229..d3709c2 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,16 +18,14 @@ 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 = "/"; @@ -55,13 +53,12 @@ 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; } @@ -69,8 +66,7 @@ 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 @@ -109,8 +105,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); @@ -172,7 +168,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); } @@ -217,8 +213,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); @@ -249,8 +245,7 @@ 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/55f6c91c/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 efc2f72..0b7e0fb 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,9 +16,7 @@ */ 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/55f6c91c/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 7d3f001..c111193 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,15 +17,13 @@ package org.apache.zeppelin.notebook; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.util.LinkedHashMap; import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** - * 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 @@ -45,22 +43,20 @@ 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); @@ -92,8 +88,7 @@ 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); } @@ -134,8 +129,7 @@ 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()) { @@ -191,8 +185,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 @@ -222,12 +216,11 @@ 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/55f6c91c/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 61a36ab..a845ec1 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,29 +17,38 @@ 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; @@ -47,32 +56,17 @@ import org.apache.zeppelin.user.Credentials; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -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 - */ +/** 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 = @@ -114,14 +108,20 @@ 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,15 +214,12 @@ 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 @@ -286,8 +283,9 @@ 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; @@ -300,8 +298,9 @@ 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())); } } @@ -346,14 +345,11 @@ 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); } @@ -366,24 +362,23 @@ 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()); + logger.debug("newParagraph user: " + newParagraph.getUser()); try { Gson gson = new Gson(); @@ -502,9 +497,7 @@ 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) { @@ -517,7 +510,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); @@ -526,10 +519,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) { @@ -653,19 +646,18 @@ 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); } @@ -697,9 +689,7 @@ 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) { @@ -741,7 +731,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) { @@ -800,9 +790,7 @@ 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); } @@ -811,7 +799,6 @@ 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 @@ -844,17 +831,21 @@ 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); } } @@ -944,21 +935,22 @@ 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/55f6c91c/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 5f98f70..83f311d 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/55f6c91c/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 d316dfb..281744f 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,9 +20,7 @@ package org.apache.zeppelin.notebook; import java.util.HashMap; import java.util.Map; -/** - * - */ +/** */ public class NoteInfo { String id; String name; @@ -64,5 +62,4 @@ public class NoteInfo { public void setConfig(Map<String, Object> config) { this.config = config; } - } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/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 28b53fb..2d5175e 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,12 +17,11 @@ 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/55f6c91c/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 b7dcdc3..fbccd80 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,21 +69,19 @@ 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; @@ -99,15 +97,21 @@ 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; @@ -128,7 +132,9 @@ 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())); } } @@ -139,7 +145,8 @@ 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); } /** @@ -150,8 +157,16 @@ 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) { @@ -183,7 +198,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 */ @@ -218,7 +233,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 */ @@ -254,8 +269,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 } @@ -291,11 +306,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) { @@ -362,14 +377,13 @@ 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; - } } @@ -412,7 +426,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); @@ -447,7 +461,8 @@ 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)); } } @@ -494,8 +509,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 */ @@ -558,28 +573,29 @@ 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; } } @@ -591,31 +607,33 @@ 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; @@ -626,13 +644,16 @@ 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; } @@ -652,10 +673,14 @@ 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); @@ -668,7 +693,6 @@ public class Notebook implements NoteEventListener { public void refreshCron(String id) { removeCron(id); synchronized (notes) { - Note note = notes.get(id); if (note == null) { return; @@ -679,7 +703,8 @@ 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; } @@ -688,9 +713,10 @@ 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(); @@ -698,14 +724,17 @@ 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/55f6c91c/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 137af65..f0b5ac1 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,13 +17,10 @@ package org.apache.zeppelin.notebook; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; +import com.google.common.base.Predicate; +import com.google.common.collect.FluentIterable; +import com.google.common.collect.Sets; import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; @@ -31,7 +28,6 @@ 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; @@ -40,15 +36,7 @@ import org.apache.zeppelin.user.AuthenticationInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -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 - */ +/** Contains authorization information for notes */ public class NotebookAuthorization { private static final Logger LOG = LoggerFactory.getLogger(NotebookAuthorization.class); private static NotebookAuthorization instance = null; @@ -83,8 +71,9 @@ 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; @@ -96,7 +85,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"); @@ -105,7 +94,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)) { @@ -113,7 +102,7 @@ public class NotebookAuthorization { } return roles; } - + private void saveToFile() { synchronized (authInfo) { NotebookAuthorizationInfoSaving info = new NotebookAuthorizationInfoSaving(); @@ -125,7 +114,7 @@ public class NotebookAuthorization { } } } - + public boolean isPublic() { return conf.isNotebookPublic(); } @@ -188,7 +177,6 @@ public class NotebookAuthorization { saveToFile(); } - public void setWriters(String noteId, Set<String> entities) { Map<String, Set<String>> noteAuthInfo = authInfo.get(noteId); entities = validateUser(entities); @@ -206,8 +194,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>(); @@ -289,24 +277,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) { @@ -334,7 +322,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"); @@ -345,7 +333,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"); @@ -378,14 +366,17 @@ 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/55f6c91c/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 629e400..2227842 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,14 +18,11 @@ 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/55f6c91c/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 01ebec6..f5a62c4 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,12 +16,9 @@ */ package org.apache.zeppelin.notebook; -import org.apache.zeppelin.interpreter.InterpreterSetting; - -/** - * Notebook event - */ +/** 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/55f6c91c/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 0b8eed8..bd34f80 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,7 +21,6 @@ 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; @@ -29,27 +28,29 @@ 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/55f6c91c/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 87dc5fd..37bc77c 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,6 +17,9 @@ 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; @@ -30,7 +33,6 @@ 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; @@ -44,7 +46,6 @@ 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; @@ -65,15 +66,9 @@ import org.apache.zeppelin.user.UserCredentials; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -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 { +/** 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 = @@ -92,8 +87,9 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> implemen // 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; @@ -104,14 +100,13 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> implemen 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; @@ -198,8 +193,8 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> implemen 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) { @@ -214,10 +209,14 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> implemen 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 = ""; @@ -271,8 +270,8 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> implemen } 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) { @@ -369,8 +368,7 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> implemen 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); @@ -379,16 +377,20 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> implemen @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(); } @@ -419,7 +421,7 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> implemen 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)); @@ -489,40 +491,42 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> implemen 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) { @@ -536,8 +540,7 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> implemen Credentials credentials = note.getCredentials(); if (subject != null) { - UserCredentials userCredentials = - credentials.getUserCredentials(subject.getUser()); + UserCredentials userCredentials = credentials.getUserCredentials(subject.getUser()); subject.setUserCredentials(userCredentials); } @@ -600,7 +603,6 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> implemen } } - public ApplicationState getApplicationState(String appId) { synchronized (apps) { for (ApplicationState as : apps) { @@ -619,8 +621,8 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> implemen } } - 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(); @@ -642,15 +644,16 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> implemen 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<>(); } @@ -705,8 +708,9 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> implemen 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) { @@ -716,9 +720,7 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> implemen return false; } - return results != null ? - results.equals(paragraph.results) : paragraph.results == null; - + return results != null ? results.equals(paragraph.results) : paragraph.results == null; } @Override @@ -742,5 +744,4 @@ public class Paragraph extends JobWithProgressPoller<InterpreterResult> implemen public static Paragraph fromJson(String json) { return Note.getGson().fromJson(json, Paragraph.class); } - } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/55f6c91c/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 8743fb7..a721b03 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,18 +17,15 @@ package org.apache.zeppelin.notebook; -import org.apache.zeppelin.interpreter.InterpreterOutput; +import java.util.List; import org.apache.zeppelin.interpreter.InterpreterResultMessage; -import org.apache.zeppelin.interpreter.InterpreterResultMessageOutput; import org.apache.zeppelin.scheduler.JobListener; -import java.util.List; - -/** - * Listen paragraph update - */ +/** 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/55f6c91c/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 0042023..eb1f872 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,21 +3,18 @@ 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"); } @@ -32,7 +29,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/55f6c91c/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 33dce22..78c58cc 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,5 +31,4 @@ public class ParagraphWithRuntimeInfo extends Paragraph { super(p); this.runtimeInfos = p.getRuntimeInfos(); } - }
