You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2014/07/23 01:50:52 UTC
git commit: Removed unnecessary includes and inline definitions.
Repository: mesos
Updated Branches:
refs/heads/master 398ca0c6d -> c9d1c4cd1
Removed unnecessary includes and inline definitions.
Dominic's Hamon review request: https://reviews.apache.org/r/18295
mergeable to today's master version, this is a lightened version to
make review easier. Note I see an improvements of ~7.5% of the
compile time.
Review: https://reviews.apache.org/r/23745
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/c9d1c4cd
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/c9d1c4cd
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/c9d1c4cd
Branch: refs/heads/master
Commit: c9d1c4cd1be097e3bcee63855847da272c43bc68
Parents: 398ca0c
Author: Isabel Jimenez <co...@isabeljimenez.com>
Authored: Tue Jul 22 16:49:52 2014 -0700
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Tue Jul 22 16:49:52 2014 -0700
----------------------------------------------------------------------
include/mesos/resources.hpp | 223 ++---------------------------
src/Makefile.am | 131 ++++++++++-------
src/common/attributes.cpp | 126 ++++++++++++++++
src/common/attributes.hpp | 123 +---------------
src/common/date_utils.cpp | 49 ++-----
src/common/date_utils.hpp | 36 ++---
src/common/factory.hpp | 1 -
src/common/http.cpp | 25 +++-
src/common/http.hpp | 1 -
src/common/parse.hpp | 4 +-
src/common/protobuf_utils.cpp | 122 ++++++++++++++++
src/common/protobuf_utils.hpp | 98 ++-----------
src/common/resources.cpp | 229 +++++++++++++++++++++++++++++-
src/common/status_utils.hpp | 2 +-
src/common/thread.cpp | 52 +++++++
src/common/thread.hpp | 47 +++---
src/common/type_utils.cpp | 158 +++++++++++++++++++++
src/common/type_utils.hpp | 133 ++---------------
src/common/values.cpp | 1 -
src/master/master.cpp | 1 +
src/slave/containerizer/isolator.hpp | 2 +
src/slave/slave.cpp | 1 +
22 files changed, 871 insertions(+), 694 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d1c4cd/include/mesos/resources.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/resources.hpp b/include/mesos/resources.hpp
index 8fc347e..9f8c594 100644
--- a/include/mesos/resources.hpp
+++ b/include/mesos/resources.hpp
@@ -19,17 +19,12 @@
#ifndef __RESOURCES_HPP__
#define __RESOURCES_HPP__
-#include <iterator>
#include <string>
-#include <utility>
-#include <vector>
#include <mesos/mesos.hpp>
#include <mesos/values.hpp>
#include <stout/bytes.hpp>
-#include <stout/foreach.hpp>
-#include <stout/none.hpp>
#include <stout/option.hpp>
@@ -101,18 +96,7 @@ public:
/**
* Returns a Resources object with only the allocatable resources.
*/
- Resources allocatable() const
- {
- Resources result;
-
- foreach (const Resource& resource, resources) {
- if (isAllocatable(resource)) {
- result.resources.Add()->MergeFrom(resource);
- }
- }
-
- return result;
- }
+ Resources allocatable() const;
size_t size() const
{
@@ -128,126 +112,26 @@ public:
return resources;
}
- bool operator == (const Resources& that) const
- {
- if (size() != that.size()) {
- return false;
- }
-
- foreach (const Resource& resource, resources) {
- Option<Resource> option = that.get(resource);
- if (option.isNone()) {
- return false;
- } else {
- if (!(resource == option.get())) {
- return false;
- }
- }
- }
-
- return true;
- }
+ bool operator == (const Resources& that) const;
bool operator != (const Resources& that) const
{
return !(*this == that);
}
- bool operator <= (const Resources& that) const
- {
- foreach (const Resource& resource, resources) {
- Option<Resource> option = that.get(resource);
- if (option.isNone()) {
- return false;
- } else {
- if (!(resource <= option.get())) {
- return false;
- }
- }
- }
-
- return true;
- }
-
- Resources operator + (const Resources& that) const
- {
- Resources result(*this);
-
- foreach (const Resource& resource, that.resources) {
- result += resource;
- }
-
- return result;
- }
-
- Resources operator - (const Resources& that) const
- {
- Resources result(*this);
-
- foreach (const Resource& resource, that.resources) {
- result -= resource;
- }
-
- return result;
- }
+ bool operator <= (const Resources& that) const;
- Resources& operator += (const Resources& that)
- {
- foreach (const Resource& resource, that.resources) {
- *this += resource;
- }
-
- return *this;
- }
+ Resources operator + (const Resources& that) const;
- Resources& operator -= (const Resources& that)
- {
- foreach (const Resource& resource, that.resources) {
- *this -= resource;
- }
-
- return *this;
- }
-
- Resources operator + (const Resource& that) const
- {
- Resources result;
-
- bool added = false;
-
- foreach (const Resource& resource, resources) {
- if (matches(resource, that)) {
- result.resources.Add()->MergeFrom(resource + that);
- added = true;
- } else {
- result.resources.Add()->MergeFrom(resource);
- }
- }
+ Resources operator - (const Resources& that) const;
- if (!added) {
- result.resources.Add()->MergeFrom(that);
- }
+ Resources& operator += (const Resources& that);
- return result;
- }
+ Resources& operator -= (const Resources& that);
- Resources operator - (const Resource& that) const
- {
- Resources result;
-
- foreach (const Resource& resource, resources) {
- if (matches(resource, that)) {
- Resource r = resource - that;
- if (!isZero(r)) {
- result.resources.Add()->MergeFrom(r);
- }
- } else {
- result.resources.Add()->MergeFrom(resource);
- }
- }
+ Resources operator + (const Resource& that) const;
- return result;
- }
+ Resources operator - (const Resource& that) const;
Resources& operator += (const Resource& that)
{
@@ -360,95 +244,6 @@ private:
};
-template <>
-inline Value::Scalar Resources::get(
- const std::string& name,
- const Value::Scalar& scalar) const
-{
- Value::Scalar total;
- bool found = false;
-
- foreach (const Resource& resource, resources) {
- if (resource.name() == name &&
- resource.type() == Value::SCALAR) {
- total += resource.scalar();
- found = true;
- }
- }
-
- if (found) {
- return total;
- }
-
- return scalar;
-}
-
-
-template <>
-inline Value::Ranges Resources::get(
- const std::string& name,
- const Value::Ranges& ranges) const
-{
- Value::Ranges total;
- bool found = false;
-
- foreach (const Resource& resource, resources) {
- if (resource.name() == name &&
- resource.type() == Value::RANGES) {
- total += resource.ranges();
- found = true;
- }
- }
-
- if (found) {
- return total;
- }
-
- return ranges;
-}
-
-
-template <>
-inline Value::Set Resources::get(
- const std::string& name,
- const Value::Set& set) const
-{
- Value::Set total;
- bool found = false;
-
- foreach (const Resource& resource, resources) {
- if (resource.name() == name &&
- resource.type() == Value::SET) {
- total += resource.set();
- found = true;
- }
- }
-
- if (found) {
- return total;
- }
-
- return set;
-}
-
-
-inline std::ostream& operator << (
- std::ostream& stream,
- const Resources& resources)
-{
- mesos::Resources::const_iterator it = resources.begin();
-
- while (it != resources.end()) {
- stream << *it;
- if (++it != resources.end()) {
- stream << "; ";
- }
- }
-
- return stream;
-}
-
-
inline std::ostream& operator << (
std::ostream& stream,
const google::protobuf::RepeatedPtrField<Resource>& resources)
http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d1c4cd/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index c216e2f..adc603a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -225,13 +225,19 @@ nodist_libmesos_no_3rdparty_la_SOURCES = \
libmesos_no_3rdparty_la_SOURCES = \
authorizer/authorizer.cpp \
- sasl/authenticatee.hpp \
- sasl/authenticator.hpp \
- sasl/auxprop.hpp \
- sasl/auxprop.cpp \
- sched/sched.cpp \
- scheduler/scheduler.cpp \
+ common/attributes.cpp \
+ common/date_utils.cpp \
+ common/http.cpp \
+ common/lock.cpp \
+ common/protobuf_utils.cpp \
+ common/resources.cpp \
+ common/thread.cpp \
+ common/type_utils.cpp \
+ common/values.cpp \
+ exec/exec.cpp \
+ files/files.cpp \
local/local.cpp \
+ logging/logging.cpp \
master/contender.cpp \
master/constants.cpp \
master/detector.cpp \
@@ -242,12 +248,18 @@ libmesos_no_3rdparty_la_SOURCES = \
master/registry.proto \
master/registrar.cpp \
master/repairer.cpp \
+ sasl/authenticatee.hpp \
+ sasl/authenticator.hpp \
+ sasl/auxprop.hpp \
+ sasl/auxprop.cpp \
+ sched/sched.cpp \
+ scheduler/scheduler.cpp \
slave/constants.cpp \
slave/gc.cpp \
+ slave/http.cpp \
slave/monitor.cpp \
slave/state.cpp \
slave/slave.cpp \
- slave/http.cpp \
slave/containerizer/containerizer.cpp \
slave/containerizer/external_containerizer.cpp \
slave/containerizer/isolator.cpp \
@@ -255,15 +267,6 @@ libmesos_no_3rdparty_la_SOURCES = \
slave/containerizer/mesos/containerizer.cpp \
slave/containerizer/mesos/launch.cpp \
slave/status_update_manager.cpp \
- exec/exec.cpp \
- common/lock.cpp \
- common/http.cpp \
- common/date_utils.cpp \
- common/resources.cpp \
- common/attributes.cpp \
- common/values.cpp \
- files/files.cpp \
- logging/logging.cpp \
usage/usage.cpp \
zookeeper/contender.cpp \
zookeeper/detector.cpp \
@@ -301,12 +304,12 @@ nodist_scheduler_HEADERS = ../include/mesos/scheduler/scheduler.pb.h
if OS_LINUX
libmesos_no_3rdparty_la_SOURCES += linux/cgroups.cpp
+ libmesos_no_3rdparty_la_SOURCES += linux/fs.cpp
libmesos_no_3rdparty_la_SOURCES += linux/perf.cpp
libmesos_no_3rdparty_la_SOURCES += slave/containerizer/isolators/cgroups/cpushare.cpp
libmesos_no_3rdparty_la_SOURCES += slave/containerizer/isolators/cgroups/mem.cpp
libmesos_no_3rdparty_la_SOURCES += slave/containerizer/isolators/cgroups/perf_event.cpp
libmesos_no_3rdparty_la_SOURCES += slave/containerizer/linux_launcher.cpp
- libmesos_no_3rdparty_la_SOURCES += linux/fs.cpp
else
EXTRA_DIST += linux/cgroups.cpp
EXTRA_DIST += linux/fs.cpp
@@ -316,10 +319,10 @@ if WITH_NETWORK_ISOLATOR
libmesos_no_3rdparty_la_SOURCES += \
linux/routing/route.cpp \
linux/routing/utils.cpp \
- linux/routing/link/link.cpp \
linux/routing/filter/arp.cpp \
linux/routing/filter/icmp.cpp \
linux/routing/filter/ip.cpp \
+ linux/routing/link/link.cpp \
linux/routing/queueing/handle.cpp \
linux/routing/queueing/ingress.cpp
@@ -348,58 +351,76 @@ endif
libmesos_no_3rdparty_la_SOURCES += \
authorizer/authorizer.hpp \
common/attributes.hpp \
- common/build.hpp common/date_utils.hpp common/factory.hpp \
- common/status_utils.hpp \
- common/parse.hpp \
- common/protobuf_utils.hpp \
+ common/build.hpp \
+ common/date_utils.hpp \
+ common/factory.hpp \
common/http.hpp \
common/lock.hpp \
- common/type_utils.hpp common/thread.hpp \
+ common/parse.hpp \
+ common/protobuf_utils.hpp \
+ common/status_utils.hpp \
+ common/type_utils.hpp \
+ common/thread.hpp \
credentials/credentials.hpp \
- examples/utils.hpp files/files.hpp \
+ examples/utils.hpp \
+ files/files.hpp \
hdfs/hdfs.hpp \
linux/cgroups.hpp \
+ linux/fs.hpp \
linux/perf.hpp \
- linux/fs.hpp local/flags.hpp local/local.hpp \
- logging/flags.hpp logging/logging.hpp \
+ local/flags.hpp \
+ local/local.hpp \
+ logging/flags.hpp \
+ logging/logging.hpp \
master/allocator.hpp \
master/contender.hpp \
master/constants.hpp \
master/detector.hpp \
- master/repairer.hpp \
- master/drf_sorter.hpp master/flags.hpp \
+ master/drf_sorter.hpp \
+ master/flags.hpp \
master/hierarchical_allocator_process.hpp \
+ master/master.hpp \
+ master/repairer.hpp \
master/registrar.hpp \
- master/master.hpp master/sorter.hpp \
- messages/messages.hpp slave/constants.hpp \
+ master/sorter.hpp \
+ messages/messages.hpp \
+ slave/constants.hpp \
+ slave/flags.hpp \
+ slave/gc.hpp \
+ slave/monitor.hpp \
+ slave/paths.hpp \
+ slave/slave.hpp \
+ slave/state.hpp \
+ slave/status_update_manager.hpp \
slave/containerizer/containerizer.hpp \
slave/containerizer/external_containerizer.hpp \
slave/containerizer/isolator.hpp \
slave/containerizer/launcher.hpp \
slave/containerizer/linux_launcher.hpp \
- slave/containerizer/mesos/containerizer.hpp \
- slave/containerizer/mesos/launch.hpp \
slave/containerizer/isolators/posix.hpp \
slave/containerizer/isolators/cgroups/cpushare.hpp \
slave/containerizer/isolators/cgroups/mem.hpp \
slave/containerizer/isolators/cgroups/perf_event.hpp \
- slave/flags.hpp slave/gc.hpp slave/monitor.hpp \
- slave/paths.hpp slave/state.hpp \
- slave/status_update_manager.hpp \
- slave/slave.hpp \
- tests/environment.hpp tests/script.hpp \
- tests/zookeeper.hpp tests/flags.hpp tests/utils.hpp \
+ slave/containerizer/mesos/containerizer.hpp \
+ slave/containerizer/mesos/launch.hpp \
tests/cluster.hpp \
tests/containerizer.hpp \
+ tests/environment.hpp \
+ tests/flags.hpp \
tests/isolator.hpp \
tests/mesos.hpp \
+ tests/script.hpp \
+ tests/utils.hpp \
+ tests/zookeeper.hpp \
tests/zookeeper_test_server.hpp \
usage/usage.hpp \
zookeeper/authentication.hpp \
zookeeper/contender.hpp \
zookeeper/detector.hpp \
- zookeeper/group.hpp zookeeper/watcher.hpp \
- zookeeper/zookeeper.hpp zookeeper/url.hpp
+ zookeeper/group.hpp \
+ zookeeper/url.hpp \
+ zookeeper/watcher.hpp \
+ zookeeper/zookeeper.hpp
libmesos_no_3rdparty_la_CPPFLAGS = $(MESOS_CPPFLAGS)
@@ -1078,11 +1099,12 @@ if WITH_NETWORK_ISOLATOR
endif
if HAS_JAVA
- mesos_tests_SOURCES += tests/zookeeper.cpp \
+ mesos_tests_SOURCES += tests/group_tests.cpp \
+ tests/registrar_zookeeper_tests.cpp \
+ tests/zookeeper.cpp \
tests/zookeeper_test_server.cpp \
- tests/zookeeper_tests.cpp \
- tests/group_tests.cpp \
- tests/registrar_zookeeper_tests.cpp
+ tests/zookeeper_tests.cpp
+
mesos_tests_CPPFLAGS += $(JAVA_CPPFLAGS)
mesos_tests_CPPFLAGS += -DZOOKEEPER_VERSION=\"$(ZOOKEEPER_VERSION)\"
mesos_tests_LDFLAGS = $(AM_LDFLAGS)
@@ -1101,31 +1123,32 @@ endif
if HAS_PYTHON
mesos_tests_DEPENDENCIES += $(MESOS_EGG)
- EXAMPLESCRIPTSPYTHON = examples/python/test_framework.py \
+ EXAMPLESCRIPTSPYTHON = examples/python/test_containerizer.py \
+ examples/python/test-containerizer \
+ examples/python/test_framework.py \
examples/python/test-framework \
examples/python/test_executor.py \
examples/python/test-executor \
- examples/python/test_containerizer.py \
- examples/python/test-containerizer
check_SCRIPTS += $(EXAMPLESCRIPTSPYTHON)
mesos_tests_DEPENDENCIES += $(EXAMPLESCRIPTSPYTHON)
endif
EXTRA_DIST += examples/python/test_containerizer.py \
- examples/python/test_framework.py \
- examples/python/test_executor.py
+ examples/python/test_executor.py \
+ examples/python/test_framework.py
+
dist_check_SCRIPTS += \
tests/balloon_framework_test.sh \
- tests/low_level_scheduler_libprocess_test.sh \
- tests/low_level_scheduler_pthread_test.sh \
- tests/test_framework_test.sh \
- tests/no_executor_framework_test.sh \
+ tests/low_level_scheduler_libprocess_test.sh \
+ tests/low_level_scheduler_pthread_test.sh \
tests/java_exception_test.sh \
tests/java_framework_test.sh \
tests/java_log_test.sh \
- tests/python_framework_test.sh
+ tests/no_executor_framework_test.sh \
+ tests/python_framework_test.sh \
+ tests/test_framework_test.sh
# We use a check-local target for now to avoid the parallel test
# runner that ships with newer versions of autotools.
http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d1c4cd/src/common/attributes.cpp
----------------------------------------------------------------------
diff --git a/src/common/attributes.cpp b/src/common/attributes.cpp
index 851c92a..aab114e 100644
--- a/src/common/attributes.cpp
+++ b/src/common/attributes.cpp
@@ -21,6 +21,8 @@
#include <glog/logging.h>
+#include <mesos/values.hpp>
+
#include <stout/foreach.hpp>
#include <stout/strings.hpp>
@@ -53,6 +55,57 @@ std::ostream& operator << (std::ostream& stream, const Attribute& attribute)
namespace internal {
+
+bool Attributes::operator == (const Attributes& that) const
+{
+ if (size() != that.size()) {
+ return false;
+ }
+
+ foreach (const Attribute& attribute, attributes) {
+ Option<Attribute> maybeAttribute = that.get(attribute);
+ if (maybeAttribute.isNone()) {
+ return false;
+ }
+ const Attribute& thatAttribute = maybeAttribute.get();
+ switch (attribute.type()) {
+ case Value::SCALAR:
+ if (!(attribute.scalar() == thatAttribute.scalar())) {
+ return false;
+ }
+ break;
+ case Value::RANGES:
+ if (!(attribute.ranges() == thatAttribute.ranges())) {
+ return false;
+ }
+ break;
+ case Value::TEXT:
+ if (!(attribute.text() == thatAttribute.text())) {
+ return false;
+ }
+ break;
+ case Value::SET:
+ LOG(FATAL) << "Sets not supported for attributes";
+ }
+ }
+
+ return true;
+}
+
+
+const Option<Attribute> Attributes::get(const Attribute& thatAttribute) const
+{
+ foreach (const Attribute& attribute, attributes) {
+ if (attribute.name() == thatAttribute.name() &&
+ attribute.type() == thatAttribute.type()) {
+ return attribute;
+ }
+ }
+
+ return None();
+}
+
+
Attribute Attributes::parse(const std::string& name, const std::string& text)
{
Attribute attribute;
@@ -105,5 +158,78 @@ Attributes Attributes::parse(const string& s)
return attributes;
}
+
+bool Attributes::isValid(const Attribute& attribute)
+{
+ if (!attribute.has_name() ||
+ attribute.name() == "" ||
+ !attribute.has_type() ||
+ !Value::Type_IsValid(attribute.type())) {
+ return false;
+ }
+
+ if (attribute.type() == Value::SCALAR) {
+ return attribute.has_scalar();
+ } else if (attribute.type() == Value::RANGES) {
+ return attribute.has_ranges();
+ } else if (attribute.type() == Value::TEXT) {
+ return attribute.has_text();
+ } else if (attribute.type() == Value::SET) {
+ // Attributes doesn't support set.
+ return false;
+ }
+
+ return false;
+}
+
+
+template <>
+Value::Scalar Attributes::get(
+ const std::string& name,
+ const Value::Scalar& scalar) const
+{
+ foreach (const Attribute& attribute, attributes) {
+ if (attribute.name() == name &&
+ attribute.type() == Value::SCALAR) {
+ return attribute.scalar();
+ }
+ }
+
+ return scalar;
+}
+
+
+template <>
+Value::Ranges Attributes::get(
+ const std::string& name,
+ const Value::Ranges& ranges) const
+{
+ foreach (const Attribute& attribute, attributes) {
+ if (attribute.name() == name &&
+ attribute.type() == Value::RANGES) {
+ return attribute.ranges();
+ }
+ }
+
+ return ranges;
+}
+
+
+template <>
+Value::Text Attributes::get(
+ const std::string& name,
+ const Value::Text& text) const
+{
+ foreach (const Attribute& attribute, attributes) {
+ if (attribute.name() == name &&
+ attribute.type() == Value::TEXT) {
+ return attribute.text();
+ }
+ }
+
+ return text;
+}
+
+
} // namespace internal {
} // namespace mesos {
http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d1c4cd/src/common/attributes.hpp
----------------------------------------------------------------------
diff --git a/src/common/attributes.hpp b/src/common/attributes.hpp
index e6271cd..0a043d5 100644
--- a/src/common/attributes.hpp
+++ b/src/common/attributes.hpp
@@ -23,14 +23,9 @@
#include <string>
#include <mesos/mesos.hpp>
-#include <mesos/values.hpp>
-#include <stout/foreach.hpp>
-#include <stout/none.hpp>
#include <stout/option.hpp>
-#include "logging/logging.hpp"
-
namespace mesos {
@@ -66,41 +61,8 @@ public:
return *this;
}
- bool operator == (const Attributes& that) const
- {
- if (size() != that.size()) {
- return false;
- }
+ bool operator == (const Attributes& that) const;
- foreach (const Attribute& attribute, attributes) {
- Option<Attribute> maybeAttribute = that.get(attribute);
- if (maybeAttribute.isNone()) {
- return false;
- }
- const Attribute& thatAttribute = maybeAttribute.get();
- switch (attribute.type()) {
- case Value::SCALAR:
- if (!(attribute.scalar() == thatAttribute.scalar())) {
- return false;
- }
- break;
- case Value::RANGES:
- if (!(attribute.ranges() == thatAttribute.ranges())) {
- return false;
- }
- break;
- case Value::TEXT:
- if (!(attribute.text() == thatAttribute.text())) {
- return false;
- }
- break;
- case Value::SET:
- LOG(FATAL) << "Sets not supported for attributes";
- }
- }
-
- return true;
- }
bool operator != (const Attributes& that) const
{
@@ -129,17 +91,7 @@ public:
return attributes.Get(index);
}
- const Option<Attribute> get(const Attribute& thatAttribute) const
- {
- foreach (const Attribute& attribute, attributes) {
- if (attribute.name() == thatAttribute.name() &&
- attribute.type() == thatAttribute.type()) {
- return attribute;
- }
- }
-
- return None();
- }
+ const Option<Attribute> get(const Attribute& thatAttribute) const;
template <typename T>
T get(const std::string& name, const T& t) const;
@@ -159,82 +111,13 @@ public:
static Attribute parse(const std::string& name, const std::string& value);
static Attributes parse(const std::string& s);
- static bool isValid(const Attribute& attribute)
- {
- if (!attribute.has_name() ||
- attribute.name() == "" ||
- !attribute.has_type() ||
- !Value::Type_IsValid(attribute.type())) {
- return false;
- }
-
- if (attribute.type() == Value::SCALAR) {
- return attribute.has_scalar();
- } else if (attribute.type() == Value::RANGES) {
- return attribute.has_ranges();
- } else if (attribute.type() == Value::TEXT) {
- return attribute.has_text();
- } else if (attribute.type() == Value::SET) {
- // Attributes doesn't support set.
- return false;
- }
-
- return false;
- }
+ static bool isValid(const Attribute& attribute);
private:
google::protobuf::RepeatedPtrField<Attribute> attributes;
};
-template <>
-inline Value::Scalar Attributes::get(
- const std::string& name,
- const Value::Scalar& scalar) const
-{
- foreach (const Attribute& attribute, attributes) {
- if (attribute.name() == name &&
- attribute.type() == Value::SCALAR) {
- return attribute.scalar();
- }
- }
-
- return scalar;
-}
-
-
-template <>
-inline Value::Ranges Attributes::get(
- const std::string& name,
- const Value::Ranges& ranges) const
-{
- foreach (const Attribute& attribute, attributes) {
- if (attribute.name() == name &&
- attribute.type() == Value::RANGES) {
- return attribute.ranges();
- }
- }
-
- return ranges;
-}
-
-
-template <>
-inline Value::Text Attributes::get(
- const std::string& name,
- const Value::Text& text) const
-{
- foreach (const Attribute& attribute, attributes) {
- if (attribute.name() == name &&
- attribute.type() == Value::TEXT) {
- return attribute.text();
- }
- }
-
- return text;
-}
-
-
} // namespace internal {
} // namespace mesos {
http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d1c4cd/src/common/date_utils.cpp
----------------------------------------------------------------------
diff --git a/src/common/date_utils.cpp b/src/common/date_utils.cpp
index 1c7565d..c5268bc 100644
--- a/src/common/date_utils.cpp
+++ b/src/common/date_utils.cpp
@@ -22,43 +22,22 @@
using std::string;
-using namespace mesos::internal;
-
-
-// Static fields in DateUtils
-bool DateUtils::useMockDate = false;
-string DateUtils::mockDate = "";
-
+namespace mesos {
+namespace internal {
+namespace DateUtils {
// Get the current date in the format used for Mesos IDs (YYYYMMDD-hhmmss).
-string DateUtils::currentDate()
-{
- if (useMockDate) {
- return mockDate;
- } else {
- time_t rawtime;
- struct tm* timeinfo;
- time(&rawtime);
- timeinfo = localtime(&rawtime);
- char date[32];
- strftime(date, sizeof(date), "%Y%m%d-%H%M%S", timeinfo);
- return date;
- }
-}
-
-
-// Unit test utility method that makes this class return a fixed string
-// as the date instead of looking up the current time.
-void DateUtils::setMockDate(string date)
+string currentDate()
{
- useMockDate = true;
- mockDate = date;
+ time_t rawtime;
+ struct tm* timeinfo;
+ time(&rawtime);
+ timeinfo = localtime(&rawtime);
+ char date[32];
+ strftime(date, sizeof(date), "%Y%m%d-%H%M%S", timeinfo);
+ return string(date);
}
-
-// Disable usage of the mock date set through setMockDate.
-void DateUtils::clearMockDate()
-{
- useMockDate = false;
- mockDate = "";
-}
+} // namespace DateUtils {
+} // namespace internal {
+} // namespace mesos {
http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d1c4cd/src/common/date_utils.hpp
----------------------------------------------------------------------
diff --git a/src/common/date_utils.hpp b/src/common/date_utils.hpp
index 523e273..5f14a06 100644
--- a/src/common/date_utils.hpp
+++ b/src/common/date_utils.hpp
@@ -21,37 +21,21 @@
#include <string>
-
-namespace mesos { namespace internal {
+namespace mesos {
+namespace internal {
/**
* Utility functions for dealing with dates.
*/
-class DateUtils
-{
-public:
- /**
- * Get the current date in the format used for Mesos IDs (YYYYMMDD-hhmmss).
- */
- static std::string currentDate();
-
- /**
- * Unit test utility method that makes this class return a fixed string
- * as the date instead of looking up the current time.
- */
- static void setMockDate(std::string date);
-
- /**
- * Disable usage of the mock date set through setMockDate.
- */
- static void clearMockDate();
+namespace DateUtils {
+/**
+ * Get the current date in the format used for Mesos IDs (YYYYMMDD-hhmmss).
+ */
+std::string currentDate();
-private:
- static bool useMockDate;
- static std::string mockDate;
-};
-}} /* namespace mesos::internal */
+} // namespace DateUtils {
+} // namespace internal {
+} // namespace mesos {
#endif
-
http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d1c4cd/src/common/factory.hpp
----------------------------------------------------------------------
diff --git a/src/common/factory.hpp b/src/common/factory.hpp
index 94056f6..cca7888 100644
--- a/src/common/factory.hpp
+++ b/src/common/factory.hpp
@@ -26,7 +26,6 @@
#include <stout/fatal.hpp>
-
// These two macros create a Factory class that constructs instances of
// subclasses of a type T, whose constructors take a parameter of type P,
// based on a registered name for each subclass. To use them:
http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d1c4cd/src/common/http.cpp
----------------------------------------------------------------------
diff --git a/src/common/http.cpp b/src/common/http.cpp
index e81a7ad..d27fe21 100644
--- a/src/common/http.cpp
+++ b/src/common/http.cpp
@@ -1,20 +1,37 @@
-#include "common/http.hpp"
+/**
+ * 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 <map>
#include <string>
#include <glog/logging.h>
+#include <mesos/mesos.hpp>
+#include <mesos/resources.hpp>
+
#include <stout/foreach.hpp>
#include <stout/stringify.hpp>
#include "common/attributes.hpp"
+#include "common/http.hpp"
#include "messages/messages.hpp"
-#include "mesos/mesos.hpp"
-#include "mesos/resources.hpp"
-
using std::map;
using std::string;
http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d1c4cd/src/common/http.hpp
----------------------------------------------------------------------
diff --git a/src/common/http.hpp b/src/common/http.hpp
index 717bbe9..8216401 100644
--- a/src/common/http.hpp
+++ b/src/common/http.hpp
@@ -36,4 +36,3 @@ JSON::Object model(const Task& task);
} // namespace mesos {
#endif // __COMMON_HTTP_HPP__
-
http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d1c4cd/src/common/parse.hpp
----------------------------------------------------------------------
diff --git a/src/common/parse.hpp b/src/common/parse.hpp
index 4eb5096..e6153d8 100644
--- a/src/common/parse.hpp
+++ b/src/common/parse.hpp
@@ -14,6 +14,8 @@
#ifndef __COMMON_PARSE_HPP__
#define __COMMON_PARSE_HPP__
+#include <mesos/mesos.hpp>
+
#include <stout/error.hpp>
#include <stout/json.hpp>
#include <stout/protobuf.hpp>
@@ -21,8 +23,6 @@
#include <stout/flags/parse.hpp>
-#include "mesos/mesos.hpp"
-
namespace flags {
template<>
http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d1c4cd/src/common/protobuf_utils.cpp
----------------------------------------------------------------------
diff --git a/src/common/protobuf_utils.cpp b/src/common/protobuf_utils.cpp
new file mode 100644
index 0000000..29fe2cd
--- /dev/null
+++ b/src/common/protobuf_utils.cpp
@@ -0,0 +1,122 @@
+/**
+ * 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 <process/clock.hpp>
+#include <process/pid.hpp>
+
+#include <stout/net.hpp>
+#include <stout/stringify.hpp>
+#include <stout/uuid.hpp>
+
+#include "common/type_utils.hpp"
+
+#include "messages/messages.hpp"
+
+namespace mesos {
+namespace internal {
+namespace protobuf {
+
+bool isTerminalState(const TaskState& state)
+{
+ return (state == TASK_FINISHED ||
+ state == TASK_FAILED ||
+ state == TASK_KILLED ||
+ state == TASK_LOST);
+}
+
+
+// TODO(vinod): Make SlaveID optional because 'StatusUpdate.SlaveID'
+// is optional.
+StatusUpdate createStatusUpdate(
+ const FrameworkID& frameworkId,
+ const Option<SlaveID>& slaveId,
+ const TaskID& taskId,
+ const TaskState& state,
+ const std::string& message = "",
+ const Option<ExecutorID>& executorId = None())
+{
+ StatusUpdate update;
+
+ update.set_timestamp(process::Clock::now().secs());
+ update.set_uuid(UUID::random().toBytes());
+ update.mutable_framework_id()->MergeFrom(frameworkId);
+
+ if (slaveId.isSome()) {
+ update.mutable_slave_id()->MergeFrom(slaveId.get());
+ }
+
+ if (executorId.isSome()) {
+ update.mutable_executor_id()->MergeFrom(executorId.get());
+ }
+
+ TaskStatus* status = update.mutable_status();
+ status->mutable_task_id()->MergeFrom(taskId);
+
+ if (slaveId.isSome()) {
+ status->mutable_slave_id()->MergeFrom(slaveId.get());
+ }
+
+ status->set_state(state);
+ status->set_message(message);
+ status->set_timestamp(update.timestamp());
+
+ return update;
+}
+
+
+Task createTask(const TaskInfo& task,
+ const TaskState& state,
+ const ExecutorID& executorId,
+ const FrameworkID& frameworkId)
+{
+ Task t;
+ t.mutable_framework_id()->MergeFrom(frameworkId);
+ t.set_state(state);
+ t.set_name(task.name());
+ t.mutable_task_id()->MergeFrom(task.task_id());
+ t.mutable_slave_id()->MergeFrom(task.slave_id());
+ t.mutable_resources()->MergeFrom(task.resources());
+
+ if (!task.has_command()) {
+ t.mutable_executor_id()->MergeFrom(executorId);
+ }
+
+ return t;
+}
+
+
+MasterInfo createMasterInfo(const process::UPID& pid)
+{
+ MasterInfo info;
+ info.set_id(stringify(pid) + "-" + UUID::random().toString());
+ info.set_ip(pid.ip);
+ info.set_port(pid.port);
+ info.set_pid(pid);
+
+ Try<std::string> hostname = net::getHostname(pid.ip);
+ if (hostname.isSome()) {
+ info.set_hostname(hostname.get());
+ }
+
+ return info;
+}
+
+
+} // namespace protobuf
+} // namespace internal {
+} // namespace mesos {
http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d1c4cd/src/common/protobuf_utils.hpp
----------------------------------------------------------------------
diff --git a/src/common/protobuf_utils.hpp b/src/common/protobuf_utils.hpp
index 0341c7f..21f3a02 100644
--- a/src/common/protobuf_utils.hpp
+++ b/src/common/protobuf_utils.hpp
@@ -21,106 +21,36 @@
#include <string>
-#include <process/pid.hpp>
-#include <process/process.hpp>
-#include <process/protobuf.hpp>
-
-#include <stout/net.hpp>
-#include <stout/none.hpp>
-#include <stout/stringify.hpp>
-#include <stout/try.hpp>
-#include <stout/uuid.hpp>
-
-#include "common/type_utils.hpp"
+#include <stout/option.hpp>
#include "messages/messages.hpp"
+// Forward declaration (in lieu of an include).
+namespace process {
+struct UPID;
+}
+
namespace mesos {
namespace internal {
namespace protobuf {
-inline bool isTerminalState(const TaskState& state)
-{
- return (state == TASK_FINISHED ||
- state == TASK_FAILED ||
- state == TASK_KILLED ||
- state == TASK_LOST);
-}
-
+bool isTerminalState(const TaskState& state);
-inline StatusUpdate createStatusUpdate(
+StatusUpdate createStatusUpdate(
const FrameworkID& frameworkId,
const Option<SlaveID>& slaveId,
const TaskID& taskId,
const TaskState& state,
const std::string& message = "",
- const Option<ExecutorID>& executorId = None())
-{
- StatusUpdate update;
-
- update.set_timestamp(process::Clock::now().secs());
- update.set_uuid(UUID::random().toBytes());
- update.mutable_framework_id()->MergeFrom(frameworkId);
-
- if (slaveId.isSome()) {
- update.mutable_slave_id()->MergeFrom(slaveId.get());
- }
-
- if (executorId.isSome()) {
- update.mutable_executor_id()->MergeFrom(executorId.get());
- }
-
- TaskStatus* status = update.mutable_status();
- status->mutable_task_id()->MergeFrom(taskId);
-
- if (slaveId.isSome()) {
- status->mutable_slave_id()->MergeFrom(slaveId.get());
- }
+ const Option<ExecutorID>& executorId = None());
- status->set_state(state);
- status->set_message(message);
- status->set_timestamp(update.timestamp());
-
- return update;
-}
-
-
-inline Task createTask(const TaskInfo& task,
- const TaskState& state,
- const ExecutorID& executorId,
- const FrameworkID& frameworkId)
-{
- Task t;
- t.mutable_framework_id()->MergeFrom(frameworkId);
- t.set_state(state);
- t.set_name(task.name());
- t.mutable_task_id()->MergeFrom(task.task_id());
- t.mutable_slave_id()->MergeFrom(task.slave_id());
- t.mutable_resources()->MergeFrom(task.resources());
-
- if (!task.has_command()) {
- t.mutable_executor_id()->MergeFrom(executorId);
- }
-
- return t;
-}
+Task createTask(const TaskInfo& task,
+ const TaskState& state,
+ const ExecutorID& executorId,
+ const FrameworkID& frameworkId);
// Helper function that creates a MasterInfo from UPID.
-inline MasterInfo createMasterInfo(const process::UPID& pid)
-{
- MasterInfo info;
- info.set_id(stringify(pid) + "-" + UUID::random().toString());
- info.set_ip(pid.ip);
- info.set_port(pid.port);
- info.set_pid(pid);
-
- Try<std::string> hostname = net::getHostname(pid.ip);
- if (hostname.isSome()) {
- info.set_hostname(hostname.get());
- }
-
- return info;
-}
+MasterInfo createMasterInfo(const process::UPID& pid);
} // namespace protobuf
} // namespace internal {
http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d1c4cd/src/common/resources.cpp
----------------------------------------------------------------------
diff --git a/src/common/resources.cpp b/src/common/resources.cpp
index d39001b..ade2a71 100644
--- a/src/common/resources.cpp
+++ b/src/common/resources.cpp
@@ -30,7 +30,6 @@
#include <stout/strings.hpp>
#include <stout/try.hpp>
-
using std::ostream;
using std::string;
using std::vector;
@@ -177,6 +176,144 @@ ostream& operator << (ostream& stream, const Resource& resource)
}
+Resources Resources::allocatable() const
+{
+ Resources result;
+
+ foreach (const Resource& resource, resources) {
+ if (isAllocatable(resource)) {
+ result.resources.Add()->MergeFrom(resource);
+ }
+ }
+
+ return result;
+}
+
+
+bool Resources::operator == (const Resources& that) const
+{
+ if (size() != that.size()) {
+ return false;
+ }
+
+ foreach (const Resource& resource, resources) {
+ Option<Resource> option = that.get(resource);
+ if (option.isNone()) {
+ return false;
+ } else {
+ if (!(resource == option.get())) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
+
+bool Resources::operator <= (const Resources& that) const
+{
+ foreach (const Resource& resource, resources) {
+ Option<Resource> option = that.get(resource);
+ if (option.isNone()) {
+ return false;
+ } else {
+ if (!(resource <= option.get())) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
+
+Resources Resources::operator + (const Resources& that) const
+{
+ Resources result(*this);
+
+ foreach (const Resource& resource, that.resources) {
+ result += resource;
+ }
+
+ return result;
+}
+
+
+Resources Resources::operator - (const Resources& that) const
+{
+ Resources result(*this);
+
+ foreach (const Resource& resource, that.resources) {
+ result -= resource;
+ }
+
+ return result;
+}
+
+
+Resources& Resources::operator += (const Resources& that)
+{
+ foreach (const Resource& resource, that.resources) {
+ *this += resource;
+ }
+
+ return *this;
+}
+
+
+Resources& Resources::operator -= (const Resources& that)
+{
+ foreach (const Resource& resource, that.resources) {
+ *this -= resource;
+ }
+
+ return *this;
+}
+
+
+Resources Resources::operator + (const Resource& that) const
+{
+ Resources result;
+
+ bool added = false;
+
+ foreach (const Resource& resource, resources) {
+ if (matches(resource, that)) {
+ result.resources.Add()->MergeFrom(resource + that);
+ added = true;
+ } else {
+ result.resources.Add()->MergeFrom(resource);
+ }
+ }
+
+ if (!added) {
+ result.resources.Add()->MergeFrom(that);
+ }
+
+ return result;
+}
+
+
+Resources Resources::operator - (const Resource& that) const
+{
+ Resources result;
+
+ foreach (const Resource& resource, resources) {
+ if (matches(resource, that)) {
+ Resource r = resource - that;
+ if (!isZero(r)) {
+ result.resources.Add()->MergeFrom(r);
+ }
+ } else {
+ result.resources.Add()->MergeFrom(resource);
+ }
+ }
+
+ return result;
+}
+
+
Resources Resources::flatten(const string& role) const
{
Resources flattened;
@@ -547,4 +684,94 @@ bool Resources::isZero(const Resource& resource)
return false;
}
+
+template <>
+Value::Scalar Resources::get(
+ const std::string& name,
+ const Value::Scalar& scalar) const
+{
+ Value::Scalar total;
+ bool found = false;
+
+ foreach (const Resource& resource, resources) {
+ if (resource.name() == name &&
+ resource.type() == Value::SCALAR) {
+ total += resource.scalar();
+ found = true;
+ }
+ }
+
+ if (found) {
+ return total;
+ }
+
+ return scalar;
+}
+
+
+template <>
+Value::Ranges Resources::get(
+ const std::string& name,
+ const Value::Ranges& ranges) const
+{
+ Value::Ranges total;
+ bool found = false;
+
+ foreach (const Resource& resource, resources) {
+ if (resource.name() == name &&
+ resource.type() == Value::RANGES) {
+ total += resource.ranges();
+ found = true;
+ }
+ }
+
+ if (found) {
+ return total;
+ }
+
+ return ranges;
+}
+
+
+template <>
+Value::Set Resources::get(
+ const std::string& name,
+ const Value::Set& set) const
+{
+ Value::Set total;
+ bool found = false;
+
+ foreach (const Resource& resource, resources) {
+ if (resource.name() == name &&
+ resource.type() == Value::SET) {
+ total += resource.set();
+ found = true;
+ }
+ }
+
+ if (found) {
+ return total;
+ }
+
+ return set;
+}
+
+
+std::ostream& operator << (
+ std::ostream& stream,
+ const Resources& resources)
+{
+ mesos::Resources::const_iterator it = resources.begin();
+
+ while (it != resources.end()) {
+ stream << *it;
+ if (++it != resources.end()) {
+ stream << "; ";
+ }
+ }
+
+ return stream;
+}
+
+
} // namespace mesos {
http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d1c4cd/src/common/status_utils.hpp
----------------------------------------------------------------------
diff --git a/src/common/status_utils.hpp b/src/common/status_utils.hpp
index 1980551..972955d 100644
--- a/src/common/status_utils.hpp
+++ b/src/common/status_utils.hpp
@@ -22,7 +22,7 @@
#include <string>
#include <stout/option.hpp>
-#include "stout/stringify.hpp"
+#include <stout/stringify.hpp>
namespace mesos {
namespace internal {
http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d1c4cd/src/common/thread.cpp
----------------------------------------------------------------------
diff --git a/src/common/thread.cpp b/src/common/thread.cpp
new file mode 100644
index 0000000..751e9e8
--- /dev/null
+++ b/src/common/thread.cpp
@@ -0,0 +1,52 @@
+/**
+ * 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 <stout/lambda.hpp>
+
+#include "common/thread.hpp"
+
+namespace thread {
+
+static void* __run(void* arg)
+{
+ lambda::function<void(void)>* function =
+ reinterpret_cast<lambda::function<void(void)>*>(arg);
+ (*function)();
+ delete function;
+ return 0;
+}
+
+
+bool start(const lambda::function<void(void)>& f, bool detach /*= false*/)
+{
+ lambda::function<void(void)>* __f = new lambda::function<void(void)>(f);
+
+ pthread_t t;
+ if (pthread_create(&t, NULL, __run, __f) != 0) {
+ return false;
+ }
+
+ if (detach && pthread_detach(t) != 0) {
+ return false;
+ }
+
+ return true;
+}
+
+
+} // namespace thread {
http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d1c4cd/src/common/thread.hpp
----------------------------------------------------------------------
diff --git a/src/common/thread.hpp b/src/common/thread.hpp
index 7e48724..9685898 100644
--- a/src/common/thread.hpp
+++ b/src/common/thread.hpp
@@ -1,3 +1,21 @@
+/**
+ * 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 __THREAD_HPP__
#define __THREAD_HPP__
@@ -12,34 +30,9 @@
namespace thread {
-void* __run(void* arg)
-{
- lambda::function<void(void)>* function =
- reinterpret_cast<lambda::function<void(void)>*>(arg);
- (*function)();
- delete function;
- return 0;
-}
-
-
-bool start(const lambda::function<void(void)>& f, bool detach = false)
-{
- lambda::function<void(void)>* __f = new lambda::function<void(void)>(f);
-
- pthread_t t;
- if (pthread_create(&t, NULL, __run, __f) != 0) {
- return false;
- }
-
- if (detach && pthread_detach(t) != 0) {
- return false;
- }
-
- return true;
-}
-
-// TODO(benh): Provide a version of 'run' that returns a type T (the
+// TODO(benh): Provide a version of 'start' that returns a type T (the
// value being a copy or preferablly via move semantics).
+bool start(const lambda::function<void(void)>& f, bool detach = false);
} // namespace thread {
http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d1c4cd/src/common/type_utils.cpp
----------------------------------------------------------------------
diff --git a/src/common/type_utils.cpp b/src/common/type_utils.cpp
new file mode 100644
index 0000000..c8fc7b3
--- /dev/null
+++ b/src/common/type_utils.cpp
@@ -0,0 +1,158 @@
+/**
+ * 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 <mesos/mesos.hpp>
+#include <mesos/resources.hpp>
+
+#include "common/attributes.hpp"
+#include "common/type_utils.hpp"
+
+namespace mesos {
+
+bool operator == (const Environment& left, const Environment& right)
+{
+ if (left.variables().size() != right.variables().size()) {
+ return false;
+ }
+
+ for (int i = 0; i < left.variables().size(); i++) {
+ const std::string& name = left.variables().Get(i).name();
+ const std::string& value = left.variables().Get(i).value();
+ bool found = false;
+ for (int j = 0; j < right.variables().size(); j++) {
+ if (name == right.variables().Get(j).name() &&
+ value == right.variables().Get(j).value()) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+
+bool operator == (const CommandInfo& left, const CommandInfo& right)
+{
+ if (left.uris().size() != right.uris().size()) {
+ return false;
+ }
+
+ for (int i=0; i<left.uris().size(); i++) {
+ bool found = false;
+ for (int j=0; j<right.uris().size(); j++) {
+ if (left.uris().Get(i) == right.uris().Get(j)) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ return false;
+ }
+ }
+
+ return left.has_environment() == right.has_environment() &&
+ (!left.has_environment() || (left.environment() == right.environment())) &&
+ left.value() == right.value();
+}
+
+
+bool operator == (const ExecutorInfo& left, const ExecutorInfo& right)
+{
+ return left.executor_id() == right.executor_id() &&
+ left.has_framework_id() == right.has_framework_id() &&
+ (!left.has_framework_id() ||
+ (left.framework_id() == right.framework_id())) &&
+ left.command() == right.command() &&
+ Resources(left.resources()) == Resources(right.resources()) &&
+ left.has_name() == right.has_name() &&
+ (!left.has_name() || (left.name() == right.name())) &&
+ left.has_source() == right.has_source() &&
+ (!left.has_source() || (left.source() == right.source())) &&
+ left.has_data() == right.has_data() &&
+ (!left.has_data() || (left.data() == right.data()));
+}
+
+
+bool operator == (const SlaveInfo& left, const SlaveInfo& right)
+{
+ // NOTE: We don't compare 'webui_hostname' and 'webui_port' since
+ // they're deprecated and do not carry any semantic meaning.
+ return left.hostname() == right.hostname() &&
+ Resources(left.resources()) == Resources(right.resources()) &&
+ internal::Attributes(left.attributes()) ==
+ internal::Attributes(right.attributes()) &&
+ left.has_id() == right.has_id() &&
+ (!left.has_id() || (left.id() == right.id())) &&
+ left.has_checkpoint() == right.has_checkpoint() &&
+ (!left.has_checkpoint() || (left.checkpoint() == right.checkpoint()));
+}
+
+
+bool operator == (const MasterInfo& left, const MasterInfo& right)
+{
+ return left.id() == right.id() &&
+ left.ip() == right.ip() &&
+ left.port() == right.port() &&
+ left.has_pid() == right.has_pid() &&
+ (!left.has_pid() || (left.pid() == right.pid())) &&
+ left.has_hostname() == right.has_hostname() &&
+ (!left.has_hostname() || (left.hostname() == right.hostname()));
+}
+
+
+namespace internal {
+
+bool operator == (const Task& left, const Task& right)
+{
+ return left.name() == right.name() &&
+ left.task_id() == right.task_id() &&
+ left.framework_id() == right.framework_id() &&
+ left.slave_id() == right.slave_id() &&
+ left.state() == right.state() &&
+ Resources(left.resources()) == Resources(right.resources()) &&
+ left.has_executor_id() == right.has_executor_id() &&
+ (!left.has_executor_id() || (left.executor_id() == right.executor_id()));
+}
+
+
+std::ostream& operator << (
+ std::ostream& stream,
+ const StatusUpdate& update)
+{
+ stream
+ << update.status().state()
+ << " (UUID: " << UUID::fromBytes(update.uuid())
+ << ") for task " << update.status().task_id();
+
+ if (update.status().has_healthy()) {
+ stream
+ << " in health state "
+ << (update.status().healthy() ? "healthy" : "unhealthy");
+ }
+
+ return stream
+ << " of framework " << update.framework_id();
+}
+
+} // namespace internal {
+
+} // namespace mesos {
http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d1c4cd/src/common/type_utils.hpp
----------------------------------------------------------------------
diff --git a/src/common/type_utils.hpp b/src/common/type_utils.hpp
index ee946a3..b6a2f4e 100644
--- a/src/common/type_utils.hpp
+++ b/src/common/type_utils.hpp
@@ -21,11 +21,6 @@
#include <boost/functional/hash.hpp>
-#include <google/protobuf/descriptor.h>
-
-#include <mesos/mesos.hpp>
-#include <mesos/resources.hpp>
-
#include <stout/uuid.hpp>
#include "common/attributes.hpp"
@@ -258,30 +253,7 @@ inline bool operator < (const ContainerID& left, const ContainerID& right)
}
-inline bool operator == (const Environment& left, const Environment& right)
-{
- if (left.variables().size() != right.variables().size()) {
- return false;
- }
-
- for (int i = 0; i < left.variables().size(); i++) {
- const std::string& name = left.variables().Get(i).name();
- const std::string& value = left.variables().Get(i).value();
- bool found = false;
- for (int j = 0; j < right.variables().size(); j++) {
- if (name == right.variables().Get(j).name() &&
- value == right.variables().Get(j).value()) {
- found = true;
- break;
- }
- }
- if (!found) {
- return false;
- }
- }
-
- return true;
-}
+bool operator == (const Environment& left, const Environment& right);
inline bool operator == (
@@ -294,73 +266,13 @@ inline bool operator == (
}
-inline bool operator == (const CommandInfo& left, const CommandInfo& right)
-{
- if (left.uris().size() != right.uris().size()) {
- return false;
- }
-
- for (int i=0; i<left.uris().size(); i++) {
- bool found = false;
- for (int j=0; j<right.uris().size(); j++) {
- if (left.uris().Get(i) == right.uris().Get(j)) {
- found = true;
- break;
- }
- }
- if (!found) {
- return false;
- }
- }
-
- return left.has_environment() == right.has_environment() &&
- (!left.has_environment() || (left.environment() == right.environment())) &&
- left.value() == right.value();
-}
-
-
-inline bool operator == (const ExecutorInfo& left, const ExecutorInfo& right)
-{
- return left.executor_id() == right.executor_id() &&
- left.has_framework_id() == right.has_framework_id() &&
- (!left.has_framework_id() ||
- (left.framework_id() == right.framework_id())) &&
- left.command() == right.command() &&
- Resources(left.resources()) == Resources(right.resources()) &&
- left.has_name() == right.has_name() &&
- (!left.has_name() || (left.name() == right.name())) &&
- left.has_source() == right.has_source() &&
- (!left.has_source() || (left.source() == right.source())) &&
- left.has_data() == right.has_data() &&
- (!left.has_data() || (left.data() == right.data()));
-}
-
+bool operator == (const CommandInfo& left, const CommandInfo& right);
-inline bool operator == (const SlaveInfo& left, const SlaveInfo& right)
-{
- // NOTE: We don't compare 'webui_hostname' and 'webui_port' since
- // they're deprecated and do not carry any semantic meaning.
- return left.hostname() == right.hostname() &&
- Resources(left.resources()) == Resources(right.resources()) &&
- internal::Attributes(left.attributes()) ==
- internal::Attributes(right.attributes()) &&
- left.has_id() == right.has_id() &&
- (!left.has_id() || (left.id() == right.id())) &&
- left.has_checkpoint() == right.has_checkpoint() &&
- (!left.has_checkpoint() || (left.checkpoint() == right.checkpoint()));
-}
+bool operator == (const ExecutorInfo& left, const ExecutorInfo& right);
+bool operator == (const SlaveInfo& left, const SlaveInfo& right);
-inline bool operator == (const MasterInfo& left, const MasterInfo& right)
-{
- return left.id() == right.id() &&
- left.ip() == right.ip() &&
- left.port() == right.port() &&
- left.has_pid() == right.has_pid() &&
- (!left.has_pid() || (left.pid() == right.pid())) &&
- left.has_hostname() == right.has_hostname() &&
- (!left.has_hostname() || (left.hostname() == right.hostname()));
-}
+bool operator == (const MasterInfo& left, const MasterInfo& right);
inline std::size_t hash_value(const FrameworkID& frameworkId)
@@ -413,37 +325,11 @@ inline std::size_t hash_value(const ContainerID& containerId)
namespace internal {
-inline bool operator == (const Task& left, const Task& right)
-{
- return left.name() == right.name() &&
- left.task_id() == right.task_id() &&
- left.framework_id() == right.framework_id() &&
- left.slave_id() == right.slave_id() &&
- left.state() == right.state() &&
- Resources(left.resources()) == Resources(right.resources()) &&
- left.has_executor_id() == right.has_executor_id() &&
- (!left.has_executor_id() || (left.executor_id() == right.executor_id()));
-}
-
+bool operator == (const Task& left, const Task& right);
-inline std::ostream& operator << (
+std::ostream& operator << (
std::ostream& stream,
- const StatusUpdate& update)
-{
- stream
- << update.status().state()
- << " (UUID: " << UUID::fromBytes(update.uuid())
- << ") for task " << update.status().task_id();
-
- if (update.status().has_healthy()) {
- stream
- << " in health state "
- << (update.status().healthy() ? "healthy" : "unhealthy");
- }
-
- return stream
- << " of framework " << update.framework_id();
-}
+ const StatusUpdate& update);
inline std::ostream& operator << (
@@ -454,7 +340,8 @@ inline std::ostream& operator << (
<< StatusUpdateRecord::Type_descriptor()->FindValueByNumber(type)->name();
}
-}} // namespace mesos { namespace internal {
+} // namespace internal {
+} // namespace mesos {
namespace mesos {
http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d1c4cd/src/common/values.cpp
----------------------------------------------------------------------
diff --git a/src/common/values.cpp b/src/common/values.cpp
index 15583fd..e90c572 100644
--- a/src/common/values.cpp
+++ b/src/common/values.cpp
@@ -32,7 +32,6 @@
#include <stout/foreach.hpp>
#include <stout/strings.hpp>
-
using std::max;
using std::min;
using std::ostream;
http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d1c4cd/src/master/master.cpp
----------------------------------------------------------------------
diff --git a/src/master/master.cpp b/src/master/master.cpp
index 152ea7d..273a516 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -41,6 +41,7 @@
#include <stout/lambda.hpp>
#include <stout/memory.hpp>
#include <stout/multihashmap.hpp>
+#include <stout/net.hpp>
#include <stout/nothing.hpp>
#include <stout/numify.hpp>
#include <stout/option.hpp>
http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d1c4cd/src/slave/containerizer/isolator.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/isolator.hpp b/src/slave/containerizer/isolator.hpp
index 8c05cd4..e52e8b1 100644
--- a/src/slave/containerizer/isolator.hpp
+++ b/src/slave/containerizer/isolator.hpp
@@ -22,6 +22,8 @@
#include <list>
#include <string>
+#include <mesos/resources.hpp>
+
#include <process/dispatch.hpp>
#include <process/future.hpp>
#include <process/owned.hpp>
http://git-wip-us.apache.org/repos/asf/mesos/blob/c9d1c4cd/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index 6f0e121..1d56918 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -45,6 +45,7 @@
#include <stout/exit.hpp>
#include <stout/fs.hpp>
#include <stout/lambda.hpp>
+#include <stout/net.hpp>
#include <stout/option.hpp>
#include <stout/os.hpp>
#include <stout/path.hpp>