use of org.apache.zeppelin.interpreter.Interpreter in project zeppelin by apache.
the class SparkIntegrationTest method testSparkSubmit.
@Test
public void testSparkSubmit() throws InterpreterException {
assumeTrue("Hadoop version mismatch, skip test", isHadoopVersionMatch());
try {
InterpreterSetting sparkSubmitInterpreterSetting = interpreterSettingManager.getInterpreterSettingByName("spark-submit");
sparkSubmitInterpreterSetting.setProperty("SPARK_HOME", sparkHome);
// test SparkSubmitInterpreter
InterpreterContext context = new InterpreterContext.Builder().setNoteId("note1").setParagraphId("paragraph_1").build();
Interpreter sparkSubmitInterpreter = interpreterFactory.getInterpreter("spark-submit", new ExecutionContext("user1", "note1", "test"));
InterpreterResult interpreterResult = sparkSubmitInterpreter.interpret("--class org.apache.spark.examples.SparkPi " + sparkHome + "/examples/jars/spark-examples*.jar ", context);
assertEquals(interpreterResult.toString(), InterpreterResult.Code.SUCCESS, interpreterResult.code());
} finally {
interpreterSettingManager.close();
}
}
use of org.apache.zeppelin.interpreter.Interpreter in project zeppelin by apache.
the class RemoteInterpreterServer method getProgress.
@Override
public int getProgress(String sessionId, String className, RemoteInterpreterContext interpreterContext) throws InterpreterRPCException, TException {
lifecycleManager.onInterpreterUse(interpreterGroupId);
Integer manuallyProvidedProgress = progressMap.get(interpreterContext.getParagraphId());
if (manuallyProvidedProgress != null) {
return manuallyProvidedProgress;
} else {
Interpreter intp = getInterpreter(sessionId, className);
if (intp == null) {
throw new InterpreterRPCException("No interpreter " + className + " existed for session " + sessionId);
}
try {
return intp.getProgress(convert(interpreterContext, null));
} catch (InterpreterException e) {
throw new InterpreterRPCException(e.toString());
}
}
}
use of org.apache.zeppelin.interpreter.Interpreter in project zeppelin by apache.
the class RemoteInterpreterServer method cancel.
@Override
public void cancel(String sessionId, String className, RemoteInterpreterContext interpreterContext) throws InterpreterRPCException, TException {
LOGGER.info("cancel {} {}", className, interpreterContext.getParagraphId());
Interpreter intp = getInterpreter(sessionId, className);
String jobId = interpreterContext.getParagraphId();
Job job = intp.getScheduler().getJob(jobId);
if (job != null && job.getStatus() == Status.PENDING) {
job.setStatus(Status.ABORT);
} else {
Thread thread = new Thread(() -> {
try {
intp.cancel(convert(interpreterContext, null));
} catch (InterpreterException e) {
LOGGER.error("Fail to cancel paragraph: {}", interpreterContext.getParagraphId());
}
});
thread.start();
}
}
use of org.apache.zeppelin.interpreter.Interpreter in project zeppelin by apache.
the class RemoteInterpreterServer method close.
@Override
public void close(String sessionId, String className) throws InterpreterRPCException, TException {
// unload all applications
for (String appId : runningApplications.keySet()) {
RunningApplication appInfo = runningApplications.get(appId);
// see NoteInterpreterLoader.SHARED_SESSION
if (appInfo.noteId.equals(sessionId) || sessionId.equals("shared_session")) {
try {
LOGGER.info("Unload App {} ", appInfo.pkg.getName());
appInfo.app.unload();
// see ApplicationState.Status.UNLOADED
intpEventClient.onAppStatusUpdate(appInfo.noteId, appInfo.paragraphId, appId, "UNLOADED");
} catch (ApplicationException e) {
LOGGER.error(e.getMessage(), e);
}
}
}
// close interpreters
if (interpreterGroup != null) {
synchronized (interpreterGroup) {
List<Interpreter> interpreters = interpreterGroup.get(sessionId);
if (interpreters != null) {
Iterator<Interpreter> it = interpreters.iterator();
while (it.hasNext()) {
Interpreter inp = it.next();
if (inp.getClassName().equals(className)) {
try {
inp.close();
} catch (InterpreterException e) {
LOGGER.warn("Fail to close interpreter", e);
}
it.remove();
break;
}
}
}
}
}
}
use of org.apache.zeppelin.interpreter.Interpreter in project zeppelin by apache.
the class ParagraphTest method credentialReplacement.
// (TODO zjffdu) temporary disable it.
// https://github.com/apache/zeppelin/pull/3416
@Ignore
@Test
public void credentialReplacement() throws Throwable {
Note mockNote = mock(Note.class);
Credentials creds = mock(Credentials.class);
when(mockNote.getCredentials()).thenReturn(creds);
Paragraph spyParagraph = spy(new Paragraph("para_1", mockNote, null));
UserCredentials uc = mock(UserCredentials.class);
when(creds.getUserCredentials(anyString())).thenReturn(uc);
UsernamePassword up = new UsernamePassword("user", "pwd");
when(uc.getUsernamePassword("ent")).thenReturn(up);
Interpreter mockInterpreter = mock(Interpreter.class);
spyParagraph.setInterpreter(mockInterpreter);
doReturn(mockInterpreter).when(spyParagraph).getBindedInterpreter();
ManagedInterpreterGroup mockInterpreterGroup = mock(ManagedInterpreterGroup.class);
when(mockInterpreter.getInterpreterGroup()).thenReturn(mockInterpreterGroup);
when(mockInterpreterGroup.getId()).thenReturn("mock_id_1");
when(mockInterpreterGroup.getAngularObjectRegistry()).thenReturn(mock(AngularObjectRegistry.class));
when(mockInterpreterGroup.getResourcePool()).thenReturn(mock(ResourcePool.class));
when(mockInterpreter.getFormType()).thenReturn(FormType.NONE);
ParagraphJobListener mockJobListener = mock(ParagraphJobListener.class);
doReturn(mockJobListener).when(spyParagraph).getListener();
InterpreterResult mockInterpreterResult = mock(InterpreterResult.class);
when(mockInterpreter.interpret(anyString(), Mockito.<InterpreterContext>any())).thenReturn(mockInterpreterResult);
when(mockInterpreterResult.code()).thenReturn(Code.SUCCESS);
AuthenticationInfo user1 = new AuthenticationInfo("user1");
spyParagraph.setAuthenticationInfo(user1);
spyParagraph.setText("val x = \"usr={user.ent}&pass={password.ent}\"");
// Credentials should only be injected when it is enabled for an interpreter or when specified in a local property
when(mockInterpreter.getProperty(Constants.INJECT_CREDENTIALS, "false")).thenReturn("false");
spyParagraph.jobRun();
verify(mockInterpreter).interpret(eq("val x = \"usr={user.ent}&pass={password.ent}\""), any(InterpreterContext.class));
when(mockInterpreter.getProperty(Constants.INJECT_CREDENTIALS, "false")).thenReturn("true");
mockInterpreter.setProperty(Constants.INJECT_CREDENTIALS, "true");
spyParagraph.jobRun();
verify(mockInterpreter).interpret(eq("val x = \"usr=user&pass=pwd\""), any(InterpreterContext.class));
// Check if local property override works
when(mockInterpreter.getProperty(Constants.INJECT_CREDENTIALS, "false")).thenReturn("true");
spyParagraph.getLocalProperties().put(Constants.INJECT_CREDENTIALS, "true");
spyParagraph.jobRun();
verify(mockInterpreter).interpret(eq("val x = \"usr=user&pass=pwd\""), any(InterpreterContext.class));
}
Aggregations