Search in sources :

Example 1 with Job

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

the class PythonInterpreter method getRunningJob.

private Job getRunningJob(String paragraphId) {
    Job foundJob = null;
    Collection<Job> jobsRunning = getScheduler().getJobsRunning();
    for (Job job : jobsRunning) {
        if (job.getId().equals(paragraphId)) {
            foundJob = job;
            break;
        }
    }
    return foundJob;
}
Also used : Job(org.apache.zeppelin.scheduler.Job)

Example 2 with Job

use of org.apache.zeppelin.scheduler.Job 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 3 with Job

use of org.apache.zeppelin.scheduler.Job 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 4 with Job

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

the class FIFOSchedulerTest method testAbort.

public void testAbort() 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);
    job1.abort();
    job2.abort();
    Thread.sleep(200);
    assertEquals(Status.ABORT, job1.getStatus());
    assertEquals(Status.ABORT, job2.getStatus());
    assertTrue((500 > (Long) job1.getReturn()));
    assertEquals(null, job2.getReturn());
}
Also used : Scheduler(org.apache.zeppelin.scheduler.Scheduler) Job(org.apache.zeppelin.scheduler.Job)

Example 5 with Job

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

the class FIFOSchedulerTest method testRemoveFromWaitingQueue.

public void testRemoveFromWaitingQueue() 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);
    job1.abort();
    job2.abort();
    Thread.sleep(200);
    assertEquals(Status.ABORT, job1.getStatus());
    assertEquals(Status.ABORT, job2.getStatus());
    assertTrue((500 > (Long) job1.getReturn()));
    assertEquals(null, job2.getReturn());
}
Also used : Scheduler(org.apache.zeppelin.scheduler.Scheduler) Job(org.apache.zeppelin.scheduler.Job)

Aggregations

Job (org.apache.zeppelin.scheduler.Job)30 Scheduler (org.apache.zeppelin.scheduler.Scheduler)15 AngularObject (org.apache.zeppelin.display.AngularObject)11 AuthenticationInfo (org.apache.zeppelin.user.AuthenticationInfo)11 Test (org.junit.Test)11 HashMap (java.util.HashMap)8 LinkedList (java.util.LinkedList)8 Map (java.util.Map)8 Properties (java.util.Properties)8 AngularObjectRegistry (org.apache.zeppelin.display.AngularObjectRegistry)8 GUI (org.apache.zeppelin.display.GUI)8 LocalResourcePool (org.apache.zeppelin.resource.LocalResourcePool)8 RemoteInterpreterResultMessage (org.apache.zeppelin.interpreter.thrift.RemoteInterpreterResultMessage)4 IOException (java.io.IOException)3 InetAddress (java.net.InetAddress)3 UnknownHostException (java.net.UnknownHostException)3 StandardCharsets (java.nio.charset.StandardCharsets)3 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3 Arrays.asList (java.util.Arrays.asList)3