Repository: mesos Updated Branches: refs/heads/master f5ec1d006 -> b0d1c6ea0
Made attributes.hpp public. This is required in order to enable callback hooks that can modify attributes of a slave during initialization. Review: https://reviews.apache.org/r/38517 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/b0d1c6ea Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/b0d1c6ea Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/b0d1c6ea Branch: refs/heads/master Commit: b0d1c6ea0b3f6ff17d4e947a5bf0258a649a8f65 Parents: f5ec1d0 Author: Felix Abecassis <[email protected]> Authored: Tue Sep 22 13:57:58 2015 -0700 Committer: Niklas Q. Nielsen <[email protected]> Committed: Tue Sep 22 13:57:59 2015 -0700 ---------------------------------------------------------------------- include/mesos/attributes.hpp | 117 ++++++++++++++++++++++++++++++++++ src/Makefile.am | 2 +- src/common/attributes.cpp | 10 +-- src/common/attributes.hpp | 122 ------------------------------------ src/common/http.cpp | 2 +- src/common/http.hpp | 2 +- src/common/type_utils.cpp | 6 +- src/master/http.cpp | 2 +- src/slave/http.cpp | 2 +- src/slave/slave.hpp | 2 +- src/tests/attributes_tests.cpp | 2 +- src/tests/registrar_tests.cpp | 2 +- 12 files changed, 129 insertions(+), 142 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/b0d1c6ea/include/mesos/attributes.hpp ---------------------------------------------------------------------- diff --git a/include/mesos/attributes.hpp b/include/mesos/attributes.hpp new file mode 100644 index 0000000..78afcd5 --- /dev/null +++ b/include/mesos/attributes.hpp @@ -0,0 +1,117 @@ +/** + * 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 __ATTRIBUTES_HPP__ +#define __ATTRIBUTES_HPP__ + +#include <iterator> +#include <string> + +#include <mesos/mesos.hpp> + +#include <stout/option.hpp> + +namespace mesos { + +std::ostream& operator<<(std::ostream& stream, const Attribute& attribute); + +class Attributes +{ +public: + Attributes() {} + + /*implicit*/ + Attributes(const google::protobuf::RepeatedPtrField<Attribute>& _attributes) + { + attributes.MergeFrom(_attributes); + } + + Attributes(const Attributes& that) + { + attributes.MergeFrom(that.attributes); + } + + Attributes& operator=(const Attributes& that) + { + if (this != &that) { + attributes.Clear(); + attributes.MergeFrom(that.attributes); + } + + return *this; + } + + bool operator==(const Attributes& that) const; + + + bool operator!=(const Attributes& that) const + { + return !(*this == that); + } + + size_t size() const + { + return attributes.size(); + } + + // Using this operator makes it easy to copy a attributes object into + // a protocol buffer field. + operator const google::protobuf::RepeatedPtrField<Attribute>&() const + { + return attributes; + } + + void add(const Attribute& attribute) + { + attributes.Add()->MergeFrom(attribute); + } + + const Attribute get(int index) const + { + return attributes.Get(index); + } + + const Option<Attribute> get(const Attribute& thatAttribute) const; + + template <typename T> + T get(const std::string& name, const T& t) const; + + typedef google::protobuf::RepeatedPtrField<Attribute>::iterator + iterator; + + typedef google::protobuf::RepeatedPtrField<Attribute>::const_iterator + const_iterator; + + iterator begin() { return attributes.begin(); } + iterator end() { return attributes.end(); } + + const_iterator begin() const { return attributes.begin(); } + const_iterator end() const { return attributes.end(); } + + static Attribute parse(const std::string& name, const std::string& value); + static Attributes parse(const std::string& s); + + static bool isValid(const Attribute& attribute); + +private: + google::protobuf::RepeatedPtrField<Attribute> attributes; +}; + +} // namespace mesos { + +#endif // __ATTRIBUTES_HPP__ http://git-wip-us.apache.org/repos/asf/mesos/blob/b0d1c6ea/src/Makefile.am ---------------------------------------------------------------------- diff --git a/src/Makefile.am b/src/Makefile.am index e224060..74c1154 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -536,6 +536,7 @@ libmesos_no_3rdparty_la_SOURCES = \ pkginclude_HEADERS = \ + $(top_srcdir)/include/mesos/attributes.hpp \ $(top_srcdir)/include/mesos/executor.hpp \ $(top_srcdir)/include/mesos/hook.hpp \ $(top_srcdir)/include/mesos/http.hpp \ @@ -740,7 +741,6 @@ libmesos_no_3rdparty_la_SOURCES += \ authentication/cram_md5/authenticator.hpp \ authentication/cram_md5/auxprop.hpp \ authorizer/local/authorizer.hpp \ - common/attributes.hpp \ common/build.hpp \ common/date_utils.hpp \ common/http.hpp \ http://git-wip-us.apache.org/repos/asf/mesos/blob/b0d1c6ea/src/common/attributes.cpp ---------------------------------------------------------------------- diff --git a/src/common/attributes.cpp b/src/common/attributes.cpp index f713bb5..8a8d624 100644 --- a/src/common/attributes.cpp +++ b/src/common/attributes.cpp @@ -21,13 +21,12 @@ #include <glog/logging.h> +#include <mesos/attributes.hpp> #include <mesos/values.hpp> #include <stout/foreach.hpp> #include <stout/strings.hpp> -#include "common/attributes.hpp" - using std::ostream; using std::string; using std::vector; @@ -52,9 +51,6 @@ std::ostream& operator<<(std::ostream& stream, const Attribute& attribute) } -namespace internal { - - bool Attributes::operator==(const Attributes& that) const { if (size() != that.size()) { @@ -108,7 +104,7 @@ const Option<Attribute> Attributes::get(const Attribute& thatAttribute) const Attribute Attributes::parse(const std::string& name, const std::string& text) { Attribute attribute; - Try<Value> result = values::parse(text); + Try<Value> result = internal::values::parse(text); if (result.isError()) { LOG(FATAL) << "Failed to parse attribute " << name @@ -229,6 +225,4 @@ Value::Text Attributes::get( return text; } - -} // namespace internal { } // namespace mesos { http://git-wip-us.apache.org/repos/asf/mesos/blob/b0d1c6ea/src/common/attributes.hpp ---------------------------------------------------------------------- diff --git a/src/common/attributes.hpp b/src/common/attributes.hpp deleted file mode 100644 index 2a7efbd..0000000 --- a/src/common/attributes.hpp +++ /dev/null @@ -1,122 +0,0 @@ -/** - * 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 __ATTRIBUTES_HPP__ -#define __ATTRIBUTES_HPP__ - -#include <iterator> -#include <string> - -#include <mesos/mesos.hpp> - -#include <stout/option.hpp> - -namespace mesos { - -std::ostream& operator<<(std::ostream& stream, const Attribute& attribute); - -namespace internal { - - -class Attributes -{ -public: - Attributes() {} - - /*implicit*/ - Attributes(const google::protobuf::RepeatedPtrField<Attribute>& _attributes) - { - attributes.MergeFrom(_attributes); - } - - Attributes(const Attributes& that) - { - attributes.MergeFrom(that.attributes); - } - - Attributes& operator=(const Attributes& that) - { - if (this != &that) { - attributes.Clear(); - attributes.MergeFrom(that.attributes); - } - - return *this; - } - - bool operator==(const Attributes& that) const; - - - bool operator!=(const Attributes& that) const - { - return !(*this == that); - } - - size_t size() const - { - return attributes.size(); - } - - // Using this operator makes it easy to copy a attributes object into - // a protocol buffer field. - operator const google::protobuf::RepeatedPtrField<Attribute>&() const - { - return attributes; - } - - void add(const Attribute& attribute) - { - attributes.Add()->MergeFrom(attribute); - } - - const Attribute get(int index) const - { - return attributes.Get(index); - } - - const Option<Attribute> get(const Attribute& thatAttribute) const; - - template <typename T> - T get(const std::string& name, const T& t) const; - - typedef google::protobuf::RepeatedPtrField<Attribute>::iterator - iterator; - - typedef google::protobuf::RepeatedPtrField<Attribute>::const_iterator - const_iterator; - - iterator begin() { return attributes.begin(); } - iterator end() { return attributes.end(); } - - const_iterator begin() const { return attributes.begin(); } - const_iterator end() const { return attributes.end(); } - - static Attribute parse(const std::string& name, const std::string& value); - static Attributes parse(const std::string& s); - - static bool isValid(const Attribute& attribute); - -private: - google::protobuf::RepeatedPtrField<Attribute> attributes; -}; - - -} // namespace internal { -} // namespace mesos { - -#endif // __ATTRIBUTES_HPP__ http://git-wip-us.apache.org/repos/asf/mesos/blob/b0d1c6ea/src/common/http.cpp ---------------------------------------------------------------------- diff --git a/src/common/http.cpp b/src/common/http.cpp index aaef10b..99b843a 100644 --- a/src/common/http.cpp +++ b/src/common/http.cpp @@ -22,6 +22,7 @@ #include <utility> #include <vector> +#include <mesos/attributes.hpp> #include <mesos/resources.hpp> #include <stout/foreach.hpp> @@ -29,7 +30,6 @@ #include <stout/stringify.hpp> #include <stout/unreachable.hpp> -#include "common/attributes.hpp" #include "common/http.hpp" #include "messages/messages.hpp" http://git-wip-us.apache.org/repos/asf/mesos/blob/b0d1c6ea/src/common/http.hpp ---------------------------------------------------------------------- diff --git a/src/common/http.hpp b/src/common/http.hpp index 058baa6..0cc98a8 100644 --- a/src/common/http.hpp +++ b/src/common/http.hpp @@ -31,10 +31,10 @@ namespace mesos { class Resources; +class Attributes; namespace internal { -class Attributes; class Task; http://git-wip-us.apache.org/repos/asf/mesos/blob/b0d1c6ea/src/common/type_utils.cpp ---------------------------------------------------------------------- diff --git a/src/common/type_utils.cpp b/src/common/type_utils.cpp index 22118b4..5f74dab 100644 --- a/src/common/type_utils.cpp +++ b/src/common/type_utils.cpp @@ -16,12 +16,11 @@ * limitations under the License. */ +#include <mesos/attributes.hpp> #include <mesos/mesos.hpp> #include <mesos/resources.hpp> #include <mesos/type_utils.hpp> -#include "common/attributes.hpp" - #include "messages/messages.hpp" namespace mesos { @@ -333,8 +332,7 @@ bool operator==(const SlaveInfo& left, const SlaveInfo& right) { return left.hostname() == right.hostname() && Resources(left.resources()) == Resources(right.resources()) && - internal::Attributes(left.attributes()) == - internal::Attributes(right.attributes()) && + Attributes(left.attributes()) == Attributes(right.attributes()) && left.id() == right.id() && left.checkpoint() == right.checkpoint() && left.port() == right.port(); http://git-wip-us.apache.org/repos/asf/mesos/blob/b0d1c6ea/src/master/http.cpp ---------------------------------------------------------------------- diff --git a/src/master/http.cpp b/src/master/http.cpp index 3e44b06..fb5315c 100644 --- a/src/master/http.cpp +++ b/src/master/http.cpp @@ -26,6 +26,7 @@ #include <boost/array.hpp> +#include <mesos/attributes.hpp> #include <mesos/type_utils.hpp> #include <mesos/authorizer/authorizer.hpp> @@ -53,7 +54,6 @@ #include <stout/try.hpp> #include <stout/utils.hpp> -#include "common/attributes.hpp" #include "common/build.hpp" #include "common/http.hpp" #include "common/protobuf_utils.hpp" http://git-wip-us.apache.org/repos/asf/mesos/blob/b0d1c6ea/src/slave/http.cpp ---------------------------------------------------------------------- diff --git a/src/slave/http.cpp b/src/slave/http.cpp index 12a4d39..cddc8ad 100644 --- a/src/slave/http.cpp +++ b/src/slave/http.cpp @@ -26,6 +26,7 @@ #include <mesos/v1/executor/executor.hpp> +#include <mesos/attributes.hpp> #include <mesos/type_utils.hpp> #include <process/help.hpp> @@ -41,7 +42,6 @@ #include <stout/stringify.hpp> #include <stout/strings.hpp> -#include "common/attributes.hpp" #include "common/build.hpp" #include "common/http.hpp" http://git-wip-us.apache.org/repos/asf/mesos/blob/b0d1c6ea/src/slave/slave.hpp ---------------------------------------------------------------------- diff --git a/src/slave/slave.hpp b/src/slave/slave.hpp index 7a54fad..8fcd2d9 100644 --- a/src/slave/slave.hpp +++ b/src/slave/slave.hpp @@ -28,6 +28,7 @@ #include <boost/circular_buffer.hpp> +#include <mesos/attributes.hpp> #include <mesos/resources.hpp> #include <mesos/type_utils.hpp> @@ -62,7 +63,6 @@ #include "slave/paths.hpp" #include "slave/state.hpp" -#include "common/attributes.hpp" #include "common/protobuf_utils.hpp" #include "files/files.hpp" http://git-wip-us.apache.org/repos/asf/mesos/blob/b0d1c6ea/src/tests/attributes_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/attributes_tests.cpp b/src/tests/attributes_tests.cpp index ded6120..4fc0c31 100644 --- a/src/tests/attributes_tests.cpp +++ b/src/tests/attributes_tests.cpp @@ -21,7 +21,7 @@ #include <gtest/gtest.h> -#include "common/attributes.hpp" +#include <mesos/attributes.hpp> using std::string; http://git-wip-us.apache.org/repos/asf/mesos/blob/b0d1c6ea/src/tests/registrar_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/registrar_tests.cpp b/src/tests/registrar_tests.cpp index 5131b57..2610a56 100644 --- a/src/tests/registrar_tests.cpp +++ b/src/tests/registrar_tests.cpp @@ -23,6 +23,7 @@ #include <string> #include <vector> +#include <mesos/attributes.hpp> #include <mesos/type_utils.hpp> #include <process/clock.hpp> @@ -35,7 +36,6 @@ #include <stout/stopwatch.hpp> #include <stout/uuid.hpp> -#include "common/attributes.hpp" #include "common/protobuf_utils.hpp" #include "log/log.hpp"
