Search in sources :

Example 11 with InterpreterOption

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

the class VFSNotebookRepoTest method setUp.

@Before
public void setUp() throws Exception {
    String zpath = System.getProperty("java.io.tmpdir") + "/ZeppelinLTest_" + System.currentTimeMillis();
    mainZepDir = new File(zpath);
    mainZepDir.mkdirs();
    new File(mainZepDir, "conf").mkdirs();
    String mainNotePath = zpath + "/notebook";
    mainNotebookDir = new File(mainNotePath);
    mainNotebookDir.mkdirs();
    System.setProperty(ConfVars.ZEPPELIN_HOME.getVarName(), mainZepDir.getAbsolutePath());
    System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_DIR.getVarName(), mainNotebookDir.getAbsolutePath());
    System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_STORAGE.getVarName(), "org.apache.zeppelin.notebook.repo.VFSNotebookRepo");
    conf = ZeppelinConfiguration.create();
    this.schedulerFactory = new SchedulerFactory();
    this.schedulerFactory = new SchedulerFactory();
    depResolver = new DependencyResolver(mainZepDir.getAbsolutePath() + "/local-repo");
    interpreterSettingManager = new InterpreterSettingManager(conf, depResolver, new InterpreterOption(true));
    factory = new InterpreterFactory(conf, null, null, null, depResolver, false, interpreterSettingManager);
    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(), new Properties());
    SearchService search = mock(SearchService.class);
    notebookRepo = new VFSNotebookRepo(conf);
    notebookAuthorization = NotebookAuthorization.init(conf);
    notebook = new Notebook(conf, notebookRepo, schedulerFactory, factory, interpreterSettingManager, this, search, notebookAuthorization, null);
}
Also used : Notebook(org.apache.zeppelin.notebook.Notebook) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) InterpreterSettingManager(org.apache.zeppelin.interpreter.InterpreterSettingManager) Dependency(org.apache.zeppelin.dep.Dependency) Properties(java.util.Properties) InterpreterFactory(org.apache.zeppelin.interpreter.InterpreterFactory) SchedulerFactory(org.apache.zeppelin.scheduler.SchedulerFactory) DependencyResolver(org.apache.zeppelin.dep.DependencyResolver) InterpreterOption(org.apache.zeppelin.interpreter.InterpreterOption) SearchService(org.apache.zeppelin.search.SearchService) InterpreterInfo(org.apache.zeppelin.interpreter.InterpreterInfo) File(java.io.File) Before(org.junit.Before)

Example 12 with InterpreterOption

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

the class StandardInterpreterLauncher method launchDirectly.

@Override
public InterpreterClient launchDirectly(InterpreterLaunchContext context) throws IOException {
    LOGGER.info("Launching new interpreter process of {}", context.getInterpreterSettingGroup());
    this.properties = context.getProperties();
    InterpreterOption option = context.getOption();
    InterpreterRunner runner = context.getRunner();
    String groupName = context.getInterpreterSettingGroup();
    String name = context.getInterpreterSettingName();
    int connectTimeout = getConnectTimeout();
    int connectionPoolSize = getConnectPoolSize();
    if (option.isExistingProcess()) {
        return new RemoteInterpreterRunningProcess(context.getInterpreterSettingName(), context.getInterpreterGroupId(), connectTimeout, connectionPoolSize, context.getIntpEventServerHost(), context.getIntpEventServerPort(), option.getHost(), option.getPort(), false);
    } else {
        // create new remote process
        String localRepoPath = zConf.getInterpreterLocalRepoPath() + File.separator + context.getInterpreterSettingId();
        return new ExecRemoteInterpreterProcess(context.getIntpEventServerPort(), context.getIntpEventServerHost(), zConf.getInterpreterPortRange(), zConf.getInterpreterDir() + "/" + groupName, localRepoPath, buildEnvFromProperties(context), connectTimeout, connectionPoolSize, name, context.getInterpreterGroupId(), option.isUserImpersonate(), runner != null ? runner.getPath() : zConf.getInterpreterRemoteRunnerPath());
    }
}
Also used : InterpreterOption(org.apache.zeppelin.interpreter.InterpreterOption) InterpreterRunner(org.apache.zeppelin.interpreter.InterpreterRunner) RemoteInterpreterRunningProcess(org.apache.zeppelin.interpreter.remote.RemoteInterpreterRunningProcess) ExecRemoteInterpreterProcess(org.apache.zeppelin.interpreter.remote.ExecRemoteInterpreterProcess)

Example 13 with InterpreterOption

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

the class ParagraphTest method returnUnchangedResultsWithDifferentUser.

