This is an automated email from the ASF dual-hosted git repository.

asekretenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit 930c7e98d17e71192dae1d49b4b2217cc2dbd8b2
Author: Andrei Sekretenko <asekrete...@mesosphere.com>
AuthorDate: Wed Sep 16 12:28:24 2020 +0200

    Added offer constraints to `updateFramework()` in the Java bindings.
    
    Review: https://reviews.apache.org/r/72900
---
 src/examples/java/TestFramework.java               |  7 +++-
 src/java/jni/construct.cpp                         | 10 ++++++
 .../jni/org_apache_mesos_MesosSchedulerDriver.cpp  | 15 +++++++--
 .../src/org/apache/mesos/MesosSchedulerDriver.java | 10 +++++-
 src/java/src/org/apache/mesos/SchedulerDriver.java | 37 ++++++++++++++++------
 5 files changed, 64 insertions(+), 15 deletions(-)

diff --git a/src/examples/java/TestFramework.java 
b/src/examples/java/TestFramework.java
index 1dea79c..1a84ca3 100644
--- a/src/examples/java/TestFramework.java
+++ b/src/examples/java/TestFramework.java
@@ -28,6 +28,8 @@ import com.google.protobuf.ByteString;
 
 import org.apache.mesos.*;
 import org.apache.mesos.Protos.*;
