Search in sources :

Example 41 with Interpreter

use of org.apache.zeppelin.interpreter.Interpreter in project SSM by Intel-bigdata.

the class Helium method suggestApp.

public HeliumPackageSuggestion suggestApp(Paragraph paragraph) {
    HeliumPackageSuggestion suggestion = new HeliumPackageSuggestion();
    Interpreter intp = paragraph.getCurrentRepl();
    if (intp == null) {
        return suggestion;
    }
    ResourcePool resourcePool = intp.getInterpreterGroup().getResourcePool();
    ResourceSet allResources;
    if (resourcePool != null) {
        if (resourcePool instanceof DistributedResourcePool) {
            allResources = ((DistributedResourcePool) resourcePool).getAll(true);
        } else {
            allResources = resourcePool.getAll();
        }
    } else {
        allResources = ResourcePoolUtils.getAllResources();
    }
    for (List<HeliumPackageSearchResult> pkgs : getAllPackageInfo().values()) {
        for (HeliumPackageSearchResult pkg : pkgs) {
            if (pkg.getPkg().getType() == HeliumPackage.Type.APPLICATION && pkg.isEnabled()) {
                ResourceSet resources = ApplicationLoader.findRequiredResourceSet(pkg.getPkg().getResources(), paragraph.getNote().getId(), paragraph.getId(), allResources);
                if (resources == null) {
                    continue;
                } else {
                    suggestion.addAvailablePackage(pkg);
                }
                break;
            }
        }
    }
    suggestion.sort();
    return suggestion;
}
Also used : Interpreter(org.apache.zeppelin.interpreter.Interpreter) ResourcePool(org.apache.zeppelin.resource.ResourcePool) DistributedResourcePool(org.apache.zeppelin.resource.DistributedResourcePool) ResourceSet(org.apache.zeppelin.resource.ResourceSet) DistributedResourcePool(org.apache.zeppelin.resource.DistributedResourcePool)

Example 42 with Interpreter

use of org.apache.zeppelin.interpreter.Interpreter in project SSM by Intel-bigdata.

the class ParagraphTest method returnUnchangedResultsWithDifferentUser.

@Test
public void returnUnchangedResultsWithDifferentUser() throws Throwable {
    InterpreterSettingManager mockInterpreterSettingManager = mock(InterpreterSettingManager.class);
    Note mockNote = mock(Note.class);
    when(mockNote.getCredentials()).thenReturn(mock(Credentials.class));
    Paragraph spyParagraph = spy(new Paragraph("para_1", mockNote, null, null, mockInterpreterSettingManager));
    doReturn("spy").when(spyParagraph).getRequiredReplName();
    Interpreter mockInterpreter = mock(Interpreter.class);
    doReturn(mockInterpreter).when(spyParagraph).getRepl(anyString());
    InterpreterGroup mockInterpreterGroup = mock(InterpreterGroup.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));
    List<InterpreterSetting> spyInterpreterSettingList = spy(Lists.<InterpreterSetting>newArrayList());
    InterpreterSetting mockInterpreterSetting = mock(InterpreterSetting.class);
    InterpreterOption mockInterpreterOption = mock(InterpreterOption.class);
    when(mockInterpreterSetting.getOption()).thenReturn(mockInterpreterOption);
    when(mockInterpreterOption.permissionIsSet()).thenReturn(false);
    when(mockInterpreterSetting.getStatus()).thenReturn(Status.READY);
    when(mockInterpreterSetting.getId()).thenReturn("mock_id_1");
    when(mockInterpreterSetting.getInterpreterGroup(anyString(), anyString())).thenReturn(mockInterpreterGroup);
    spyInterpreterSettingList.add(mockInterpreterSetting);
    when(mockNote.getId()).thenReturn("any_id");
    when(mockInterpreterSettingManager.getInterpreterSettings(anyString())).thenReturn(spyInterpreterSettingList);
    doReturn("spy script body").when(spyParagraph).getScriptBody();
    when(mockInterpreter.getFormType()).thenReturn(FormType.NONE);
    ParagraphJobListener mockJobListener = mock(ParagraphJobListener.class);
    doReturn(mockJobListener).when(spyParagraph).getListener();
    doNothing().when(mockJobListener).onOutputUpdateAll(Mockito.<Paragraph>any(), Mockito.anyList());
    InterpreterResult mockInterpreterResult = mock(InterpreterResult.class);
    when(mockInterpreter.interpret(anyString(), Mockito.<InterpreterContext>any())).thenReturn(mockInterpreterResult);
    when(mockInterpreterResult.code()).thenReturn(Code.SUCCESS);
    // Actual test
    List<InterpreterResultMessage> result1 = Lists.newArrayList();
    result1.add(new InterpreterResultMessage(Type.TEXT, "result1"));
    when(mockInterpreterResult.message()).thenReturn(result1);
    AuthenticationInfo user1 = new AuthenticationInfo("user1");
    spyParagraph.setAuthenticationInfo(user1);
    spyParagraph.jobRun();
    Paragraph p1 = spyParagraph.getUserParagraph(user1.getUser());
    List<InterpreterResultMessage> result2 = Lists.newArrayList();
    result2.add(new InterpreterResultMessage(Type.TEXT, "result2"));
    when(mockInterpreterResult.message()).thenReturn(result2);
    AuthenticationInfo user2 = new AuthenticationInfo("user2");
    spyParagraph.setAuthenticationInfo(user2);
    spyParagraph.jobRun();
    Paragraph p2 = spyParagraph.getUserParagraph(user2.getUser());
    assertNotEquals(p1.getReturn().toString(), p2.getReturn().toString());
    assertEquals(p1, spyParagraph.getUserParagraph(user1.getUser()));
}
Also used : Interpreter(org.apache.zeppelin.interpreter.Interpreter) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) ResourcePool(org.apache.zeppelin.resource.ResourcePool) InterpreterSettingManager(org.apache.zeppelin.interpreter.InterpreterSettingManager) InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) InterpreterOption(org.apache.zeppelin.interpreter.InterpreterOption) InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup) Credentials(org.apache.zeppelin.user.Credentials) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) Test(org.junit.Test)

