Java Code Examples for org.apache.zeppelin.interpreter.InterpreterContext#set()

The following examples show how to use org.apache.zeppelin.interpreter.InterpreterContext#set() . 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: KotlinSparkInterpreter.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
@Override
public InterpreterResult interpret(String st, InterpreterContext context)
    throws InterpreterException {

  if (isSparkVersionUnsupported()) {
    return unsupportedMessage;
  }

  z.setInterpreterContext(context);
  z.setGui(context.getGui());
  z.setNoteGui(context.getNoteGui());
  InterpreterContext.set(context);

  jsc.setJobGroup(buildJobGroupId(context), buildJobDesc(context), false);
  jsc.setLocalProperty("spark.scheduler.pool", context.getLocalProperties().get("pool"));

  InterpreterOutput out = context.out;
  PrintStream scalaOut = Console.out();
  PrintStream newOut = (out != null) ? new PrintStream(out) : null;

  Console.setOut(newOut);
  InterpreterResult result = interpreter.interpret(st, context);
  Console.setOut(scalaOut);

  return result;
}
 
Example 2
Source File: SparkInterpreterTest.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
@Test
public void testDisableSparkUI_1() throws InterpreterException {
  Properties properties = new Properties();
  properties.setProperty(SparkStringConstants.MASTER_PROP_NAME, "local");
  properties.setProperty(SparkStringConstants.APP_NAME_PROP_NAME, "test");
  properties.setProperty("zeppelin.spark.maxResult", "100");
  properties.setProperty("spark.ui.enabled", "false");
  // disable color output for easy testing
  properties.setProperty("zeppelin.spark.scala.color", "false");
  properties.setProperty("zeppelin.spark.deprecatedMsg.show", "false");

  interpreter = new SparkInterpreter(properties);
  interpreter.setInterpreterGroup(mock(InterpreterGroup.class));
  InterpreterContext.set(getInterpreterContext());
  interpreter.open();

  InterpreterContext context = getInterpreterContext();
  InterpreterResult result = interpreter.interpret("sc.range(1, 10).sum", context);
  assertEquals(InterpreterResult.Code.SUCCESS, result.code());

  // spark job url is not sent
  verify(mockRemoteEventClient, never()).onParaInfosReceived(any(Map.class));
}
 
Example 3
Source File: RInterpreterTest.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvalidR() throws InterpreterException {
  tearDown();

  Properties properties = new Properties();
  properties.setProperty("zeppelin.R.cmd", "invalid_r");
  properties.setProperty("spark.master", "local");
  properties.setProperty("spark.app.name", "test");

  InterpreterGroup interpreterGroup = new InterpreterGroup();
  Interpreter rInterpreter = new LazyOpenInterpreter(new RInterpreter(properties));
  interpreterGroup.addInterpreterToSession(rInterpreter, "session_1");
  rInterpreter.setInterpreterGroup(interpreterGroup);

  InterpreterContext context = getInterpreterContext();
  InterpreterContext.set(context);

  try {
    rInterpreter.interpret("1+1", getInterpreterContext());
    fail("Should fail to open SparkRInterpreter");
  } catch (InterpreterException e) {
    String stacktrace = ExceptionUtils.getStackTrace(e);
    assertTrue(stacktrace, stacktrace.contains("No such file or directory"));
  }
}
 
Example 4
Source File: SparkInterpreterTest.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
@Test
public void testDisableSparkUI_2() throws InterpreterException {
  Properties properties = new Properties();
  properties.setProperty(SparkStringConstants.MASTER_PROP_NAME, "local");
  properties.setProperty(SparkStringConstants.APP_NAME_PROP_NAME, "test");
  properties.setProperty("zeppelin.spark.maxResult", "100");
  properties.setProperty("zeppelin.spark.ui.hidden", "true");
  // disable color output for easy testing
  properties.setProperty("zeppelin.spark.scala.color", "false");
  properties.setProperty("zeppelin.spark.deprecatedMsg.show", "false");

  interpreter = new SparkInterpreter(properties);
  interpreter.setInterpreterGroup(mock(InterpreterGroup.class));
  InterpreterContext.set(getInterpreterContext());
  interpreter.open();

  InterpreterContext context = getInterpreterContext();
  InterpreterResult result = interpreter.interpret("sc.range(1, 10).sum", context);
  assertEquals(InterpreterResult.Code.SUCCESS, result.code());

  // spark job url is not sent
  verify(mockRemoteEventClient, never()).onParaInfosReceived(any(Map.class));
}
 
