use of org.apache.zeppelin.interpreter.Interpreter in project zeppelin by apache.
the class SparkIntegrationTest method testInterpreterBasics.
private void testInterpreterBasics() throws IOException, InterpreterException, XmlPullParserException {
// add jars & packages for testing
InterpreterSetting sparkInterpreterSetting = interpreterSettingManager.getInterpreterSettingByName("spark");
sparkInterpreterSetting.setProperty("spark.jars.packages", "com.maxmind.geoip2:geoip2:2.5.0");
sparkInterpreterSetting.setProperty("SPARK_PRINT_LAUNCH_COMMAND", "true");
sparkInterpreterSetting.setProperty("zeppelin.python.gatewayserver_address", "127.0.0.1");
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model = reader.read(new FileReader("pom.xml"));
sparkInterpreterSetting.setProperty("spark.jars", new File("target/zeppelin-interpreter-integration-" + model.getVersion() + ".jar").getAbsolutePath());
// test SparkInterpreter
Interpreter sparkInterpreter = interpreterFactory.getInterpreter("spark.spark", new ExecutionContext("user1", "note1", "test"));
InterpreterContext context = new InterpreterContext.Builder().setNoteId("note1").setParagraphId("paragraph_1").build();
InterpreterResult interpreterResult = sparkInterpreter.interpret("sc.version", context);
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
String detectedSparkVersion = interpreterResult.message().get(0).getData();
assertTrue(detectedSparkVersion + " doesn't contain " + this.sparkVersion, detectedSparkVersion.contains(this.sparkVersion));
interpreterResult = sparkInterpreter.interpret("sc.range(1,10).sum()", context);
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
assertTrue(interpreterResult.toString(), interpreterResult.message().get(0).getData().contains("45"));
interpreterResult = sparkInterpreter.interpret("sc.getConf.get(\"spark.user.name\")", context);
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
assertTrue(interpreterResult.toString(), interpreterResult.message().get(0).getData().contains("user1"));
// test jars & packages can be loaded correctly
interpreterResult = sparkInterpreter.interpret("import org.apache.zeppelin.interpreter.integration.DummyClass\n" + "import com.maxmind.geoip2._", context);
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
// test PySparkInterpreter
Interpreter pySparkInterpreter = interpreterFactory.getInterpreter("spark.pyspark", new ExecutionContext("user1", "note1", "test"));
interpreterResult = pySparkInterpreter.interpret("sqlContext.createDataFrame([(1,'a'),(2,'b')], ['id','name']).registerTempTable('test')", context);
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
// test IPySparkInterpreter
Interpreter ipySparkInterpreter = interpreterFactory.getInterpreter("spark.ipyspark", new ExecutionContext("user1", "note1", "test"));
interpreterResult = ipySparkInterpreter.interpret("sqlContext.table('test').show()", context);
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
// test SparkSQLInterpreter
Interpreter sqlInterpreter = interpreterFactory.getInterpreter("spark.sql", new ExecutionContext("user1", "note1", "test"));
interpreterResult = sqlInterpreter.interpret("select count(1) as c from test", context);
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
assertEquals(interpreterResult.toString(), InterpreterResult.Type.TABLE, interpreterResult.message().get(0).getType());
assertEquals(interpreterResult.toString(), "c\n2\n", interpreterResult.message().get(0).getData());
// test SparkRInterpreter
Interpreter sparkrInterpreter = interpreterFactory.getInterpreter("spark.r", new ExecutionContext("user1", "note1", "test"));
if (isSpark2() || isSpark3()) {
interpreterResult = sparkrInterpreter.interpret("df <- as.DataFrame(faithful)\nhead(df)", context);
} else {
interpreterResult = sparkrInterpreter.interpret("df <- createDataFrame(sqlContext, faithful)\nhead(df)", context);
}
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
assertEquals(interpreterResult.toString(), InterpreterResult.Type.TEXT, interpreterResult.message().get(0).getType());
assertTrue(interpreterResult.toString(), interpreterResult.message().get(0).getData().contains("eruptions waiting"));
}
use of org.apache.zeppelin.interpreter.Interpreter in project zeppelin by apache.
the class SparkSubmitIntegrationTest method testYarnMode.
@Test
public void testYarnMode() throws InterpreterException, YarnException {
try {
// test SparkSubmitInterpreterSetting
Interpreter sparkSubmitInterpreter = interpreterFactory.getInterpreter("spark-submit", new ExecutionContext("user1", "note1", "test"));
InterpreterContext context = new InterpreterContext.Builder().setNoteId("note1").setParagraphId("paragraph_1").build();
String yarnAppName = "yarn_example";
InterpreterResult interpreterResult = sparkSubmitInterpreter.interpret("--master yarn-cluster --class org.apache.spark.examples.SparkPi " + "--conf spark.app.name=" + yarnAppName + " --conf spark.driver.memory=512m " + "--conf spark.executor.memory=512m " + sparkHome + "/examples/jars/spark-examples_2.11-2.4.7.jar", context);
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
GetApplicationsRequest request = GetApplicationsRequest.newInstance(EnumSet.of(YarnApplicationState.FINISHED));
GetApplicationsResponse response = hadoopCluster.getYarnCluster().getResourceManager().getClientRMService().getApplications(request);
assertTrue(response.getApplicationList().size() >= 1);
List<ApplicationReport> apps = response.getApplicationList().stream().filter(app -> app.getName().equals(yarnAppName)).collect(Collectors.toList());
assertEquals(1, apps.size());
} finally {
interpreterSettingManager.close();
}
}
use of org.apache.zeppelin.interpreter.Interpreter in project zeppelin by apache.
the class SparkSubmitIntegrationTest method testLocalMode.
@Test
public void testLocalMode() throws InterpreterException, YarnException {
try {
// test SparkSubmitInterpreterSetting
Interpreter sparkSubmitInterpreter = interpreterFactory.getInterpreter("spark-submit", new ExecutionContext("user1", "note1", "test"));
InterpreterContext context = new InterpreterContext.Builder().setNoteId("note1").setParagraphId("paragraph_1").build();
InterpreterResult interpreterResult = sparkSubmitInterpreter.interpret("--master yarn-cluster --class org.apache.spark.examples.SparkPi " + sparkHome + "/examples/jars/spark-examples_2.11-2.4.7.jar", context);
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
// no yarn application launched
GetApplicationsRequest request = GetApplicationsRequest.newInstance(EnumSet.of(YarnApplicationState.RUNNING));
GetApplicationsResponse response = hadoopCluster.getYarnCluster().getResourceManager().getClientRMService().getApplications(request);
assertEquals(0, response.getApplicationList().size());
} finally {
interpreterSettingManager.close();
}
}
use of org.apache.zeppelin.interpreter.Interpreter in project zeppelin by apache.
the class SparkSubmitIntegrationTest method testCancelSparkYarnApp.
@Test
public void testCancelSparkYarnApp() throws InterpreterException, YarnException, TimeoutException, InterruptedException {
try {
// test SparkSubmitInterpreterSetting
Interpreter sparkSubmitInterpreter = interpreterFactory.getInterpreter("spark-submit", new ExecutionContext("user1", "note1", "test"));
InterpreterContext context = new InterpreterContext.Builder().setNoteId("note1").setParagraphId("paragraph_1").build();
final Waiter waiter = new Waiter();
Thread thread = new Thread() {
@Override
public void run() {
try {
String yarnAppName = "yarn_cancel_example";
InterpreterResult interpreterResult = sparkSubmitInterpreter.interpret("--master yarn-cluster --class org.apache.spark.examples.SparkPi " + "--conf spark.app.name=" + yarnAppName + " --conf spark.driver.memory=512m " + "--conf spark.executor.memory=512m " + sparkHome + "/examples/jars/spark-examples_2.11-2.4.7.jar", context);
assertEquals(interpreterResult.toString(), InterpreterResult.Code.INCOMPLETE, interpreterResult.code());
assertTrue(interpreterResult.toString(), interpreterResult.toString().contains("Paragraph received a SIGTERM"));
} catch (InterpreterException e) {
waiter.fail("Should not throw exception\n" + ExceptionUtils.getStackTrace(e));
}
waiter.resume();
}
};
thread.start();
long start = System.currentTimeMillis();
long threshold = 120 * 1000;
while ((System.currentTimeMillis() - start) < threshold) {
GetApplicationsRequest request = GetApplicationsRequest.newInstance(EnumSet.of(YarnApplicationState.RUNNING));
GetApplicationsResponse response = hadoopCluster.getYarnCluster().getResourceManager().getClientRMService().getApplications(request);
if (response.getApplicationList().size() >= 1) {
break;
}
Thread.sleep(5 * 1000);
}
sparkSubmitInterpreter.cancel(context);
waiter.await(10000);
} finally {
interpreterSettingManager.close();
}
}
use of org.apache.zeppelin.interpreter.Interpreter in project zeppelin by apache.
the class RemoteInterpreterTest method testSharedMode.
@Test
public void testSharedMode() throws InterpreterException, IOException {
interpreterSetting.getOption().setPerUser(InterpreterOption.SHARED);
Interpreter interpreter1 = interpreterSetting.getDefaultInterpreter("user1", note1Id);
Interpreter interpreter2 = interpreterSetting.getDefaultInterpreter("user2", note1Id);
assertTrue(interpreter1 instanceof RemoteInterpreter);
RemoteInterpreter remoteInterpreter1 = (RemoteInterpreter) interpreter1;
assertTrue(interpreter2 instanceof RemoteInterpreter);
RemoteInterpreter remoteInterpreter2 = (RemoteInterpreter) interpreter2;
assertEquals(remoteInterpreter1.getScheduler(), remoteInterpreter2.getScheduler());
InterpreterContext context1 = createDummyInterpreterContext();
assertEquals("hello", remoteInterpreter1.interpret("hello", context1).message().get(0).getData());
assertEquals(Interpreter.FormType.NATIVE, interpreter1.getFormType());
assertEquals(0, remoteInterpreter1.getProgress(context1));
assertNotNull(remoteInterpreter1.getOrCreateInterpreterProcess());
assertTrue(remoteInterpreter1.getInterpreterGroup().getRemoteInterpreterProcess().isRunning());
assertEquals("hello", remoteInterpreter2.interpret("hello", context1).message().get(0).getData());
assertEquals(remoteInterpreter1.getInterpreterGroup().getRemoteInterpreterProcess(), remoteInterpreter2.getInterpreterGroup().getRemoteInterpreterProcess());
// Call InterpreterGroup.close instead of Interpreter.close, otherwise we will have the
// RemoteInterpreterProcess leakage.
remoteInterpreter1.getInterpreterGroup().close(remoteInterpreter1.getSessionId());
assertNull(remoteInterpreter1.getInterpreterGroup().getRemoteInterpreterProcess());
InterpreterResult result = remoteInterpreter1.interpret("hello", context1);
assertEquals(Code.ERROR, result.code());
assertEquals("Interpreter process is not running\n", result.message().get(0).getData());
}
Aggregations