0

I'm in the process of writing a client for Apache Mesos' new HTTP Scheduler API using RxJava and RxNetty.

I've managed to successfully create the connection with RxNetty and create an Observable<Event> from the resulting chunked stream.

Now I'm at the point of trying to model a sink that can be used to send calls back to Mesos in order to claim/decline resource offers, acknowledge task status updates, etc.

The message that will be sent to sent to Mesos is a Call, I need to be able to provide an onCompleted or onError for every Call that comes into the Sink. This is due to Mesos performing synchronous validation on the Call being sent to it.

I'm essentially trying to allow for the following:

final MesosSchedulerClient client = new MesosSchedulerClient();
final Observable<Event> events = client.openEventStream(subscribeCall);

final Observable<Observable<Call>> ackCalls = events
    .filter(event -> event.getType() == Event.Type.UPDATE && event.getUpdate().getStatus().hasUuid())
    .zipWith(frameworkIDObservable, (Event e, AtomicReference<FrameworkID>> fwId) -> {
        final TaskStatus status = e.getUpdate().getStatus();
        final Call ackCall = ackUpdate(fwId.get(), status.getUuid(), status.getAgentId(), status.getTaskId());
        return Observable.just(ackCall)
            .doOnComplete(() -> { ... })
            .doOnError((e) -> { ... });
    });

client.sink(ackCalls);

Right now I've come up with a custom object[1] that extends Subject and specifies the Call and Action0 for onCompleted and Action1<Throwable> for onError. Though, I would prefer to use the existing constructs from RxJava if possible. Sample usage of what I've come up with[2].

Any guidance would be greatly appreciated.

[1] https://github.com/BenWhitehead/mesos-rxjava/blob/sink-operation/mesos-rxjava-core/src/main/java/org/apache/mesos/rx/java/SinkOperation.java#L17

[2] https://github.com/BenWhitehead/mesos-rxjava/blob/sink-operation/mesos-rxjava-example/mesos-rxjava-example-framework/src/main/java/org/apache/mesos/rx/java/example/framework/sleepy/Main.java#L117-L124

  • I'm not familiar with mesos and don't fully understand what you want to achieve. Extending Subject seems to be unnecessary as you don't take subscribers; instead, you may want to use Subscribers.create() or extend Subscriber. – akarnokd Nov 08 '15 at 20:51
  • Thanks for the guidance @akarnokd I'll investigate creating a Subscriber. – Ben Whitehead Nov 11 '15 at 01:29
  • Thanks @akarnokd I switched to using a Subscriber. – Ben Whitehead Nov 12 '15 at 19:58

1 Answers1

0

The solution I ended up with was to create a custom Subscriber that would process the event stream and send the requests back to mesos.