Example 5
Source File: IPyFlinkInterpreterTest.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
@Override
protected void startInterpreter(Properties properties) throws InterpreterException {
  InterpreterContext context = getInterpreterContext();
  context.setIntpEventClient(mockIntpEventClient);
  InterpreterContext.set(context);

  this.flinkScalaInterpreter = new LazyOpenInterpreter(
      new FlinkInterpreter(properties));
  intpGroup = new InterpreterGroup();
  intpGroup.put("session_1", new ArrayList<Interpreter>());
  intpGroup.get("session_1").add(flinkScalaInterpreter);
  flinkScalaInterpreter.setInterpreterGroup(intpGroup);

  LazyOpenInterpreter pyFlinkInterpreter =
      new LazyOpenInterpreter(new PyFlinkInterpreter(properties));
  intpGroup.get("session_1").add(pyFlinkInterpreter);
  pyFlinkInterpreter.setInterpreterGroup(intpGroup);

  interpreter = new LazyOpenInterpreter(new IPyFlinkInterpreter(properties));
  intpGroup.get("session_1").add(interpreter);
  interpreter.setInterpreterGroup(intpGroup);

  interpreter.open();

  angularObjectRegistry = new AngularObjectRegistry("flink", null);
}
 
Example 6
Source File: PythonInterpreterTest.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
@Override
public void setUp() throws InterpreterException {

  intpGroup = new InterpreterGroup();

  Properties properties = new Properties();
  properties.setProperty("zeppelin.python.maxResult", "3");
  properties.setProperty("zeppelin.python.useIPython", "false");
  properties.setProperty("zeppelin.python.gatewayserver_address", "127.0.0.1");

  interpreter = new LazyOpenInterpreter(new PythonInterpreter(properties));

  intpGroup.put("note", new LinkedList<Interpreter>());
  intpGroup.get("note").add(interpreter);
  interpreter.setInterpreterGroup(intpGroup);

  InterpreterContext.set(getInterpreterContext());
  interpreter.open();
}
 
Example 7
Source File: PySubmarineInterpreterTest.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
@Override
public void setUp() throws InterpreterException {
  intpGroup = new InterpreterGroup();
  Properties properties = new Properties();
  properties.setProperty(ZEPPELIN_SUBMARINE_AUTH_TYPE, "simple");
  properties.setProperty("zeppelin.python.useIPython", "false");
  properties.setProperty("zeppelin.python.gatewayserver_address", "127.0.0.1");
  properties.setProperty(SubmarineConstants.SUBMARINE_HADOOP_PRINCIPAL, "user");

  pySubmarineIntp = new PySubmarineInterpreter(properties);

  intpGroup.put("note", new LinkedList<Interpreter>());
  intpGroup.get("note").add(pySubmarineIntp);
  pySubmarineIntp.setInterpreterGroup(intpGroup);

  InterpreterContext.set(getIntpContext());
  pySubmarineIntp.open();
}
 
Example 8
Source File: IPyFlinkInterpreter.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
/**
 * Called by python process.
 */
public void initJavaThread() {
  InterpreterContext.set(curInterpreterContext);
  originalClassLoader = Thread.currentThread().getContextClassLoader();
  Thread.currentThread().setContextClassLoader(flinkInterpreter.getFlinkScalaShellLoader());
  flinkInterpreter.createPlannerAgain();
}
 
Example 9
Source File: PythonInterpreter.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Override
public InterpreterResult interpret(String st, InterpreterContext context)
    throws InterpreterException {
  if (iPythonInterpreter != null) {
    return iPythonInterpreter.interpret(st, context);
  }

  outputStream.setInterpreterOutput(context.out);
  ZeppelinContext z = getZeppelinContext();
  z.setInterpreterContext(context);
  z.setGui(context.getGui());
  z.setNoteGui(context.getNoteGui());
  InterpreterContext.set(context);

  preCallPython(context);
  callPython(new PythonInterpretRequest(st, false));

  if (statementError) {
    return new InterpreterResult(Code.ERROR, statementOutput);
  } else {
    try {
      context.out.flush();
    } catch (IOException e) {
      throw new InterpreterException(e);
    }
    if (pythonProcessLauncher.isRunning()) {
      return new InterpreterResult(Code.SUCCESS);
    } else {
      return new InterpreterResult(Code.ERROR,
              "Python process is abnormally exited, please check your code and log.");
    }
  }
}
 
Example 10
Source File: PythonInterpreterTest.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Test
public void testFailtoLaunchPythonProcess() throws InterpreterException {
  tearDown();

  intpGroup = new InterpreterGroup();

  Properties properties = new Properties();
  properties.setProperty("zeppelin.python", "invalid_python");
  properties.setProperty("zeppelin.python.useIPython", "false");
  properties.setProperty("zeppelin.python.gatewayserver_address", "127.0.0.1");

  interpreter = new LazyOpenInterpreter(new PythonInterpreter(properties));

  intpGroup.put("note", new LinkedList<Interpreter>());
  intpGroup.get("note").add(interpreter);
  interpreter.setInterpreterGroup(intpGroup);

  InterpreterContext.set(getInterpreterContext());

  try {
    interpreter.interpret("1+1", getInterpreterContext());
    fail("Should fail to open PythonInterpreter");
  } catch (InterpreterException e) {
    String stacktrace = ExceptionUtils.getStackTrace(e);
    assertTrue(stacktrace, stacktrace.contains("No such file or directory"));
  }
}
 
