You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by as...@apache.org on 2020/09/25 16:04:36 UTC
[mesos] branch master updated (098315f -> 930c7e9)
This is an automated email from the ASF dual-hosted git repository.
asekretenko pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git.
from 098315f Exposed hierarchical allocator recovery parameters as master flags.
new 739a704 Added `OfferConstraints` validity criteria into protobuf comments.
new 242f49e Added a test for creating a filter from default `OfferConstraints`.
new 28ff20d Made offer constraints filter and protobuf non-optional inside the code.
new fcfa327 Added offer constraints to `MesosSchedulerDriver::updateFramework()`.
new 930c7e9 Added offer constraints to `updateFramework()` in the Java bindings.
The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
include/mesos/allocator/allocator.hpp | 9 +++-
include/mesos/scheduler.hpp | 22 ++++++----
include/mesos/scheduler/scheduler.proto | 9 ++++
include/mesos/v1/scheduler/scheduler.proto | 9 ++++
src/examples/java/TestFramework.java | 7 ++-
src/java/jni/construct.cpp | 10 +++++
.../jni/org_apache_mesos_MesosSchedulerDriver.cpp | 16 +++++--
.../src/org/apache/mesos/MesosSchedulerDriver.java | 10 ++++-
src/java/src/org/apache/mesos/SchedulerDriver.java | 37 +++++++++++-----
.../allocator/mesos/offer_constraints_filter.cpp | 6 +++
src/master/framework.cpp | 10 ++---
src/master/http.cpp | 4 +-
src/master/master.cpp | 50 ++++++++--------------
src/master/master.hpp | 18 ++++----
src/master/readonly_handler.cpp | 6 +--
.../scheduler/mesos_scheduler_driver_impl.cpp | 4 +-
src/sched/sched.cpp | 25 ++++++++---
.../master/offer_constraints_filter_tests.cpp | 13 ++++++
src/tests/master/update_framework_tests.cpp | 18 ++++----
src/tests/scheduler_driver_tests.cpp | 2 +-
20 files changed, 191 insertions(+), 94 deletions(-)
[mesos] 02/05: Added a test for creating a filter from default
`OfferConstraints`.
Posted by as...@apache.org.
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 242f49ee95e0bcac68d67e0d07f0ce5f3a133e87
Author: Andrei Sekretenko <as...@mesosphere.com>
AuthorDate: Tue Sep 22 14:55:43 2020 +0200
Added a test for creating a filter from default `OfferConstraints`.
Review: https://reviews.apache.org/r/72899
---
src/tests/master/offer_constraints_filter_tests.cpp | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/src/tests/master/offer_constraints_filter_tests.cpp b/src/tests/master/offer_constraints_filter_tests.cpp
index f80d56c..64b6f12 100644
--- a/src/tests/master/offer_constraints_filter_tests.cpp
+++ b/src/tests/master/offer_constraints_filter_tests.cpp
@@ -581,3 +581,16 @@ TEST(OfferConstraintsFilter, TwoRoles)
EXPECT_TRUE(
filter->isAgentExcluded("roleB", slaveInfoWithAttributes("foo:123")));
}
+
+
+// Tests that using default-constructed `OfferConstraints` to construct
+// a filter results in a no-op filter that does not exclude any agents
+// (and not, for example, in an error).
+TEST(OfferConstraintsFilter, DefaultOfferConstraints)
+{
+ const Try<OfferConstraintsFilter> filter = createFilter(OfferConstraints{});
+
+ ASSERT_SOME(filter);
+
+ EXPECT_FALSE(filter->isAgentExcluded("role", SlaveInfo{}));
+}
[mesos] 05/05: Added offer constraints to `updateFramework()` in
the Java bindings.
Posted by as...@apache.org.
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 <as...@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);
}
[mesos] 01/05: Added `OfferConstraints` validity criteria into
protobuf comments.
Posted by as...@apache.org.
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 739a704a11f6cfc68ab6e035c7e945d8f5774303
Author: Andrei Sekretenko <as...@mesosphere.com>
AuthorDate: Tue Sep 22 14:55:13 2020 +0200
Added `OfferConstraints` validity criteria into protobuf comments.
Review: https://reviews.apache.org/r/72898
---
include/mesos/scheduler/scheduler.proto | 9 +++++++++
include/mesos/v1/scheduler/scheduler.proto | 9 +++++++++
2 files changed, 18 insertions(+)
diff --git a/include/mesos/scheduler/scheduler.proto b/include/mesos/scheduler/scheduler.proto
index f70738c..f70d379 100644
--- a/include/mesos/scheduler/scheduler.proto
+++ b/include/mesos/scheduler/scheduler.proto
@@ -443,6 +443,15 @@ message AttributeConstraint {
// NOTE: Even if a particular resource matches offer constraints of a
// framework's role, there is still no guarantee that it will ever be offered
// to this role of the framework.
+//
+// NOTE: Each `Group` must contain at least one constraint, and
+// `RoleConstraints` must contain at least one `Group`, otherwise
+// the message is not valid.
+//
+// NOTE: Frameworks are allowed to use default-constructed
+// `OfferConstraints` (instead of not setting the `offer_constraints` field)
+// in the SUBSCRIBE/UPDATE_FRAMEWORK calls to indicate subscription without
+// any offer constraints.
message OfferConstraints {
message RoleConstraints {
message Group {
diff --git a/include/mesos/v1/scheduler/scheduler.proto b/include/mesos/v1/scheduler/scheduler.proto
index 364d2c8..a8596b6 100644
--- a/include/mesos/v1/scheduler/scheduler.proto
+++ b/include/mesos/v1/scheduler/scheduler.proto
@@ -441,6 +441,15 @@ message AttributeConstraint {
// NOTE: Even if a particular resource matches offer constraints of a
// framework's role, there is still no guarantee that it will ever be offered
// to this role of the framework.
+//
+// NOTE: Each `Group` must contain at least one constraint, and
+// `RoleConstraints` must contain at least one `Group`, otherwise
+// the message is not valid.
+//
+// NOTE: Frameworks are allowed to use default-constructed
+// `OfferConstraints` (instead of not setting the `offer_constraints` field)
+// in the SUBSCRIBE/UPDATE_FRAMEWORK calls to indicate subscription without
+// any offer constraints.
message OfferConstraints {
message RoleConstraints {
message Group {
[mesos] 03/05: Made offer constraints filter and protobuf
non-optional inside the code.
Posted by as...@apache.org.
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 28ff20d4990ec2097852a5cd16966628d89c31d3
Author: Andrei Sekretenko <as...@mesosphere.com>
AuthorDate: Thu Sep 24 16:12:46 2020 +0200
Made offer constraints filter and protobuf non-optional inside the code.
Given that Mesos now provides a guarantee that specifying no offer
constraint in UPDATE_FRAMEWORK/SUBSCRIBE call is equivalent to
specifying default-constructed `OfferConstraints`, and that we are
intending to make the V0 scheduler driver always require offer
constraints as an argument to the `updateFramework()`, it no longer
makes sense to keep `OfferConstraints`/`OfferConstraintsFilter`
optional inside the Mesos code base.
This patch replaces a non-set `Option<OfferConstraints>` with
default-constructed `OfferConstraints`, and a non-set
`Option<OfferConstraintsFilter>` with a default-constructed filter.
Review: https://reviews.apache.org/r/72897
---
include/mesos/allocator/allocator.hpp | 9 +++-
.../allocator/mesos/offer_constraints_filter.cpp | 6 +++
src/master/framework.cpp | 10 ++---
src/master/http.cpp | 4 +-
src/master/master.cpp | 50 ++++++++--------------
src/master/master.hpp | 18 ++++----
src/master/readonly_handler.cpp | 6 +--
7 files changed, 49 insertions(+), 54 deletions(-)
diff --git a/include/mesos/allocator/allocator.hpp b/include/mesos/allocator/allocator.hpp
index b0a5d6a..c378f78 100644
--- a/include/mesos/allocator/allocator.hpp
+++ b/include/mesos/allocator/allocator.hpp
@@ -110,7 +110,12 @@ public:
const Options& options,
scheduler::OfferConstraints&& constraints);
- OfferConstraintsFilter() = delete;
+ /*
+ * Constructs a no-op filter that does not exclude any agents/resources from
+ * being offered. This is equivalent to passing default-constructed
+ * `OfferConstraints` to the factory method `create()`.
+ */
+ OfferConstraintsFilter();
// Definitions of these need `OfferConstraintsFilterImpl` to be a complete
// type.
@@ -149,7 +154,7 @@ struct FrameworkOptions
/**
* The internal representation of framework's offer constraints.
*/
- Option<OfferConstraintsFilter> offerConstraintsFilter;
+ OfferConstraintsFilter offerConstraintsFilter;
};
diff --git a/src/master/allocator/mesos/offer_constraints_filter.cpp b/src/master/allocator/mesos/offer_constraints_filter.cpp
index 441ebc1..45199ca 100644
--- a/src/master/allocator/mesos/offer_constraints_filter.cpp
+++ b/src/master/allocator/mesos/offer_constraints_filter.cpp
@@ -472,6 +472,12 @@ OfferConstraintsFilter::OfferConstraintsFilter(
{}
+OfferConstraintsFilter::OfferConstraintsFilter()
+ : OfferConstraintsFilter(
+ CHECK_NOTERROR(OfferConstraintsFilterImpl::create({Bytes(0), 0}, {})))
+{}
+
+
OfferConstraintsFilter::OfferConstraintsFilter(OfferConstraintsFilter&&) =
default;
diff --git a/src/master/framework.cpp b/src/master/framework.cpp
index 980828e..a93172a 100644
--- a/src/master/framework.cpp
+++ b/src/master/framework.cpp
@@ -35,7 +35,7 @@ Framework::Framework(
Master* const master,
const Flags& masterFlags,
const FrameworkInfo& info,
- Option<OfferConstraints>&& offerConstraints,
+ OfferConstraints&& offerConstraints,
const process::UPID& pid,
const Owned<ObjectApprovers>& approvers,
const process::Time& time)
@@ -57,7 +57,7 @@ Framework::Framework(
Master* const master,
const Flags& masterFlags,
const FrameworkInfo& info,
- Option<OfferConstraints>&& offerConstraints,
+ OfferConstraints&& offerConstraints,
const StreamingHttpConnection<v1::scheduler::Event>& http,
const Owned<ObjectApprovers>& approvers,
const process::Time& time)
@@ -83,7 +83,7 @@ Framework::Framework(
master,
masterFlags,
info,
- None(),
+ OfferConstraints{},
RECOVERED,
false,
nullptr,
@@ -95,7 +95,7 @@ Framework::Framework(
Master* const _master,
const Flags& masterFlags,
const FrameworkInfo& _info,
- Option<OfferConstraints>&& offerConstraints,
+ OfferConstraints&& offerConstraints,
State state,
bool active_,
const Owned<ObjectApprovers>& approvers,
@@ -538,7 +538,7 @@ void Framework::removeOperation(Operation* operation)
void Framework::update(
const FrameworkInfo& newInfo,
- Option<OfferConstraints>&& offerConstraints)
+ OfferConstraints&& offerConstraints)
{
// We only merge 'info' from the same framework 'id'.
CHECK_EQ(info.id(), newInfo.id());
diff --git a/src/master/http.cpp b/src/master/http.cpp
index 3d8e709..c4595cc 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -1301,9 +1301,7 @@ mesos::master::Response::GetFrameworks::Framework model(
_framework.mutable_offered_resources()->Add()->CopyFrom(resource);
}
- if (framework.offerConstraints().isSome()) {
- *_framework.mutable_offer_constraints() = *framework.offerConstraints();
- }
+ *_framework.mutable_offer_constraints() = framework.offerConstraints();
return _framework;
}
diff --git a/src/master/master.cpp b/src/master/master.cpp
index 576ae10..d6d3ea7 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -2675,17 +2675,13 @@ void Master::subscribe(
Option<Error> validationError =
validateFramework(frameworkInfo, subscribe.suppressed_roles());
- Option<OfferConstraints> offerConstraints;
- if (subscribe.has_offer_constraints()) {
- offerConstraints = std::move(*subscribe.mutable_offer_constraints());
- }
-
allocator::FrameworkOptions allocatorOptions;
// TODO(asekretenko): Validate roles in offer constraints (see MESOS-10176).
- if (validationError.isNone() && offerConstraints.isSome()) {
+ if (validationError.isNone()) {
Try<OfferConstraintsFilter> filter = OfferConstraintsFilter::create(
- offerConstraintsFilterOptions, OfferConstraints(*offerConstraints));
+ offerConstraintsFilterOptions,
+ OfferConstraints(subscribe.offer_constraints()));
if (filter.isError()) {
validationError = Error(std::move(filter.error()));
@@ -2715,7 +2711,7 @@ void Master::subscribe(
void (Master::*_subscribe)(
StreamingHttpConnection<v1::scheduler::Event>,
FrameworkInfo&&,
- Option<OfferConstraints>&&,
+ OfferConstraints&&,
bool,
FrameworkOptions&&,
const Future<Owned<ObjectApprovers>>&) = &Self::_subscribe;
@@ -2728,7 +2724,7 @@ void Master::subscribe(
_subscribe,
http,
std::move(frameworkInfo),
- std::move(offerConstraints),
+ std::move(*subscribe.mutable_offer_constraints()),
subscribe.force(),
std::move(allocatorOptions),
lambda::_1));
@@ -2738,7 +2734,7 @@ void Master::subscribe(
void Master::_subscribe(
StreamingHttpConnection<v1::scheduler::Event> http,
FrameworkInfo&& frameworkInfo,
- Option<OfferConstraints>&& offerConstraints,
+ OfferConstraints&& offerConstraints,
bool force,
::mesos::allocator::FrameworkOptions&& options,
const Future<Owned<ObjectApprovers>>& objectApprovers)
@@ -2937,17 +2933,13 @@ void Master::subscribe(
validationError = validateFrameworkAuthentication(frameworkInfo, from);
}
- Option<OfferConstraints> offerConstraints;
- if (subscribe.has_offer_constraints()) {
- offerConstraints = std::move(*subscribe.mutable_offer_constraints());
- }
-
allocator::FrameworkOptions allocatorOptions;
// TODO(asekretenko): Validate roles in offer constraints (see MESOS-10176).
- if (validationError.isNone() && offerConstraints.isSome()) {
+ if (validationError.isNone()) {
Try<OfferConstraintsFilter> filter = OfferConstraintsFilter::create(
- offerConstraintsFilterOptions, OfferConstraints(*offerConstraints));
+ offerConstraintsFilterOptions,
+ OfferConstraints(subscribe.offer_constraints()));
if (filter.isError()) {
validationError = Error(std::move(filter.error()));
@@ -2991,7 +2983,7 @@ void Master::subscribe(
void (Master::*_subscribe)(
const UPID&,
FrameworkInfo&&,
- Option<OfferConstraints>&&,
+ OfferConstraints&&,
bool,
::mesos::allocator::FrameworkOptions&&,
const Future<Owned<ObjectApprovers>>&) = &Self::_subscribe;
@@ -3004,7 +2996,7 @@ void Master::subscribe(
_subscribe,
from,
std::move(frameworkInfo),
- std::move(offerConstraints),
+ std::move(*subscribe.mutable_offer_constraints()),
subscribe.force(),
std::move(allocatorOptions),
lambda::_1));
@@ -3014,7 +3006,7 @@ void Master::subscribe(
void Master::_subscribe(
const UPID& from,
FrameworkInfo&& frameworkInfo,
- Option<OfferConstraints>&& offerConstraints,
+ OfferConstraints&& offerConstraints,
bool force,
::mesos::allocator::FrameworkOptions&& options,
const Future<Owned<ObjectApprovers>>& objectApprovers)
@@ -3296,13 +3288,11 @@ Future<process::http::Response> Master::updateFramework(
const bool frameworkInfoChanged =
!typeutils::equivalent(framework->info, call.framework_info());
- Option<OfferConstraints> offerConstraints;
allocator::FrameworkOptions allocatorOptions;
- if (call.has_offer_constraints()) {
- // TODO(asekretenko): Validate roles in offer constraints (see MESOS-10176).
- Try<OfferConstraintsFilter> filter = OfferConstraintsFilter::create(
- offerConstraintsFilterOptions,
- OfferConstraints(call.offer_constraints()));
+ // TODO(asekretenko): Validate roles in offer constraints (see MESOS-10176).
+ Try<OfferConstraintsFilter> filter = OfferConstraintsFilter::create(
+ offerConstraintsFilterOptions,
+ OfferConstraints(call.offer_constraints()));
if (filter.isError()) {
return process::http::BadRequest(
@@ -3310,9 +3300,7 @@ Future<process::http::Response> Master::updateFramework(
filter.error());
}
- allocatorOptions.offerConstraintsFilter = std::move(*filter);
- offerConstraints = std::move(*call.mutable_offer_constraints());
- }
+ allocatorOptions.offerConstraintsFilter = std::move(*filter);
ActionObject actionObject =
ActionObject::frameworkRegistration(call.framework_info());
@@ -3338,7 +3326,7 @@ Future<process::http::Response> Master::updateFramework(
updateFramework(
framework,
call.framework_info(),
- std::move(offerConstraints),
+ std::move(*call.mutable_offer_constraints()),
std::move(allocatorOptions));
if (frameworkInfoChanged) {
@@ -7504,7 +7492,7 @@ void Master::unregisterSlave(const UPID& from, const SlaveID& slaveId)
void Master::updateFramework(
Framework* framework,
const FrameworkInfo& frameworkInfo,
- Option<OfferConstraints>&& offerConstraints,
+ OfferConstraints&& offerConstraints,
::mesos::allocator::FrameworkOptions&& allocatorOptions)
{
LOG(INFO) << "Updating framework " << *framework << " with roles "
diff --git a/src/master/master.hpp b/src/master/master.hpp
index 95aca58..83d8190 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -670,7 +670,7 @@ protected:
void updateFramework(
Framework* framework,
const FrameworkInfo& frameworkInfo,
- Option<::mesos::scheduler::OfferConstraints>&& offerConstraints,
+ ::mesos::scheduler::OfferConstraints&& offerConstraints,
::mesos::allocator::FrameworkOptions&& allocatorOptions);
void sendFrameworkUpdates(const Framework& framework);
@@ -904,7 +904,7 @@ private:
void _subscribe(
StreamingHttpConnection<v1::scheduler::Event> http,
FrameworkInfo&& frameworkInfo,
- Option<scheduler::OfferConstraints>&& offerConstraints,
+ scheduler::OfferConstraints&& offerConstraints,
bool force,
::mesos::allocator::FrameworkOptions&& allocatorOptions,
const process::Future<process::Owned<ObjectApprovers>>& objectApprovers);
@@ -916,7 +916,7 @@ private:
void _subscribe(
const process::UPID& from,
FrameworkInfo&& frameworkInfo,
- Option<scheduler::OfferConstraints>&& offerConstraints,
+ scheduler::OfferConstraints&& offerConstraints,
bool force,
::mesos::allocator::FrameworkOptions&& allocatorOptions,
const process::Future<process::Owned<ObjectApprovers>>& objectApprovers);
@@ -2416,7 +2416,7 @@ struct Framework
Master* const master,
const Flags& masterFlags,
const FrameworkInfo& info,
- Option<::mesos::scheduler::OfferConstraints>&& offerConstraints,
+ ::mesos::scheduler::OfferConstraints&& offerConstraints,
const process::UPID& _pid,
const process::Owned<ObjectApprovers>& objectApprovers,
const process::Time& time = process::Clock::now());
@@ -2424,7 +2424,7 @@ struct Framework
Framework(Master* const master,
const Flags& masterFlags,
const FrameworkInfo& info,
- Option<::mesos::scheduler::OfferConstraints>&& offerConstraints,
+ ::mesos::scheduler::OfferConstraints&& offerConstraints,
const StreamingHttpConnection<v1::scheduler::Event>& _http,
const process::Owned<ObjectApprovers>& objectApprovers,
const process::Time& time = process::Clock::now());
@@ -2493,7 +2493,7 @@ struct Framework
// 'webui_url', 'capabilities', and 'labels'.
void update(
const FrameworkInfo& newInfo,
- Option<::mesos::scheduler::OfferConstraints>&& offerConstraints);
+ ::mesos::scheduler::OfferConstraints&& offerConstraints);
// Reactivate framework with new connection: update connection-related state
// and mark the framework as CONNECTED, regardless of the previous state.
@@ -2544,7 +2544,7 @@ struct Framework
// action on object.
Try<bool> approved(const authorization::ActionObject& actionObject) const;
- const Option<::mesos::scheduler::OfferConstraints>& offerConstraints() const
+ const ::mesos::scheduler::OfferConstraints& offerConstraints() const
{
return offerConstraints_;
}
@@ -2635,7 +2635,7 @@ private:
Framework(Master* const _master,
const Flags& masterFlags,
const FrameworkInfo& _info,
- Option<::mesos::scheduler::OfferConstraints>&& offerConstraints,
+ ::mesos::scheduler::OfferConstraints&& offerConstraints,
State state,
bool active,
const process::Owned<ObjectApprovers>& objectApprovers,
@@ -2671,7 +2671,7 @@ private:
process::Owned<ObjectApprovers> objectApprovers;
// The last offer constraints with which the framework has been subscribed.
- Option<::mesos::scheduler::OfferConstraints> offerConstraints_;
+ ::mesos::scheduler::OfferConstraints offerConstraints_;
};
diff --git a/src/master/readonly_handler.cpp b/src/master/readonly_handler.cpp
index df499d1..034419b 100644
--- a/src/master/readonly_handler.cpp
+++ b/src/master/readonly_handler.cpp
@@ -258,10 +258,8 @@ void FullFrameworkWriter::operator()(JSON::ObjectWriter* writer) const
writer->field("labels", framework_->info.labels());
}
- if (framework_->offerConstraints().isSome()) {
- writer->field(
- "offer_constraints", JSON::Protobuf(*framework_->offerConstraints()));
- };
+ writer->field(
+ "offer_constraints", JSON::Protobuf(framework_->offerConstraints()));
}
[mesos] 04/05: Added offer constraints to
`MesosSchedulerDriver::updateFramework()`.
Posted by as...@apache.org.
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 fcfa3271c0c4fc2d8c6ae7cfd88cd82d26d2e1d1
Author: Andrei Sekretenko <as...@mesosphere.com>
AuthorDate: Wed Sep 16 12:25:19 2020 +0200
Added offer constraints to `MesosSchedulerDriver::updateFramework()`.
This patch adds an ability to set V0 framework's offer constraints
via the C++ V0 scheduler driver.
Review: https://reviews.apache.org/r/72874
---
include/mesos/scheduler.hpp | 22 ++++++++++++-------
.../jni/org_apache_mesos_MesosSchedulerDriver.cpp | 3 ++-
.../scheduler/mesos_scheduler_driver_impl.cpp | 4 +++-
src/sched/sched.cpp | 25 ++++++++++++++++------
src/tests/master/update_framework_tests.cpp | 18 ++++++++--------
src/tests/scheduler_driver_tests.cpp | 2 +-
6 files changed, 48 insertions(+), 26 deletions(-)
diff --git a/include/mesos/scheduler.hpp b/include/mesos/scheduler.hpp
index 61cc846..1401c34 100644
--- a/include/mesos/scheduler.hpp
+++ b/include/mesos/scheduler.hpp
@@ -23,6 +23,7 @@
#include <vector>
#include <mesos/mesos.hpp>
+#include <mesos/scheduler/scheduler.pb.h>
// Mesos scheduler interface and scheduler driver. A scheduler is used
// to interact with Mesos in order to run distributed computations.
@@ -344,14 +345,16 @@ public:
virtual Status reconcileTasks(
const std::vector<TaskStatus>& statuses) = 0;
- // Inform Mesos master about changes to the `FrameworkInfo` and
- // the set of suppressed roles. The driver will store the new
- // `FrameworkInfo` and the new set of suppressed roles, and all
- // subsequent re-registrations will use them.
+ // 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
@@ -362,7 +365,8 @@ public:
// during driver initialization.
virtual Status updateFramework(
const FrameworkInfo& frameworkInfo,
- const std::vector<std::string>& suppressedRoles) = 0;
+ const std::vector<std::string>& suppressedRoles,
+ ::mesos::scheduler::OfferConstraints&& offerConstraints) = 0;
};
@@ -524,7 +528,9 @@ public:
Status updateFramework(
const FrameworkInfo& frameworkInfo,
- const std::vector<std::string>& suppressedRoles) override;
+ const std::vector<std::string>& suppressedRoles,
+ ::mesos::scheduler::OfferConstraints&& offerConstraints)
+ override;
protected:
// Used to detect (i.e., choose) the master.
diff --git a/src/java/jni/org_apache_mesos_MesosSchedulerDriver.cpp b/src/java/jni/org_apache_mesos_MesosSchedulerDriver.cpp
index 1817bba..4d71765 100644
--- a/src/java/jni/org_apache_mesos_MesosSchedulerDriver.cpp
+++ b/src/java/jni/org_apache_mesos_MesosSchedulerDriver.cpp
@@ -1086,7 +1086,8 @@ Java_org_apache_mesos_MesosSchedulerDriver_updateFramework(
MesosSchedulerDriver* driver =
(MesosSchedulerDriver*) env->GetLongField(thiz, __driver);
- Status status = driver->updateFramework(frameworkInfo, suppressedRoles);
+ Status status = driver->updateFramework(
+ frameworkInfo, suppressedRoles, ::mesos::scheduler::OfferConstraints());
return convert<Status>(env, status);
}
diff --git a/src/python/scheduler/src/mesos/scheduler/mesos_scheduler_driver_impl.cpp b/src/python/scheduler/src/mesos/scheduler/mesos_scheduler_driver_impl.cpp
index 256632a..17260cd 100644
--- a/src/python/scheduler/src/mesos/scheduler/mesos_scheduler_driver_impl.cpp
+++ b/src/python/scheduler/src/mesos/scheduler/mesos_scheduler_driver_impl.cpp
@@ -859,7 +859,9 @@ PyObject* MesosSchedulerDriverImpl_updateFramework(
return nullptr;
}
- Status status = self->driver->updateFramework(framework, *suppressedRoles);
+ Status status = self->driver->updateFramework(
+ framework, *suppressedRoles, ::mesos::scheduler::OfferConstraints{});
+
return PyInt_FromLong(status);
}
diff --git a/src/sched/sched.cpp b/src/sched/sched.cpp
index 768ce7d..119a062 100644
--- a/src/sched/sched.cpp
+++ b/src/sched/sched.cpp
@@ -105,6 +105,8 @@ using namespace mesos::scheduler;
using google::protobuf::RepeatedPtrField;
+using mesos::scheduler::OfferConstraints;
+
using mesos::master::detector::MasterDetector;
using process::Clock;
@@ -839,6 +841,7 @@ protected:
Call::Subscribe* subscribe = call.mutable_subscribe();
subscribe->mutable_framework_info()->CopyFrom(framework);
+ *subscribe->mutable_offer_constraints() = offerConstraints;
*subscribe->mutable_suppressed_roles() = RepeatedPtrField<string>(
suppressedRoles.begin(), suppressedRoles.end());
@@ -1645,7 +1648,8 @@ protected:
void updateFramework(
const FrameworkInfo& framework_,
- set<string>&& suppressedRoles_)
+ set<string>&& suppressedRoles_,
+ OfferConstraints&& offerConstraints_)
{
if (!framework.has_id() || framework.id().value().empty()) {
error("MesosSchedulerDriver::updateFramework() must not be called"
@@ -1664,6 +1668,7 @@ protected:
framework = framework_;
suppressedRoles = std::move(suppressedRoles_);
+ offerConstraints = std::move(offerConstraints_);
if (connected) {
sendUpdateFramework();
@@ -1725,8 +1730,10 @@ private:
*call.mutable_framework_id() = framework.id();
call.set_type(Call::UPDATE_FRAMEWORK);
- *call.mutable_update_framework()->mutable_framework_info() = framework;
- *call.mutable_update_framework()->mutable_suppressed_roles() =
+ Call::UpdateFramework* updateFramework = call.mutable_update_framework();
+ *updateFramework->mutable_framework_info() = framework;
+ *updateFramework->mutable_offer_constraints() = offerConstraints;
+ *updateFramework->mutable_suppressed_roles() =
RepeatedPtrField<string>(suppressedRoles.begin(), suppressedRoles.end());
VLOG(1) << "Sending UPDATE_FRAMEWORK message";
@@ -1740,6 +1747,7 @@ private:
Scheduler* scheduler;
FrameworkInfo framework;
set<string> suppressedRoles;
+ OfferConstraints offerConstraints;
std::recursive_mutex* mutex;
Latch* latch;
@@ -2476,7 +2484,8 @@ Status MesosSchedulerDriver::reconcileTasks(
Status MesosSchedulerDriver::updateFramework(
const FrameworkInfo& update,
- const vector<string>& suppressedRoles_)
+ const vector<string>& suppressedRoles_,
+ OfferConstraints&& offerConstraints_)
{
synchronized (mutex) {
if (status != DRIVER_RUNNING) {
@@ -2497,8 +2506,12 @@ Status MesosSchedulerDriver::updateFramework(
<< " " << suppressedRoles_.size() - suppressedRoles.size()
<< " duplicates " << suppressedRoles_;
- dispatch(process, &SchedulerProcess::updateFramework, framework,
- std::move(suppressedRoles));
+ dispatch(
+ process,
+ &SchedulerProcess::updateFramework,
+ framework,
+ std::move(suppressedRoles),
+ std::move(offerConstraints_));
return status;
}
diff --git a/src/tests/master/update_framework_tests.cpp b/src/tests/master/update_framework_tests.cpp
index d6c45f6..3f86573 100644
--- a/src/tests/master/update_framework_tests.cpp
+++ b/src/tests/master/update_framework_tests.cpp
@@ -1003,7 +1003,7 @@ TEST_F(UpdateFrameworkV0Test, DriverErrorWhenCalledBeforeRegistration)
driver.start();
- driver.updateFramework(DEFAULT_FRAMEWORK_INFO, {});
+ driver.updateFramework(DEFAULT_FRAMEWORK_INFO, {}, {});
AWAIT_READY(error);
EXPECT_EQ(error.get(),
@@ -1042,7 +1042,7 @@ TEST_F(UpdateFrameworkV0Test, DriverErrorOnFrameworkIDMismatch)
*update.mutable_id() = frameworkId.get();
*update.mutable_id()->mutable_value() += "-deadbeef";
- driver.updateFramework(update, {});
+ driver.updateFramework(update, {}, {});
AWAIT_READY(error);
EXPECT_EQ(
@@ -1084,7 +1084,7 @@ TEST_F(UpdateFrameworkV0Test, CheckpointingChangeFails)
FrameworkInfo update = changeAllMutableFields(DEFAULT_FRAMEWORK_INFO);
update.set_checkpoint(!update.checkpoint());
*update.mutable_id() = frameworkId.get();
- driver.updateFramework(update, {});
+ driver.updateFramework(update, {}, {});
AWAIT_READY(error);
EXPECT_TRUE(strings::contains(
@@ -1142,7 +1142,7 @@ TEST_F(UpdateFrameworkV0Test, MutableFieldsUpdateSuccessfully)
FrameworkInfo update = changeAllMutableFields(DEFAULT_FRAMEWORK_INFO);
*update.mutable_id() = frameworkId.get();
- driver.updateFramework(update, {});
+ driver.updateFramework(update, {}, {});
AWAIT_READY(updateFrameworkMessage);
@@ -1235,7 +1235,7 @@ TEST_F(UpdateFrameworkV0Test, OffersOnAddingRole)
update.add_roles("new_role");
*update.mutable_id() = frameworkId.get();
- driver.updateFramework(update, {});
+ driver.updateFramework(update, {}, {});
AWAIT_READY(offers);
@@ -1295,7 +1295,7 @@ TEST_F(UpdateFrameworkV0Test, RescindOnRemovingRoles)
update.clear_roles();
*update.mutable_id() = frameworkId.get();
- driver.updateFramework(update, {});
+ driver.updateFramework(update, {}, {});
AWAIT_READY(rescindedOfferId);
AWAIT_READY(recoverResources);
@@ -1366,7 +1366,7 @@ TEST_F(UpdateFrameworkV0Test, SuppressedRoles)
vector<string> suppressedRoles(
update.roles().begin(), update.roles().end());
- driver.updateFramework(update, suppressedRoles);
+ driver.updateFramework(update, suppressedRoles, {});
// Ensure that the allocator processes the update, so that this test
// does not rely on Master maintaining an ordering between scheduler API calls
@@ -1442,8 +1442,8 @@ TEST_F(UpdateFrameworkV0Test, UnsuppressClearsFilters)
vector<string> suppressedRoles(
update.roles().begin(), update.roles().end());
- driver.updateFramework(update, suppressedRoles);
- driver.updateFramework(update, {});
+ driver.updateFramework(update, suppressedRoles, {});
+ driver.updateFramework(update, {}, {});
// Now the previously declined agent should be re-offered.
Clock::pause();
diff --git a/src/tests/scheduler_driver_tests.cpp b/src/tests/scheduler_driver_tests.cpp
index 63d7a3b..b45c367 100644
--- a/src/tests/scheduler_driver_tests.cpp
+++ b/src/tests/scheduler_driver_tests.cpp
@@ -692,7 +692,7 @@ TEST_F(MesosSchedulerDriverTest, ReviveSingleRole)
// In addition to setting a filter, suppress role2 (to check that
// reviveOffers() not only removes filters, but also unsuppresses roles).
*frameworkInfo.mutable_id() = frameworkId.get();
- driver.updateFramework(frameworkInfo, {"role2"});
+ driver.updateFramework(frameworkInfo, {"role2"}, {});
// Wait for updateFramework() to be dispatched to the allocator.
// Otherwise, REVIVE might be processed by the allocator before the update.