use of org.apache.mesos.v1.scheduler.Protos.Event in project Singularity by HubSpot.
the class SingularityMesosSchedulerClient method shutdown.
/**
* Sent by the scheduler to shutdown a specific custom executor. When an executor gets a shutdown event,
* it is expected to kill all its tasks (and send TASK_KILLED updates) and terminate. If an executor
* doesn’t terminate within a certain timeout, the agent will forcefully destroy the container
* (executor and its tasks) and transition its active tasks to TASK_LOST.
*
* @param executorId
*/
public void shutdown(ExecutorID executorId) {
Builder shutdown = build().setShutdown(Shutdown.newBuilder().setExecutorId(executorId));
sendCall(shutdown, Type.SHUTDOWN);
}
use of org.apache.mesos.v1.scheduler.Protos.Event 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);
}
}
Aggregations