Search in sources :

Example 6 with Dependency

use of org.apache.zeppelin.dep.Dependency in project zeppelin by apache.

the class InterpreterSettingTest method perNoteScopedModeCloseAndRemoveInterpreterGroupTest.

@Test
public void perNoteScopedModeCloseAndRemoveInterpreterGroupTest() {
    InterpreterOption interpreterOption = new InterpreterOption();
    interpreterOption.setPerNote(InterpreterOption.SCOPED);
    InterpreterSetting interpreterSetting = new InterpreterSetting("", "", "", new ArrayList<InterpreterInfo>(), new Properties(), new ArrayList<Dependency>(), interpreterOption, "", null);
    interpreterSetting.setInterpreterGroupFactory(new InterpreterGroupFactory() {

        @Override
        public InterpreterGroup createInterpreterGroup(String interpreterGroupId, InterpreterOption option) {
            return new InterpreterGroup(interpreterGroupId);
        }
    });
    Interpreter mockInterpreter1 = mock(RemoteInterpreter.class);
    List<Interpreter> interpreterList1 = new ArrayList<>();
    interpreterList1.add(mockInterpreter1);
    InterpreterGroup interpreterGroup = interpreterSetting.getInterpreterGroup("user1", "note1");
    interpreterGroup.put(interpreterSetting.getInterpreterSessionKey("user1", "note1"), interpreterList1);
    Interpreter mockInterpreter2 = mock(RemoteInterpreter.class);
    List<Interpreter> interpreterList2 = new ArrayList<>();
    interpreterList2.add(mockInterpreter2);
    interpreterGroup = interpreterSetting.getInterpreterGroup("user1", "note2");
    interpreterGroup.put(interpreterSetting.getInterpreterSessionKey("user1", "note2"), interpreterList2);
    assertEquals(1, interpreterSetting.getAllInterpreterGroups().size());
    assertEquals(2, interpreterSetting.getInterpreterGroup("user1", "note1").size());
    assertEquals(2, interpreterSetting.getInterpreterGroup("user1", "note2").size());
    interpreterSetting.closeAndRemoveInterpreterGroup("note1", "user1");
    assertEquals(1, interpreterSetting.getInterpreterGroup("user1", "note2").size());
    // Check if non-existed key works or not
    interpreterSetting.closeAndRemoveInterpreterGroup("note1", "user1");
    assertEquals(1, interpreterSetting.getInterpreterGroup("user1", "note2").size());
    interpreterSetting.closeAndRemoveInterpreterGroup("note2", "user1");
    assertEquals(0, interpreterSetting.getAllInterpreterGroups().size());
}
Also used : RemoteInterpreter(org.apache.zeppelin.interpreter.remote.RemoteInterpreter) ArrayList(java.util.ArrayList) Dependency(org.apache.zeppelin.dep.Dependency) Properties(java.util.Properties) Test(org.junit.Test)

Example 7 with Dependency

use of org.apache.zeppelin.dep.Dependency in project zeppelin by apache.

the class InterpreterFactoryTest method testInterpreterAliases.

@Test
public void testInterpreterAliases() throws IOException, RepositoryException {
    interpreterSettingManager = new InterpreterSettingManager(conf, depResolver, new InterpreterOption(true));
    factory = new InterpreterFactory(conf, null, null, null, depResolver, false, interpreterSettingManager);
    final InterpreterInfo info1 = new InterpreterInfo("className1", "name1", true, null);
    final InterpreterInfo info2 = new InterpreterInfo("className2", "name1", true, null);
    interpreterSettingManager.add("group1", new ArrayList<InterpreterInfo>() {

        {
            add(info1);
        }
    }, new ArrayList<Dependency>(), new InterpreterOption(true), Collections.EMPTY_MAP, "/path1", null);
    interpreterSettingManager.add("group2", new ArrayList<InterpreterInfo>() {

        {
            add(info2);
        }
    }, new ArrayList<Dependency>(), new InterpreterOption(true), Collections.EMPTY_MAP, "/path2", null);
    final InterpreterSetting setting1 = interpreterSettingManager.createNewSetting("test-group1", "group1", new ArrayList<Dependency>(), new InterpreterOption(true), new Properties());
    final InterpreterSetting setting2 = interpreterSettingManager.createNewSetting("test-group2", "group1", new ArrayList<Dependency>(), new InterpreterOption(true), new Properties());
    interpreterSettingManager.setInterpreters("user", "note", new ArrayList<String>() {

        {
            add(setting1.getId());
            add(setting2.getId());
        }
    });
    assertEquals("className1", factory.getInterpreter("user1", "note", "test-group1").getClassName());
    assertEquals("className1", factory.getInterpreter("user1", "note", "group1").getClassName());
}
Also used : Dependency(org.apache.zeppelin.dep.Dependency) Properties(java.util.Properties) Test(org.junit.Test)

