Search in sources :

Example 21 with Interpreter

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();
    }
}
Also used : Interpreter(org.apache.zeppelin.interpreter.Interpreter) ExecutionContext(org.apache.zeppelin.interpreter.ExecutionContext) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) Test(org.junit.Test)

Example 22 with Interpreter

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());
        }
    }
}
Also used : InterpreterRPCException(org.apache.zeppelin.interpreter.thrift.InterpreterRPCException) Interpreter(org.apache.zeppelin.interpreter.Interpreter) LazyOpenInterpreter(org.apache.zeppelin.interpreter.LazyOpenInterpreter) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException)

Example 23 with Interpreter

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();
    }
}
Also used : Interpreter(org.apache.zeppelin.interpreter.Interpreter) LazyOpenInterpreter(org.apache.zeppelin.interpreter.LazyOpenInterpreter) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) Job(org.apache.zeppelin.scheduler.Job)

Example 24 with Interpreter

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;
                    }
                }
            }
        }
    }
}
Also used : ApplicationException(org.apache.zeppelin.helium.ApplicationException) Interpreter(org.apache.zeppelin.interpreter.Interpreter) LazyOpenInterpreter(org.apache.zeppelin.interpreter.LazyOpenInterpreter) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException)

Example 25 with Interpreter

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));
}
Also used : Interpreter(org.apache.zeppelin.interpreter.Interpreter) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) ResourcePool(org.apache.zeppelin.resource.ResourcePool) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) UsernamePassword(org.apache.zeppelin.user.UsernamePassword) ManagedInterpreterGroup(org.apache.zeppelin.interpreter.ManagedInterpreterGroup) UserCredentials(org.apache.zeppelin.user.UserCredentials) InterpreterContext(org.apache.zeppelin.interpreter.InterpreterContext) UserCredentials(org.apache.zeppelin.user.UserCredentials) Credentials(org.apache.zeppelin.user.Credentials) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) Ignore(org.junit.Ignore) AbstractInterpreterTest(org.apache.zeppelin.interpreter.AbstractInterpreterTest) Test(org.junit.Test)

Aggregations

Interpreter (org.apache.zeppelin.interpreter.Interpreter)85 Test (org.junit.Test)46 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)42 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)30 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)27 LazyOpenInterpreter (org.apache.zeppelin.interpreter.LazyOpenInterpreter)26 AbstractInterpreterTest (org.apache.zeppelin.interpreter.AbstractInterpreterTest)21 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)21 InterpreterException (org.apache.zeppelin.interpreter.InterpreterException)20 Properties (java.util.Properties)19 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)11 ExecutionContext (org.apache.zeppelin.interpreter.ExecutionContext)11 IOException (java.io.IOException)10 InterpreterOutput (org.apache.zeppelin.interpreter.InterpreterOutput)10 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)9 WrappedInterpreter (org.apache.zeppelin.interpreter.WrappedInterpreter)7 ArrayList (java.util.ArrayList)6 InterpreterNotFoundException (org.apache.zeppelin.interpreter.InterpreterNotFoundException)6 ManagedInterpreterGroup (org.apache.zeppelin.interpreter.ManagedInterpreterGroup)6 Before (org.junit.Before)6