You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by qi...@apache.org on 2016/12/29 03:01:56 UTC
mesos git commit: Added backport of MESOS-6571 to 1.1.x.
Repository: mesos
Updated Branches:
refs/heads/1.1.x 2342bc335 -> f5b6cb8d6
Added backport of MESOS-6571 to 1.1.x.
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/f5b6cb8d
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/f5b6cb8d
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/f5b6cb8d
Branch: refs/heads/1.1.x
Commit: f5b6cb8d65f8d704afe72b8adc84a3bb2e95e51b
Parents: 2342bc3
Author: Qian Zhang <zh...@gmail.com>
Authored: Thu Dec 29 10:50:33 2016 +0800
Committer: Qian Zhang <zh...@gmail.com>
Committed: Thu Dec 29 10:50:33 2016 +0800
----------------------------------------------------------------------
src/Makefile.am | 1 +
src/cli/execute.cpp | 81 +++++++++++++++++++++++++++++++++++++++--------
src/common/parse.hpp | 16 ----------
src/v1/parse.hpp | 62 ++++++++++++++++++++++++++++++++++++
4 files changed, 130 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/f5b6cb8d/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 790e8b1..5316cbb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1084,6 +1084,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/f5b6cb8d/src/cli/execute.cpp
----------------------------------------------------------------------
diff --git a/src/cli/execute.cpp b/src/cli/execute.cpp
index 94ac463..c2dd87a 100644
--- a/src/cli/execute.cpp
+++ b/src/cli/execute.cpp
@@ -46,6 +46,8 @@
#include "internal/devolve.hpp"
+#include "v1/parse.hpp"
+
using std::cerr;
using std::cout;
using std::endl;
@@ -95,6 +97,43 @@ public:
"master",
"Mesos master (e.g., IP:PORT).");
+ add(&Flags::task,
+ "task",
+ "The value could be a JSON-formatted string of `TaskInfo` or a\n"
+ "file path containing the JSON-formatted `TaskInfo`. Path must\n"
+ "be of the form `file:///path/to/file` or `/path/to/file`."
+ "\n"
+ "See the `TaskInfo` message in `mesos.proto` for the expected\n"
+ "format. NOTE: `agent_id` need not to be set.\n"
+ "\n"
+ "Example:\n"
+ "{\n"
+ " \"name\": \"Name of the task\",\n"
+ " \"task_id\": {\"value\" : \"Id of the task\"},\n"
+ " \"agent_id\": {\"value\" : \"\"},\n"
+ " \"resources\": [\n"
+ " {\n"
+ " \"name\": \"cpus\",\n"
+ " \"type\": \"SCALAR\",\n"
+ " \"scalar\": {\n"
+ " \"value\": 0.1\n"
+ " },\n"
+ " \"role\": \"*\"\n"
+ " },\n"
+ " {\n"
+ " \"name\": \"mem\",\n"
+ " \"type\": \"SCALAR\",\n"
+ " \"scalar\": {\n"
+ " \"value\": 32\n"
+ " },\n"
+ " \"role\": \"*\"\n"
+ " }\n"
+ " ],\n"
+ " \"command\": {\n"
+ " \"value\": \"sleep 1000\"\n"
+ " }\n"
+ "}");
+
add(&task_group,
"task_group",
"The value could be a JSON-formatted string of `TaskGroupInfo` or a\n"
@@ -267,6 +306,7 @@ public:
Option<string> master;
Option<string> name;
+ Option<TaskInfo> task;
Option<TaskGroupInfo> task_group;
bool shell;
Option<string> command;
@@ -779,21 +819,13 @@ int main(int argc, char** argv)
return EXIT_FAILURE;
}
- if (flags.task_group.isSome() &&
- (flags.name.isSome() ||
- flags.command.isSome() ||
- flags.environment.isSome() ||
- flags.appc_image.isSome() ||
- flags.docker_image.isSome() ||
- flags.volumes.isSome())) {
+ if (flags.task.isSome() && flags.task_group.isSome()) {
cerr << flags.usage(
"Either task or task group should be set but not both. Provide"
- " either '--name, --command, --env, --appc_image, --docker_image,"
- " --volumes' OR '--task_group'") << endl;
- return EXIT_FAILURE;
- }
+ " either '--task' OR '--task_group'") << endl;
- if (flags.task_group.isNone()) {
+ return EXIT_FAILURE;
+ } else if (flags.task.isNone() && flags.task_group.isNone()) {
if (flags.name.isNone()) {
cerr << flags.usage("Missing required option --name") << endl;
return EXIT_FAILURE;
@@ -803,6 +835,27 @@ int main(int argc, char** argv)
cerr << flags.usage("Missing required option --command") << endl;
return EXIT_FAILURE;
}
+ } else {
+ // Either --task or --task_group is set.
+ if (flags.name.isSome() ||
+ flags.command.isSome() ||
+ flags.environment.isSome() ||
+ flags.appc_image.isSome() ||
+ flags.docker_image.isSome() ||
+ flags.volumes.isSome()) {
+ cerr << flags.usage(
+ "'--name, --command, --env, --appc_image, --docker_image,"
+ " --volumes' can only be set when both '--task' and"
+ " '--task_group' are not set") << endl;
+ return EXIT_FAILURE;
+ }
+
+ if (flags.task.isSome() && flags.networks.isSome()) {
+ cerr << flags.usage(
+ "'--networks' can only be set when"
+ " '--task' is not set") << endl;
+ return EXIT_FAILURE;
+ }
}
Result<string> user = os::user();
@@ -961,9 +1014,9 @@ int main(int argc, char** argv)
}
}
- Option<TaskInfo> taskInfo = None();
+ Option<TaskInfo> taskInfo = flags.task;
- if (flags.task_group.isNone()) {
+ if (flags.task.isNone() && flags.task_group.isNone()) {
TaskInfo task;
task.set_name(flags.name.get());
task.mutable_task_id()->set_value(flags.name.get());
http://git-wip-us.apache.org/repos/asf/mesos/blob/f5b6cb8d/src/common/parse.hpp
----------------------------------------------------------------------
diff --git a/src/common/parse.hpp b/src/common/parse.hpp
index 62a333c..51582a4 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 <>
http://git-wip-us.apache.org/repos/asf/mesos/blob/f5b6cb8d/src/v1/parse.hpp
----------------------------------------------------------------------
diff --git a/src/v1/parse.hpp b/src/v1/parse.hpp
new file mode 100644
index 0000000..2e4af98
--- /dev/null
+++ b/src/v1/parse.hpp
@@ -0,0 +1,62 @@
+// 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>
+
+// This file differs from its counterpart in master branch, here it only
+// includes the 'parse' methods for v1's 'TaskGroupInfo' and 'TaskInfo'.
+// In master branch, it also includes 'parse' methods for some other v1's
+// protobuf message, since we do not plan to include those related features
+// in 1.1.x releases, those 'parse' methods are not included here too.
+
+namespace flags {
+
+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());
+}
+
+
+template <>
+inline Try<mesos::v1::TaskInfo> 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::TaskInfo>(json.get());
+}
+
+} // namespace flags {
+
+#endif // __V1_PARSE_HPP__