+import org.apache.mesos.scheduler.Protos.OfferConstraints;
+import org.apache.mesos.scheduler.Protos.AttributeConstraint;
 
 public class TestFramework {
   static class TestScheduler implements Scheduler {
@@ -50,7 +52,10 @@ public class TestFramework {
       // Clear suppressed roles.
       FrameworkInfo.Builder builder = framework.toBuilder();
       builder.setId(frameworkId);
-      driver.updateFramework(builder.build(), new ArrayList<String>());
+      driver.updateFramework(
+          builder.build(),
+          new ArrayList<String>(),
+          OfferConstraints.getDefaultInstance());
     }
 
     @Override
diff --git a/src/java/jni/construct.cpp b/src/java/jni/construct.cpp
index a48ca07..d45ed6c 100644
--- a/src/java/jni/construct.cpp
+++ b/src/java/jni/construct.cpp
@@ -25,6 +25,8 @@
 
 #include <mesos/mesos.hpp>
 
+#include <mesos/scheduler/scheduler.hpp>
+
 #include <mesos/v1/mesos.hpp>
 
 #include <mesos/v1/scheduler/scheduler.hpp>
@@ -147,6 +149,14 @@ FrameworkInfo construct(JNIEnv* env, jobject jobj)
   return constructViaProtobufSerialization<FrameworkInfo>(env, jobj);
 }
 
+template <>
+::mesos::scheduler::OfferConstraints construct(JNIEnv* env, jobject jobj)
+{
+  return constructViaProtobufSerialization<
+      ::mesos::scheduler::OfferConstraints>(env, jobj);
+}
+
+
 
 template <>
 Credential construct(JNIEnv* env, jobject jobj)
diff --git a/src/java/jni/org_apache_mesos_MesosSchedulerDriver.cpp 
b/src/java/jni/org_apache_mesos_MesosSchedulerDriver.cpp
index 4d71765..4efde30 100644
--- a/src/java/jni/org_apache_mesos_MesosSchedulerDriver.cpp
+++ b/src/java/jni/org_apache_mesos_MesosSchedulerDriver.cpp
@@ -1068,18 +1068,27 @@ 
Java_org_apache_mesos_MesosSchedulerDriver_reconcileTasks(
 
 /* Class:     org_apache_mesos_MesosSchedulerDriver
  * Method:    updateFramework
- * Signature: 
(Lorg/apache/mesos/Protos/FrameworkInfo;Ljava/util/Collection;)Lorg/apache/mesos/Protos/Status;
+ * Signature: 
(Lorg/apache/mesos/Protos/FrameworkInfo;Ljava/util/Collection;Lorg/apache/mesos/scheduler/Protos/OfferConstraints;)Lorg/apache/mesos/Protos/Status;
  */
 JNIEXPORT jobject JNICALL
 Java_org_apache_mesos_MesosSchedulerDriver_updateFramework(
-    JNIEnv* env, jobject thiz, jobject jframeworkInfo, jobject 
jsuppressedRoles)
+    JNIEnv* env,
+    jobject thiz,
+    jobject jframeworkInfo,
+    jobject jsuppressedRoles,
+    jobject jofferConstraints)
 {
+  using ::mesos::scheduler::OfferConstraints;
+
   const FrameworkInfo& frameworkInfo =
     construct<FrameworkInfo>(env, jframeworkInfo);
 
   const vector<string> suppressedRoles =
     constructFromIterable<string>(env, jsuppressedRoles);
 
+  ::mesos::scheduler::OfferConstraints offerConstraints =
+    construct<OfferConstraints>(env, jofferConstraints);
+
   jclass clazz = env->GetObjectClass(thiz);
 
   jfieldID __driver = env->GetFieldID(clazz, "__driver", "J");
@@ -1087,7 +1096,7 @@ 
Java_org_apache_mesos_MesosSchedulerDriver_updateFramework(
     (MesosSchedulerDriver*) env->GetLongField(thiz, __driver);
 
   Status status = driver->updateFramework(
-      frameworkInfo, suppressedRoles, ::mesos::scheduler::OfferConstraints());
+      frameworkInfo, suppressedRoles, std::move(offerConstraints));
 
   return convert<Status>(env, status);
 }
diff --git a/src/java/src/org/apache/mesos/MesosSchedulerDriver.java 
b/src/java/src/org/apache/mesos/MesosSchedulerDriver.java
index 3e74be9..4fdae33 100644
--- a/src/java/src/org/apache/mesos/MesosSchedulerDriver.java
+++ b/src/java/src/org/apache/mesos/MesosSchedulerDriver.java
@@ -19,6 +19,7 @@
 package org.apache.mesos;
 
 import org.apache.mesos.Protos.*;
+import org.apache.mesos.scheduler.Protos.OfferConstraints;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -408,7 +409,14 @@ public class MesosSchedulerDriver implements 
SchedulerDriver {
   public native Status reconcileTasks(Collection<TaskStatus> statuses);
 
   public native Status updateFramework(FrameworkInfo frameworkInfo,
-                                       Collection<String> suppressedRoles);
+                                       Collection<String> suppressedRoles,
+                                       OfferConstraints offerConstraints);
+
+  public Status updateFramework(FrameworkInfo frameworkInfo,
+                                Collection<String> suppressedRoles) {
+    return updateFramework(
+        frameworkInfo, suppressedRoles, OfferConstraints.getDefaultInstance());
+  }
 
   protected native void initialize();
   protected native void finalize();
diff --git a/src/java/src/org/apache/mesos/SchedulerDriver.java 
b/src/java/src/org/apache/mesos/SchedulerDriver.java
index e04916e..b400034 100644
--- a/src/java/src/org/apache/mesos/SchedulerDriver.java
+++ b/src/java/src/org/apache/mesos/SchedulerDriver.java
@@ -19,6 +19,8 @@
 package org.apache.mesos;
 
 import org.apache.mesos.Protos.*;
+import org.apache.mesos.scheduler.Protos.OfferConstraints;
+
 
 import java.util.Collection;
 import java.util.Map;
@@ -364,14 +366,17 @@ public interface SchedulerDriver {
    */
   Status reconcileTasks(Collection<TaskStatus> statuses);
 
-  /**
-   * Inform Mesos master about changes to the `FrameworkInfo` and the list of
-   * suppressed roles. The driver will store the new `FrameworkInfo` and the 
new
-   * suppressed roles list, and all subsequent re-registrations will use it.
+  /*
+   * Requests Mesos master to change the `FrameworkInfo`, the set of suppressed
+   * roles and the offer constraints. The driver will store the new
+   * `FrameworkInfo`, the new set of suppressed roles and the new offer
+   * constraints, and all subsequent re-registrations will use them.
    *
    * NOTE: If the supplied info is invalid or fails authorization,
-   * the `error()` callback will be invoked asynchronously (after
-   * the master replies with a `FrameworkErrorMessage`).
+   * or the supplied offer constraints are not valid, the `error()` callback
+   * will be invoked asynchronously (after the master replies with a
+   * `FrameworkErrorMessage`). Note that validity of non-empty (i.e.
+   * not default-constructed) offer constraints may depend on master flags.
    *
    * NOTE: This must be called after initial registration with the
    * master completes and the `FrameworkID` is assigned. The assigned
@@ -381,14 +386,26 @@ public interface SchedulerDriver {
    * fields will be auto-populated using the same approach used
    * during driver initialization.
    *
-   * @param frameworkInfo  The new FrameworkInfo.
-   *
-   * @param suppressedRoles The new list of suppressed roles.
+   * @param frameworkInfo     The new FrameworkInfo.
+   * @param suppressedRoles   The new list of suppressed roles.
+   * @param offerConstraints  The new offer constraints.
    *
-   * @return               The state of the driver after the call.
+   * @return                  The state of the driver after the call.
    *
    * @see FrameworkInfo
+   * @see OfferConstraints
    */
   Status updateFramework(FrameworkInfo frameworkInfo,
+                         Collection<String> suppressedRoles,
+                         OfferConstraints offerConstraints);
+
+ /**
+  * @deprecated
+  * To call UPDATE_FRAMEWORK without setting offer constraints,
+  * use the new `updateFramework()` signature and pass empty constraints
+  * (for example, the ones returned by 
`OfferConstraints.getDefaultInstance()`).
+  */
+  @Deprecated
+  Status updateFramework(FrameworkInfo frameworkInfo,
                          Collection<String> suppressedRoles);
 }

Reply via email to