Example 8 with Dependency

use of org.apache.zeppelin.dep.Dependency in project zeppelin by apache.

the class InterpreterFactoryTest method testRemoteRepl.

@Test
public void testRemoteRepl() throws Exception {
    interpreterSettingManager = new InterpreterSettingManager(conf, depResolver, new InterpreterOption(true));
    ArrayList<InterpreterInfo> interpreterInfos = new ArrayList<>();
    interpreterInfos.add(new InterpreterInfo(MockInterpreter1.class.getName(), "mock1", true, new HashMap<String, Object>()));
    interpreterSettingManager.add("mock1", interpreterInfos, new ArrayList<Dependency>(), new InterpreterOption(), Maps.<String, InterpreterProperty>newHashMap(), "mock1", null);
    Properties intp1Properties = new Properties();
    intp1Properties.put("PROPERTY_1", "VALUE_1");
    intp1Properties.put("property_2", "value_2");
    interpreterSettingManager.createNewSetting("mock1", "mock1", new ArrayList<Dependency>(), new InterpreterOption(true), intp1Properties);
    factory = new InterpreterFactory(conf, null, null, null, depResolver, false, interpreterSettingManager);
    List<InterpreterSetting> all = interpreterSettingManager.get();
    InterpreterSetting mock1Setting = null;
    for (InterpreterSetting setting : all) {
        if (setting.getName().equals("mock1")) {
            mock1Setting = setting;
            break;
        }
    }
    InterpreterGroup interpreterGroup = mock1Setting.getInterpreterGroup("user", "sharedProcess");
    factory.createInterpretersForNote(mock1Setting, "user", "sharedProcess", "session");
    // get interpreter
    assertNotNull("get Interpreter", interpreterGroup.get("session").get(0));
    assertTrue(interpreterGroup.get("session").get(0) instanceof LazyOpenInterpreter);
    LazyOpenInterpreter lazyInterpreter = (LazyOpenInterpreter) (interpreterGroup.get("session").get(0));
    assertTrue(lazyInterpreter.getInnerInterpreter() instanceof RemoteInterpreter);
    RemoteInterpreter remoteInterpreter = (RemoteInterpreter) lazyInterpreter.getInnerInterpreter();
    assertEquals("VALUE_1", remoteInterpreter.getEnv().get("PROPERTY_1"));
    assertEquals("value_2", remoteInterpreter.getProperty("property_2"));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Dependency(org.apache.zeppelin.dep.Dependency) Properties(java.util.Properties) RemoteInterpreter(org.apache.zeppelin.interpreter.remote.RemoteInterpreter) Test(org.junit.Test)

Example 9 with Dependency

use of org.apache.zeppelin.dep.Dependency in project zeppelin by apache.

the class InterpreterFactoryTest method setUp.

@Before
public void setUp() throws Exception {
    tmpDir = new File(System.getProperty("java.io.tmpdir") + "/ZeppelinLTest_" + System.currentTimeMillis());
    tmpDir.mkdirs();
    new File(tmpDir, "conf").mkdirs();
    FileUtils.copyDirectory(new File("src/test/resources/interpreter"), new File(tmpDir, "interpreter"));
    System.setProperty(ConfVars.ZEPPELIN_HOME.getVarName(), tmpDir.getAbsolutePath());
    System.setProperty(ConfVars.ZEPPELIN_INTERPRETER_GROUP_ORDER.getVarName(), "mock1,mock2,mock11,dev");
    conf = new ZeppelinConfiguration();
    schedulerFactory = new SchedulerFactory();
    depResolver = new DependencyResolver(tmpDir.getAbsolutePath() + "/local-repo");
    interpreterSettingManager = new InterpreterSettingManager(conf, depResolver, new InterpreterOption(true));
    factory = new InterpreterFactory(conf, null, null, null, depResolver, false, interpreterSettingManager);
    context = new InterpreterContext("note", "id", null, "title", "text", null, null, null, null, null, null, null);
    ArrayList<InterpreterInfo> interpreterInfos = new ArrayList<>();
    interpreterInfos.add(new InterpreterInfo(MockInterpreter1.class.getName(), "mock1", true, new HashMap<String, Object>()));
    interpreterSettingManager.add("mock1", interpreterInfos, new ArrayList<Dependency>(), new InterpreterOption(), Maps.<String, InterpreterProperty>newHashMap(), "mock1", null);
    Properties intp1Properties = new Properties();
    intp1Properties.put("PROPERTY_1", "VALUE_1");
    intp1Properties.put("property_2", "value_2");
    interpreterSettingManager.createNewSetting("mock1", "mock1", new ArrayList<Dependency>(), new InterpreterOption(true), intp1Properties);
    ArrayList<InterpreterInfo> interpreterInfos2 = new ArrayList<>();
    interpreterInfos2.add(new InterpreterInfo(MockInterpreter2.class.getName(), "mock2", true, new HashMap<String, Object>()));
    interpreterSettingManager.add("mock2", interpreterInfos2, new ArrayList<Dependency>(), new InterpreterOption(), Maps.<String, InterpreterProperty>newHashMap(), "mock2", null);
    interpreterSettingManager.createNewSetting("mock2", "mock2", new ArrayList<Dependency>(), new InterpreterOption(), new Properties());
    SearchService search = mock(SearchService.class);
    notebookRepo = new VFSNotebookRepo(conf);
    notebookAuthorization = NotebookAuthorization.init(conf);
    notebook = new Notebook(conf, notebookRepo, schedulerFactory, factory, interpreterSettingManager, jobListenerFactory, search, notebookAuthorization, null);
}
Also used : Notebook(org.apache.zeppelin.notebook.Notebook) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Dependency(org.apache.zeppelin.dep.Dependency) Properties(java.util.Properties) SchedulerFactory(org.apache.zeppelin.scheduler.SchedulerFactory) DependencyResolver(org.apache.zeppelin.dep.DependencyResolver) VFSNotebookRepo(org.apache.zeppelin.notebook.repo.VFSNotebookRepo) ZeppelinConfiguration(org.apache.zeppelin.conf.ZeppelinConfiguration) SearchService(org.apache.zeppelin.search.SearchService) Before(org.junit.Before)

Example 10 with Dependency

use of org.apache.zeppelin.dep.Dependency in project zeppelin by apache.

the class InterpreterSettingManager method createFromInterpreterSettingRef.

private InterpreterSetting createFromInterpreterSettingRef(InterpreterSetting o) {
    // should return immutable objects
    List<InterpreterInfo> infos = (null == o.getInterpreterInfos()) ? new ArrayList<InterpreterInfo>() : new ArrayList<>(o.getInterpreterInfos());
    List<Dependency> deps = (null == o.getDependencies()) ? new ArrayList<Dependency>() : new ArrayList<>(o.getDependencies());
    Properties props = convertInterpreterProperties((Map<String, InterpreterProperty>) o.getProperties());
    InterpreterOption option = InterpreterOption.fromInterpreterOption(o.getOption());
    InterpreterSetting setting = new InterpreterSetting(o.getName(), o.getName(), infos, props, deps, option, o.getPath(), o.getInterpreterRunner());
    setting.setInterpreterGroupFactory(interpreterGroupFactory);
    return setting;
}
Also used : Dependency(org.apache.zeppelin.dep.Dependency) Properties(java.util.Properties)

Aggregations

Dependency (org.apache.zeppelin.dep.Dependency)22 Properties (java.util.Properties)17 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)8 RemoteInterpreter (org.apache.zeppelin.interpreter.remote.RemoteInterpreter)6 File (java.io.File)5 DependencyResolver (org.apache.zeppelin.dep.DependencyResolver)4 SchedulerFactory (org.apache.zeppelin.scheduler.SchedulerFactory)4 SearchService (org.apache.zeppelin.search.SearchService)4 Before (org.junit.Before)4 VFSNotebookRepo (org.apache.zeppelin.notebook.repo.VFSNotebookRepo)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 Map (java.util.Map)2 ZeppelinConfiguration (org.apache.zeppelin.conf.ZeppelinConfiguration)2 Notebook (org.apache.zeppelin.notebook.Notebook)2 Credentials (org.apache.zeppelin.user.Credentials)2 RepositoryException (org.sonatype.aether.RepositoryException)2