From c4c891834f7cc329f806d6a608db5ce5f421ec11 Mon Sep 17 00:00:00 2001 From: Philipp Dallig Date: Wed, 4 Sep 2024 17:58:10 +0200 Subject: [PATCH] Remove raw types for AngularObject --- .../zeppelin/shell/BaseInterpreterTest.java | 6 +- .../integration/ZeppelinSparkClusterTest.java | 4 +- .../zeppelin/display/AngularObject.java | 28 +++--- .../display/AngularObjectListener.java | 4 +- .../display/AngularObjectRegistry.java | 85 +++++++++---------- .../AngularObjectRegistryListener.java | 8 +- .../zeppelin/helium/ApplicationLoader.java | 6 +- .../HeliumAppAngularObjectRegistry.java | 8 +- .../apache/zeppelin/helium/HeliumPackage.java | 2 +- .../InvokeResourceMethodEventMessage.java | 15 ++-- .../remote/RemoteInterpreterServer.java | 8 +- .../display/AngularObjectRegistryTest.java | 26 +++--- .../zeppelin/display/AngularObjectTest.java | 48 +++++------ .../zeppelin/service/JobManagerService.java | 6 -- .../zeppelin/service/NotebookService.java | 8 +- .../service/SessionManagerService.java | 7 +- .../zeppelin/socket/NotebookServer.java | 68 ++++++--------- .../zeppelin/socket/NotebookServerTest.java | 34 ++++---- .../RemoteInterpreterEventServer.java | 7 +- .../remote/RemoteAngularObject.java | 5 +- .../remote/RemoteAngularObjectRegistry.java | 10 +-- .../interpreter/remote/RemoteInterpreter.java | 4 +- .../org/apache/zeppelin/notebook/Note.java | 20 ++--- .../apache/zeppelin/notebook/Notebook.java | 15 ++-- .../apache/zeppelin/notebook/NoteTest.java | 3 +- .../zeppelin/notebook/ParagraphTest.java | 4 +- 26 files changed, 200 insertions(+), 239 deletions(-) diff --git a/shell/src/test/java/org/apache/zeppelin/shell/BaseInterpreterTest.java b/shell/src/test/java/org/apache/zeppelin/shell/BaseInterpreterTest.java index 35b6934ec14..41f61d4a4af 100644 --- a/shell/src/test/java/org/apache/zeppelin/shell/BaseInterpreterTest.java +++ b/shell/src/test/java/org/apache/zeppelin/shell/BaseInterpreterTest.java @@ -49,19 +49,19 @@ protected InterpreterContext getIntpContext() { @Override public void onAddAngularObject(String interpreterGroupId, - AngularObject angularObject) { + AngularObject angularObject) { onAdd.incrementAndGet(); } @Override public void onUpdateAngularObject(String interpreterGroupId, - AngularObject angularObject) { + AngularObject angularObject) { onUpdate.incrementAndGet(); } @Override public void onRemoveAngularObject(String interpreterGroupId, - AngularObject angularObject) { + AngularObject angularObject) { onRemove.incrementAndGet(); } }); diff --git a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ZeppelinSparkClusterTest.java b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ZeppelinSparkClusterTest.java index d3c087f313a..b0423382903 100644 --- a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ZeppelinSparkClusterTest.java +++ b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ZeppelinSparkClusterTest.java @@ -799,7 +799,7 @@ public void testAngularObjects() throws IOException, InterpreterNotFoundExceptio note.run(p1.getId(), true); assertEquals(Status.FINISHED, p1.getStatus()); // angular object is saved to InterpreterGroup's AngularObjectRegistry - List angularObjects; + List> angularObjects; try { angularObjects = p1.getBindedInterpreter().getInterpreterGroup() .getAngularObjectRegistry().getAll(note.getId(), null); @@ -848,7 +848,7 @@ public void testAngularObjects() throws IOException, InterpreterNotFoundExceptio p3.setText("%spark z.angularBindGlobal(\"name2\", \"world2\")"); note.run(p3.getId(), true); assertEquals(Status.FINISHED, p3.getStatus()); - List globalAngularObjects; + List> globalAngularObjects; try { globalAngularObjects = p3.getBindedInterpreter().getInterpreterGroup() .getAngularObjectRegistry().getAll(null, null); diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/display/AngularObject.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/display/AngularObject.java index a2393b32a35..1dc845bc155 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/display/AngularObject.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/display/AngularObject.java @@ -42,7 +42,7 @@ public class AngularObject implements JsonSerializable { private String name; private T object; - private transient AngularObjectListener listener; + private transient AngularObjectListener listener; private transient List watchers = new LinkedList<>(); private String noteId; // noteId belonging to. null for global scope @@ -67,7 +67,7 @@ public AngularObject() { * @param listener event listener */ public AngularObject(String name, T o, String noteId, String paragraphId, - AngularObjectListener listener) { + AngularObjectListener listener) { this.name = name; this.noteId = noteId; this.paragraphId = paragraphId; @@ -178,7 +178,6 @@ public void set(T o, boolean emit) { emit(); } LOGGER.debug("Update angular object: {} with value: {}", name, o); - final Logger LOGGER = LoggerFactory.getLogger(AngularObject.class); List ws = new LinkedList<>(); synchronized (watchers) { ws.addAll(watchers); @@ -186,16 +185,14 @@ public void set(T o, boolean emit) { ExecutorService executor = ExecutorFactory.singleton().createOrGet("angularObjectWatcher", 50); for (final AngularObjectWatcher w : ws) { - executor.submit(new Runnable() { - @Override - public void run() { - try { - w.watch(before, after); - } catch (Exception e) { - LOGGER.error("Exception on watch", e); - } + Runnable task = () -> { + try { + w.watch(before, after); + } catch (Exception e) { + LOGGER.error("Exception on watch", e); } - }); + }; + executor.submit(task); } } @@ -203,7 +200,7 @@ public void run() { * Set event listener for this object * @param listener */ - public void setListener(AngularObjectListener listener) { + public void setListener(AngularObjectListener listener) { this.listener = listener; } @@ -211,7 +208,7 @@ public void setListener(AngularObjectListener listener) { * Get event listener of this object * @return event listener */ - public AngularObjectListener getListener() { + public AngularObjectListener getListener() { return listener; } @@ -262,7 +259,8 @@ public String toJson() { return GSON.toJson(this); } - public static AngularObject fromJson(String json) { + @SuppressWarnings("unchecked") + public static AngularObject fromJson(String json) { return GSON.fromJson(json, AngularObject.class); } } diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/display/AngularObjectListener.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/display/AngularObjectListener.java index 20f34af0e37..4539e4f27ad 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/display/AngularObjectListener.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/display/AngularObjectListener.java @@ -20,6 +20,6 @@ /** * */ -public interface AngularObjectListener { - void updated(AngularObject updatedObject); +public interface AngularObjectListener { + void updated(AngularObject updatedObject); } diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/display/AngularObjectRegistry.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/display/AngularObjectRegistry.java index 54d9814f714..875d1af259e 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/display/AngularObjectRegistry.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/display/AngularObjectRegistry.java @@ -21,6 +21,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Map.Entry; /** * AngularObjectRegistry keeps all the object that binded to Angular Display System. @@ -31,24 +32,22 @@ * - Global scope : Shared to all notebook that uses the same interpreter group */ public class AngularObjectRegistry { - Map> registry = new HashMap<>(); - private final String GLOBAL_KEY = "_GLOBAL_"; + Map>> registry = new HashMap<>(); + private static final String GLOBAL_KEY = "_GLOBAL_"; private AngularObjectRegistryListener listener; private String interpreterGroupId; - private AngularObjectListener angularObjectListener; + private AngularObjectListener angularObjectListener; public AngularObjectRegistry(final String interpreterGroupId, final AngularObjectRegistryListener listener) { this.interpreterGroupId = interpreterGroupId; this.listener = listener; - angularObjectListener = new AngularObjectListener() { - @Override - public void updated(AngularObject updatedObject) { - if (listener != null) { - listener.onUpdateAngularObject(interpreterGroupId, updatedObject); - } + angularObjectListener = (AngularObject updatedObject) -> { + if (listener != null) { + listener.onUpdateAngularObject(interpreterGroupId, updatedObject); } }; + } public AngularObjectRegistryListener getListener() { @@ -68,7 +67,7 @@ public AngularObjectRegistryListener getListener() { * @param paragraphId paragraphId belongs to. null for notebook scope * @return AngularObject that added */ - public AngularObject add(String name, Object o, String noteId, String paragraphId) { + public AngularObject add(String name, Object o, String noteId, String paragraphId) { return add(name, o, noteId, paragraphId, true); } @@ -83,15 +82,11 @@ private String getRegistryKey(String noteId, String paragraphId) { } } } - - private Map getRegistryForKey(String noteId, String paragraphId) { + + private Map> getRegistryForKey(String noteId, String paragraphId) { synchronized (registry) { String key = getRegistryKey(noteId, paragraphId); - if (!registry.containsKey(key)) { - registry.put(key, new HashMap()); - } - - return registry.get(key); + return registry.computeIfAbsent(key, k -> new HashMap<>()); } } @@ -109,12 +104,12 @@ private Map getRegistryForKey(String noteId, String parag * @param emit skip firing onAdd event on false * @return AngularObject that added */ - public AngularObject add(String name, Object o, String noteId, String paragraphId, + public AngularObject add(String name, Object o, String noteId, String paragraphId, boolean emit) { - AngularObject ao = createNewAngularObject(name, o, noteId, paragraphId); + AngularObject ao = createNewAngularObject(name, o, noteId, paragraphId); synchronized (registry) { - Map noteLocalRegistry = getRegistryForKey(noteId, paragraphId); + Map> noteLocalRegistry = getRegistryForKey(noteId, paragraphId); noteLocalRegistry.put(name, ao); if (listener != null && emit) { listener.onAddAngularObject(interpreterGroupId, ao); @@ -124,12 +119,12 @@ public AngularObject add(String name, Object o, String noteId, String paragraphI return ao; } - protected AngularObject createNewAngularObject(String name, Object o, String noteId, + protected AngularObject createNewAngularObject(String name, Object o, String noteId, String paragraphId) { - return new AngularObject(name, o, noteId, paragraphId, angularObjectListener); + return new AngularObject<>(name, o, noteId, paragraphId, angularObjectListener); } - protected AngularObjectListener getAngularObjectListener() { + protected AngularObjectListener getAngularObjectListener() { return angularObjectListener; } @@ -141,7 +136,7 @@ protected AngularObjectListener getAngularObjectListener() { * @param paragraphId paragraphId belongs to. null for notebook scope * @return removed object. null if object is not found in registry */ - public AngularObject remove(String name, String noteId, String paragraphId) { + public AngularObject remove(String name, String noteId, String paragraphId) { return remove(name, noteId, paragraphId, true); } @@ -154,10 +149,10 @@ public AngularObject remove(String name, String noteId, String paragraphId) { * @param emit skip fireing onRemove event on false * @return removed object. null if object is not found in registry */ - public AngularObject remove(String name, String noteId, String paragraphId, boolean emit) { + public AngularObject remove(String name, String noteId, String paragraphId, boolean emit) { synchronized (registry) { - Map r = getRegistryForKey(noteId, paragraphId); - AngularObject o = r.remove(name); + Map> r = getRegistryForKey(noteId, paragraphId); + AngularObject o = r.remove(name); if (listener != null && emit) { listener.onRemoveAngularObject(interpreterGroupId, o); } @@ -177,8 +172,8 @@ public AngularObject remove(String name, String noteId, String paragraphId, bool */ public void removeAll(String noteId, String paragraphId) { synchronized (registry) { - List all = getAll(noteId, paragraphId); - for (AngularObject ao : all) { + List> all = getAll(noteId, paragraphId); + for (AngularObject ao : all) { remove(ao.getName(), noteId, paragraphId); } } @@ -191,9 +186,9 @@ public void removeAll(String noteId, String paragraphId) { * @param paragraphId paragraphId that belongs to * @return angularobject. null when not found */ - public AngularObject get(String name, String noteId, String paragraphId) { + public AngularObject get(String name, String noteId, String paragraphId) { synchronized (registry) { - Map r = getRegistryForKey(noteId, paragraphId); + Map> r = getRegistryForKey(noteId, paragraphId); return r.get(name); } } @@ -204,17 +199,17 @@ public AngularObject get(String name, String noteId, String paragraphId) { * @param paragraphId paragraphId that belongs to * @return all angularobject in the scope */ - public List getAll(String noteId, String paragraphId) { - List all = new LinkedList<>(); + public List> getAll(String noteId, String paragraphId) { + List> all = new LinkedList<>(); synchronized (registry) { - Map r = getRegistryForKey(noteId, paragraphId); + Map> r = getRegistryForKey(noteId, paragraphId); if (r != null) { all.addAll(r.values()); } } return all; } - + /** * Get all angular object related to specific note. * That includes all global scope objects, notebook scope objects and paragraph scope objects @@ -223,16 +218,16 @@ public List getAll(String noteId, String paragraphId) { * @param noteId * @return */ - public List getAllWithGlobal(String noteId) { - List all = new LinkedList<>(); + public List> getAllWithGlobal(String noteId) { + List> all = new LinkedList<>(); synchronized (registry) { - Map global = getRegistryForKey(null, null); + Map> global = getRegistryForKey(null, null); if (global != null) { all.addAll(global.values()); } - for (String key : registry.keySet()) { - if (key.startsWith(noteId)) { - all.addAll(registry.get(key).values()); + for (Entry>> registryEntry : registry.entrySet()) { + if (registryEntry.getKey().startsWith(noteId)) { + all.addAll(registryEntry.getValue().values()); } } } @@ -243,14 +238,14 @@ public String getInterpreterGroupId() { return interpreterGroupId; } - public Map> getRegistry() { + public Map>> getRegistry() { return registry; } - public void setRegistry(Map> registry) { + public void setRegistry(Map>> registry) { this.registry = registry; - for (Map map : registry.values()) { - for (AngularObject ao : map.values()) { + for (Map> map : registry.values()) { + for (AngularObject ao : map.values()) { ao.setListener(angularObjectListener); } } diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/display/AngularObjectRegistryListener.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/display/AngularObjectRegistryListener.java index 77350b6055f..6230fc52c9a 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/display/AngularObjectRegistryListener.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/display/AngularObjectRegistryListener.java @@ -22,7 +22,9 @@ * Listener class for angular object operations, such as add, update, remove. */ public interface AngularObjectRegistryListener { - void onAddAngularObject(String interpreterGroupId, AngularObject angularObject); - void onUpdateAngularObject(String interpreterGroupId, AngularObject angularObject); - void onRemoveAngularObject(String interpreterGroupId, AngularObject angularObject); + void onAddAngularObject(String interpreterGroupId, AngularObject angularObject); + + void onUpdateAngularObject(String interpreterGroupId, AngularObject angularObject); + + void onRemoveAngularObject(String interpreterGroupId, AngularObject angularObject); } diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/helium/ApplicationLoader.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/helium/ApplicationLoader.java index 7ba68c60d21..1bdf958d81e 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/helium/ApplicationLoader.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/helium/ApplicationLoader.java @@ -21,8 +21,6 @@ import org.apache.zeppelin.resource.Resource; import org.apache.zeppelin.resource.ResourcePool; import org.apache.zeppelin.resource.ResourceSet; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.File; import java.lang.reflect.Constructor; @@ -38,7 +36,6 @@ * Load application */ public class ApplicationLoader { - private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationLoader.class); private final DependencyResolver depResolver; private final ResourcePool resourcePool; @@ -129,8 +126,7 @@ public Application load(HeliumPackage packageInfo, ApplicationContext context) try { Constructor constructor = appClass.getConstructor(ApplicationContext.class); - Application app = new ClassLoaderApplication(constructor.newInstance(context), cl); - return app; + return new ClassLoaderApplication(constructor.newInstance(context), cl); } catch (Exception e) { throw new ApplicationException(e); } finally { diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/helium/HeliumAppAngularObjectRegistry.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/helium/HeliumAppAngularObjectRegistry.java index dedb603add8..2f234145f5f 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/helium/HeliumAppAngularObjectRegistry.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/helium/HeliumAppAngularObjectRegistry.java @@ -37,19 +37,19 @@ public HeliumAppAngularObjectRegistry(AngularObjectRegistry angularObjectRegistr this.appId = appId; } - public AngularObject add(String name, Object o) { + public AngularObject add(String name, Object o) { return angularObjectRegistry.add(name, o, noteId, appId); } - public AngularObject remove(String name) { + public AngularObject remove(String name) { return angularObjectRegistry.remove(name, noteId, appId); } - public AngularObject get(String name) { + public AngularObject get(String name) { return angularObjectRegistry.get(name, noteId, appId); } - public List getAll() { + public List> getAll() { return angularObjectRegistry.getAll(noteId, appId); } } diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/helium/HeliumPackage.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/helium/HeliumPackage.java index 51b0fcbe513..cef96cb1463 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/helium/HeliumPackage.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/helium/HeliumPackage.java @@ -22,7 +22,6 @@ import org.apache.zeppelin.common.JsonSerializable; import java.util.Arrays; -import java.util.HashMap; import java.util.Map; import java.util.Optional; @@ -141,6 +140,7 @@ public SpellPackageInfo getSpellInfo() { public Map getConfig() { return config; } + @Override public String toJson() { return gson.toJson(this); } diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/InvokeResourceMethodEventMessage.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/InvokeResourceMethodEventMessage.java index aaf3d7b0e71..1663780ddf0 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/InvokeResourceMethodEventMessage.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/InvokeResourceMethodEventMessage.java @@ -35,7 +35,7 @@ public class InvokeResourceMethodEventMessage implements JsonSerializable { public InvokeResourceMethodEventMessage( ResourceId resourceId, String methodName, - Class[] paramtypes, + Class[] paramtypes, Object[] params, String returnResourceName ) { @@ -54,12 +54,12 @@ public InvokeResourceMethodEventMessage( this.returnResourceName = returnResourceName; } - public Class [] getParamTypes() throws ClassNotFoundException { + public Class[] getParamTypes() throws ClassNotFoundException { if (paramClassnames == null) { return null; } - Class [] types = new Class[paramClassnames.length]; + Class[] types = new Class[paramClassnames.length]; for (int i = 0; i < paramClassnames.length; i++) { types[i] = this.getClass().getClassLoader().loadClass(paramClassnames[i]); } @@ -73,17 +73,17 @@ public boolean shouldPutResultIntoResourcePool() { @Override public int hashCode() { - String hash = resourceId.hashCode() + methodName; + StringBuilder hash = new StringBuilder(resourceId.hashCode() + methodName); if (paramClassnames != null) { for (String name : paramClassnames) { - hash += name; + hash.append(name); } } if (returnResourceName != null) { - hash += returnResourceName; + hash.append(returnResourceName); } - return hash.hashCode(); + return hash.toString().hashCode(); } @Override @@ -96,6 +96,7 @@ public boolean equals(Object o) { } } + @Override public String toJson() { return gson.toJson(this); } diff --git a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterServer.java b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterServer.java index 6ef35eec74a..dc3838d3a3d 100644 --- a/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterServer.java +++ b/zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreterServer.java @@ -1129,7 +1129,7 @@ public void angularObjectUpdate(String name, String noteId, String paragraphId, throws InterpreterRPCException, TException{ AngularObjectRegistry registry = interpreterGroup.getAngularObjectRegistry(); // first try local objects - AngularObject ao = registry.get(name, noteId, paragraphId); + AngularObject ao = registry.get(name, noteId, paragraphId); if (ao == null) { LOGGER.debug("Angular object {} not exists", name); return; @@ -1182,7 +1182,7 @@ public void angularObjectAdd(String name, String noteId, String paragraphId, Str throws InterpreterRPCException, TException{ AngularObjectRegistry registry = interpreterGroup.getAngularObjectRegistry(); // first try local objects - AngularObject ao = registry.get(name, noteId, paragraphId); + AngularObject ao = registry.get(name, noteId, paragraphId); if (ao != null) { angularObjectUpdate(name, noteId, paragraphId, object); return; @@ -1307,9 +1307,9 @@ public ByteBuffer resourceInvokeMethod( @Override public void angularRegistryPush(String registryAsString) throws InterpreterRPCException, TException { try { - Map> deserializedRegistry = gson + Map>> deserializedRegistry = gson .fromJson(registryAsString, - new TypeToken>>() { + new TypeToken>>>() { }.getType()); interpreterGroup.getAngularObjectRegistry().setRegistry(deserializedRegistry); } catch (Exception e) { diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/display/AngularObjectRegistryTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/display/AngularObjectRegistryTest.java index a271117d09f..c68aea57f1a 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/display/AngularObjectRegistryTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/display/AngularObjectRegistryTest.java @@ -38,17 +38,17 @@ void testBasic() throws TException { new AngularObjectRegistryListener() { @Override - public void onAddAngularObject(String interpreterGroupId, AngularObject angularObject) { + public void onAddAngularObject(String interpreterGroupId, AngularObject angularObject) { onAdd.incrementAndGet(); } @Override - public void onUpdateAngularObject(String interpreterGroupId, AngularObject angularObject) { + public void onUpdateAngularObject(String interpreterGroupId, AngularObject angularObject) { onUpdate.incrementAndGet(); } @Override - public void onRemoveAngularObject(String interpreterGroupId, AngularObject angularObject) { + public void onRemoveAngularObject(String interpreterGroupId, AngularObject angularObject) { onRemove.incrementAndGet(); } }); @@ -80,11 +80,11 @@ public void onRemoveAngularObject(String interpreterGroupId, AngularObject angul @Test void testGetDependOnScope() throws TException { AngularObjectRegistry registry = new AngularObjectRegistry("intpId", null); - AngularObject ao1 = registry.add("name1", "o1", "noteId1", "paragraphId1"); - AngularObject ao2 = registry.add("name2", "o2", "noteId1", "paragraphId1"); - AngularObject ao3 = registry.add("name2", "o3", "noteId1", "paragraphId2"); - AngularObject ao4 = registry.add("name3", "o4", "noteId1", null); - AngularObject ao5 = registry.add("name4", "o5", null, null); + registry.add("name1", "o1", "noteId1", "paragraphId1"); + registry.add("name2", "o2", "noteId1", "paragraphId1"); + registry.add("name2", "o3", "noteId1", "paragraphId2"); + registry.add("name3", "o4", "noteId1", null); + registry.add("name4", "o5", null, null); assertNull(registry.get("name3", "noteId1", "paragraphId1")); @@ -99,11 +99,11 @@ void testGetDependOnScope() throws TException { @Test void testGetAllDependOnScope() throws TException { AngularObjectRegistry registry = new AngularObjectRegistry("intpId", null); - AngularObject ao1 = registry.add("name1", "o", "noteId1", "paragraphId1"); - AngularObject ao2 = registry.add("name2", "o", "noteId1", "paragraphId1"); - AngularObject ao3 = registry.add("name2", "o", "noteId1", "paragraphId2"); - AngularObject ao4 = registry.add("name3", "o", "noteId1", null); - AngularObject ao5 = registry.add("name4", "o", null, null); + registry.add("name1", "o", "noteId1", "paragraphId1"); + registry.add("name2", "o", "noteId1", "paragraphId1"); + registry.add("name2", "o", "noteId1", "paragraphId2"); + registry.add("name3", "o", "noteId1", null); + registry.add("name4", "o", null, null); assertEquals(2, registry.getAll("noteId1", "paragraphId1").size()); assertEquals(1, registry.getAll("noteId1", "paragraphId2").size()); diff --git a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/display/AngularObjectTest.java b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/display/AngularObjectTest.java index 4e86d495269..f561101d929 100644 --- a/zeppelin-interpreter/src/test/java/org/apache/zeppelin/display/AngularObjectTest.java +++ b/zeppelin-interpreter/src/test/java/org/apache/zeppelin/display/AngularObjectTest.java @@ -31,48 +31,48 @@ class AngularObjectTest { @Test void testEquals() { assertEquals( - new AngularObject("name", "value", "note1", null, null), - new AngularObject("name", "value", "note1", null, null) + new AngularObject("name", "value", "note1", null, null), + new AngularObject("name", "value", "note1", null, null) ); assertEquals( - new AngularObject("name", "value", "note1", "paragraph1", null), - new AngularObject("name", "value", "note1", "paragraph1", null) + new AngularObject("name", "value", "note1", "paragraph1", null), + new AngularObject("name", "value", "note1", "paragraph1", null) ); assertEquals( - new AngularObject("name", "value", null, null, null), - new AngularObject("name", "value", null, null, null) + new AngularObject("name", "value", null, null, null), + new AngularObject("name", "value", null, null, null) ); assertEquals( - new AngularObject("name", "value1", null, null, null), - new AngularObject("name", "value2", null, null, null) + new AngularObject("name", "value1", null, null, null), + new AngularObject("name", "value2", null, null, null) ); assertNotSame( - new AngularObject("name1", "value", null, null, null), - new AngularObject("name2", "value", null, null, null) + new AngularObject("name1", "value", null, null, null), + new AngularObject("name2", "value", null, null, null) ); assertNotSame( - new AngularObject("name1", "value", "note1", null, null), - new AngularObject("name2", "value", "note2", null, null) + new AngularObject("name1", "value", "note1", null, null), + new AngularObject("name2", "value", "note2", null, null) ); assertNotSame( - new AngularObject("name1", "value", "note", null, null), - new AngularObject("name2", "value", null, null, null) + new AngularObject("name1", "value", "note", null, null), + new AngularObject("name2", "value", null, null, null) ); assertNotSame( - new AngularObject("name", "value", "note", "paragraph1", null), - new AngularObject("name", "value", "note", "paragraph2", null) + new AngularObject("name", "value", "note", "paragraph1", null), + new AngularObject("name", "value", "note", "paragraph2", null) ); assertNotSame( - new AngularObject("name", "value", "note1", null, null), - new AngularObject("name", "value", "note1", "paragraph1", null) + new AngularObject("name", "value", "note1", null, null), + new AngularObject("name", "value", "note1", "paragraph1", null) ); @@ -81,11 +81,11 @@ void testEquals() { @Test void testListener() throws TException { final AtomicInteger updated = new AtomicInteger(0); - AngularObject ao = new AngularObject("name", "value", "note1", null, - new AngularObjectListener() { + AngularObject ao = new AngularObject<>("name", "value", "note1", null, + new AngularObjectListener() { @Override - public void updated(AngularObject updatedObject) { + public void updated(AngularObject updatedObject) { updated.incrementAndGet(); } }); @@ -107,10 +107,10 @@ public void updated(AngularObject updatedObject) { void testWatcher() throws InterruptedException, TException { final AtomicInteger updated = new AtomicInteger(0); final AtomicInteger onWatch = new AtomicInteger(0); - AngularObject ao = new AngularObject("name", "value", "note1", null, - new AngularObjectListener() { + AngularObject ao = new AngularObject<>("name", "value", "note1", null, + new AngularObjectListener() { @Override - public void updated(AngularObject updatedObject) { + public void updated(AngularObject updatedObject) { updated.incrementAndGet(); } }); diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/service/JobManagerService.java b/zeppelin-server/src/main/java/org/apache/zeppelin/service/JobManagerService.java index 0c521aa520f..1403a6b0404 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/service/JobManagerService.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/service/JobManagerService.java @@ -26,23 +26,17 @@ import org.apache.zeppelin.notebook.Notebook; import org.apache.zeppelin.notebook.Paragraph; import org.apache.zeppelin.scheduler.Job; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.io.IOException; import java.util.ArrayList; import java.util.Date; import java.util.LinkedList; import java.util.List; -import java.util.stream.Collectors; /** * Service class for JobManager Page */ public class JobManagerService { - private static final Logger LOGGER = LoggerFactory.getLogger(JobManagerService.class); - private final Notebook notebook; private final AuthorizationService authorizationService; private final ZeppelinConfiguration zConf; diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/service/NotebookService.java b/zeppelin-server/src/main/java/org/apache/zeppelin/service/NotebookService.java index dea55ac7c60..66b089254ee 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/service/NotebookService.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/service/NotebookService.java @@ -1400,11 +1400,10 @@ private Paragraph setParagraphUsingMessage(Note note, Message fromMessage, Strin public void updateAngularObject(String noteId, String paragraphId, String interpreterGroupId, String varName, Object varValue, ServiceContext context, - ServiceCallback callback) throws IOException { + ServiceCallback> callback) throws IOException { String user = context.getAutheInfo().getUser(); - AngularObject ao = null; - boolean global = false; + AngularObject ao = null; // propagate change to (Remote) AngularObjectRegistry List settings = notebook.processNote(noteId, note -> { @@ -1436,16 +1435,13 @@ public void updateAngularObject(String noteId, String paragraphId, String interp } else { // path from client -> server ao.set(varValue, false); - global = true; } } else { // path from client -> server ao.set(varValue, false); - global = false; } } else { ao.set(varValue, false); - global = false; } break; } diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/service/SessionManagerService.java b/zeppelin-server/src/main/java/org/apache/zeppelin/service/SessionManagerService.java index 0aa096a847c..6d55eeafe10 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/service/SessionManagerService.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/service/SessionManagerService.java @@ -19,11 +19,9 @@ package org.apache.zeppelin.service; import org.apache.zeppelin.conf.ZeppelinConfiguration; -import org.apache.zeppelin.interpreter.InterpreterGroup; import org.apache.zeppelin.interpreter.InterpreterSettingManager; import org.apache.zeppelin.interpreter.ManagedInterpreterGroup; import org.apache.zeppelin.interpreter.remote.RemoteInterpreterProcess; -import org.apache.zeppelin.notebook.Note; import org.apache.zeppelin.notebook.Notebook; import org.apache.zeppelin.common.SessionInfo; import org.apache.zeppelin.scheduler.ExecutorFactory; @@ -53,16 +51,13 @@ public class SessionManagerService { private final InterpreterSettingManager interpreterSettingManager; private final Notebook notebook; private final ScheduledExecutorService sessionCheckerExecutor; - private final ZeppelinConfiguration zConf; public SessionManagerService(Notebook notebook, InterpreterSettingManager interpreterSettingManager, ZeppelinConfiguration zConf) { this.notebook = notebook; this.interpreterSettingManager = interpreterSettingManager; - this.zConf = zConf; this.sessionCheckerExecutor = ExecutorFactory.singleton().createOrGetScheduled("Session-Checker-Executor", 1); - int sessionCheckerInterval = - zConf.getInt(ZeppelinConfiguration.ConfVars.ZEPPELIN_SESSION_CHECK_INTERVAL); + int sessionCheckerInterval = zConf.getInt(ZeppelinConfiguration.ConfVars.ZEPPELIN_SESSION_CHECK_INTERVAL); this.sessionCheckerExecutor.scheduleAtFixedRate(() -> { LOGGER.info("Start session check task"); Iterator> iter = sessions.entrySet().iterator(); diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java b/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java index d6a8b079fc6..74c89bc8653 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java @@ -43,7 +43,6 @@ import javax.inject.Inject; import javax.inject.Provider; import javax.websocket.CloseReason; -import javax.websocket.Endpoint; import javax.websocket.EndpointConfig; import javax.websocket.OnClose; import javax.websocket.OnError; @@ -282,15 +281,14 @@ public void onMessage(NotebookSocket conn, String msg) { try { Message receivedMessage = deserializeMessage(msg); if (receivedMessage.op != OP.PING) { - LOGGER.debug("RECEIVE: " + receivedMessage.op + - ", RECEIVE PRINCIPAL: " + receivedMessage.principal + - ", RECEIVE TICKET: " + receivedMessage.ticket + - ", RECEIVE ROLES: " + receivedMessage.roles + - ", RECEIVE DATA: " + receivedMessage.data); - } - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("RECEIVE MSG = " + receivedMessage); + LOGGER.debug("RECEIVE: {}, RECEIVE PRINCIPAL: {}, RECEIVE TICKET: {}, RECEIVE ROLES: {}, RECEIVE DATA: {}", + receivedMessage.op, + receivedMessage.principal, + receivedMessage.ticket, + receivedMessage.roles, + receivedMessage.data); } + LOGGER.trace("RECEIVE MSG = {}", receivedMessage); TicketContainer.Entry ticketEntry = TicketContainer.instance.getTicketEntry(receivedMessage.principal); if (ticketEntry == null || StringUtils.isEmpty(ticketEntry.getTicket())) { @@ -854,21 +852,6 @@ void permissionError(NotebookSocket conn, String op, String userName, Set userAndRoles, - String principal, String op) - throws IOException { - if (!authorizationService.isWriter(noteId, userAndRoles)) { - permissionError(conn, op, principal, userAndRoles, authorizationService.getOwners(noteId)); - return false; - } - - return true; - } - private void getNote(NotebookSocket conn, ServiceContext context, Message fromMessage) throws IOException { String noteId = (String) fromMessage.get("id"); if (noteId == null) { @@ -924,8 +907,8 @@ private void updateAngularObjectRegistry(NotebookSocket conn, Note note) { RemoteAngularObjectRegistry registry = (RemoteAngularObjectRegistry) interpreterGroup.getAngularObjectRegistry(); - List angularObjects = note.getAngularObjects(interpreterGroup.getId()); - for (AngularObject ao : angularObjects) { + List> angularObjects = note.getAngularObjects(interpreterGroup.getId()); + for (AngularObject ao : angularObjects) { if (StringUtils.equals(ao.getNoteId(), note.getId()) && StringUtils.equals(ao.getParagraphId(), paragraph.getId())) { pushAngularObjectToRemoteRegistry(ao.getNoteId(), ao.getParagraphId(), @@ -1388,13 +1371,12 @@ private void angularObjectUpdated(NotebookSocket conn, String interpreterGroupId = (String) fromMessage.get("interpreterGroupId"); String varName = (String) fromMessage.get("name"); Object varValue = fromMessage.get("value"); - String user = fromMessage.principal; getNotebookService().updateAngularObject(noteId, paragraphId, interpreterGroupId, varName, varValue, context, - new WebSocketServiceCallback(conn) { + new WebSocketServiceCallback>(conn) { @Override - public void onSuccess(AngularObject ao, ServiceContext context) throws IOException { + public void onSuccess(AngularObject ao, ServiceContext context) throws IOException { super.onSuccess(ao, context); connectionManager.broadcastExcept(noteId, new Message( @@ -1439,7 +1421,7 @@ protected void angularObjectClientBind(NotebookSocket conn, Message fromMessage) } final RemoteAngularObjectRegistry registry = (RemoteAngularObjectRegistry) interpreterGroup.getAngularObjectRegistry(); - AngularObject ao = pushAngularObjectToRemoteRegistry(noteId, paragraphId, varName, varValue, + AngularObject ao = pushAngularObjectToRemoteRegistry(noteId, paragraphId, varName, varValue, registry, interpreterGroup.getId(), conn); note.addOrUpdateAngularObject(interpreterGroup.getId(), ao); } @@ -1473,8 +1455,7 @@ protected void angularObjectClientUnbind(NotebookSocket conn, Message fromMessag } final RemoteAngularObjectRegistry registry = (RemoteAngularObjectRegistry) interpreterGroup.getAngularObjectRegistry(); - AngularObject ao = - removeAngularFromRemoteRegistry(noteId, paragraphId, varName, registry, interpreterGroup.getId(), conn); + removeAngularFromRemoteRegistry(noteId, paragraphId, varName, registry, interpreterGroup.getId(), conn); note.deleteAngularObject(interpreterGroup.getId(), noteId, paragraphId, varName); } return null; @@ -1489,12 +1470,12 @@ private InterpreterGroup findInterpreterGroupForParagraph(Note note, String para return paragraph.getBindedInterpreter().getInterpreterGroup(); } - private AngularObject pushAngularObjectToRemoteRegistry(String noteId, String paragraphId, String varName, + private AngularObject pushAngularObjectToRemoteRegistry(String noteId, String paragraphId, String varName, Object varValue, RemoteAngularObjectRegistry remoteRegistry, String interpreterGroupId, NotebookSocket conn) { - final AngularObject ao = remoteRegistry.addAndNotifyRemoteProcess(varName, varValue, noteId, paragraphId); + final AngularObject ao = remoteRegistry.addAndNotifyRemoteProcess(varName, varValue, noteId, paragraphId); connectionManager.broadcastExcept(noteId, new Message(OP.ANGULAR_OBJECT_UPDATE) .put("angularObject", ao) @@ -1504,11 +1485,11 @@ private AngularObject pushAngularObjectToRemoteRegistry(String noteId, String pa return ao; } - private AngularObject removeAngularFromRemoteRegistry(String noteId, String paragraphId, String varName, + private AngularObject removeAngularFromRemoteRegistry(String noteId, String paragraphId, String varName, RemoteAngularObjectRegistry remoteRegistry, String interpreterGroupId, NotebookSocket conn) { - final AngularObject ao = remoteRegistry.removeAndNotifyRemoteProcess(varName, noteId, paragraphId); + final AngularObject ao = remoteRegistry.removeAndNotifyRemoteProcess(varName, noteId, paragraphId); connectionManager.broadcastExcept(noteId, new Message(OP.ANGULAR_OBJECT_REMOVE) .put("angularObject", ao) .put("interpreterGroupId", interpreterGroupId).put("noteId", noteId) @@ -2142,8 +2123,8 @@ private void sendAllAngularObjects(Note note, String user, NotebookSocket conn) } AngularObjectRegistry registry = intpSetting.getInterpreterGroup(user, note.getId()).getAngularObjectRegistry(); - List objects = registry.getAllWithGlobal(note.getId()); - for (AngularObject object : objects) { + List> objects = registry.getAllWithGlobal(note.getId()); + for (AngularObject object : objects) { conn.send(serializeMessage( new Message(OP.ANGULAR_OBJECT_UPDATE).put("angularObject", object) .put("interpreterGroupId", @@ -2157,12 +2138,12 @@ private void sendAllAngularObjects(Note note, String user, NotebookSocket conn) } @Override - public void onAddAngularObject(String interpreterGroupId, AngularObject angularObject) { + public void onAddAngularObject(String interpreterGroupId, AngularObject angularObject) { onUpdateAngularObject(interpreterGroupId, angularObject); } @Override - public void onUpdateAngularObject(String interpreterGroupId, AngularObject angularObject) { + public void onUpdateAngularObject(String interpreterGroupId, AngularObject angularObject) { if (getNotebook() == null) { return; } @@ -2189,7 +2170,8 @@ public void onUpdateAngularObject(String interpreterGroupId, AngularObject angul } } - private void updateNoteAngularObject(String noteId, AngularObject angularObject, String interpreterGroupId) throws IOException { + private void updateNoteAngularObject(String noteId, AngularObject angularObject, String interpreterGroupId) + throws IOException { List intpSettings = getNotebook(). processNote(noteId, note -> note.getBindedInterpreterSettings(new ArrayList<>(authorizationService.getOwners(note.getId())))); if (intpSettings.isEmpty()) { @@ -2202,7 +2184,7 @@ private void updateNoteAngularObject(String noteId, AngularObject angularObject, } @Override - public void onRemoveAngularObject(String interpreterGroupId, AngularObject angularObject) { + public void onRemoveAngularObject(String interpreterGroupId, AngularObject angularObject) { // not global scope, so we just need to load the corresponded note. if (angularObject.getNoteId() != null) { String noteId = angularObject.getNoteId(); @@ -2218,7 +2200,7 @@ public void onRemoveAngularObject(String interpreterGroupId, AngularObject angul } } - private void removeNoteAngularObject(String noteId, AngularObject angularObject, String interpreterGroupId) { + private void removeNoteAngularObject(String noteId, AngularObject angularObject, String interpreterGroupId) { List settingIds = getNotebook().getInterpreterSettingManager().getSettingIds(); for (String id : settingIds) { diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/socket/NotebookServerTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/socket/NotebookServerTest.java index 3eaf74d6835..6e77e62bc61 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/socket/NotebookServerTest.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/socket/NotebookServerTest.java @@ -48,7 +48,6 @@ import org.apache.commons.io.IOUtils; import org.apache.thrift.TException; -import org.apache.zeppelin.conf.ZeppelinConfiguration; import org.apache.zeppelin.display.AngularObject; import org.apache.zeppelin.display.AngularObjectBuilder; import org.apache.zeppelin.interpreter.InterpreterGroup; @@ -146,7 +145,7 @@ void testCollaborativeEditing() throws IOException { break; } } - + assertNotNull(createdNoteInfo); Message message = new Message(OP.GET_NOTE).put("id", createdNoteInfo.getId()); notebookServer.onMessage(sock1, message.toJson()); notebookServer.onMessage(sock2, message.toJson()); @@ -215,7 +214,7 @@ void testMakeSureNoAngularObjectBroadcastToWebsocketWhoFireTheEvent() break; } } - + assertNotNull(interpreterGroup); notebook.processNote(note1Id, note1 -> { // start interpreter process @@ -294,7 +293,7 @@ void testAngularObjectSaveToNote() break; } } - + assertNotNull(interpreterGroup); String p1Id = notebook.processNote(note1Id, note1 -> { // start interpreter process @@ -335,15 +334,17 @@ void testAngularObjectSaveToNote() .put("name", "COMMAND_TYPE") .put("value", "COMMAND_TYPE_VALUE") .put("interpreterGroupId", interpreterGroup.getId()).toJson()); - List list = notebook.processNote(note1Id, note1-> note1.getAngularObjects("angular-shared_process")); + List> list = + notebook.processNote(note1Id, note1 -> note1.getAngularObjects("angular-shared_process")); assertEquals(1, list.size()); assertEquals(note1Id, list.get(0).getNoteId()); assertEquals(p1Id, list.get(0).getParagraphId()); assertEquals("COMMAND_TYPE", list.get(0).getName()); assertEquals("COMMAND_TYPE_VALUE", list.get(0).get()); // Check if the interpreterGroup AngularObjectRegistry is updated - Map> mapRegistry = interpreterGroup.getAngularObjectRegistry().getRegistry(); - AngularObject ao = mapRegistry.get(note1Id + "_" + p1Id).get("COMMAND_TYPE"); + Map>> mapRegistry = + interpreterGroup.getAngularObjectRegistry().getRegistry(); + AngularObject ao = mapRegistry.get(note1Id + "_" + p1Id).get("COMMAND_TYPE"); assertEquals("COMMAND_TYPE", ao.getName()); assertEquals("COMMAND_TYPE_VALUE", ao.get()); @@ -363,7 +364,7 @@ void testAngularObjectSaveToNote() assertEquals("COMMAND_TYPE_VALUE_UPDATE", list.get(0).get()); // Check if the interpreterGroup AngularObjectRegistry is updated mapRegistry = interpreterGroup.getAngularObjectRegistry().getRegistry(); - AngularObject ao1 = mapRegistry.get(note1Id + "_" + p1Id).get("COMMAND_TYPE"); + AngularObject ao1 = mapRegistry.get(note1Id + "_" + p1Id).get("COMMAND_TYPE"); assertEquals("COMMAND_TYPE", ao1.getName()); assertEquals("COMMAND_TYPE_VALUE_UPDATE", ao1.get()); @@ -379,7 +380,7 @@ void testAngularObjectSaveToNote() assertEquals(0, list.size()); // Check if the interpreterGroup AngularObjectRegistry is delete mapRegistry = interpreterGroup.getAngularObjectRegistry().getRegistry(); - AngularObject ao2 = mapRegistry.get(note1Id + "_" + p1Id).get("COMMAND_TYPE"); + AngularObject ao2 = mapRegistry.get(note1Id + "_" + p1Id).get("COMMAND_TYPE"); assertNull(ao2); } finally { if (note1Id != null) { @@ -404,6 +405,7 @@ void testLoadAngularObjectFromNote() throws IOException, InterruptedException { break; } } + assertNotNull(interpreterGroup); String p1Id = notebook.processNote(note1Id, note1 -> { // start interpreter process @@ -422,7 +424,7 @@ void testLoadAngularObjectFromNote() throws IOException, InterruptedException { Thread.sleep(1000); // set note AngularObject - AngularObject ao = new AngularObject("COMMAND_TYPE", "COMMAND_TYPE_VALUE", note1Id, p1Id, null); + AngularObject ao = new AngularObject<>("COMMAND_TYPE", "COMMAND_TYPE_VALUE", note1Id, p1Id, null); notebook.processNote(note1Id, note1 -> { note1.addOrUpdateAngularObject("angular-shared_process", ao); @@ -435,7 +437,8 @@ void testLoadAngularObjectFromNote() throws IOException, InterruptedException { notebookServer.onOpen(sock1); // Check the AngularObjectRegistry of the interpreterGroup before executing GET_NOTE - Map> mapRegistry1 = interpreterGroup.getAngularObjectRegistry().getRegistry(); + Map>> mapRegistry1 = + interpreterGroup.getAngularObjectRegistry().getRegistry(); assertEquals(0, mapRegistry1.size()); // open the notebook from sockets, AngularObjectRegistry that triggers the update of the interpreterGroup @@ -443,9 +446,10 @@ void testLoadAngularObjectFromNote() throws IOException, InterruptedException { Thread.sleep(1000); // After executing GET_NOTE, check the AngularObjectRegistry of the interpreterGroup - Map> mapRegistry2 = interpreterGroup.getAngularObjectRegistry().getRegistry(); + Map>> mapRegistry2 = + interpreterGroup.getAngularObjectRegistry().getRegistry(); assertEquals(2, mapRegistry1.size()); - AngularObject ao1 = mapRegistry2.get(note1Id + "_" + p1Id).get("COMMAND_TYPE"); + AngularObject ao1 = mapRegistry2.get(note1Id + "_" + p1Id).get("COMMAND_TYPE"); assertEquals("COMMAND_TYPE", ao1.getName()); assertEquals("COMMAND_TYPE_VALUE", ao1.get()); } finally { @@ -562,7 +566,7 @@ void bindAngularObjectToRemoteForParagraphs() throws Exception { when(paragraph.getBindedInterpreter().getInterpreterGroup()).thenReturn(mdGroup); - final AngularObject ao1 = AngularObjectBuilder.build(varName, value, "noteId", + final AngularObject ao1 = AngularObjectBuilder.build(varName, value, "noteId", "paragraphId"); when(mdRegistry.addAndNotifyRemoteProcess(varName, value, "noteId", "paragraphId")) @@ -621,7 +625,7 @@ void unbindAngularObjectFromRemoteForParagraphs() throws Exception { when(paragraph.getBindedInterpreter().getInterpreterGroup()).thenReturn(mdGroup); - final AngularObject ao1 = AngularObjectBuilder.build(varName, value, "noteId", + final AngularObject ao1 = AngularObjectBuilder.build(varName, value, "noteId", "paragraphId"); when(mdRegistry.removeAndNotifyRemoteProcess(varName, "noteId", "paragraphId")).thenReturn(ao1); NotebookSocket conn = mock(NotebookSocket.class); diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/RemoteInterpreterEventServer.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/RemoteInterpreterEventServer.java index d2649ab226e..085257899fb 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/RemoteInterpreterEventServer.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/RemoteInterpreterEventServer.java @@ -49,7 +49,6 @@ import org.apache.zeppelin.interpreter.thrift.RemoteInterpreterResultMessage; import org.apache.zeppelin.interpreter.thrift.RunParagraphsEvent; import org.apache.zeppelin.interpreter.thrift.WebUrlInfo; -import org.apache.zeppelin.notebook.Note; import org.apache.zeppelin.resource.RemoteResource; import org.apache.zeppelin.resource.Resource; import org.apache.zeppelin.resource.ResourceId; @@ -286,7 +285,7 @@ public void runParagraphs(RunParagraphsEvent event) throws InterpreterRPCExcepti @Override public void addAngularObject(String intpGroupId, String json) throws InterpreterRPCException, TException { LOGGER.debug("Add AngularObject, interpreterGroupId: {}, json: {}", intpGroupId, json); - AngularObject angularObject = AngularObject.fromJson(json); + AngularObject angularObject = AngularObject.fromJson(json); InterpreterGroup interpreterGroup = interpreterSettingManager.getInterpreterGroupById(intpGroupId); if (interpreterGroup == null) { @@ -314,13 +313,13 @@ public void addAngularObject(String intpGroupId, String json) throws Interpreter @Override public void updateAngularObject(String intpGroupId, String json) throws InterpreterRPCException, TException { - AngularObject angularObject = AngularObject.fromJson(json); + AngularObject angularObject = AngularObject.fromJson(json); InterpreterGroup interpreterGroup = interpreterSettingManager.getInterpreterGroupById(intpGroupId); if (interpreterGroup == null) { throw new InterpreterRPCException("Invalid InterpreterGroupId: " + intpGroupId); } - AngularObject localAngularObject = interpreterGroup.getAngularObjectRegistry().get( + AngularObject localAngularObject = interpreterGroup.getAngularObjectRegistry().get( angularObject.getName(), angularObject.getNoteId(), angularObject.getParagraphId()); if (localAngularObject instanceof RemoteAngularObject) { // to avoid ping-pong loop diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteAngularObject.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteAngularObject.java index 62c8efd2010..fbc1c3fb3ac 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteAngularObject.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteAngularObject.java @@ -19,19 +19,18 @@ import org.apache.zeppelin.display.AngularObject; import org.apache.zeppelin.display.AngularObjectListener; -import org.apache.zeppelin.interpreter.InterpreterGroup; import org.apache.zeppelin.interpreter.ManagedInterpreterGroup; /** * Proxy for AngularObject that exists in remote interpreter process */ -public class RemoteAngularObject extends AngularObject { +public class RemoteAngularObject extends AngularObject { private transient ManagedInterpreterGroup interpreterGroup; RemoteAngularObject(String name, Object o, String noteId, String paragraphId, ManagedInterpreterGroup interpreterGroup, - AngularObjectListener listener) { + AngularObjectListener listener) { super(name, o, noteId, paragraphId, listener); this.interpreterGroup = interpreterGroup; } diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteAngularObjectRegistry.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteAngularObjectRegistry.java index f4f77f45162..c285872bc59 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteAngularObjectRegistry.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteAngularObjectRegistry.java @@ -51,7 +51,7 @@ private RemoteInterpreterProcess getRemoteInterpreterProcess() { * @param noteId * @return */ - public AngularObject addAndNotifyRemoteProcess(final String name, + public AngularObject addAndNotifyRemoteProcess(final String name, final Object o, final String noteId, final String paragraphId) { @@ -78,7 +78,7 @@ public AngularObject addAndNotifyRemoteProcess(final String name, * @param paragraphId * @return */ - public AngularObject removeAndNotifyRemoteProcess(final String name, + public AngularObject removeAndNotifyRemoteProcess(final String name, final String noteId, final String paragraphId) { RemoteInterpreterProcess remoteInterpreterProcess = getRemoteInterpreterProcess(); @@ -94,14 +94,14 @@ public AngularObject removeAndNotifyRemoteProcess(final String name, } public void removeAllAndNotifyRemoteProcess(String noteId, String paragraphId) { - List all = getAll(noteId, paragraphId); - for (AngularObject ao : all) { + List> all = getAll(noteId, paragraphId); + for (AngularObject ao : all) { removeAndNotifyRemoteProcess(ao.getName(), noteId, paragraphId); } } @Override - protected AngularObject createNewAngularObject(String name, Object o, String noteId, String + protected AngularObject createNewAngularObject(String name, Object o, String noteId, String paragraphId) { return new RemoteAngularObject(name, o, noteId, paragraphId, interpreterGroup, getAngularObjectListener()); diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java index 859e4e2ddcb..c70345c4290 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/remote/RemoteInterpreter.java @@ -387,12 +387,12 @@ private void pushAngularObjectRegistryToRemote(Client client) throws TException final AngularObjectRegistry angularObjectRegistry = this.getInterpreterGroup() .getAngularObjectRegistry(); if (angularObjectRegistry != null && angularObjectRegistry.getRegistry() != null) { - final Map> registry = angularObjectRegistry + final Map>> registry = angularObjectRegistry .getRegistry(); LOGGER.info("Push local angular object registry from ZeppelinServer to" + " remote interpreter group {}", this.getInterpreterGroup().getId()); final java.lang.reflect.Type registryType = new TypeToken>>() { + Map>>>() { }.getType(); client.angularRegistryPush(GSON.toJson(registry, registryType)); } 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 8b7622e1ef1..ad0ce7a506f 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 @@ -78,7 +78,7 @@ public class Note implements JsonSerializable { private Map noteParams = new LinkedHashMap<>(); private Map noteForms = new LinkedHashMap<>(); - private Map> angularObjects = new HashMap<>(); + private Map>> angularObjects = new HashMap<>(); /* * note configurations. @@ -310,11 +310,11 @@ public void setCredentials(Credentials credentials) { this.credentials = credentials; } - Map> getAngularObjects() { + Map>> getAngularObjects() { return angularObjects; } - public List getAngularObjects(String intpGroupId) { + public List> getAngularObjects(String intpGroupId) { if (!angularObjects.containsKey(intpGroupId)) { return new ArrayList<>(); } @@ -324,8 +324,8 @@ public List getAngularObjects(String intpGroupId) { /** * Add or update the note AngularObject. */ - public void addOrUpdateAngularObject(String intpGroupId, AngularObject angularObject) { - List angularObjectList; + public void addOrUpdateAngularObject(String intpGroupId, AngularObject angularObject) { + List> angularObjectList; if (!angularObjects.containsKey(intpGroupId)) { angularObjectList = new ArrayList<>(); angularObjects.put(intpGroupId, angularObjectList); @@ -333,14 +333,14 @@ public void addOrUpdateAngularObject(String intpGroupId, AngularObject angularOb angularObjectList = angularObjects.get(intpGroupId); // Delete existing AngularObject - Iterator iter = angularObjectList.iterator(); + Iterator> iter = angularObjectList.iterator(); while(iter.hasNext()){ String noteId = ""; String paragraphId = ""; String name = ""; Object object = iter.next(); if (object instanceof AngularObject) { - AngularObject ao = (AngularObject)object; + AngularObject ao = (AngularObject) object; noteId = ao.getNoteId(); paragraphId = ao.getParagraphId(); name = ao.getName(); @@ -370,14 +370,14 @@ public void deleteAngularObject(String intpGroupId, String noteId, String paragr if (angularObjects.containsKey(intpGroupId)) { // Delete existing AngularObject - Iterator iter = angularObjects.get(intpGroupId).iterator(); + Iterator> iter = angularObjects.get(intpGroupId).iterator(); while(iter.hasNext()){ String noteIdCandidate = ""; String paragraphIdCandidate = ""; String nameCandidate = ""; Object object = iter.next(); - if (object instanceof AngularObject) { - AngularObject ao = (AngularObject)object; + if (object instanceof AngularObject) { + AngularObject ao = (AngularObject) object; noteIdCandidate = ao.getNoteId(); paragraphIdCandidate = ao.getParagraphId(); nameCandidate = ao.getName(); 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 1f98c716f19..dc126cce66c 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 @@ -623,7 +623,6 @@ public Note getNoteByRevision(String noteId, String notePath, } } - @SuppressWarnings("rawtypes") public Note loadNoteFromRepo(String id, AuthenticationInfo subject) { Note note = null; try { @@ -661,14 +660,14 @@ public Note loadNoteFromRepo(String id, AuthenticationInfo subject) { } } - Map> savedObjects = note.getAngularObjects(); + Map>> savedObjects = note.getAngularObjects(); if (savedObjects != null) { - for (Entry> intpGroupNameEntry : savedObjects.entrySet()) { + for (Entry>> intpGroupNameEntry : savedObjects.entrySet()) { String intpGroupName = intpGroupNameEntry.getKey(); - List objectList = intpGroupNameEntry.getValue(); + List> objectList = intpGroupNameEntry.getValue(); - for (AngularObject object : objectList) { + for (AngularObject object : objectList) { SnapshotAngularObject snapshot = angularObjectSnapshot.get(object.getName()); if (snapshot == null || snapshot.getLastUpdate().before(lastUpdatedDate)) { angularObjectSnapshot.put(object.getName(), @@ -722,10 +721,10 @@ public void reloadAllNotes(AuthenticationInfo subject) throws IOException { private class SnapshotAngularObject { String intpGroupId; - AngularObject angularObject; + AngularObject angularObject; Date lastUpdate; - SnapshotAngularObject(String intpGroupId, AngularObject angularObject, Date lastUpdate) { + SnapshotAngularObject(String intpGroupId, AngularObject angularObject, Date lastUpdate) { super(); this.intpGroupId = intpGroupId; this.angularObject = angularObject; @@ -736,7 +735,7 @@ String getIntpGroupId() { return intpGroupId; } - AngularObject getAngularObject() { + AngularObject getAngularObject() { return angularObject; } diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NoteTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NoteTest.java index b7d1cb9ad78..f5f6cf0ca39 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NoteTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NoteTest.java @@ -210,7 +210,8 @@ public void testNoteJson() throws IOException { p.setResult(new InterpreterResult(InterpreterResult.Code.SUCCESS, "1.6.2")); p.settings.getForms().put("textbox_1", new TextBox("name", "default_name")); p.settings.getParams().put("textbox_1", "my_name"); - note.getAngularObjects().put("ao_1", Arrays.asList(new AngularObject("name_1", "value_1", note.getId(), p.getId(), null))); + note.getAngularObjects().put("ao_1", + Arrays.asList(new AngularObject("name_1", "value_1", note.getId(), p.getId(), null))); // test Paragraph Json Paragraph p2 = p.fromJson(p.toJson()); diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/ParagraphTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/ParagraphTest.java index 869d5622fcb..c1644af5ba9 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/ParagraphTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/ParagraphTest.java @@ -221,10 +221,10 @@ void should_extract_variable_from_angular_object_registry() throws Exception { final Paragraph paragraph = new Paragraph(note, null); final String paragraphId = paragraph.getId(); - final AngularObject nameAO = AngularObjectBuilder.build("name", "DuyHai DOAN", noteId, + final AngularObject nameAO = AngularObjectBuilder.build("name", "DuyHai DOAN", noteId, paragraphId); - final AngularObject ageAO = AngularObjectBuilder.build("age", 34, noteId, null); + final AngularObject ageAO = AngularObjectBuilder.build("age", 34, noteId, null); when(note.getId()).thenReturn(noteId); when(registry.get("name", noteId, paragraphId)).thenReturn(nameAO);