mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
ZEPPELIN-2386. Add parameter to check running current paragraph in ZeppelinContext
This commit is contained in:
parent
540ceb87d8
commit
03995a3780
4 changed files with 77 additions and 13 deletions
|
|
@ -311,7 +311,7 @@ public class ZeppelinContext {
|
|||
*/
|
||||
@ZeppelinApi
|
||||
public void run(String noteId, String paragraphId) {
|
||||
run(noteId, paragraphId, interpreterContext);
|
||||
run(noteId, paragraphId, interpreterContext, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -320,8 +320,27 @@ public class ZeppelinContext {
|
|||
*/
|
||||
@ZeppelinApi
|
||||
public void run(String paragraphId) {
|
||||
run(paragraphId, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run paragraph by id
|
||||
* @param paragraphId
|
||||
* @param checkCurrentParagraph
|
||||
*/
|
||||
@ZeppelinApi
|
||||
public void run(String paragraphId, boolean checkCurrentParagraph) {
|
||||
String noteId = interpreterContext.getNoteId();
|
||||
run(noteId, paragraphId, interpreterContext);
|
||||
run(noteId, paragraphId, interpreterContext, checkCurrentParagraph);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run paragraph by id
|
||||
* @param noteId
|
||||
*/
|
||||
@ZeppelinApi
|
||||
public void run(String noteId, String paragraphId, InterpreterContext context) {
|
||||
run(noteId, paragraphId, context, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -330,8 +349,9 @@ public class ZeppelinContext {
|
|||
* @param context
|
||||
*/
|
||||
@ZeppelinApi
|
||||
public void run(String noteId, String paragraphId, InterpreterContext context) {
|
||||
if (paragraphId.equals(context.getParagraphId())) {
|
||||
public void run(String noteId, String paragraphId, InterpreterContext context,
|
||||
boolean checkCurrentParagraph) {
|
||||
if (paragraphId.equals(context.getParagraphId()) && checkCurrentParagraph) {
|
||||
throw new InterpreterException("Can not run current Paragraph");
|
||||
}
|
||||
|
||||
|
|
@ -411,24 +431,50 @@ public class ZeppelinContext {
|
|||
*/
|
||||
@ZeppelinApi
|
||||
public void run(int idx) {
|
||||
run(idx, true);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param idx paragraph index
|
||||
* @param checkCurrentParagraph check whether you call this run method in the current paragraph.
|
||||
* Set it to false only when you are sure you are not invoking this method to run current
|
||||
* paragraph. Otherwise you would run current paragraph in infinite loop.
|
||||
*/
|
||||
public void run(int idx, boolean checkCurrentParagraph) {
|
||||
String noteId = interpreterContext.getNoteId();
|
||||
run(noteId, idx, interpreterContext);
|
||||
run(noteId, idx, interpreterContext, checkCurrentParagraph);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run paragraph at index
|
||||
* @param noteId
|
||||
* @param idx index starting from 0
|
||||
* @param context interpreter context
|
||||
*/
|
||||
public void run(String noteId, int idx, InterpreterContext context) {
|
||||
run(noteId, idx, context, true);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param noteId
|
||||
* @param idx paragraph index
|
||||
* @param context interpreter context
|
||||
* @param checkCurrentParagraph check whether you call this run method in the current paragraph.
|
||||
* Set it to false only when you are sure you are not invoking this method to run current
|
||||
* paragraph. Otherwise you would run current paragraph in infinite loop.
|
||||
*/
|
||||
public void run(String noteId, int idx, InterpreterContext context,
|
||||
boolean checkCurrentParagraph) {
|
||||
List<InterpreterContextRunner> runners = getInterpreterContextRunner(noteId, context);
|
||||
if (idx >= runners.size()) {
|
||||
throw new InterpreterException("Index out of bound");
|
||||
}
|
||||
|
||||
InterpreterContextRunner runner = runners.get(idx);
|
||||
if (runner.getParagraphId().equals(context.getParagraphId())) {
|
||||
throw new InterpreterException("Can not run current Paragraph");
|
||||
if (runner.getParagraphId().equals(context.getParagraphId()) && checkCurrentParagraph) {
|
||||
throw new InterpreterException("Can not run current Paragraph: " + runner.getParagraphId());
|
||||
}
|
||||
|
||||
runner.run();
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ import org.slf4j.LoggerFactory;
|
|||
* @param <T>
|
||||
*/
|
||||
public class AngularObject<T> {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AngularObject.class);
|
||||
|
||||
private String name;
|
||||
private T object;
|
||||
|
||||
|
|
@ -172,7 +174,7 @@ public class AngularObject<T> {
|
|||
if (emit) {
|
||||
emit();
|
||||
}
|
||||
|
||||
LOGGER.debug("Update angular object: " + name + " with value: " + o);
|
||||
final Logger logger = LoggerFactory.getLogger(AngularObject.class);
|
||||
List<AngularObjectWatcher> ws = new LinkedList<>();
|
||||
synchronized (watchers) {
|
||||
|
|
|
|||
|
|
@ -183,10 +183,11 @@ public class NotebookServer extends WebSocketServlet
|
|||
Notebook notebook = notebook();
|
||||
try {
|
||||
Message messagereceived = deserializeMessage(msg);
|
||||
LOG.debug("RECEIVE << " + messagereceived.op);
|
||||
LOG.debug("RECEIVE PRINCIPAL << " + messagereceived.principal);
|
||||
LOG.debug("RECEIVE TICKET << " + messagereceived.ticket);
|
||||
LOG.debug("RECEIVE ROLES << " + messagereceived.roles);
|
||||
LOG.debug("RECEIVE << " + messagereceived.op +
|
||||
", RECEIVE PRINCIPAL << " + messagereceived.principal +
|
||||
", RECEIVE TICKET << " + messagereceived.ticket +
|
||||
", RECEIVE ROLES << " + messagereceived.roles +
|
||||
", RECEIVE DATA << " + messagereceived.data);
|
||||
|
||||
if (LOG.isTraceEnabled()) {
|
||||
LOG.trace("RECEIVE MSG = " + messagereceived);
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ public class ZeppelinIT extends AbstractZeppelinIT {
|
|||
* z.run(2, context)
|
||||
* }
|
||||
*/
|
||||
setTextOfParagraph(4, "z.angularWatch(\"myVar\", (before:Object, after:Object, context:org.apache.zeppelin.interpreter.InterpreterContext)=>{ z.run(2)})");
|
||||
setTextOfParagraph(4, "z.angularWatch(\"myVar\", (before:Object, after:Object, context:org.apache.zeppelin.interpreter.InterpreterContext)=>{ z.run(2, false)})");
|
||||
runParagraph(4);
|
||||
waitForParagraph(4, "FINISHED");
|
||||
|
||||
|
|
@ -157,6 +157,21 @@ public class ZeppelinIT extends AbstractZeppelinIT {
|
|||
waitForText("myVar=3", By.xpath(
|
||||
getParagraphXPath(3) + "//div[contains(@id,\"_text\") and @class=\"text\"]"));
|
||||
|
||||
|
||||
/*
|
||||
* Click element, again and see watcher still works
|
||||
*/
|
||||
driver.findElement(By.xpath(
|
||||
getParagraphXPath(1) + "//div[@id=\"angularTestButton\"]")).click();
|
||||
// check expected text
|
||||
waitForText("BindingTest_4_", By.xpath(
|
||||
getParagraphXPath(1) + "//div[@id=\"angularTestButton\"]"));
|
||||
waitForParagraph(3, "FINISHED");
|
||||
|
||||
// check expected text by watcher
|
||||
waitForText("myVar=4", By.xpath(
|
||||
getParagraphXPath(3) + "//div[contains(@id,\"_text\") and @class=\"text\"]"));
|
||||
|
||||
/*
|
||||
* Unbind
|
||||
* z.angularUnbind("myVar")
|
||||
|
|
|
|||
Loading…
Reference in a new issue