Search in sources :

Example 1 with Status

use of org.apache.zeppelin.scheduler.Job.Status in project zeppelin by apache.

the class NotebookServer method broadcastSpellExecution.

private void broadcastSpellExecution(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws IOException {
    final String paragraphId = (String) fromMessage.get("id");
    if (paragraphId == null) {
        return;
    }
    String noteId = getOpenNoteId(conn);
    if (!hasParagraphWriterPermission(conn, notebook, noteId, userAndRoles, fromMessage.principal, "write")) {
        return;
    }
    String text = (String) fromMessage.get("paragraph");
    String title = (String) fromMessage.get("title");
    Status status = Status.valueOf((String) fromMessage.get("status"));
    Map<String, Object> params = (Map<String, Object>) fromMessage.get("params");
    Map<String, Object> config = (Map<String, Object>) fromMessage.get("config");
    final Note note = notebook.getNote(noteId);
    Paragraph p = setParagraphUsingMessage(note, fromMessage, paragraphId, text, title, params, config);
    p.setResult(fromMessage.get("results"));
    p.setErrorMessage((String) fromMessage.get("errorMessage"));
    p.setStatusWithoutNotification(status);
    addNewParagraphIfLastParagraphIsExecuted(note, p);
    if (!persistNoteWithAuthInfo(conn, note, p)) {
        return;
    }
    // broadcast to other clients only
    broadcastExcept(note.getId(), new Message(OP.RUN_PARAGRAPH_USING_SPELL).put("paragraph", p), conn);
}
Also used : Status(org.apache.zeppelin.scheduler.Job.Status) 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) JsonObject(com.google.gson.JsonObject) AngularObject(org.apache.zeppelin.display.AngularObject) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Paragraph(org.apache.zeppelin.notebook.Paragraph)

Example 2 with Status

use of org.apache.zeppelin.scheduler.Job.Status in project zeppelin by apache.

the class NotebookTest method testNotebookEventListener.

@Test
public void testNotebookEventListener() throws IOException {
    final AtomicInteger onNoteRemove = new AtomicInteger(0);
    final AtomicInteger onNoteCreate = new AtomicInteger(0);
    final AtomicInteger onParagraphRemove = new AtomicInteger(0);
    final AtomicInteger onParagraphCreate = new AtomicInteger(0);
    final AtomicInteger unbindInterpreter = new AtomicInteger(0);
    notebook.addNotebookEventListener(new NotebookEventListener() {

        @Override
        public void onNoteRemove(Note note) {
            onNoteRemove.incrementAndGet();
        }

        @Override
        public void onNoteCreate(Note note) {
            onNoteCreate.incrementAndGet();
        }

        @Override
        public void onUnbindInterpreter(Note note, InterpreterSetting setting) {
            unbindInterpreter.incrementAndGet();
        }

        @Override
        public void onParagraphRemove(Paragraph p) {
            onParagraphRemove.incrementAndGet();
        }

        @Override
        public void onParagraphCreate(Paragraph p) {
            onParagraphCreate.incrementAndGet();
        }

        @Override
        public void onParagraphStatusChange(Paragraph p, Status status) {
        }
    });
    Note note1 = notebook.createNote(anonymous);
    assertEquals(1, onNoteCreate.get());
    Paragraph p1 = note1.addParagraph(AuthenticationInfo.ANONYMOUS);
    assertEquals(1, onParagraphCreate.get());
    note1.addCloneParagraph(p1);
    assertEquals(2, onParagraphCreate.get());
    note1.removeParagraph(anonymous.getUser(), p1.getId());
    assertEquals(1, onParagraphRemove.get());
    List<String> settings = notebook.getBindedInterpreterSettingsIds(note1.getId());
    notebook.bindInterpretersToNote(anonymous.getUser(), note1.getId(), new LinkedList<String>());
    assertEquals(settings.size(), unbindInterpreter.get());
    notebook.removeNote(note1.getId(), anonymous);
    assertEquals(1, onNoteRemove.get());
    assertEquals(1, onParagraphRemove.get());
}
Also used : Status(org.apache.zeppelin.scheduler.Job.Status) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 3 with Status

use of org.apache.zeppelin.scheduler.Job.Status in project zeppelin by apache.

the class NotebookTest method testSchedulePoolUsage.

@Test
public void testSchedulePoolUsage() throws InterruptedException, IOException {
    final int timeout = 30;
    final String everySecondCron = "* * * * * ?";
    final CountDownLatch jobsToExecuteCount = new CountDownLatch(13);
    final Note note = notebook.createNote(anonymous);
    executeNewParagraphByCron(note, everySecondCron);
    afterStatusChangedListener = new StatusChangedListener() {

        @Override
        public void onStatusChanged(Job job, Status before, Status after) {
            if (after == Status.FINISHED) {
                jobsToExecuteCount.countDown();
            }
        }
    };
    assertTrue(jobsToExecuteCount.await(timeout, TimeUnit.SECONDS));
    terminateScheduledNote(note);
    afterStatusChangedListener = null;
}
Also used : Status(org.apache.zeppelin.scheduler.Job.Status) CountDownLatch(java.util.concurrent.CountDownLatch) Job(org.apache.zeppelin.scheduler.Job) Test(org.junit.Test)

Aggregations

Status (org.apache.zeppelin.scheduler.Job.Status)3 Test (org.junit.Test)2 JsonObject (com.google.gson.JsonObject)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AngularObject (org.apache.zeppelin.display.AngularObject)1 InterpreterResultMessage (org.apache.zeppelin.interpreter.InterpreterResultMessage)1 Note (org.apache.zeppelin.notebook.Note)1 Paragraph (org.apache.zeppelin.notebook.Paragraph)1 Message (org.apache.zeppelin.notebook.socket.Message)1 WatcherMessage (org.apache.zeppelin.notebook.socket.WatcherMessage)1 Job (org.apache.zeppelin.scheduler.Job)1