Repository: mesos Updated Branches: refs/heads/master 057fd2c67 -> 0b02dc7a8
Added input and output functions for v1::CapabilityInfo. Review: https://reviews.apache.org/r/52780/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/0b02dc7a Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/0b02dc7a Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/0b02dc7a Branch: refs/heads/master Commit: 0b02dc7a8efae70375d98f27898bbcca4092b691 Parents: f6d5b88 Author: Benjamin Bannier <[email protected]> Authored: Tue Oct 18 10:21:19 2016 -0700 Committer: Jie Yu <[email protected]> Committed: Tue Oct 18 13:39:24 2016 -0700 ---------------------------------------------------------------------- include/mesos/v1/mesos.hpp | 5 ++++ src/Makefile.am | 1 + src/cli/execute.cpp | 2 +- src/common/parse.hpp | 17 +------------ src/v1/mesos.cpp | 9 +++++++ src/v1/parse.hpp | 54 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 71 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/0b02dc7a/include/mesos/v1/mesos.hpp ---------------------------------------------------------------------- diff --git a/include/mesos/v1/mesos.hpp b/include/mesos/v1/mesos.hpp index f171458..2ba72e9 100644 --- a/include/mesos/v1/mesos.hpp +++ b/include/mesos/v1/mesos.hpp @@ -244,6 +244,11 @@ inline bool operator<(const TaskID& left, const TaskID& right) } +std::ostream& operator<<( + std::ostream& stream, + const CapabilityInfo& capabilityInfo); + + std::ostream& operator<<(std::ostream& stream, const ContainerID& containerId); http://git-wip-us.apache.org/repos/asf/mesos/blob/0b02dc7a/src/Makefile.am ---------------------------------------------------------------------- diff --git a/src/Makefile.am b/src/Makefile.am index 3bcc0f2..0a32f75 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1020,6 +1020,7 @@ libmesos_no_3rdparty_la_SOURCES += \ uri/schemes/hdfs.hpp \ uri/schemes/http.hpp \ usage/usage.hpp \ + v1/parse.hpp \ version/version.hpp \ watcher/whitelist_watcher.hpp http://git-wip-us.apache.org/repos/asf/mesos/blob/0b02dc7a/src/cli/execute.cpp ---------------------------------------------------------------------- diff --git a/src/cli/execute.cpp b/src/cli/execute.cpp index c7d6aa8..e694853 100644 --- a/src/cli/execute.cpp +++ b/src/cli/execute.cpp @@ -46,7 +46,7 @@ #include "internal/devolve.hpp" -#include "common/parse.hpp" +#include "v1/parse.hpp" using std::cerr; using std::cout; http://git-wip-us.apache.org/repos/asf/mesos/blob/0b02dc7a/src/common/parse.hpp ---------------------------------------------------------------------- diff --git a/src/common/parse.hpp b/src/common/parse.hpp index 62a333c..ee26717 100644 --- a/src/common/parse.hpp +++ b/src/common/parse.hpp @@ -15,8 +15,6 @@ #include <mesos/mesos.hpp> -#include <mesos/v1/mesos.hpp> - #include <mesos/authorizer/acls.hpp> #include <mesos/module/module.hpp> @@ -90,20 +88,6 @@ inline Try<mesos::ContainerInfo> parse(const std::string& value) } -template <> -inline Try<mesos::v1::TaskGroupInfo> parse(const std::string& value) -{ - // Convert from string or file to JSON. - Try<JSON::Object> json = parse<JSON::Object>(value); - if (json.isError()) { - return Error(json.error()); - } - - // Convert from JSON to Protobuf. - return protobuf::parse<mesos::v1::TaskGroupInfo>(json.get()); -} - - // When the same variable is listed multiple times, // uses only the last value. template <> @@ -190,6 +174,7 @@ inline Try<mesos::CapabilityInfo> parse(const std::string& value) return protobuf::parse<mesos::CapabilityInfo>(json.get()); } + } // namespace flags { #endif // __COMMON_PARSE_HPP__ http://git-wip-us.apache.org/repos/asf/mesos/blob/0b02dc7a/src/v1/mesos.cpp ---------------------------------------------------------------------- diff --git a/src/v1/mesos.cpp b/src/v1/mesos.cpp index 0f88aba..4c8ee91 100644 --- a/src/v1/mesos.cpp +++ b/src/v1/mesos.cpp @@ -16,6 +16,8 @@ #include <ostream> +#include <stout/protobuf.hpp> + #include <mesos/v1/attributes.hpp> #include <mesos/v1/mesos.hpp> #include <mesos/v1/resources.hpp> @@ -381,6 +383,13 @@ bool operator!=(const TaskStatus& left, const TaskStatus& right) return !(left == right); } + +ostream& operator<<(ostream& stream, const CapabilityInfo& capabilityInfo) +{ + return stream << JSON::protobuf(capabilityInfo); +} + + ostream& operator<<(ostream& stream, const ContainerID& containerId) { return stream << containerId.value(); http://git-wip-us.apache.org/repos/asf/mesos/blob/0b02dc7a/src/v1/parse.hpp ---------------------------------------------------------------------- diff --git a/src/v1/parse.hpp b/src/v1/parse.hpp new file mode 100644 index 0000000..8882b32 --- /dev/null +++ b/src/v1/parse.hpp @@ -0,0 +1,54 @@ +// Licensed 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 __V1_PARSE_HPP__ +#define __V1_PARSE_HPP__ + +#include <stout/error.hpp> +#include <stout/json.hpp> +#include <stout/protobuf.hpp> +#include <stout/try.hpp> + +#include <stout/flags/parse.hpp> + +#include <mesos/v1/mesos.hpp> + +namespace flags { + +template <> +inline Try<mesos::v1::CapabilityInfo> parse(const std::string& value) +{ + Try<JSON::Object> json = parse<JSON::Object>(value); + if (json.isError()) { + return Error(json.error()); + } + + return protobuf::parse<mesos::v1::CapabilityInfo>(json.get()); +} + + +template <> +inline Try<mesos::v1::TaskGroupInfo> parse(const std::string& value) +{ + // Convert from string or file to JSON. + Try<JSON::Object> json = parse<JSON::Object>(value); + if (json.isError()) { + return Error(json.error()); + } + + // Convert from JSON to Protobuf. + return protobuf::parse<mesos::v1::TaskGroupInfo>(json.get()); +} + +} // namespace flags { + +#endif // __V1_PARSE_HPP__
