Search in sources :

Example 76 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.

the class RemoteInterpreterTest method testRemoteSchedulerSharingSubmit.

@Test
public void testRemoteSchedulerSharingSubmit() throws TTransportException, IOException, InterruptedException {
    Properties p = new Properties();
    intpGroup.put("note", new LinkedList<Interpreter>());
    final RemoteInterpreter intpA = createMockInterpreterA(p);
    intpGroup.get("note").add(intpA);
    intpA.setInterpreterGroup(intpGroup);
    final RemoteInterpreter intpB = createMockInterpreterB(p);
    intpGroup.get("note").add(intpB);
    intpB.setInterpreterGroup(intpGroup);
    intpA.open();
    intpB.open();
    long start = System.currentTimeMillis();
    Job jobA = new Job("jobA", null) {

        private Object r;

        @Override
        public Object getReturn() {
            return r;
        }

        @Override
        public void setResult(Object results) {
            this.r = results;
        }

        @Override
        public int progress() {
            return 0;
        }

        @Override
        public Map<String, Object> info() {
            return null;
        }

        @Override
        protected Object jobRun() throws Throwable {
            return intpA.interpret("500", new InterpreterContext("note", "jobA", null, "title", "text", new AuthenticationInfo(), new HashMap<String, Object>(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), new LocalResourcePool("pool1"), new LinkedList<InterpreterContextRunner>(), null));
        }

        @Override
        protected boolean jobAbort() {
            return false;
        }
    };
    intpA.getScheduler().submit(jobA);
    Job jobB = new Job("jobB", null) {

        private Object r;

        @Override
        public Object getReturn() {
            return r;
        }

        @Override
        public void setResult(Object results) {
            this.r = results;
        }

        @Override
        public int progress() {
            return 0;
        }

        @Override
        public Map<String, Object> info() {
            return null;
        }

        @Override
        protected Object jobRun() throws Throwable {
            return intpB.interpret("500", new InterpreterContext("note", "jobB", null, "title", "text", new AuthenticationInfo(), new HashMap<String, Object>(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), new LocalResourcePool("pool1"), new LinkedList<InterpreterContextRunner>(), null));
        }

        @Override
        protected boolean jobAbort() {
            return false;
        }
    };
    intpB.getScheduler().submit(jobB);
    // wait until both job finished
    while (jobA.getStatus() != Status.FINISHED || jobB.getStatus() != Status.FINISHED) {
        Thread.sleep(100);
    }
    long end = System.currentTimeMillis();
    assertTrue(end - start >= 1000);
    assertEquals("1000", ((InterpreterResult) jobB.getReturn()).message().get(0).getData());
    intpA.close();
    intpB.close();
}
Also used : LocalResourcePool(org.apache.zeppelin.resource.LocalResourcePool) HashMap(java.util.HashMap) Properties(java.util.Properties) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) LinkedList(java.util.LinkedList) AngularObject(org.apache.zeppelin.display.AngularObject) GUI(org.apache.zeppelin.display.GUI) Job(org.apache.zeppelin.scheduler.Job) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) Test(org.junit.Test)

Example 77 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.

the class NotebookServer method removeParagraph.

private void removeParagraph(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;
    }
    /** We dont want to remove the last paragraph */
    final Note note = notebook.getNote(noteId);
    if (!note.isLastParagraph(paragraphId)) {
        AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
        Paragraph para = note.removeParagraph(subject.getUser(), paragraphId);
        note.persist(subject);
        if (para != null) {
            broadcast(note.getId(), new Message(OP.PARAGRAPH_REMOVED).put("id", para.getId()));
        }
    }
}
Also used : 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) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Paragraph(org.apache.zeppelin.notebook.Paragraph)

Example 78 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.

the class NotebookServer method importNote.

protected Note importNote(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws IOException {
    Note note = null;
    if (fromMessage != null) {
        String noteName = (String) ((Map) fromMessage.get("note")).get("name");
        String noteJson = gson.toJson(fromMessage.get("note"));
        AuthenticationInfo subject = null;
        if (fromMessage.principal != null) {
            subject = new AuthenticationInfo(fromMessage.principal);
        } else {
            subject = new AuthenticationInfo("anonymous");
        }
        note = notebook.importNote(noteJson, noteName, subject);
        note.persist(subject);
        broadcastNote(note);
        broadcastNoteList(subject, userAndRoles);
    }
    return note;
}
Also used : Note(org.apache.zeppelin.notebook.Note) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo)

Example 79 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.

the class NotebookServer method insertParagraph.

private String insertParagraph(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook, Message fromMessage) throws IOException {
    final int index = (int) Double.parseDouble(fromMessage.get("index").toString());
    String noteId = getOpenNoteId(conn);
    final Note note = notebook.getNote(noteId);
    AuthenticationInfo subject = new AuthenticationInfo(fromMessage.principal);
    if (!hasParagraphWriterPermission(conn, notebook, noteId, userAndRoles, fromMessage.principal, "write")) {
        return null;
    }
    Paragraph newPara = note.insertParagraph(index, subject);
    note.persist(subject);
    broadcastNewParagraph(note, newPara);
    return newPara.getId();
}
Also used : Note(org.apache.zeppelin.notebook.Note) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Paragraph(org.apache.zeppelin.notebook.Paragraph)

Example 80 with AuthenticationInfo

use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.

the class NotebookRestApi method importNote.

/**
   * import new note REST API
   *
   * @param req - note Json
   * @return JSON with new note ID
   * @throws IOException
   */
@POST
@Path("import")
@ZeppelinApi
public Response importNote(String req) throws IOException {
    AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
    Note newNote = notebook.importNote(req, null, subject);
    return new JsonResponse<>(Status.OK, "", newNote.getId()).build();
}
Also used : Note(org.apache.zeppelin.notebook.Note) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) POST(javax.ws.rs.POST)

Aggregations

AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)128 Test (org.junit.Test)44 HashMap (java.util.HashMap)40 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)29 Properties (java.util.Properties)28 Note (org.apache.zeppelin.notebook.Note)27 LocalResourcePool (org.apache.zeppelin.resource.LocalResourcePool)23 LinkedList (java.util.LinkedList)22 GUI (org.apache.zeppelin.display.GUI)22 Map (java.util.Map)21 ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)20 AngularObject (org.apache.zeppelin.display.AngularObject)19 InterpreterResultMessage (org.apache.zeppelin.interpreter.InterpreterResultMessage)19 IOException (java.io.IOException)18 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)18 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)18 Paragraph (org.apache.zeppelin.notebook.Paragraph)18 InterpreterOutput (org.apache.zeppelin.interpreter.InterpreterOutput)16 Path (javax.ws.rs.Path)15 HashSet (java.util.HashSet)13