Example 11
Source File: FlinkInterpreterTest.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
private InterpreterContext getInterpreterContext() {
  InterpreterContext context = InterpreterContext.builder()
          .setParagraphId("paragraphId")
          .setInterpreterOut(new InterpreterOutput(null))
          .setAngularObjectRegistry(angularObjectRegistry)
          .setIntpEventClient(mock(RemoteInterpreterEventClient.class))
          .build();
  InterpreterContext.set(context);
  return context;
}
 
Example 12
Source File: AbstractInterpreter.java    From submarine with Apache License 2.0 5 votes vote down vote up
protected InterpreterContext getIntpContext() {
  if (this.interpreterContext == null) {
    this.interpreterContext = InterpreterContext.builder()
            .setInterpreterOut(new InterpreterOutput(null))
            .build();
    InterpreterContext.set(this.interpreterContext);
  }
  return this.interpreterContext;
}
 
Example 13
Source File: ShinyInterpreterTest.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws InterpreterException {
  Properties properties = new Properties();

  InterpreterContext context = getInterpreterContext();
  InterpreterContext.set(context);
  interpreter = new ShinyInterpreter(properties);

  InterpreterGroup interpreterGroup = new InterpreterGroup();
  interpreterGroup.addInterpreterToSession(new LazyOpenInterpreter(interpreter), "session_1");
  interpreter.setInterpreterGroup(interpreterGroup);

  interpreter.open();
}
 
Example 14
Source File: PySparkInterpreterTest.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Override
public void setUp() throws InterpreterException {
  Properties properties = new Properties();
  properties.setProperty(SparkStringConstants.MASTER_PROP_NAME, "local");
  properties.setProperty(SparkStringConstants.APP_NAME_PROP_NAME, "Zeppelin Test");
  properties.setProperty("zeppelin.spark.useHiveContext", "false");
  properties.setProperty("zeppelin.spark.maxResult", "3");
  properties.setProperty("zeppelin.spark.importImplicit", "true");
  properties.setProperty("zeppelin.pyspark.python", "python");
  properties.setProperty("zeppelin.dep.localrepo", Files.createTempDir().getAbsolutePath());
  properties.setProperty("zeppelin.pyspark.useIPython", "false");
  properties.setProperty("zeppelin.python.gatewayserver_address", "127.0.0.1");
  properties.setProperty("zeppelin.spark.deprecatedMsg.show", "false");

  // create interpreter group
  intpGroup = new InterpreterGroup();
  intpGroup.put("note", new LinkedList<Interpreter>());

  InterpreterContext context = InterpreterContext.builder()
      .setInterpreterOut(new InterpreterOutput(null))
      .setIntpEventClient(mockRemoteEventClient)
      .build();
  InterpreterContext.set(context);
  LazyOpenInterpreter sparkInterpreter =
      new LazyOpenInterpreter(new SparkInterpreter(properties));

  intpGroup.get("note").add(sparkInterpreter);
  sparkInterpreter.setInterpreterGroup(intpGroup);

  LazyOpenInterpreter iPySparkInterpreter =
      new LazyOpenInterpreter(new IPySparkInterpreter(properties));
  intpGroup.get("note").add(iPySparkInterpreter);
  iPySparkInterpreter.setInterpreterGroup(intpGroup);

  interpreter = new LazyOpenInterpreter(new PySparkInterpreter(properties));
  intpGroup.get("note").add(interpreter);
  interpreter.setInterpreterGroup(intpGroup);

  interpreter.open();
}
 
