Added '--task' into mesos-execute. Review: https://reviews.apache.org/r/53645/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/77da99a9 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/77da99a9 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/77da99a9 Branch: refs/heads/master Commit: 77da99a9ca2d7bd5ba61c276290c1cb60bb55445 Parents: bf52cc1 Author: Qian Zhang <zhq527...@gmail.com> Authored: Tue Nov 22 09:32:21 2016 +0800 Committer: Qian Zhang <zhq527...@gmail.com> Committed: Tue Nov 22 09:32:21 2016 +0800 ---------------------------------------------------------------------- src/cli/execute.cpp | 78 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 64 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/77da99a9/src/cli/execute.cpp ---------------------------------------------------------------------- diff --git a/src/cli/execute.cpp b/src/cli/execute.cpp index dac895c..ddf7eca 100644 --- a/src/cli/execute.cpp +++ b/src/cli/execute.cpp @@ -97,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(&Flags::task_group, "task_group", "The value could be a JSON-formatted string of `TaskGroupInfo` or a\n" @@ -305,6 +342,7 @@ public: string master; Option<string> name; + Option<TaskInfo> task; Option<TaskGroupInfo> task_group; bool shell; Option<string> command; @@ -828,21 +866,12 @@ int main(int argc, char** argv) LOG(WARNING) << warning.message; } - 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; + " either '--task' OR '--task_group'") << endl; return EXIT_FAILURE; - } - - if (flags.task_group.isNone()) { + } else if (flags.task.isNone() && flags.task_group.isNone()) { if (flags.name.isNone()) { cerr << flags.usage("Missing required option --name") << endl; return EXIT_FAILURE; @@ -852,6 +881,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; + } } if (flags.content_type == "json" || @@ -1022,9 +1072,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());