Search in sources :

Example 16 with Dependency

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

the class InterpreterSettingTest method sharedModeCloseandRemoveInterpreterGroupTest.

@Test
public void sharedModeCloseandRemoveInterpreterGroupTest() {
    InterpreterOption interpreterOption = new InterpreterOption();
    interpreterOption.setPerUser(InterpreterOption.SHARED);
    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);
    // This won't effect anything
    Interpreter mockInterpreter2 = mock(RemoteInterpreter.class);
    List<Interpreter> interpreterList2 = new ArrayList<>();
    interpreterList2.add(mockInterpreter2);
    interpreterGroup = interpreterSetting.getInterpreterGroup("user2", "note1");
    interpreterGroup.put(interpreterSetting.getInterpreterSessionKey("user2", "note1"), interpreterList2);
    assertEquals(1, interpreterSetting.getInterpreterGroup("user1", "note1").size());
    interpreterSetting.closeAndRemoveInterpreterGroup("note1", "user2");
    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 17 with Dependency

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

the class HeliumApplicationFactoryTest method setUp.

@Before
public void setUp() throws Exception {
    tmpDir = new File(System.getProperty("java.io.tmpdir") + "/ZepelinLTest_" + System.currentTimeMillis());
    tmpDir.mkdirs();
    File confDir = new File(tmpDir, "conf");
    confDir.mkdirs();
    notebookDir = new File(tmpDir + "/notebook");
    notebookDir.mkdirs();
    File home = // zeppelin/zeppelin-zengine/target/test-classes/note
    new File(getClass().getClassLoader().getResource("note").getFile()).getParentFile().getParentFile().getParentFile().getParentFile();
    System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_HOME.getVarName(), home.getAbsolutePath());
    System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_CONF_DIR.getVarName(), tmpDir.getAbsolutePath() + "/conf");
    System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_NOTEBOOK_DIR.getVarName(), notebookDir.getAbsolutePath());
    conf = new ZeppelinConfiguration();
    this.schedulerFactory = new SchedulerFactory();
    heliumAppFactory = new HeliumApplicationFactory();
    depResolver = new DependencyResolver(tmpDir.getAbsolutePath() + "/local-repo");
    interpreterSettingManager = new InterpreterSettingManager(conf, depResolver, new InterpreterOption(true));
    factory = new InterpreterFactory(conf, null, null, heliumAppFactory, depResolver, false, interpreterSettingManager);
    HashMap<String, String> env = new HashMap<>();
    env.put("ZEPPELIN_CLASSPATH", new File("./target/test-classes").getAbsolutePath());
    factory.setEnv(env);
    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);
    interpreterSettingManager.createNewSetting("mock1", "mock1", new ArrayList<Dependency>(), new InterpreterOption(true), new Properties());
    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 = NotebookAuthorization.init(conf);
    notebook = new Notebook(conf, notebookRepo, schedulerFactory, factory, interpreterSettingManager, this, search, notebookAuthorization, new Credentials(false, null));
    heliumAppFactory.setNotebook(notebook);
    notebook.addNotebookEventListener(heliumAppFactory);
    anonymous = new AuthenticationInfo("anonymous");
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Dependency(org.apache.zeppelin.dep.Dependency) Properties(java.util.Properties) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) 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) File(java.io.File) Credentials(org.apache.zeppelin.user.Credentials) Before(org.junit.Before)

Example 18 with Dependency

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

the class InterpreterFactoryTest method testMultiUser.

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

        {
            add(info1);
        }
    }, new ArrayList<Dependency>(), new InterpreterOption(true), Collections.EMPTY_MAP, "/path1", null);
    InterpreterOption perUserInterpreterOption = new InterpreterOption(true, InterpreterOption.ISOLATED, InterpreterOption.SHARED);
    final InterpreterSetting setting1 = interpreterSettingManager.createNewSetting("test-group1", "group1", new ArrayList<Dependency>(), perUserInterpreterOption, new Properties());
    interpreterSettingManager.setInterpreters("user1", "note", new ArrayList<String>() {

        {
            add(setting1.getId());
        }
    });
    interpreterSettingManager.setInterpreters("user2", "note", new ArrayList<String>() {

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

Example 19 with Dependency

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

the class InterpreterFactoryTest method testRestartInterpreterInIsolatedMode.

/**
   * 2 users' interpreters in isolated mode. Each user has one interpreterGroup. Restarting user1's interpreter
   * won't affect user2's interpreter
   * @throws Exception
   */
@Test
public void testRestartInterpreterInIsolatedMode() 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;
        }
    }
    mock1Setting.getOption().setPerUser("isolated");
    mock1Setting.getOption().setPerNote("shared");
    // set remote as false so that we won't create new remote interpreter process
    mock1Setting.getOption().setRemote(false);
    mock1Setting.getOption().setHost("localhost");
    mock1Setting.getOption().setPort(2222);
    InterpreterGroup interpreterGroup1 = mock1Setting.getInterpreterGroup("user1", "note1");
    InterpreterGroup interpreterGroup2 = mock1Setting.getInterpreterGroup("user2", "note2");
    factory.createInterpretersForNote(mock1Setting, "user1", "note1", "shared_session");
    factory.createInterpretersForNote(mock1Setting, "user2", "note2", "shared_session");
    LazyOpenInterpreter interpreter1 = (LazyOpenInterpreter) interpreterGroup1.get("shared_session").get(0);
    interpreter1.open();
    LazyOpenInterpreter interpreter2 = (LazyOpenInterpreter) interpreterGroup2.get("shared_session").get(0);
    interpreter2.open();
    mock1Setting.closeAndRemoveInterpreterGroup("note1", "user1");
    assertFalse(interpreter1.isOpen());
    assertTrue(interpreter2.isOpen());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Dependency(org.apache.zeppelin.dep.Dependency) Properties(java.util.Properties) Test(org.junit.Test)

Example 20 with Dependency

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

the class InterpreterFactoryTest method testInvalidInterpreterSettingName.

@Test
public void testInvalidInterpreterSettingName() {
    try {
        interpreterSettingManager.createNewSetting("new.mock1", "mock1", new LinkedList<Dependency>(), new InterpreterOption(false), new Properties());
        fail("expect fail because of invalid InterpreterSetting Name");
    } catch (IOException e) {
        assertEquals("'.' is invalid for InterpreterSetting name.", e.getMessage());
    }
}
Also used : Dependency(org.apache.zeppelin.dep.Dependency) Properties(java.util.Properties) Test(org.junit.Test)

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