Search in sources :

Example 1 with Message

use of org.apache.mesos.v1.scheduler.Protos.Call.Message in project Singularity by HubSpot.

the class SingularityMesosSchedulerClient method frameworkMessage.

/**
 * Sent by the scheduler to send arbitrary binary data to the executor. Mesos neither interprets this data nor
 * makes any guarantees about the delivery of this message to the executor. data is raw bytes encoded in Base64.
 *
 * @param executorId
 * @param agentId
 * @param data
 */
public void frameworkMessage(ExecutorID executorId, AgentID agentId, byte[] data) {
    Builder message = build().setMessage(Message.newBuilder().setAgentId(agentId).setExecutorId(executorId).setData(ByteString.copyFrom(data)));
    sendCall(message, Type.MESSAGE);
}
Also used : MesosClientBuilder(com.mesosphere.mesos.rx.java.MesosClientBuilder) ProtobufMesosClientBuilder(com.mesosphere.mesos.rx.java.protobuf.ProtobufMesosClientBuilder) Builder(org.apache.mesos.v1.scheduler.Protos.Call.Builder)

Example 2 with Message

use of org.apache.mesos.v1.scheduler.Protos.Call.Message in project Singularity by HubSpot.

the class SingularityMesosSchedulerClient method connect.

/**
 * Sets up the connection and is blocking in wait for calls from mesos
 * master.
 */
private void connect(URI mesosMasterURI, FrameworkInfo frameworkInfo, SingularityMesosScheduler scheduler) throws URISyntaxException {
    MesosClientBuilder<Call, Event> clientBuilder = ProtobufMesosClientBuilder.schedulerUsingProtos().mesosUri(mesosMasterURI).applicationUserAgentEntry(UserAgentEntries.userAgentEntryForMavenArtifact("com.hubspot.singularity", "SingularityService")).onBackpressureBuffer(scheduler.getEventBufferSize(), () -> {
        String message = String.format("Overflow of event buffer (%s), singularity could not keep up!", scheduler.getEventBufferSize());
        scheduler.onUncaughtException(new EventBufferOverflowException(message));
    }, BackpressureOverflow.ON_OVERFLOW_ERROR);
    Call subscribeCall = Call.newBuilder().setType(Call.Type.SUBSCRIBE).setFrameworkId(frameworkInfo.getId()).setSubscribe(Call.Subscribe.newBuilder().setFrameworkInfo(frameworkInfo).build()).build();
    MesosClientBuilder<Call, Event> subscribe = clientBuilder.subscribe(subscribeCall);
    subscribe.processStream(unicastEvents -> {
        final Observable<Event> events = unicastEvents.share();
        events.filter(event -> event.getType() == Event.Type.ERROR).map(event -> event.getError().getMessage()).subscribe(scheduler::error, scheduler::onUncaughtException);
        events.filter(event -> event.getType() == Event.Type.FAILURE).map(Event::getFailure).subscribe(scheduler::failure, scheduler::onUncaughtException);
        events.filter(event -> event.getType() == Event.Type.HEARTBEAT).subscribe(scheduler::heartbeat, scheduler::onUncaughtException);
        events.filter(event -> event.getType() == Event.Type.INVERSE_OFFERS).map(event -> event.getInverseOffers().getInverseOffersList()).subscribe(scheduler::inverseOffers, scheduler::onUncaughtException);
        events.filter(event -> event.getType() == Event.Type.MESSAGE).map(Event::getMessage).subscribe(scheduler::message, scheduler::onUncaughtException);
        events.filter(event -> event.getType() == Event.Type.OFFERS).map(event -> event.getOffers().getOffersList()).subscribe(scheduler::resourceOffers, scheduler::onUncaughtException);
        events.filter(event -> event.getType() == Event.Type.RESCIND).map(event -> event.getRescind().getOfferId()).subscribe(scheduler::rescind, scheduler::onUncaughtException);
        events.filter(event -> event.getType() == Event.Type.RESCIND_INVERSE_OFFER).map(event -> event.getRescindInverseOffer().getInverseOfferId()).subscribe(scheduler::rescindInverseOffer, scheduler::onUncaughtException);
        events.filter(event -> event.getType() == Event.Type.SUBSCRIBED).map(Event::getSubscribed).subscribe(subscribed -> {
            this.frameworkId = subscribed.getFrameworkId();
            scheduler.subscribed(subscribed);
        }, scheduler::onUncaughtException);
        events.filter(event -> event.getType() == Event.Type.UPDATE).map(event -> event.getUpdate().getStatus()).filter(status -> {
            if (!status.hasAgentId() || !status.getAgentId().hasValue()) {
                LOG.warn("Filtering out status update without agentId {}", status);
                return false;
            } else {
                return true;
            }
        }).subscribe(scheduler::statusUpdate, scheduler::onUncaughtException);
        // This is the observable that is responsible for sending calls to mesos master.
        PublishSubject<Optional<SinkOperation<Call>>> p = PublishSubject.create();
        // toSerialised handles the fact that we can add calls on different threads.
        publisher = p.toSerialized();
        return publisher;
    });
    MesosClient<Call, Event> client = clientBuilder.build();
    openStream = client.openStream();
    try {
        openStream.await();
    } catch (Throwable t) {
        LOG.error("Observable was unexpectedly closed", t);
        scheduler.onConnectException(t);
    }
}
Also used : MesosClientBuilder(com.mesosphere.mesos.rx.java.MesosClientBuilder) ProtobufMesosClientBuilder(com.mesosphere.mesos.rx.java.protobuf.ProtobufMesosClientBuilder) Reconcile(org.apache.mesos.v1.scheduler.Protos.Call.Reconcile) URISyntaxException(java.net.URISyntaxException) Inject(com.google.inject.Inject) UIConfiguration(com.hubspot.singularity.config.UIConfiguration) LoggerFactory(org.slf4j.LoggerFactory) SinkOperations(com.mesosphere.mesos.rx.java.SinkOperations) Offer(org.apache.mesos.v1.Protos.Offer) Event(org.apache.mesos.v1.scheduler.Protos.Event) FrameworkID(org.apache.mesos.v1.Protos.FrameworkID) Observable(rx.Observable) Type(org.apache.mesos.v1.scheduler.Protos.Call.Type) Filters(org.apache.mesos.v1.Protos.Filters) MesosClient(com.mesosphere.mesos.rx.java.MesosClient) SerializedSubject(rx.subjects.SerializedSubject) URI(java.net.URI) BackpressureOverflow(rx.BackpressureOverflow) SingularityConfiguration(com.hubspot.singularity.config.SingularityConfiguration) Acknowledge(org.apache.mesos.v1.scheduler.Protos.Call.Acknowledge) UiResource(com.hubspot.singularity.resources.ui.UiResource) FrameworkInfo(org.apache.mesos.v1.Protos.FrameworkInfo) Accept(org.apache.mesos.v1.scheduler.Protos.Call.Accept) Builder(org.apache.mesos.v1.scheduler.Protos.Call.Builder) Logger(org.slf4j.Logger) AgentID(org.apache.mesos.v1.Protos.AgentID) Message(org.apache.mesos.v1.scheduler.Protos.Call.Message) OfferID(org.apache.mesos.v1.Protos.OfferID) ExecutorID(org.apache.mesos.v1.Protos.ExecutorID) ByteString(com.google.protobuf.ByteString) SingularityServiceUIModule(com.hubspot.singularity.resources.SingularityServiceUIModule) Decline(org.apache.mesos.v1.scheduler.Protos.Call.Decline) List(java.util.List) Kill(org.apache.mesos.v1.scheduler.Protos.Call.Kill) Shutdown(org.apache.mesos.v1.scheduler.Protos.Call.Shutdown) UserAgentEntries(com.mesosphere.mesos.rx.java.util.UserAgentEntries) TaskID(org.apache.mesos.v1.Protos.TaskID) Call(org.apache.mesos.v1.scheduler.Protos.Call) Request(org.apache.mesos.v1.scheduler.Protos.Call.Request) Optional(java.util.Optional) Named(com.google.inject.name.Named) AwaitableSubscription(com.mesosphere.mesos.rx.java.AwaitableSubscription) SinkOperation(com.mesosphere.mesos.rx.java.SinkOperation) KillPolicy(org.apache.mesos.v1.Protos.KillPolicy) MesosConfiguration(com.hubspot.singularity.config.MesosConfiguration) PublishSubject(rx.subjects.PublishSubject) Call(org.apache.mesos.v1.scheduler.Protos.Call) Optional(java.util.Optional) Event(org.apache.mesos.v1.scheduler.Protos.Event) ByteString(com.google.protobuf.ByteString)

