-
Notifications
You must be signed in to change notification settings - Fork 209
Better cvd help stop message #2713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jemoreira
wants to merge
1
commit into
google:main
Choose a base branch
from
jemoreira:stop
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+56
−37
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ | |
| #include "cuttlefish/flag_parser/gflags_compat.h" | ||
| #include "cuttlefish/host/commands/cvd/cli/command_request.h" | ||
| #include "cuttlefish/host/commands/cvd/cli/commands/command_handler.h" | ||
| #include "cuttlefish/host/commands/cvd/cli/help_format.h" | ||
| #include "cuttlefish/host/commands/cvd/cli/selector/selector.h" | ||
| #include "cuttlefish/host/commands/cvd/cli/types.h" | ||
| #include "cuttlefish/host/commands/cvd/cli/utils.h" | ||
|
|
@@ -41,39 +42,12 @@ | |
| namespace cuttlefish { | ||
| namespace { | ||
|
|
||
| constexpr char kSummaryHelpText[] = "Stop all instances in a group"; | ||
|
|
||
| constexpr char kDetailedHelpText[] = | ||
| R"""( | ||
| Stops all instances in an instance group | ||
|
|
||
| Usage: | ||
| cvd stop [--wait_for_launcher=SECONDS] [--clear_instance_dirs] | ||
|
|
||
| Stops a running cuttlefish instance group. | ||
|
|
||
| --wait_for_launcher=SECONDS The number of seconds to wait for the launcher to | ||
| respond to the stop request. If SECONDS is 0 it will wait | ||
| indefinitely. Defaults to 5 seconds. | ||
|
|
||
| --clear_instance_dirs If provided the instance directories will be deleted | ||
| after stopping. | ||
| )"""; | ||
| constexpr char kSummaryHelpText[] = "Stop Cuttlefish instances"; | ||
|
|
||
| struct StopFlags { | ||
| size_t wait_for_launcher_secs = 5; | ||
| bool clear_instance_dirs = false; | ||
| }; | ||
| Result<StopFlags> ParseCommandFlags(cvd_common::Args& args) { | ||
| StopFlags flag_values; | ||
| std::vector<Flag> flags = { | ||
| GflagsCompatFlag("wait_for_launcher", flag_values.wait_for_launcher_secs), | ||
| GflagsCompatFlag("clear_instance_dirs", flag_values.clear_instance_dirs), | ||
| }; | ||
| CF_EXPECT(ConsumeFlags(flags, args, {.fail_on_unexpected_argument = true})); | ||
| return flag_values; | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| CvdStopCommandHandler::CvdStopCommandHandler(InstanceManager& instance_manager) | ||
|
|
@@ -89,10 +63,11 @@ Result<void> CvdStopCommandHandler::Handle(const CommandRequest& request) { | |
| auto group = CF_EXPECT(selector::SelectGroup(instance_manager_, request)); | ||
| CF_EXPECT(group.HasActiveInstances(), "Selected group is not running"); | ||
|
|
||
| StopFlags flags = CF_EXPECT(ParseCommandFlags(cmd_args)); | ||
| CF_EXPECT(ConsumeFlags(CF_EXPECT(Flags(request)), cmd_args, | ||
| {.fail_on_unexpected_argument = true})); | ||
| std::optional<std::chrono::seconds> launcher_timeout; | ||
| if (flags.wait_for_launcher_secs > 0) { | ||
| launcher_timeout.emplace(flags.wait_for_launcher_secs); | ||
| if (flags_.wait_for_launcher_secs > 0) { | ||
| launcher_timeout.emplace(flags_.wait_for_launcher_secs); | ||
| } | ||
|
|
||
| std::vector<unsigned> instance_nums; | ||
|
|
@@ -109,8 +84,8 @@ Result<void> CvdStopCommandHandler::Handle(const CommandRequest& request) { | |
|
|
||
| Result<void> stop_outcome = instance_manager_.StopInstanceGroup( | ||
| group, launcher_timeout, | ||
| flags.clear_instance_dirs ? InstanceDirActionOnStop::Clear | ||
| : InstanceDirActionOnStop::Keep, | ||
| flags_.clear_instance_dirs ? InstanceDirActionOnStop::Clear | ||
| : InstanceDirActionOnStop::Keep, | ||
| instance_nums); | ||
|
|
||
| GatherVmStopMetrics(group); | ||
|
|
@@ -127,9 +102,43 @@ std::string CvdStopCommandHandler::SummaryHelp() const { | |
| return kSummaryHelpText; | ||
| } | ||
|
|
||
| Result<std::string> CvdStopCommandHandler::DetailedHelp( | ||
| const CommandRequest& request) { | ||
| return kDetailedHelpText; | ||
| std::vector<HelpParagraph> CvdStopCommandHandler::Description() const { | ||
| std::vector<HelpParagraph> description; | ||
| description.emplace_back( | ||
| HelpParagraph::Raw("Usage:\n cvd [selectors] stop [args]")); | ||
| description.emplace_back( | ||
| "Stop a subset of instances from a group. A single instance, severall or " | ||
| "all instances in a group can be stopped at once. To stop instances from " | ||
| "different groups the command must be invoked multiple times."); | ||
| description.emplace_back( | ||
| "Instances must be in 'Running' or 'Starting' states, otherwise the " | ||
| "command will fail. Instances will be left in 'Stopped' state if the " | ||
| "command succeeds and can later be started with the `cvd start` " | ||
| "command."); | ||
| description.emplace_back( | ||
| "The stop operation attemps to graciously stop the instances by sending " | ||
| "an ACPI shutdown. If the shutdown doesn't complete within the " | ||
|
Comment on lines
+119
to
+120
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no "ACPI shutdown", was this hallucinated? The distinction is whether processes are |
||
| "configured timeout the virtual machines and accompanying processes are " | ||
| "forcefully terminated. Logs, virtual disks and other files are " | ||
| "preserved after a stop completes unless --clear_instance_dirs is " | ||
| "given."); | ||
| return description; | ||
| } | ||
|
|
||
| Result<std::vector<Flag>> CvdStopCommandHandler::Flags(const CommandRequest&) { | ||
| return std::vector<Flag>{ | ||
| GflagsCompatFlag("wait_for_launcher_seconds", | ||
| flags_.wait_for_launcher_secs) | ||
| .Alias("wait_for_launcher") | ||
| .Help("Number of seconds to wait for the running instance(s) " | ||
| "to report that it stopped successfully before " | ||
| "forcefully stopping it."), | ||
| GflagsCompatFlag("clear_instance_dirs", flags_.clear_instance_dirs) | ||
| .Help("Deletes log files, temporary files, virtual disks " | ||
| "overlays and other instance specific state. It does " | ||
| "not delete the original disk images, but reverts any " | ||
| "changes the instance may have written to disk."), | ||
| }; | ||
| } | ||
|
|
||
| std::unique_ptr<CvdCommandHandler> NewCvdStopCommandHandler( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
several