Example 15
Source File: SparkRInterpreterTest.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidR() throws InterpreterException {
  tearDown();

  Properties properties = new Properties();
  properties.setProperty("zeppelin.R.cmd", "invalid_r");
  properties.setProperty(SparkStringConstants.MASTER_PROP_NAME, "local");
  properties.setProperty(SparkStringConstants.APP_NAME_PROP_NAME, "test");
  
  InterpreterGroup interpreterGroup = new InterpreterGroup();
  Interpreter sparkRInterpreter = new LazyOpenInterpreter(new SparkRInterpreter(properties));
  Interpreter sparkInterpreter = new LazyOpenInterpreter(new SparkInterpreter(properties));
  interpreterGroup.addInterpreterToSession(sparkRInterpreter, "session_1");
  interpreterGroup.addInterpreterToSession(sparkInterpreter, "session_1");
  sparkRInterpreter.setInterpreterGroup(interpreterGroup);
  sparkInterpreter.setInterpreterGroup(interpreterGroup);

  InterpreterContext context = getInterpreterContext();
  InterpreterContext.set(context);

  try {
    sparkRInterpreter.interpret("1+1", getInterpreterContext());
    fail("Should fail to open SparkRInterpreter");
  } catch (InterpreterException e) {
    String stacktrace = ExceptionUtils.getStackTrace(e);
    assertTrue(stacktrace, stacktrace.contains("No such file or directory"));
  }
}
 
Example 16
Source File: IPyFlinkInterpreterTest.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
protected InterpreterContext getInterpreterContext() {
  InterpreterContext context = InterpreterContext.builder()
          .setNoteId("noteId")
          .setParagraphId("paragraphId")
          .setInterpreterOut(new InterpreterOutput(null))
          .setAngularObjectRegistry(angularObjectRegistry)
          .setIntpEventClient(mock(RemoteInterpreterEventClient.class))
          .build();
  InterpreterContext.set(context);
  return context;
}
 
Example 17
Source File: IRKernelTest.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws InterpreterException {
  Properties properties = new Properties();

  InterpreterContext context = getInterpreterContext();
  InterpreterContext.set(context);
  interpreter = createInterpreter(properties);

  InterpreterGroup interpreterGroup = new InterpreterGroup();
  interpreterGroup.addInterpreterToSession(new LazyOpenInterpreter(interpreter), "session_1");
  interpreter.setInterpreterGroup(interpreterGroup);

  interpreter.open();
}
 
Example 18
Source File: IPyFlinkInterpreterTest.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
private static InterpreterContext createInterpreterContext() {
  InterpreterContext context = InterpreterContext.builder()
          .setNoteId("noteId")
          .setParagraphId("paragraphId")
          .setInterpreterOut(new InterpreterOutput(null))
          .setIntpEventClient(mock(RemoteInterpreterEventClient.class))
          .setAngularObjectRegistry(angularObjectRegistry)
          .build();
  InterpreterContext.set(context);
  return context;
}
 
Example 19
Source File: SqlInterpreterTest.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws InterpreterException, IOException {
  Properties p = getFlinkProperties();
  flinkInterpreter = new FlinkInterpreter(p);
  iPyFlinkInterpreter = new IPyFlinkInterpreter(p);
  pyFlinkInterpreter = new PyFlinkInterpreter(p);
  sqlInterpreter = createFlinkSqlInterpreter(p);
  InterpreterGroup intpGroup = new InterpreterGroup();
  flinkInterpreter.setInterpreterGroup(intpGroup);
  sqlInterpreter.setInterpreterGroup(intpGroup);
  iPyFlinkInterpreter.setInterpreterGroup(intpGroup);
  pyFlinkInterpreter.setInterpreterGroup(intpGroup);
  intpGroup.addInterpreterToSession(flinkInterpreter, "session_1");
  intpGroup.addInterpreterToSession(sqlInterpreter, "session_1");
  intpGroup.addInterpreterToSession(iPyFlinkInterpreter, "session_1");
  intpGroup.addInterpreterToSession(pyFlinkInterpreter, "session_1");

  angularObjectRegistry = new AngularObjectRegistry("flink", null);
  InterpreterContext.set(getInterpreterContext());
  flinkInterpreter.open();
  sqlInterpreter.open();
  iPyFlinkInterpreter.open();
  pyFlinkInterpreter.open();

  hiveShell.execute("drop database if exists test_db CASCADE");
  hiveShell.execute("create database test_db");
  hiveShell.execute("use test_db");

  InterpreterResult result = sqlInterpreter.interpret("use test_db",
          getInterpreterContext());
  assertEquals(Code.SUCCESS, result.code());
}
 
Example 20
Source File: SubmarineInterpreterTest.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Override
public void setUp() throws InterpreterException {
  Properties properties = new Properties();
  properties.setProperty(ZEPPELIN_SUBMARINE_AUTH_TYPE, "simple");
  properties.setProperty("zeppelin.python.useIPython", "false");
  properties.setProperty("zeppelin.python.gatewayserver_address", "127.0.0.1");
  properties.setProperty(SubmarineConstants.SUBMARINE_HADOOP_KEYTAB, "keytab");
  properties.setProperty(SubmarineConstants.SUBMARINE_HADOOP_PRINCIPAL, "user");

  submarineIntp = new SubmarineInterpreter(properties);

  InterpreterContext.set(getIntpContext());
  submarineIntp.open();
}