@Ignore
public void returnUnchangedResultsWithDifferentUser() throws Throwable {
    Note mockNote = mock(Note.class);
    when(mockNote.getCredentials()).thenReturn(mock(Credentials.class));
    Paragraph spyParagraph = spy(new Paragraph("para_1", mockNote, null));
    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));
    List<InterpreterSetting> spyInterpreterSettingList = spy(new ArrayList<>());
    InterpreterSetting mockInterpreterSetting = mock(InterpreterSetting.class);
    when(mockInterpreterGroup.getInterpreterSetting()).thenReturn(mockInterpreterSetting);
    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.getOrCreateInterpreterGroup(anyString(), anyString())).thenReturn(mockInterpreterGroup);
    when(mockInterpreterSetting.isUserAuthorized(any(List.class))).thenReturn(true);
    spyInterpreterSettingList.add(mockInterpreterSetting);
    when(mockNote.getId()).thenReturn("any_id");
    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);
    // Actual test
    List<InterpreterResultMessage> result1 = new ArrayList<>();
    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());
    mockInterpreterResult = mock(InterpreterResult.class);
    when(mockInterpreter.interpret(anyString(), Mockito.<InterpreterContext>any())).thenReturn(mockInterpreterResult);
    when(mockInterpreterResult.code()).thenReturn(Code.SUCCESS);
    List<InterpreterResultMessage> result2 = new ArrayList<>();
    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) ArrayList(java.util.ArrayList) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) ResourcePool(org.apache.zeppelin.resource.ResourcePool) InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) ManagedInterpreterGroup(org.apache.zeppelin.interpreter.ManagedInterpreterGroup) InterpreterOption(org.apache.zeppelin.interpreter.InterpreterOption) ArrayList(java.util.ArrayList) List(java.util.List) UserCredentials(org.apache.zeppelin.user.UserCredentials) Credentials(org.apache.zeppelin.user.Credentials) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) Ignore(org.junit.Ignore)

Example 14 with InterpreterOption

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

the class K8sStandardInterpreterLauncherTest method testK8sLauncher.

@Test
public void testK8sLauncher() throws IOException {
    // given
    ZeppelinConfiguration zConf = ZeppelinConfiguration.create();
    K8sStandardInterpreterLauncher launcher = new K8sStandardInterpreterLauncher(zConf, null);
    Properties properties = new Properties();
    properties.setProperty("ENV_1", "VALUE_1");
    properties.setProperty("property_1", "value_1");
    InterpreterOption option = new InterpreterOption();
    option.setUserImpersonate(true);
    InterpreterLaunchContext context = new InterpreterLaunchContext(properties, option, null, "user1", "intpGroupId", "groupId", "sh", "name", 0, "host");
    // when
    InterpreterClient client = launcher.launch(context);
    // then
    assertTrue(client instanceof K8sRemoteInterpreterProcess);
}
Also used : InterpreterOption(org.apache.zeppelin.interpreter.InterpreterOption) ZeppelinConfiguration(org.apache.zeppelin.conf.ZeppelinConfiguration) Properties(java.util.Properties) Test(org.junit.Test)

Example 15 with InterpreterOption

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

the class ClusterInterpreterLauncherTest method testCreateIntpProcessDockerMode.

@Test
public void testCreateIntpProcessDockerMode() throws IOException {
    zconf.setRunMode(ZeppelinConfiguration.RUN_MODE.DOCKER);
    ClusterInterpreterLauncher launcher = new ClusterInterpreterLauncher(zconf, null);
    Properties properties = new Properties();
    properties.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_CONNECT_TIMEOUT.getVarName(), "1000");
    InterpreterOption option = new InterpreterOption();
    option.setUserImpersonate(true);
    InterpreterLaunchContext context = new InterpreterLaunchContext(properties, option, null, "user1", "intpGroupId3", "groupId3", "groupName", "name", 0, "host");
    InterpreterClient client = launcher.launch(context);
    assertTrue(client instanceof DockerInterpreterProcess);
}
Also used : InterpreterOption(org.apache.zeppelin.interpreter.InterpreterOption) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

InterpreterOption (org.apache.zeppelin.interpreter.InterpreterOption)25 Properties (java.util.Properties)20 Test (org.junit.Test)17 ZeppelinConfiguration (org.apache.zeppelin.conf.ZeppelinConfiguration)12 ExecRemoteInterpreterProcess (org.apache.zeppelin.interpreter.remote.ExecRemoteInterpreterProcess)10 InterpreterSettingManager (org.apache.zeppelin.interpreter.InterpreterSettingManager)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 DependencyResolver (org.apache.zeppelin.dep.DependencyResolver)4 InterpreterFactory (org.apache.zeppelin.interpreter.InterpreterFactory)3 InterpreterInfo (org.apache.zeppelin.interpreter.InterpreterInfo)3 Credentials (org.apache.zeppelin.user.Credentials)3 Before (org.junit.Before)3 Path (java.nio.file.Path)2 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)2 Interpreter (org.apache.zeppelin.interpreter.Interpreter)2 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)2 InterpreterResultMessage (org.apache.zeppelin.interpreter.InterpreterResultMessage)2 InterpreterRunner (org.apache.zeppelin.interpreter.InterpreterRunner)2 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)2