Java Code Examples for org.apache.zeppelin.interpreter.InterpreterResult#Type

The following examples show how to use org.apache.zeppelin.interpreter.InterpreterResult#Type . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HeliumApplicationFactory.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
@Override
public void onOutputUpdated(
    String noteId, String paragraphId, int index, String appId,
    InterpreterResult.Type type, String output) {
  ApplicationState appToUpdate = getAppState(noteId, paragraphId, appId);

  if (appToUpdate != null) {
    appToUpdate.setOutput(output);
  } else {
    logger.error("Can't find app {}", appId);
  }

  if (applicationEventListener != null) {
    applicationEventListener.onOutputUpdated(noteId, paragraphId, index, appId, type, output);
  }
}
 
Example 2
Source File: NotebookServer.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
/**
 * This callback is for the paragraph that runs on ZeppelinServer.
 *
 * @param output output to update (replace)
 */
@Override
public void onOutputUpdated(String noteId, String paragraphId, int index,
                            InterpreterResult.Type type, String output) {
  Message msg = new Message(OP.PARAGRAPH_UPDATE_OUTPUT).put("noteId", noteId)
      .put("paragraphId", paragraphId).put("index", index).put("type", type).put("data", output);
  try {
    Note note = getNotebook().getNote(noteId);
    if (note == null) {
      LOG.warn("Note " + noteId + " note found");
      return;
    }
    Paragraph paragraph = note.getParagraph(paragraphId);
    paragraph.updateOutputBuffer(index, type, output);
    if (note.isPersonalizedMode()) {
      String user = note.getParagraph(paragraphId).getUser();
      if (null != user) {
        getConnectionManager().multicastToUser(user, msg);
      }
    } else {
      getConnectionManager().broadcast(noteId, msg);
    }
  } catch (IOException e) {
    LOG.warn("Fail to call onOutputUpdated", e);
  }
}
 
Example 3
Source File: Paragraph.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
public void updateOutputBuffer(int index, InterpreterResult.Type type, String output) {
  InterpreterResultMessage interpreterResultMessage = new InterpreterResultMessage(type, output);;
  if (outputBuffer.size() == index) {
    outputBuffer.add(interpreterResultMessage);
  } else if (outputBuffer.size() > index) {
    outputBuffer.set(index, interpreterResultMessage);
  } else {
    LOGGER.warn("Get output of index: " + index + ", but there's only " +
            outputBuffer.size() + " output in outputBuffer");
  }
}
 
Example 4
Source File: RemoteInterpreterEventClient.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
public void onInterpreterOutputUpdate(
    String noteId, String paragraphId, int outputIndex,
    InterpreterResult.Type type, String output) {
  try {
    callRemoteFunction(client -> {
      client.updateOutput(
              new OutputUpdateEvent(noteId, paragraphId, outputIndex, type.name(), output, null));
      return null;
    });

  } catch (Exception e) {
    LOGGER.warn("Fail to updateOutput", e);
  }
}
 
Example 5
Source File: RemoteInterpreterEventClient.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
public void onAppOutputUpdate(
    String noteId, String paragraphId, int index, String appId,
    InterpreterResult.Type type, String output) {
  AppOutputUpdateEvent event =
      new AppOutputUpdateEvent(noteId, paragraphId, appId, index, type.name(), output);
  try {
    callRemoteFunction(client -> {
      client.updateAppOutput(event);
      return null;
    });
  } catch (Exception e) {
    LOGGER.warn("Fail to updateAppOutput: " + event, e);
  }
}
 
Example 6
Source File: PythonInterpreterMatplotlibTest.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Test
// Test for when configuration is set to auto-close figures after show().
public void testClose() throws IOException, InterpreterException {
  InterpreterResult ret;
  InterpreterResult ret1;
  InterpreterResult ret2;
  ret = python.interpret("import matplotlib.pyplot as plt", context);
  ret = python.interpret("z.configure_mpl(interactive=False)", context);
  ret = python.interpret("plt.plot([1, 2, 3])", context);
  ret1 = python.interpret("plt.show()", context);

  // Second call to show() should print nothing, and Type should be TEXT.
  // This is because when close=True, there should be no living instances
  // of FigureManager, causing show() to return before setting the output
  // type to HTML.
  ret = python.interpret("plt.show()", context);

  assertEquals(new String(out.getOutputAt(0).toByteArray()),
      InterpreterResult.Code.SUCCESS, ret.code());
  assertEquals(0, ret.message().size());

  // Now test that new plot is drawn. It should be identical to the
  // previous one.
  ret = python.interpret("plt.plot([1, 2, 3])", context);
  String msg1 = new String(out.getOutputAt(0).toByteArray());
  InterpreterResult.Type type1 = out.getOutputAt(0).getType();

  ret2 = python.interpret("plt.show()", context);
  String msg2 = new String(out.getOutputAt(0).toByteArray());
  InterpreterResult.Type type2 = out.getOutputAt(0).getType();

  assertEquals(msg1, msg2);
  assertEquals(type1, type2);
}
 
Example 7
Source File: NotebookServer.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
/**
 * When application update output.
 */
@Override
public void onOutputUpdated(String noteId, String paragraphId, int index, String appId,
                            InterpreterResult.Type type, String output) {
  Message msg =
      new Message(OP.APP_UPDATE_OUTPUT).put("noteId", noteId).put("paragraphId", paragraphId)
          .put("index", index).put("type", type).put("appId", appId).put("data", output);
  getConnectionManager().broadcast(noteId, msg);
}
 
Example 8
Source File: ApplicationEventListener.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
void onOutputUpdated(
String noteId, String paragraphId, int index, String appId,
InterpreterResult.Type type, String output);
 
Example 9
Source File: RemoteInterpreterProcessListener.java    From zeppelin with Apache License 2.0 2 votes vote down vote up
/**
 * Invoked when the whole output is updated
 * @param noteId
 * @param paragraphId
 * @param index
 * @param type
 * @param output
 */
void onOutputUpdated(
    String noteId, String paragraphId, int index, InterpreterResult.Type type, String output);
 
Example 10
Source File: RemoteSchedulerTest.java    From zeppelin with Apache License 2.0 2 votes vote down vote up
@Override
public void onOutputUpdated(String noteId, String paragraphId, int index, InterpreterResult.Type type, String output) {

}
 
Example 11
Source File: RemoteInterpreterOutputTestStream.java    From zeppelin with Apache License 2.0 2 votes vote down vote up
@Override
public void onOutputUpdated(String noteId, String paragraphId, int index, InterpreterResult.Type type, String output) {

}