You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by al...@apache.org on 2018/08/02 13:46:21 UTC
[2/2] mesos git commit: Moved around some functions definitions
between files.
Moved around some functions definitions between files.
This commit contains some fixups to the move of the `Framework`
implementation code to a separate file in the previous commit.
* Change `Framework::send()` to use an out-of-class definition.
* Move back trivial functions back to the header file.
* Move private constructor to the top of the file in `framework.cpp`.
Review: https://reviews.apache.org/r/68166/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/72878f8c
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/72878f8c
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/72878f8c
Branch: refs/heads/master
Commit: 72878f8c26a546fbab1010e73ea7b68cf6afc2e3
Parents: 42cbba5
Author: Benno Evers <be...@mesosphere.com>
Authored: Thu Aug 2 15:24:51 2018 +0200
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Thu Aug 2 15:28:12 2018 +0200
----------------------------------------------------------------------
src/master/framework.cpp | 88 ++++++++++++++++---------------------------
src/master/master.hpp | 73 ++++++++++++++++++++++++-----------
2 files changed, 84 insertions(+), 77 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/72878f8c/src/master/framework.cpp
----------------------------------------------------------------------
diff --git a/src/master/framework.cpp b/src/master/framework.cpp
index d17d7dd..7cfe9f4 100644
--- a/src/master/framework.cpp
+++ b/src/master/framework.cpp
@@ -54,6 +54,38 @@ Framework::Framework(
{}
+Framework::Framework(
+ Master* const _master,
+ const Flags& masterFlags,
+ const FrameworkInfo& _info,
+ State state,
+ const process::Time& time)
+ : master(_master),
+ info(_info),
+ roles(protobuf::framework::getRoles(_info)),
+ capabilities(_info.capabilities()),
+ state(state),
+ registeredTime(time),
+ reregisteredTime(time),
+ completedTasks(masterFlags.max_completed_tasks_per_framework),
+ unreachableTasks(masterFlags.max_unreachable_tasks_per_framework),
+ metrics(_info)
+{
+ CHECK(_info.has_id());
+
+ setFrameworkState(state);
+
+ foreach (const std::string& role, roles) {
+ // NOTE: It's possible that we're already being tracked under the role
+ // because a framework can unsubscribe from a role while it still has
+ // resources allocated to the role.
+ if (!isTrackedUnderRole(role)) {
+ trackUnderRole(role);
+ }
+ }
+}
+
+
Framework::~Framework()
{
if (http.isSome()) {
@@ -463,12 +495,6 @@ void Framework::removeOperation(Operation* operation)
}
-const FrameworkID Framework::id() const
-{
- return info.id();
-}
-
-
void Framework::update(const FrameworkInfo& newInfo)
{
// We only merge 'info' from the same framework 'id'.
@@ -662,56 +688,6 @@ void Framework::heartbeat()
}
-bool Framework::active() const
-{
- return state == ACTIVE;
-}
-
-
-bool Framework::connected() const
-{
- return state == ACTIVE || state == INACTIVE;
-}
-
-
-bool Framework::recovered() const
-{
- return state == RECOVERED;
-}
-
-
-Framework::Framework(
- Master* const _master,
- const Flags& masterFlags,
- const FrameworkInfo& _info,
- State state,
- const process::Time& time)
- : master(_master),
- info(_info),
- roles(protobuf::framework::getRoles(_info)),
- capabilities(_info.capabilities()),
- state(state),
- registeredTime(time),
- reregisteredTime(time),
- completedTasks(masterFlags.max_completed_tasks_per_framework),
- unreachableTasks(masterFlags.max_unreachable_tasks_per_framework),
- metrics(_info)
-{
- CHECK(_info.has_id());
-
- setFrameworkState(state);
-
- foreach (const std::string& role, roles) {
- // NOTE: It's possible that we're already being tracked under the role
- // because a framework can unsubscribe from a role while it still has
- // resources allocated to the role.
- if (!isTrackedUnderRole(role)) {
- trackUnderRole(role);
- }
- }
-}
-
-
bool Framework::isTrackedUnderRole(const std::string& role) const
{
CHECK(master->isWhitelistedRole(role))
http://git-wip-us.apache.org/repos/asf/mesos/blob/72878f8c/src/master/master.hpp
----------------------------------------------------------------------
diff --git a/src/master/master.hpp b/src/master/master.hpp
index ce1a7e1..209b998 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -2316,27 +2316,7 @@ struct Framework
// Sends a message to the connected framework.
template <typename Message>
- void send(const Message& message)
- {
- if (!connected()) {
- LOG(WARNING) << "Master attempted to send message to disconnected"
- << " framework " << *this;
- }
-
- // TODO(gilbert): add a helper to transform `SchedulerDriver` API messages
- // directly to v0 events.
- metrics.incrementEvent(devolve(evolve(message)));
-
- if (http.isSome()) {
- if (!http->send(message)) {
- LOG(WARNING) << "Unable to send event to framework " << *this << ":"
- << " connection closed";
- }
- } else {
- CHECK_SOME(pid);
- master->send(pid.get(), message);
- }
- }
+ void send(const Message& message);
void addCompletedTask(Task&& task);
@@ -2513,6 +2493,57 @@ private:
};
+// Sends a message to the connected framework.
+template <typename Message>
+void Framework::send(const Message& message)
+{
+ if (!connected()) {
+ LOG(WARNING) << "Master attempted to send message to disconnected"
+ << " framework " << *this;
+ }
+
+ // TODO(gilbert): add a helper to transform `SchedulerDriver` API messages
+ // directly to v0 events.
+ metrics.incrementEvent(devolve(evolve(message)));
+
+ if (http.isSome()) {
+ if (!http->send(message)) {
+ LOG(WARNING) << "Unable to send event to framework " << *this << ":"
+ << " connection closed";
+ }
+ } else {
+ CHECK_SOME(pid);
+ master->send(pid.get(), message);
+ }
+}
+
+
+// TODO(bevers): Check if there is anything preventing us from
+// returning a const reference here.
+inline const FrameworkID Framework::id() const
+{
+ return info.id();
+}
+
+
+inline bool Framework::active() const
+{
+ return state == ACTIVE;
+}
+
+
+inline bool Framework::connected() const
+{
+ return state == ACTIVE || state == INACTIVE;
+}
+
+
+inline bool Framework::recovered() const
+{
+ return state == RECOVERED;
+}
+
+
inline std::ostream& operator<<(
std::ostream& stream,
const Framework& framework)