You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by me...@apache.org on 2016/03/09 08:26:10 UTC
[2/4] mesos git commit: Moved the implementation of updateWeights out
of header.
Moved the implementation of updateWeights out of header.
Review: https://reviews.apache.org/r/43863/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/6817219d
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/6817219d
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/6817219d
Branch: refs/heads/master
Commit: 6817219d8c6fc75b901730ba55608dba148f9ed0
Parents: d0fc4fd
Author: Yongqiao Wang <yq...@cn.ibm.com>
Authored: Tue Mar 8 14:59:41 2016 -0800
Committer: Adam B <ad...@mesosphere.io>
Committed: Tue Mar 8 23:18:41 2016 -0800
----------------------------------------------------------------------
src/CMakeLists.txt | 1 +
src/Makefile.am | 2 ++
src/master/master.cpp | 3 +-
src/master/master.hpp | 50 --------------------------
src/master/weights.cpp | 70 +++++++++++++++++++++++++++++++++++++
src/master/weights.hpp | 70 +++++++++++++++++++++++++++++++++++++
src/master/weights_handler.cpp | 4 ++-
7 files changed, 148 insertions(+), 52 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/6817219d/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b78d0f4..e9f7c3a 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -208,6 +208,7 @@ set(MASTER_SRC
master/registrar.cpp
master/repairer.cpp
master/validation.cpp
+ master/weights.cpp
master/weights_handler.cpp
master/allocator/allocator.cpp
master/allocator/mesos/hierarchical.cpp
http://git-wip-us.apache.org/repos/asf/mesos/blob/6817219d/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index b449343..b24f0f5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -627,6 +627,7 @@ libmesos_no_3rdparty_la_SOURCES += \
master/registrar.cpp \
master/repairer.cpp \
master/validation.cpp \
+ master/weights.cpp \
master/weights_handler.cpp \
master/allocator/allocator.cpp \
master/allocator/mesos/hierarchical.cpp \
@@ -741,6 +742,7 @@ libmesos_no_3rdparty_la_SOURCES += \
master/registry.hpp \
master/repairer.hpp \
master/validation.hpp \
+ master/weights.hpp \
master/allocator/mesos/allocator.hpp \
master/allocator/mesos/hierarchical.hpp \
master/allocator/mesos/metrics.hpp \
http://git-wip-us.apache.org/repos/asf/mesos/blob/6817219d/src/master/master.cpp
----------------------------------------------------------------------
diff --git a/src/master/master.cpp b/src/master/master.cpp
index a952c0a..249e82f 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -83,6 +83,7 @@
#include "master/flags.hpp"
#include "master/master.hpp"
+#include "master/weights.hpp"
#include "module/manager.hpp"
@@ -1578,7 +1579,7 @@ Future<Nothing> Master::_recover(const Registry& registry)
weightInfo.set_weight(weight);
weightInfos.push_back(weightInfo);
}
- registrar->apply(Owned<Operation>(new UpdateWeights(weightInfos)));
+ registrar->apply(Owned<Operation>(new weights::UpdateWeights(weightInfos)));
}
// Recovery is now complete!
http://git-wip-us.apache.org/repos/asf/mesos/blob/6817219d/src/master/master.hpp
----------------------------------------------------------------------
diff --git a/src/master/master.hpp b/src/master/master.hpp
index a1b4f03..4fa88f1 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -1529,56 +1529,6 @@ private:
};
-// Implementation of weights update Registrar operation.
-class UpdateWeights : public Operation
-{
-public:
- explicit UpdateWeights(const std::vector<WeightInfo>& _weightInfos)
- : weightInfos(_weightInfos) {}
-
-protected:
- virtual Try<bool> perform(Registry* registry, hashset<SlaveID>*, bool)
- {
- bool mutated = false;
- if (weightInfos.empty()) {
- return false; // No mutation.
- }
-
- foreach (const WeightInfo& weightInfo, weightInfos) {
- bool hasStored = false;
- for (int i = 0; i < registry->weights().size(); ++i) {
- Registry::Weight* weight = registry->mutable_weights(i);
-
- if (weight->info().role() != weightInfo.role()) {
- continue;
- }
-
- hasStored = true;
-
- // If there is already weight stored for the specified role
- // and also its value is changed, update the entry.
- if (weight->info().weight() != weightInfo.weight()) {
- weight->mutable_info()->CopyFrom(weightInfo);
- mutated = true;
- }
- break;
- }
-
- // If there is no weight yet for this role in registry,
- // create a new entry.
- if (!hasStored) {
- registry->add_weights()->mutable_info()->CopyFrom(weightInfo);
- mutated = true;
- }
- }
- return mutated;
- }
-
-private:
- const std::vector<WeightInfo> weightInfos;
-};
-
-
// Implementation of slave admission Registrar operation.
class AdmitSlave : public Operation
{
http://git-wip-us.apache.org/repos/asf/mesos/blob/6817219d/src/master/weights.cpp
----------------------------------------------------------------------
diff --git a/src/master/weights.cpp b/src/master/weights.cpp
new file mode 100644
index 0000000..4942ac8
--- /dev/null
+++ b/src/master/weights.cpp
@@ -0,0 +1,70 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "master/weights.hpp"
+
+namespace mesos {
+namespace internal {
+namespace master {
+namespace weights {
+
+UpdateWeights::UpdateWeights(const std::vector<WeightInfo>& _weightInfos)
+ : weightInfos(_weightInfos) {}
+
+
+Try<bool> UpdateWeights::perform(Registry* registry, hashset<SlaveID>*, bool)
+{
+ bool mutated = false;
+ if (weightInfos.empty()) {
+ return false; // No mutation.
+ }
+
+ foreach (const WeightInfo& weightInfo, weightInfos) {
+ bool hasStored = false;
+ for (int i = 0; i < registry->weights().size(); ++i) {
+ Registry::Weight* weight = registry->mutable_weights(i);
+
+ if (weight->info().role() != weightInfo.role()) {
+ continue;
+ }
+
+ hasStored = true;
+
+ // If there is already weight stored for the specified role
+ // and also its value is changed, update the entry.
+ if (weight->info().weight() != weightInfo.weight()) {
+ weight->mutable_info()->CopyFrom(weightInfo);
+ mutated = true;
+ }
+
+ break;
+ }
+
+ // If there is no weight yet for this role in registry,
+ // create a new entry.
+ if (!hasStored) {
+ registry->add_weights()->mutable_info()->CopyFrom(weightInfo);
+ mutated = true;
+ }
+ }
+
+ return mutated;
+}
+
+} // namespace weights {
+} // namespace master {
+} // namespace internal {
+} // namespace mesos {
http://git-wip-us.apache.org/repos/asf/mesos/blob/6817219d/src/master/weights.hpp
----------------------------------------------------------------------
diff --git a/src/master/weights.hpp b/src/master/weights.hpp
new file mode 100644
index 0000000..80d1369
--- /dev/null
+++ b/src/master/weights.hpp
@@ -0,0 +1,70 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __MASTER_WEIGHTS_HPP__
+#define __MASTER_WEIGHTS_HPP__
+
+#include <string>
+
+#include <mesos/mesos.hpp>
+
+#include <stout/error.hpp>
+#include <stout/option.hpp>
+#include <stout/try.hpp>
+
+#include "master/registrar.hpp"
+#include "master/registry.hpp"
+
+namespace mesos {
+namespace internal {
+namespace master {
+namespace weights {
+
+// We do not impose any constraints upon weights registry operations.
+// It is up to the master to determine whether a weights update
+// request is valid. Hence weights registry operations never fail (i.e.
+// `perform()` never returns an `Error`). Note that this does not
+// influence registry failures, e.g. a network partition may occur and
+// will render the operation hanging (i.e. `Future` for the operation
+// will not be set).
+
+// The `strict` flag is not relevant for weights update operations: they will
+// always succeed, even if the flag is set to `true`.
+
+/**
+ * Updates weights for the specified roles. No assumptions are made here:
+ * the roles may be unknown to the master, or weights can be already set
+ * for the roles. If there are no weights stored for the roles, some new
+ * entries are created, otherwise the existing entries are updated.
+ */
+class UpdateWeights : public Operation
+{
+public:
+ explicit UpdateWeights(const std::vector<WeightInfo>& _weightInfos);
+
+protected:
+ Try<bool> perform(Registry* registry, hashset<SlaveID>*, bool);
+
+private:
+ const std::vector<WeightInfo> weightInfos;
+};
+
+} // namespace weights {
+} // namespace master {
+} // namespace internal {
+} // namespace mesos {
+
+#endif // __MASTER_WEIGHTS_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/6817219d/src/master/weights_handler.cpp
----------------------------------------------------------------------
diff --git a/src/master/weights_handler.cpp b/src/master/weights_handler.cpp
index be4b5ab..9e4ab19 100644
--- a/src/master/weights_handler.cpp
+++ b/src/master/weights_handler.cpp
@@ -22,6 +22,8 @@
#include <stout/stringify.hpp>
#include <stout/strings.hpp>
+#include "master/weights.hpp"
+
namespace http = process::http;
using google::protobuf::RepeatedPtrField;
@@ -112,7 +114,7 @@ Future<http::Response> Master::WeightsHandler::_update(
{
// Update the registry and acknowledge the request.
return master->registrar->apply(Owned<Operation>(
- new UpdateWeights(weightInfos)))
+ new weights::UpdateWeights(weightInfos)))
.then(defer(master->self(), [=](bool result) -> Future<http::Response> {
CHECK(result);