Example 3 with Message

use of org.apache.mesos.v1.scheduler.Protos.Call.Message in project Singularity by HubSpot.

the class SingularityMesosSchedulerImpl method message.

@Override
public void message(Message message) {
    ExecutorID executorID = message.getExecutorId();
    AgentID slaveId = message.getAgentId();
    byte[] data = message.getData().toByteArray();
    LOG.info("Framework message from executor {} on slave {} with {} bytes of data", executorID, slaveId, data.length);
    messageHandler.handleMessage(executorID, slaveId, data);
}
Also used : ExecutorID(org.apache.mesos.v1.Protos.ExecutorID) AgentID(org.apache.mesos.v1.Protos.AgentID)

Aggregations

MesosClientBuilder (com.mesosphere.mesos.rx.java.MesosClientBuilder)2 ProtobufMesosClientBuilder (com.mesosphere.mesos.rx.java.protobuf.ProtobufMesosClientBuilder)2 AgentID (org.apache.mesos.v1.Protos.AgentID)2 ExecutorID (org.apache.mesos.v1.Protos.ExecutorID)2 Builder (org.apache.mesos.v1.scheduler.Protos.Call.Builder)2 Inject (com.google.inject.Inject)1 Named (com.google.inject.name.Named)1 ByteString (com.google.protobuf.ByteString)1 MesosConfiguration (com.hubspot.singularity.config.MesosConfiguration)1 SingularityConfiguration (com.hubspot.singularity.config.SingularityConfiguration)1 UIConfiguration (com.hubspot.singularity.config.UIConfiguration)1 SingularityServiceUIModule (com.hubspot.singularity.resources.SingularityServiceUIModule)1 UiResource (com.hubspot.singularity.resources.ui.UiResource)1 AwaitableSubscription (com.mesosphere.mesos.rx.java.AwaitableSubscription)1 MesosClient (com.mesosphere.mesos.rx.java.MesosClient)1 SinkOperation (com.mesosphere.mesos.rx.java.SinkOperation)1 SinkOperations (com.mesosphere.mesos.rx.java.SinkOperations)1 UserAgentEntries (com.mesosphere.mesos.rx.java.util.UserAgentEntries)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1