This is an automated email from the ASF dual-hosted git repository. bmahler pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mesos.git
commit 5d2732692541ec9aecba20c501fb5e35a19ab49f Author: Andrei Sekretenko <[email protected]> AuthorDate: Tue Jul 2 00:26:37 2019 -0400 Added constructors with a list of suppressed roles to Java V0 bindings. Review: https://reviews.apache.org/r/70945/ --- .../jni/org_apache_mesos_MesosSchedulerDriver.cpp | 23 +++++ .../src/org/apache/mesos/MesosSchedulerDriver.java | 106 +++++++++++++++++++++ 2 files changed, 129 insertions(+) diff --git a/src/java/jni/org_apache_mesos_MesosSchedulerDriver.cpp b/src/java/jni/org_apache_mesos_MesosSchedulerDriver.cpp index 5ac9a64..f81a69a 100644 --- a/src/java/jni/org_apache_mesos_MesosSchedulerDriver.cpp +++ b/src/java/jni/org_apache_mesos_MesosSchedulerDriver.cpp @@ -548,12 +548,34 @@ JNIEXPORT void JNICALL Java_org_apache_mesos_MesosSchedulerDriver_initialize jcredential = env->GetObjectField(thiz, credential.get()); } + // Get out the suppressedRoles passed into the constructor. + // + // NOTE: Older versions (< 1.9.0) of MesosSchedulerDriver do not set the + // 'suppressedRoles' field. To be backwards compatible, we should use an empty + // list of suppressed roles if the field is not set. + + Result<jfieldID> suppressedRolesFieldID = getFieldID( + env, clazz, "suppressedRoles", "Ljava/util/Collection;"); + if (suppressedRolesFieldID.isError()) { + return; // Exception has been thrown. + } + + vector<string> suppressedRoles; + if (suppressedRolesFieldID.isSome()) { + jobject jsuppressedRoles = + env->GetObjectField(thiz, suppressedRolesFieldID.get()); + if (jsuppressedRoles != nullptr) { + suppressedRoles = constructFromIterable<string>(env, jsuppressedRoles); + } + } + // Create the C++ driver. MesosSchedulerDriver* driver = nullptr; if (jcredential != nullptr) { driver = new MesosSchedulerDriver( scheduler, construct<FrameworkInfo>(env, jframework), + suppressedRoles, construct<string>(env, jmaster), construct(env, jimplicitAcknowledgements), construct<Credential>(env, jcredential)); @@ -561,6 +583,7 @@ JNIEXPORT void JNICALL Java_org_apache_mesos_MesosSchedulerDriver_initialize driver = new MesosSchedulerDriver( scheduler, construct<FrameworkInfo>(env, jframework), + suppressedRoles, construct<string>(env, jmaster), construct(env, jimplicitAcknowledgements)); } diff --git a/src/java/src/org/apache/mesos/MesosSchedulerDriver.java b/src/java/src/org/apache/mesos/MesosSchedulerDriver.java index fb16b67..772a738 100644 --- a/src/java/src/org/apache/mesos/MesosSchedulerDriver.java +++ b/src/java/src/org/apache/mesos/MesosSchedulerDriver.java @@ -105,6 +105,7 @@ public class MesosSchedulerDriver implements SchedulerDriver { this.scheduler = scheduler; this.framework = framework; + this.suppressedRoles = null; this.master = master; this.implicitAcknowledgements = true; this.credential = null; @@ -146,6 +147,7 @@ public class MesosSchedulerDriver implements SchedulerDriver { this.scheduler = scheduler; this.framework = framework; + this.suppressedRoles = null; this.master = master; this.implicitAcknowledgements = true; this.credential = credential; @@ -185,6 +187,7 @@ public class MesosSchedulerDriver implements SchedulerDriver { this.scheduler = scheduler; this.framework = framework; + this.suppressedRoles = null; this.master = master; this.implicitAcknowledgements = implicitAcknowledgements; this.credential = null; @@ -231,6 +234,7 @@ public class MesosSchedulerDriver implements SchedulerDriver { this.scheduler = scheduler; this.framework = framework; + this.suppressedRoles = null; this.master = master; this.implicitAcknowledgements = implicitAcknowledgements; this.credential = credential; @@ -238,6 +242,107 @@ public class MesosSchedulerDriver implements SchedulerDriver { initialize(); } + /** + * Same as the other constructors, except that it accepts the newly + * introduced 'suppressedRoles' parameter. + * + * @param scheduler The scheduler implementation which callbacks are invoked + * upon scheduler events. + * @param framework The frameworkInfo describing the current framework. + * @param suppressedRoles The collection of initially suppressed roles. + * @param master The address to the currently active Mesos master. + * @param implicitAcknowledgements Whether the driver should send + * acknowledgements on behalf of the scheduler. Setting this to + * false allows schedulers to perform their own acknowledgements, + * which enables asynchronous / batch processing of status updates. + */ + public MesosSchedulerDriver(Scheduler scheduler, + FrameworkInfo framework, + Collection<String> suppressedRoles, + String master, + boolean implicitAcknowledgements) { + + if (scheduler == null) { + throw new NullPointerException("Not expecting a null Scheduler"); + } + + if (framework == null) { + throw new NullPointerException("Not expecting a null FrameworkInfo"); + } + + if (suppressedRoles == null) { + throw new NullPointerException("Not expecting a null suppressedRoles"); + } + + if (master == null) { + throw new NullPointerException("Not expecting a null master"); + } + + this.scheduler = scheduler; + this.framework = framework; + this.suppressedRoles = suppressedRoles; + this.master = master; + this.implicitAcknowledgements = implicitAcknowledgements; + this.credential = null; + + initialize(); + } + + + /** + * Same as the other constructors, except that it accepts the newly + * introduced 'suppressedRoles' parameter. + * + * @param scheduler The scheduler implementation which callbacks are invoked + * upon scheduler events. + * @param framework The frameworkInfo describing the current framework. + * @param suppressedRoles The collection of initially suppressed roles. + * @param master The address to the currently active Mesos master. + * @param implicitAcknowledgements Whether the driver should send + * acknowledgements on behalf of the scheduler. Setting this to + * false allows schedulers to perform their own acknowledgements, + * which enables asynchronous / batch processing of status updates. + * @param credential The credentials that will be used used to authenticate + * calls from this scheduler. + */ + public MesosSchedulerDriver(Scheduler scheduler, + FrameworkInfo framework, + Collection<String> suppressedRoles, + String master, + boolean implicitAcknowledgements, + Credential credential) { + + if (scheduler == null) { + throw new NullPointerException("Not expecting a null Scheduler"); + } + + if (framework == null) { + throw new NullPointerException("Not expecting a null FrameworkInfo"); + } + + if (suppressedRoles == null) { + throw new NullPointerException("Not expecting a null suppressedRoles"); + } + + if (master == null) { + throw new NullPointerException("Not expecting a null master"); + } + + if (credential == null) { + throw new NullPointerException("Not expecting a null credential"); + } + + this.scheduler = scheduler; + this.framework = framework; + this.suppressedRoles = suppressedRoles; + this.master = master; + this.implicitAcknowledgements = implicitAcknowledgements; + this.credential = credential; + + initialize(); + } + + public native Status start(); public native Status stop(boolean failover); @@ -306,6 +411,7 @@ public class MesosSchedulerDriver implements SchedulerDriver { private final Scheduler scheduler; private final FrameworkInfo framework; + private final Collection<String> suppressedRoles; private final String master; private final boolean implicitAcknowledgements; private final Credential credential;
