Search in sources :

Example 1 with JobAssignmentResult

use of io.mantisrx.server.core.JobAssignmentResult in project mantis by Netflix.

the class SimpleSchedulerObserver method main.

public static void main(String[] args) {
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    objectMapper.registerModule(new Jdk8Module());
    try {
        Args.parse(SimpleSchedulerObserver.class, args);
    } catch (IllegalArgumentException e) {
        Args.usage(SimpleSchedulerObserver.class);
        System.exit(1);
    }
    Properties properties = new Properties();
    try (InputStream inputStream = new FileInputStream(propFile)) {
        properties.load(inputStream);
    } catch (IOException e) {
        e.printStackTrace();
    }
    System.out.println("Listening to scheduling assignments with jobId=" + jobId);
    final CountDownLatch latch = new CountDownLatch(1);
    SimpleSchedulerObserver schedulerObserver = new SimpleSchedulerObserver(properties);
    final AtomicReference<JobAssignmentResult> ref = new AtomicReference<>(null);
    schedulerObserver.getObservable(jobId).filter(new Func1<JobAssignmentResult, Boolean>() {

        @Override
        public Boolean call(JobAssignmentResult jobAssignmentResult) {
            if (jobAssignmentResult == null)
                return false;
            if (jobAssignmentResult.isIdentical(ref.get()))
                return false;
            ref.set(jobAssignmentResult);
            return true;
        }
    }).doOnNext(new Action1<JobAssignmentResult>() {

        @Override
        public void call(JobAssignmentResult jobAssignmentResult) {
            System.out.println("Failures for job " + jobAssignmentResult.getJobId() + ":");
            for (JobAssignmentResult.Failure failure : jobAssignmentResult.getFailures()) try {
                System.out.println("  " + objectMapper.writeValueAsString(failure));
            } catch (JsonProcessingException e) {
                e.printStackTrace();
            }
        }
    }).doOnCompleted(new Action0() {

        @Override
        public void call() {
            latch.countDown();
        }
    }).doOnError(new Action1<Throwable>() {

        @Override
        public void call(Throwable throwable) {
            throwable.printStackTrace();
            latch.countDown();
        }
    }).subscribe();
    System.out.println("Subscribed.");
    try {
        latch.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : Action0(rx.functions.Action0) Action1(rx.functions.Action1) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) Properties(java.util.Properties) CountDownLatch(java.util.concurrent.CountDownLatch) JobAssignmentResult(io.mantisrx.server.core.JobAssignmentResult) FileInputStream(java.io.FileInputStream) Jdk8Module(io.mantisrx.shaded.com.fasterxml.jackson.datatype.jdk8.Jdk8Module) JsonProcessingException(io.mantisrx.shaded.com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

JobAssignmentResult (io.mantisrx.server.core.JobAssignmentResult)1 JsonProcessingException (io.mantisrx.shaded.com.fasterxml.jackson.core.JsonProcessingException)1 Jdk8Module (io.mantisrx.shaded.com.fasterxml.jackson.datatype.jdk8.Jdk8Module)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Properties (java.util.Properties)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Action0 (rx.functions.Action0)1 Action1 (rx.functions.Action1)1