Search in sources :

Example 1 with Notebook

use of org.apache.zeppelin.notebook.Notebook in project zeppelin by apache.

the class NotebookServer method generateNotesInfo.

public List<Map<String, String>> generateNotesInfo(boolean needsReload, AuthenticationInfo subject, Set<String> userAndRoles) {
    Notebook notebook = notebook();
    ZeppelinConfiguration conf = notebook.getConf();
    String homescreenNoteId = conf.getString(ConfVars.ZEPPELIN_NOTEBOOK_HOMESCREEN);
    boolean hideHomeScreenNotebookFromList = conf.getBoolean(ConfVars.ZEPPELIN_NOTEBOOK_HOMESCREEN_HIDE);
    if (needsReload) {
        try {
            notebook.reloadAllNotes(subject);
        } catch (IOException e) {
            LOG.error("Fail to reload notes from repository", e);
        }
    }
    List<Note> notes = notebook.getAllNotes(userAndRoles);
    List<Map<String, String>> notesInfo = new LinkedList<>();
    for (Note note : notes) {
        Map<String, String> info = new HashMap<>();
        if (hideHomeScreenNotebookFromList && note.getId().equals(homescreenNoteId)) {
            continue;
        }
        info.put("id", note.getId());
        info.put("name", note.getName());
        notesInfo.add(info);
    }
    return notesInfo;
}
Also used : Notebook(org.apache.zeppelin.notebook.Notebook) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ZeppelinConfiguration(org.apache.zeppelin.conf.ZeppelinConfiguration) Note(org.apache.zeppelin.notebook.Note) IOException(java.io.IOException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList)

Example 2 with Notebook

use of org.apache.zeppelin.notebook.Notebook in project zeppelin by apache.

the class NotebookServer method onGetParagraphRunners.

@Override
public void onGetParagraphRunners(String noteId, String paragraphId, RemoteWorksEventListener callback) {
    Notebook notebookIns = notebook();
    List<InterpreterContextRunner> runner = new LinkedList<>();
    if (notebookIns == null) {
        LOG.info("intepreter request notebook instance is null");
        callback.onFinished(notebookIns);
    }
    try {
        Note note = notebookIns.getNote(noteId);
        if (note != null) {
            if (paragraphId != null) {
                Paragraph paragraph = note.getParagraph(paragraphId);
                if (paragraph != null) {
                    runner.add(paragraph.getInterpreterContextRunner());
                }
            } else {
                for (Paragraph p : note.getParagraphs()) {
                    runner.add(p.getInterpreterContextRunner());
                }
            }
        }
        callback.onFinished(runner);
    } catch (NullPointerException e) {
        LOG.warn(e.getMessage());
        callback.onError();
    }
}
Also used : InterpreterContextRunner(org.apache.zeppelin.interpreter.InterpreterContextRunner) Notebook(org.apache.zeppelin.notebook.Notebook) Note(org.apache.zeppelin.notebook.Note) LinkedList(java.util.LinkedList) Paragraph(org.apache.zeppelin.notebook.Paragraph)

Example 3 with Notebook

use of org.apache.zeppelin.notebook.Notebook in project zeppelin by apache.

the class NotebookServer method broadcastUpdateNoteJobInfo.

public void broadcastUpdateNoteJobInfo(long lastUpdateUnixTime) throws IOException {
    List<Map<String, Object>> noteJobs = new LinkedList<>();
    Notebook notebookObject = notebook();
    List<Map<String, Object>> jobNotes = null;
    if (notebookObject != null) {
        jobNotes = notebook().getJobListByUnixTime(false, lastUpdateUnixTime, null);
        noteJobs = jobNotes == null ? noteJobs : jobNotes;
    }
    Map<String, Object> response = new HashMap<>();
    response.put("lastResponseUnixTime", System.currentTimeMillis());
    response.put("jobs", noteJobs != null ? noteJobs : new LinkedList<>());
    broadcast(JOB_MANAGER_SERVICE.JOB_MANAGER_PAGE.getKey(), new Message(OP.LIST_UPDATE_NOTE_JOBS).put("noteRunningJobs", response));
}
Also used : Notebook(org.apache.zeppelin.notebook.Notebook) InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Message(org.apache.zeppelin.notebook.socket.Message) WatcherMessage(org.apache.zeppelin.notebook.socket.WatcherMessage) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) AngularObject(org.apache.zeppelin.display.AngularObject) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList)

Example 4 with Notebook

use of org.apache.zeppelin.notebook.Notebook in project zeppelin by apache.

the class NotebookServer method onUpdate.

@Override
public void onUpdate(String interpreterGroupId, AngularObject object) {
    Notebook notebook = notebook();
    if (notebook == null) {
        return;
    }
    List<Note> notes = notebook.getAllNotes();
    for (Note note : notes) {
        if (object.getNoteId() != null && !note.getId().equals(object.getNoteId())) {
            continue;
        }
        List<InterpreterSetting> intpSettings = notebook.getInterpreterSettingManager().getInterpreterSettings(note.getId());
        if (intpSettings.isEmpty()) {
            continue;
        }
        broadcast(note.getId(), new Message(OP.ANGULAR_OBJECT_UPDATE).put("angularObject", object).put("interpreterGroupId", interpreterGroupId).put("noteId", note.getId()).put("paragraphId", object.getParagraphId()));
    }
}
Also used : Notebook(org.apache.zeppelin.notebook.Notebook) InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Message(org.apache.zeppelin.notebook.socket.Message) WatcherMessage(org.apache.zeppelin.notebook.socket.WatcherMessage) Note(org.apache.zeppelin.notebook.Note) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting)

Example 5 with Notebook

use of org.apache.zeppelin.notebook.Notebook 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)

Aggregations

Notebook (org.apache.zeppelin.notebook.Notebook)79 Test (org.junit.Test)53 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)48 Paragraph (org.apache.zeppelin.notebook.Paragraph)43 TypeToken (com.google.gson.reflect.TypeToken)33 Map (java.util.Map)25 HashMap (java.util.HashMap)24 Note (org.apache.zeppelin.notebook.Note)20 IOException (java.io.IOException)15 ArrayList (java.util.ArrayList)12 AuthorizationService (org.apache.zeppelin.notebook.AuthorizationService)12 Before (org.junit.Before)12 ZeppelinConfiguration (org.apache.zeppelin.conf.ZeppelinConfiguration)11 List (java.util.List)10 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)10 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)9 BeforeClass (org.junit.BeforeClass)9 InterpreterSettingManager (org.apache.zeppelin.interpreter.InterpreterSettingManager)8 InterpreterGroup (org.apache.zeppelin.interpreter.InterpreterGroup)7 RemoteAngularObjectRegistry (org.apache.zeppelin.interpreter.remote.RemoteAngularObjectRegistry)7