Search in sources :

Example 26 with LinkedList

use of java.util.LinkedList in project zeppelin by apache.

the class RemoteInterpreterTest method testRemoteInterperterCall.

@Test
public void testRemoteInterperterCall() throws TTransportException, IOException {
    Properties p = new Properties();
    intpGroup.put("note", new LinkedList<Interpreter>());
    RemoteInterpreter intpA = createMockInterpreterA(p);
    intpGroup.get("note").add(intpA);
    intpA.setInterpreterGroup(intpGroup);
    RemoteInterpreter intpB = createMockInterpreterB(p);
    intpGroup.get("note").add(intpB);
    intpB.setInterpreterGroup(intpGroup);
    RemoteInterpreterProcess process = intpA.getInterpreterProcess();
    process.equals(intpB.getInterpreterProcess());
    assertFalse(process.isRunning());
    assertEquals(0, process.getNumIdleClient());
    assertEquals(0, process.referenceCount());
    // initializa all interpreters in the same group
    intpA.open();
    assertTrue(process.isRunning());
    assertEquals(1, process.getNumIdleClient());
    assertEquals(2, process.referenceCount());
    intpA.interpret("1", new InterpreterContext("note", "id", null, "title", "text", new AuthenticationInfo(), new HashMap<String, Object>(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), new LocalResourcePool("pool1"), new LinkedList<InterpreterContextRunner>(), null));
    intpB.open();
    assertEquals(2, process.referenceCount());
    intpA.close();
    assertEquals(1, process.referenceCount());
    intpB.close();
    assertEquals(0, process.referenceCount());
    assertFalse(process.isRunning());
}
Also used : LocalResourcePool(org.apache.zeppelin.resource.LocalResourcePool) HashMap(java.util.HashMap) GUI(org.apache.zeppelin.display.GUI) Properties(java.util.Properties) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 27 with LinkedList

use of java.util.LinkedList in project zeppelin by apache.

the class RemoteInterpreterTest method testInterpreterGroupResetDuringProcessRunning.

@Test
public void testInterpreterGroupResetDuringProcessRunning() throws InterruptedException {
    Properties p = new Properties();
    intpGroup.put("note", new LinkedList<Interpreter>());
    final RemoteInterpreter intpA = createMockInterpreterA(p);
    intpGroup.get("note").add(intpA);
    intpA.setInterpreterGroup(intpGroup);
    intpA.open();
    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("2000", 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);
    // wait for job started
    while (intpA.getScheduler().getJobsRunning().size() == 0) {
        Thread.sleep(100);
    }
    // restart interpreter
    RemoteInterpreterProcess processA = intpA.getInterpreterProcess();
    intpA.close();
    InterpreterGroup newInterpreterGroup = new InterpreterGroup(intpA.getInterpreterGroup().getId());
    newInterpreterGroup.put("note", new LinkedList<Interpreter>());
    intpA.setInterpreterGroup(newInterpreterGroup);
    intpA.open();
    RemoteInterpreterProcess processB = intpA.getInterpreterProcess();
    assertNotSame(processA.hashCode(), processB.hashCode());
}
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 28 with LinkedList

use of java.util.LinkedList in project zeppelin by apache.

the class RemoteInterpreterTest method testRunParallel.

@Test
public void testRunParallel() throws InterruptedException {
    Properties p = new Properties();
    p.put("parallel", "true");
    intpGroup.put("note", new LinkedList<Interpreter>());
    final RemoteInterpreter intpA = createMockInterpreterA(p);
    intpGroup.get("note").add(intpA);
    intpA.setInterpreterGroup(intpGroup);
    intpA.open();
    int concurrency = 4;
    final int timeToSleep = 1000;
    final List<InterpreterResultMessage> results = new LinkedList<>();
    long start = System.currentTimeMillis();
    Scheduler scheduler = intpA.getScheduler();
    for (int i = 0; i < concurrency; i++) {
        final String jobId = Integer.toString(i);
        scheduler.submit(new Job(jobId, Integer.toString(i), null, 300) {

            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 {
                String stmt = Integer.toString(timeToSleep);
                InterpreterResult ret = intpA.interpret(stmt, new InterpreterContext("note", jobId, null, "title", "text", new AuthenticationInfo(), new HashMap<String, Object>(), new GUI(), new AngularObjectRegistry(intpGroup.getId(), null), new LocalResourcePool("pool1"), new LinkedList<InterpreterContextRunner>(), null));
                synchronized (results) {
                    results.addAll(ret.message());
                    results.notify();
                }
                return stmt;
            }

            @Override
            protected boolean jobAbort() {
                return false;
            }
        });
    }
    // wait for job finished
    synchronized (results) {
        while (results.size() != concurrency) {
            results.wait(300);
        }
    }
    long end = System.currentTimeMillis();
    assertTrue(end - start < timeToSleep * concurrency);
    intpA.close();
}
Also used : LocalResourcePool(org.apache.zeppelin.resource.LocalResourcePool) Scheduler(org.apache.zeppelin.scheduler.Scheduler) Properties(java.util.Properties) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) GUI(org.apache.zeppelin.display.GUI) Job(org.apache.zeppelin.scheduler.Job) RemoteInterpreterResultMessage(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterResultMessage) LinkedList(java.util.LinkedList) AngularObject(org.apache.zeppelin.display.AngularObject) HashMap(java.util.HashMap) Map(java.util.Map) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) Test(org.junit.Test)

Example 29 with LinkedList

use of java.util.LinkedList 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 30 with LinkedList

use of java.util.LinkedList 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)

Aggregations

LinkedList (java.util.LinkedList)10856 Test (org.junit.Test)1545 List (java.util.List)1517 HashMap (java.util.HashMap)1413 ArrayList (java.util.ArrayList)1368 Map (java.util.Map)915 IOException (java.io.IOException)826 File (java.io.File)721 HashSet (java.util.HashSet)632 LinkedHashMap (java.util.LinkedHashMap)390 GenericValue (org.apache.ofbiz.entity.GenericValue)296 Iterator (java.util.Iterator)281 Set (java.util.Set)274 Date (java.util.Date)249 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)232 Collection (java.util.Collection)208 Collectors (java.util.stream.Collectors)162 Delegator (org.apache.ofbiz.entity.Delegator)162 URL (java.net.URL)159 Locale (java.util.Locale)159