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();
}
}
Aggregations