Example 43 with Interpreter

use of org.apache.zeppelin.interpreter.Interpreter in project SSM by Intel-bigdata.

the class MockInterpreterB method getInterpreterA.

public MockInterpreterA getInterpreterA() {
    InterpreterGroup interpreterGroup = getInterpreterGroup();
    synchronized (interpreterGroup) {
        for (List<Interpreter> interpreters : interpreterGroup.values()) {
            boolean belongsToSameNoteGroup = false;
            MockInterpreterA a = null;
            for (Interpreter intp : interpreters) {
                if (intp.getClassName().equals(MockInterpreterA.class.getName())) {
                    Interpreter p = intp;
                    while (p instanceof WrappedInterpreter) {
                        p = ((WrappedInterpreter) p).getInnerInterpreter();
                    }
                    a = (MockInterpreterA) p;
                }
                Interpreter p = intp;
                while (p instanceof WrappedInterpreter) {
                    p = ((WrappedInterpreter) p).getInnerInterpreter();
                }
                if (this == p) {
                    belongsToSameNoteGroup = true;
                }
            }
            if (belongsToSameNoteGroup) {
                return a;
            }
        }
    }
    return null;
}
Also used : WrappedInterpreter(org.apache.zeppelin.interpreter.WrappedInterpreter) Interpreter(org.apache.zeppelin.interpreter.Interpreter) WrappedInterpreter(org.apache.zeppelin.interpreter.WrappedInterpreter) InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup)

Example 44 with Interpreter

use of org.apache.zeppelin.interpreter.Interpreter in project zeppelin by apache.

the class SparkSqlInterpreter method getSparkInterpreter.

private SparkInterpreter getSparkInterpreter() {
    LazyOpenInterpreter lazy = null;
    SparkInterpreter spark = null;
    Interpreter p = getInterpreterInTheSameSessionByClassName(SparkInterpreter.class.getName());
    while (p instanceof WrappedInterpreter) {
        if (p instanceof LazyOpenInterpreter) {
            lazy = (LazyOpenInterpreter) p;
        }
        p = ((WrappedInterpreter) p).getInnerInterpreter();
    }
    spark = (SparkInterpreter) p;
    if (lazy != null) {
        lazy.open();
    }
    return spark;
}
Also used : WrappedInterpreter(org.apache.zeppelin.interpreter.WrappedInterpreter) LazyOpenInterpreter(org.apache.zeppelin.interpreter.LazyOpenInterpreter) LazyOpenInterpreter(org.apache.zeppelin.interpreter.LazyOpenInterpreter) Interpreter(org.apache.zeppelin.interpreter.Interpreter) WrappedInterpreter(org.apache.zeppelin.interpreter.WrappedInterpreter)

Example 45 with Interpreter

use of org.apache.zeppelin.interpreter.Interpreter in project zeppelin by apache.

the class DepInterpreter method getSparkInterpreter.

private SparkInterpreter getSparkInterpreter() {
    InterpreterGroup intpGroup = getInterpreterGroup();
    if (intpGroup == null) {
        return null;
    }
    Interpreter p = getInterpreterInTheSameSessionByClassName(SparkInterpreter.class.getName());
    if (p == null) {
        return null;
    }
    while (p instanceof WrappedInterpreter) {
        p = ((WrappedInterpreter) p).getInnerInterpreter();
    }
    return (SparkInterpreter) p;
}
Also used : WrappedInterpreter(org.apache.zeppelin.interpreter.WrappedInterpreter) Interpreter(org.apache.zeppelin.interpreter.Interpreter) WrappedInterpreter(org.apache.zeppelin.interpreter.WrappedInterpreter) InterpreterGroup(org.apache.zeppelin.interpreter.InterpreterGroup)

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