Search in sources :

Example 6 with Scheduler

use of org.apache.zeppelin.scheduler.Scheduler in project zeppelin by apache.

the class RemoteInterpreterServer method interpret.

@Override
public RemoteInterpreterResult interpret(String noteId, String className, String st, RemoteInterpreterContext interpreterContext) throws TException {
    if (logger.isDebugEnabled()) {
        logger.debug("st:\n{}", st);
    }
    Interpreter intp = getInterpreter(noteId, className);
    InterpreterContext context = convert(interpreterContext);
    context.setClassName(intp.getClassName());
    Scheduler scheduler = intp.getScheduler();
    InterpretJobListener jobListener = new InterpretJobListener();
    InterpretJob job = new InterpretJob(interpreterContext.getParagraphId(), "remoteInterpretJob_" + System.currentTimeMillis(), jobListener, JobProgressPoller.DEFAULT_INTERVAL_MSEC, intp, st, context);
    scheduler.submit(job);
    while (!job.isTerminated()) {
        synchronized (jobListener) {
            try {
                jobListener.wait(1000);
            } catch (InterruptedException e) {
                logger.info("Exception in RemoteInterpreterServer while interpret, jobListener.wait", e);
            }
        }
    }
    InterpreterResult result;
    if (job.getStatus() == Status.ERROR) {
        result = new InterpreterResult(Code.ERROR, Job.getStack(job.getException()));
    } else {
        result = (InterpreterResult) job.getReturn();
        // in case of job abort in PENDING status, result can be null
        if (result == null) {
            result = new InterpreterResult(Code.KEEP_PREVIOUS_RESULT);
        }
    }
    return convert(result, context.getConfig(), context.getGui());
}
Also used : Scheduler(org.apache.zeppelin.scheduler.Scheduler)

Example 7 with Scheduler

use of org.apache.zeppelin.scheduler.Scheduler in project zeppelin by apache.

the class Paragraph method jobAbort.

@Override
protected boolean jobAbort() {
    Interpreter repl = getRepl(getRequiredReplName());
    if (repl == null) {
        // when interpreters are already destroyed
        return true;
    }
    Scheduler scheduler = repl.getScheduler();
    if (scheduler == null) {
        return true;
    }
    Job job = scheduler.removeFromWaitingQueue(getId());
    if (job != null) {
        job.setStatus(Status.ABORT);
    } else {
        repl.cancel(getInterpreterContextWithoutRunner(null));
    }
    return true;
}
Also used : Scheduler(org.apache.zeppelin.scheduler.Scheduler) Job(org.apache.zeppelin.scheduler.Job)

Example 8 with Scheduler

use of org.apache.zeppelin.scheduler.Scheduler in project zeppelin by apache.

the class FIFOSchedulerTest method testRun.

public void testRun() throws InterruptedException {
    Scheduler s = schedulerSvc.createOrGetFIFOScheduler("test");
    assertEquals(0, s.getJobsRunning().size());
    assertEquals(0, s.getJobsWaiting().size());
    Job job1 = new SleepingJob("job1", null, 500);
    Job job2 = new SleepingJob("job2", null, 500);
    s.submit(job1);
    s.submit(job2);
    Thread.sleep(200);
    assertEquals(Status.RUNNING, job1.getStatus());
    assertEquals(Status.PENDING, job2.getStatus());
    assertEquals(1, s.getJobsRunning().size());
    assertEquals(1, s.getJobsWaiting().size());
    Thread.sleep(500);
    assertEquals(Status.FINISHED, job1.getStatus());
    assertEquals(Status.RUNNING, job2.getStatus());
    assertTrue((500 < (Long) job1.getReturn()));
    assertEquals(1, s.getJobsRunning().size());
    assertEquals(0, s.getJobsWaiting().size());
}
Also used : Scheduler(org.apache.zeppelin.scheduler.Scheduler) Job(org.apache.zeppelin.scheduler.Job)

Example 9 with Scheduler

use of org.apache.zeppelin.scheduler.Scheduler in project zeppelin by apache.

the class ParallelSchedulerTest method testRun.

public void testRun() throws InterruptedException {
    Scheduler s = schedulerSvc.createOrGetParallelScheduler("test", 2);
    assertEquals(0, s.getJobsRunning().size());
    assertEquals(0, s.getJobsWaiting().size());
    Job job1 = new SleepingJob("job1", null, 500);
    Job job2 = new SleepingJob("job2", null, 500);
    Job job3 = new SleepingJob("job3", null, 500);
    s.submit(job1);
    s.submit(job2);
    s.submit(job3);
    Thread.sleep(200);
    assertEquals(Status.RUNNING, job1.getStatus());
    assertEquals(Status.RUNNING, job2.getStatus());
    assertEquals(Status.PENDING, job3.getStatus());
    assertEquals(2, s.getJobsRunning().size());
    assertEquals(1, s.getJobsWaiting().size());
    Thread.sleep(500);
    assertEquals(Status.FINISHED, job1.getStatus());
    assertEquals(Status.FINISHED, job2.getStatus());
    assertEquals(Status.RUNNING, job3.getStatus());
    assertEquals(1, s.getJobsRunning().size());
    assertEquals(0, s.getJobsWaiting().size());
}
Also used : Scheduler(org.apache.zeppelin.scheduler.Scheduler) Job(org.apache.zeppelin.scheduler.Job)

Example 10 with Scheduler

use of org.apache.zeppelin.scheduler.Scheduler in project zeppelin by apache.

the class RemoteInterpreterTest method testRunOrderPreserved.

@Test
public void testRunOrderPreserved() 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();
    int concurrency = 3;
    final List<InterpreterResultMessage> results = new LinkedList<>();
    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, 200) {

            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 {
                InterpreterResult ret = intpA.interpret(getJobName(), 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 null;
            }

            @Override
            protected boolean jobAbort() {
                return false;
            }
        });
    }
    // wait for job finished
    synchronized (results) {
        while (results.size() != concurrency) {
            results.wait(300);
        }
    }
    int i = 0;
    for (InterpreterResultMessage result : results) {
        assertEquals(Integer.toString(i++), result.getData());
    }
    assertEquals(concurrency, i);
    intpA.close();
}
Also used : LocalResourcePool(org.apache.zeppelin.resource.LocalResourcePool) Scheduler(org.apache.zeppelin.scheduler.Scheduler) Properties(java.util.Properties) RemoteInterpreterResultMessage(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterResultMessage) LinkedList(java.util.LinkedList) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) AngularObject(org.apache.zeppelin.display.AngularObject) GUI(org.apache.zeppelin.display.GUI) Job(org.apache.zeppelin.scheduler.Job) HashMap(java.util.HashMap) Map(java.util.Map) AngularObjectRegistry(org.apache.zeppelin.display.AngularObjectRegistry) Test(org.junit.Test)

Aggregations

Scheduler (org.apache.zeppelin.scheduler.Scheduler)10 Job (org.apache.zeppelin.scheduler.Job)7 Properties (java.util.Properties)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 AngularObject (org.apache.zeppelin.display.AngularObject)2 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)2 GUI (org.apache.zeppelin.display.GUI)2 RemoteInterpreterResultMessage (org.apache.zeppelin.interpreter.thrift.RemoteInterpreterResultMessage)2 LocalResourcePool (org.apache.zeppelin.resource.LocalResourcePool)2 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)2 FIFOScheduler (org.apache.zeppelin.scheduler.FIFOScheduler)1 ParallelScheduler (org.apache.zeppelin.scheduler.ParallelScheduler)1