diff --git a/base/cvd/cuttlefish/host/commands/cvd/acloud/converter.cpp b/base/cvd/cuttlefish/host/commands/cvd/acloud/converter.cpp index 10fb6de525..cbba43d170 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/acloud/converter.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/acloud/converter.cpp @@ -573,7 +573,7 @@ Result ConvertAcloudCreate( } if (pet_name) { const auto [group_name, instance_name] = - CF_EXPECT(selector::BreakDeviceName(*pet_name), + CF_EXPECT(BreakDeviceName(*pet_name), *pet_name << " must be a group name followed by - " << "followed by an instance name."); std::string group_name_arg = "--"; diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/create.cpp b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/create.cpp index 960e50e38b..058cde89e1 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/create.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/create.cpp @@ -32,18 +32,18 @@ #include "common/libs/utils/flag_parser.h" #include "common/libs/utils/result.h" #include "common/libs/utils/users.h" -#include "cuttlefish/host/commands/cvd/legacy/cvd_server.pb.h" #include "cuttlefish/host/commands/cvd/instances/cvd_persistent_data.pb.h" +#include "cuttlefish/host/commands/cvd/legacy/cvd_server.pb.h" #include "host/commands/cvd/cli/command_sequence.h" -#include "host/commands/cvd/utils/common.h" -#include "host/commands/cvd/cli/selector/creation_analyzer.h" -#include "host/commands/cvd/instances/instance_database_types.h" -#include "host/commands/cvd/instances/instance_group_record.h" -#include "host/commands/cvd/cli/selector/selector_constants.h" #include "host/commands/cvd/cli/commands/host_tool_target.h" #include "host/commands/cvd/cli/commands/server_handler.h" -#include "host/commands/cvd/cli/utils.h" +#include "host/commands/cvd/cli/selector/creation_analyzer.h" +#include "host/commands/cvd/cli/selector/selector_constants.h" #include "host/commands/cvd/cli/types.h" +#include "host/commands/cvd/cli/utils.h" +#include "host/commands/cvd/instances/instance_database_types.h" +#include "host/commands/cvd/instances/instance_group_record.h" +#include "host/commands/cvd/utils/common.h" namespace cuttlefish { namespace { @@ -156,9 +156,10 @@ Result CreateLoadCommand(const CommandRequest& request, .Build()); } -Result CreateStartCommand( - const CommandRequest& request, const selector::LocalInstanceGroup& group, - const cvd_common::Args& args, const cvd_common::Envs& envs) { +Result CreateStartCommand(const CommandRequest& request, + const LocalInstanceGroup& group, + const cvd_common::Args& args, + const cvd_common::Envs& envs) { return CF_EXPECT( CommandRequestBuilder() .SetEnv(envs) @@ -192,8 +193,7 @@ Result GetEnvs(const CommandRequest& request) { return envs; } -cvd::InstanceGroupInfo GroupInfoFromGroup( - const selector::LocalInstanceGroup& group) { +cvd::InstanceGroupInfo GroupInfoFromGroup(const LocalInstanceGroup& group) { cvd::InstanceGroupInfo info; info.set_group_name(group.GroupName()); for (const auto& instance : group.Instances()) { @@ -241,10 +241,10 @@ class CvdCreateCommandHandler : public CvdServerHandler { Result DetailedHelp(std::vector&) const override; private: - Result GetOrCreateGroup( + Result GetOrCreateGroup( const cvd_common::Args& subcmd_args, const cvd_common::Envs& envs, const CommandRequest& request, bool acquire_file_locks); - Result CreateSymlinks(const selector::LocalInstanceGroup& group); + Result CreateSymlinks(const LocalInstanceGroup& group); static void MarkLockfiles(std::vector& lock_files, const InUseState state); @@ -272,7 +272,7 @@ Result CvdCreateCommandHandler::CanHandle( return Contains(CmdList(), invocation.command); } -Result CvdCreateCommandHandler::GetOrCreateGroup( +Result CvdCreateCommandHandler::GetOrCreateGroup( const std::vector& subcmd_args, const cvd_common::Envs& envs, const CommandRequest& request, bool acquire_file_locks) { using CreationAnalyzerParam = @@ -291,8 +291,8 @@ Result CvdCreateCommandHandler::GetOrCreateGroup( lock_files.emplace_back(std::move(*instance.instance_file_lock_)); } - auto groups = CF_EXPECT(instance_manager_.FindGroups(selector::Query( - selector::kGroupNameField, group_creation_info.group_name))); + auto groups = CF_EXPECT(instance_manager_.FindGroups( + Query(selector::kGroupNameField, group_creation_info.group_name))); CF_EXPECTF(groups.size() <= 1, "Expected no more than one group with given name: {}", group_creation_info.group_name); @@ -322,7 +322,7 @@ Result CvdCreateCommandHandler::GetOrCreateGroup( // For backward compatibility, we add extra symlink in home dir Result CvdCreateCommandHandler::CreateSymlinks( - const selector::LocalInstanceGroup& group) { + const LocalInstanceGroup& group) { auto system_wide_home = CF_EXPECT(SystemWideUserHome()); CF_EXPECT(EnsureDirectoryExists(group.HomeDir())); auto smallest_id = std::numeric_limits::max(); @@ -385,7 +385,7 @@ Result CvdCreateCommandHandler::Handle( GetOrCreateGroup(subcmd_args, envs, request, flags.acquire_file_locks)); group.SetAllStates(cvd::INSTANCE_STATE_STOPPED); - group.SetStartTime(selector::CvdServerClock::now()); + group.SetStartTime(CvdServerClock::now()); instance_manager_.UpdateInstanceGroup(group); cvd::Response response; diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/display.cpp b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/display.cpp index a4afe05b06..128f7739dc 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/display.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/display.cpp @@ -125,7 +125,7 @@ class CvdDisplayCommandHandler : public CvdServerHandler { CvdFlag instance_num_flag("instance_num"); auto instance_num_opt = CF_EXPECT(instance_num_flag.FilterFlag(subcmd_args)); - selector::Queries extra_queries; + Queries extra_queries; if (instance_num_opt) { extra_queries.emplace_back(selector::kInstanceIdField, *instance_num_opt); } diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/load_configs.cpp b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/load_configs.cpp index ac6ef80f9a..3b6a2001b2 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/load_configs.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/load_configs.cpp @@ -24,14 +24,14 @@ #include "common/libs/utils/result.h" #include "host/commands/cvd/cli/command_request.h" #include "host/commands/cvd/cli/command_sequence.h" -#include "host/commands/cvd/utils/common.h" -#include "host/commands/cvd/fetch/fetch_cvd.h" -#include "host/commands/cvd/instances/instance_manager.h" -#include "host/commands/cvd/utils/interrupt_listener.h" #include "host/commands/cvd/cli/parser/load_configs_parser.h" #include "host/commands/cvd/cli/selector/selector_constants.h" -#include "host/commands/cvd/cli/utils.h" #include "host/commands/cvd/cli/types.h" +#include "host/commands/cvd/cli/utils.h" +#include "host/commands/cvd/fetch/fetch_cvd.h" +#include "host/commands/cvd/instances/instance_manager.h" +#include "host/commands/cvd/utils/common.h" +#include "host/commands/cvd/utils/interrupt_listener.h" namespace cuttlefish { namespace { @@ -98,7 +98,7 @@ class LoadConfigsCommand : public CvdServerHandler { { std::lock_guard lock(group_creation_mtx); auto group_res = instance_manager_.FindGroup( - selector::Query(selector::kHomeField, group_home_directory)); + Query(selector::kHomeField, group_home_directory)); if (!group_res.ok()) { LOG(ERROR) << "Failed to load group from database: " << group_res.error().Message(); @@ -143,8 +143,7 @@ class LoadConfigsCommand : public CvdServerHandler { } Result LoadGroup(const CommandRequest& request, - selector::LocalInstanceGroup& group, - CvdFlags cvd_flags) { + LocalInstanceGroup& group, CvdFlags cvd_flags) { auto mkdir_res = EnsureDirectoryExists(cvd_flags.load_directories.launch_home_directory, 0775, /* group_name */ ""); @@ -195,9 +194,9 @@ class LoadConfigsCommand : public CvdServerHandler { .Build()); } - Result BuildLaunchCmd( - const CommandRequest& request, const CvdFlags& cvd_flags, - const selector::LocalInstanceGroup& group) { + Result BuildLaunchCmd(const CommandRequest& request, + const CvdFlags& cvd_flags, + const LocalInstanceGroup& group) { // Add system flag for multi-build scenario std::string system_build_arg = fmt::format( "--system_image_dir={}", @@ -228,7 +227,7 @@ class LoadConfigsCommand : public CvdServerHandler { } private: - Result CreateGroup(const CvdFlags& cvd_flags) { + Result CreateGroup(const CvdFlags& cvd_flags) { selector::GroupCreationInfo group_info{ .home = cvd_flags.load_directories.launch_home_directory, .host_artifacts_path = diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/power.cpp b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/power.cpp index b8ca74031c..8359c80074 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/power.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/power.cpp @@ -29,14 +29,14 @@ #include "common/libs/utils/files.h" #include "common/libs/utils/subprocess.h" #include "common/libs/utils/users.h" -#include "host/commands/cvd/utils/common.h" -#include "host/commands/cvd/cli/flag.h" -#include "host/commands/cvd/instances/instance_database_types.h" -#include "host/commands/cvd/cli/selector/selector_constants.h" #include "host/commands/cvd/cli/commands/host_tool_target.h" #include "host/commands/cvd/cli/commands/server_handler.h" -#include "host/commands/cvd/cli/utils.h" +#include "host/commands/cvd/cli/flag.h" +#include "host/commands/cvd/cli/selector/selector_constants.h" #include "host/commands/cvd/cli/types.h" +#include "host/commands/cvd/cli/utils.h" +#include "host/commands/cvd/instances/instance_database_types.h" +#include "host/commands/cvd/utils/common.h" namespace cuttlefish { namespace { @@ -155,7 +155,7 @@ class CvdDevicePowerCommandHandler : public CvdServerHandler { CvdFlag instance_num_flag("instance_num"); auto instance_num_opt = CF_EXPECT(instance_num_flag.FilterFlag(subcmd_args)); - selector::Queries extra_queries; + Queries extra_queries; if (instance_num_opt) { extra_queries.emplace_back(selector::kInstanceIdField, *instance_num_opt); } diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/remove.cpp b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/remove.cpp index b5f0d45bfa..93b65f70c1 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/remove.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/remove.cpp @@ -95,13 +95,13 @@ class RemoveCvdCommandHandler : public CvdServerHandler { } private: - Result StopGroup(selector::LocalInstanceGroup& group, + Result StopGroup(LocalInstanceGroup& group, const CommandRequest& request) const { if (!group.HasActiveInstances()) { return {}; } auto config_path = - CF_EXPECT(selector::GetCuttlefishConfigPath(group.HomeDir())); + CF_EXPECT(GetCuttlefishConfigPath(group.HomeDir())); CF_EXPECT(instance_manager_.IssueStopCommand(request, config_path, group)); return {}; } diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/start.cpp b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/start.cpp index 5e86d74f8f..54906074de 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/start.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/start.cpp @@ -36,20 +36,20 @@ #include "common/libs/utils/flag_parser.h" #include "common/libs/utils/result.h" #include "common/libs/utils/users.h" -#include "cuttlefish/host/commands/cvd/legacy/cvd_server.pb.h" #include "cuttlefish/host/commands/cvd/instances/cvd_persistent_data.pb.h" -#include "host/commands/cvd/utils/common.h" +#include "cuttlefish/host/commands/cvd/legacy/cvd_server.pb.h" +#include "host/commands/cvd/cli/commands/host_tool_target.h" +#include "host/commands/cvd/cli/commands/server_handler.h" #include "host/commands/cvd/cli/group_selector.h" -#include "host/commands/cvd/utils/interrupt_listener.h" +#include "host/commands/cvd/cli/types.h" +#include "host/commands/cvd/cli/utils.h" +#include "host/commands/cvd/instances/instance_group_record.h" #include "host/commands/cvd/instances/operator_client.h" #include "host/commands/cvd/instances/reset_client_utils.h" -#include "host/commands/cvd/instances/instance_group_record.h" -#include "host/commands/cvd/cli/commands/host_tool_target.h" -#include "host/commands/cvd/cli/commands/server_handler.h" #include "host/commands/cvd/instances/status_fetcher.h" +#include "host/commands/cvd/utils/common.h" +#include "host/commands/cvd/utils/interrupt_listener.h" #include "host/commands/cvd/utils/subprocess_waiter.h" -#include "host/commands/cvd/cli/utils.h" -#include "host/commands/cvd/cli/types.h" #include "host/libs/config/config_constants.h" namespace cuttlefish { @@ -111,7 +111,7 @@ Result> ExtractWebRTCDeviceIds( } std::vector GenerateUniqueWebRTCDeviceIds( - const selector::LocalInstanceGroup& group) { + const LocalInstanceGroup& group) { std::vector ids; ids.reserve(group.Instances().size()); for (const auto& instance : group.Instances()) { @@ -123,7 +123,7 @@ std::vector GenerateUniqueWebRTCDeviceIds( } Result UpdateWebrtcDeviceIds(cvd_common::Args& args, - selector::LocalInstanceGroup& group) { + LocalInstanceGroup& group) { std::vector webrtc_ids = CF_EXPECT(ExtractWebRTCDeviceIds(args)); std::vector generated_webrtc_ids = GenerateUniqueWebRTCDeviceIds(group); @@ -153,8 +153,8 @@ Result UpdateWebrtcDeviceIds(cvd_common::Args& args, * 3. If not, --instance_nums= * */ -static Result UpdateInstanceArgs( - cvd_common::Args& args, const selector::LocalInstanceGroup& group) { +static Result UpdateInstanceArgs(cvd_common::Args& args, + const LocalInstanceGroup& group) { CF_EXPECT(!group.Instances().empty()); std::string old_instance_nums; @@ -213,7 +213,7 @@ Result SymlinkPreviousConfig(const std::string& group_home_dir) { } Result> PreregisterGroup( - const selector::LocalInstanceGroup& group) { + const LocalInstanceGroup& group) { std::unique_ptr operator_conn = CF_EXPECT(OperatorControlConn::Create()); CF_EXPECT(operator_conn->Preregister(group)); @@ -235,37 +235,36 @@ class CvdStartCommandHandler : public CvdServerHandler { Result DetailedHelp(std::vector&) const override; private: - Result LaunchDevice(Command command, - selector::LocalInstanceGroup& group, + Result LaunchDevice(Command command, LocalInstanceGroup& group, const cvd_common::Envs& envs, const CommandRequest& request); Result LaunchDeviceInterruptible( - Command command, selector::LocalInstanceGroup& group, - const cvd_common::Envs& envs, const CommandRequest& request); - - Result ConstructCvdNonHelpCommand( - const std::string& bin_file, const selector::LocalInstanceGroup& group, - const cvd_common::Args& args, const cvd_common::Envs& envs, + Command command, LocalInstanceGroup& group, const cvd_common::Envs& envs, const CommandRequest& request); + Result ConstructCvdNonHelpCommand(const std::string& bin_file, + const LocalInstanceGroup& group, + const cvd_common::Args& args, + const cvd_common::Envs& envs, + const CommandRequest& request); + struct GroupAndLockFiles { - selector::LocalInstanceGroup group; + LocalInstanceGroup group; std::vector lock_files; }; - Result FillOutNewInstanceInfo( - cvd::Response&& response, const selector::LocalInstanceGroup& group); + Result FillOutNewInstanceInfo(cvd::Response&& response, + const LocalInstanceGroup& group); - Result UpdateArgs(cvd_common::Args& args, - selector::LocalInstanceGroup& group); + Result UpdateArgs(cvd_common::Args& args, LocalInstanceGroup& group); Result UpdateEnvs(cvd_common::Envs& envs, - const selector::LocalInstanceGroup& group); + const LocalInstanceGroup& group); Result FindStartBin(const std::string& android_host_out); - Result AcloudCompatActions(const selector::LocalInstanceGroup& group, + Result AcloudCompatActions(const LocalInstanceGroup& group, const cvd_common::Envs& envs, const CommandRequest& request); InstanceManager& instance_manager_; @@ -274,7 +273,7 @@ class CvdStartCommandHandler : public CvdServerHandler { }; Result CvdStartCommandHandler::AcloudCompatActions( - const selector::LocalInstanceGroup& group, const cvd_common::Envs& envs, + const LocalInstanceGroup& group, const cvd_common::Envs& envs, const CommandRequest& request) { // rm -fr "TempDir()/acloud_cvd_temp/local-instance-" std::string acloud_compat_home_prefix = @@ -356,8 +355,8 @@ Result CvdStartCommandHandler::CanHandle( return Contains(supported_commands_, invocation.command); } -Result CvdStartCommandHandler::UpdateArgs( - cvd_common::Args& args, selector::LocalInstanceGroup& group) { +Result CvdStartCommandHandler::UpdateArgs(cvd_common::Args& args, + LocalInstanceGroup& group) { CF_EXPECT(UpdateInstanceArgs(args, group)); CF_EXPECT(UpdateWebrtcDeviceIds(args, group)); // for backward compatibility, older cvd host tools don't accept group_id @@ -374,7 +373,7 @@ Result CvdStartCommandHandler::UpdateArgs( } Result CvdStartCommandHandler::UpdateEnvs( - cvd_common::Envs& envs, const selector::LocalInstanceGroup& group) { + cvd_common::Envs& envs, const LocalInstanceGroup& group) { CF_EXPECT(!group.Instances().empty()); envs[kCuttlefishInstanceEnvVarName] = std::to_string(group.Instances()[0].id()); @@ -392,7 +391,7 @@ Result CvdStartCommandHandler::UpdateEnvs( } Result CvdStartCommandHandler::ConstructCvdNonHelpCommand( - const std::string& bin_file, const selector::LocalInstanceGroup& group, + const std::string& bin_file, const LocalInstanceGroup& group, const cvd_common::Args& args, const cvd_common::Envs& envs, const CommandRequest& request) { auto bin_path = group.HostArtifactsPath(); @@ -583,7 +582,7 @@ Result CvdStartCommandHandler::Handle( }); auto listener_handle = CF_EXPECT(std::move(handle_res)); group.SetAllStates(cvd::INSTANCE_STATE_STARTING); - group.SetStartTime(selector::CvdServerClock::now()); + group.SetStartTime(CvdServerClock::now()); CF_EXPECT(instance_manager_.UpdateInstanceGroup(group)); auto response = CF_EXPECT( LaunchDeviceInterruptible(std::move(command), group, envs, request)); @@ -610,8 +609,7 @@ static constexpr char kStopFailure[] = R"( cvd start failed, and stopping run_cvd processes failed. )"; -static Result CvdResetGroup( - const selector::LocalInstanceGroup& group) { +static Result CvdResetGroup(const LocalInstanceGroup& group) { auto run_cvd_process_manager = RunCvdProcessManager::Get(); if (!run_cvd_process_manager.ok()) { return CommandResponse(cvd::Status::INTERNAL, kCollectorFailure); @@ -630,7 +628,7 @@ static Result CvdResetGroup( } Result CvdStartCommandHandler::LaunchDevice( - Command launch_command, selector::LocalInstanceGroup& group, + Command launch_command, LocalInstanceGroup& group, const cvd_common::Envs& envs, const CommandRequest& request) { // Don't destroy the returned object until after the devices have started, it // holds a connection to the orchestrator that ensures the devices remain @@ -668,8 +666,8 @@ Result CvdStartCommandHandler::LaunchDevice( } Result CvdStartCommandHandler::LaunchDeviceInterruptible( - Command command, selector::LocalInstanceGroup& group, - const cvd_common::Envs& envs, const CommandRequest& request) { + Command command, LocalInstanceGroup& group, const cvd_common::Envs& envs, + const CommandRequest& request) { // cvd_internal_start uses the config from the previous invocation to // determine the default value for the -report_anonymous_usage_stats flag so // we symlink that to the group's home directory, this link will be @@ -695,7 +693,7 @@ Result CvdStartCommandHandler::LaunchDeviceInterruptible( } Result CvdStartCommandHandler::FillOutNewInstanceInfo( - cvd::Response&& response, const selector::LocalInstanceGroup& group) { + cvd::Response&& response, const LocalInstanceGroup& group) { auto new_response = std::move(response); auto& command_response = *(new_response.mutable_command_response()); auto& instance_group_info = diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/status.cpp b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/status.cpp index 335a564ad4..4031c51174 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/status.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/status.cpp @@ -165,20 +165,20 @@ Result CvdStatusCommandHandler::Handle( if (!request.Selectors().instance_names && flags.instance_name.empty()) { // No attempt at selecting an instance, get group status instead - selector::LocalInstanceGroup group = CF_EXPECT( + LocalInstanceGroup group = CF_EXPECT( instance_manager_.SelectGroup(request.Selectors(), request.Env())); status_array = CF_EXPECT(group.FetchStatus( std::chrono::seconds(flags.wait_for_launcher_seconds))); instance_manager_.UpdateInstanceGroup(group); } else { - std::pair pair = + std::pair pair = flags.instance_name.empty() ? CF_EXPECT(instance_manager_.SelectInstance(request.Selectors(), request.Env())) : CF_EXPECT(instance_manager_.FindInstanceById( CF_EXPECT(IdFromInstanceNameFlag(flags.instance_name)))); - selector::LocalInstance instance = pair.first; - selector::LocalInstanceGroup group = pair.second; + LocalInstance instance = pair.first; + LocalInstanceGroup group = pair.second; status_array.append(CF_EXPECT(instance.FetchStatus( std::chrono::seconds(flags.wait_for_launcher_seconds)))); instance_manager_.UpdateInstanceGroup(group); diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/group_selector.cpp b/base/cvd/cuttlefish/host/commands/cvd/cli/group_selector.cpp index 12fa40019d..179173efb8 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/group_selector.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/group_selector.cpp @@ -22,15 +22,15 @@ #include #include "host/commands/cvd/cli/interruptible_terminal.h" -#include "host/commands/cvd/instances/instance_group_record.h" #include "host/commands/cvd/cli/selector/selector_constants.h" #include "host/commands/cvd/cli/utils.h" +#include "host/commands/cvd/instances/instance_database_types.h" +#include "host/commands/cvd/instances/instance_group_record.h" namespace cuttlefish { namespace { -std::string SelectionMenu( - const std::vector& groups) { +std::string SelectionMenu(const std::vector& groups) { // Multiple instance groups found, please choose one: // [i] : group_name (created: TIME) // instance0.device_name() (id: instance_id) @@ -40,7 +40,7 @@ std::string SelectionMenu( int group_idx = 0; for (const auto& group : groups) { fmt::print(ss, " [{}] : {} (created: {})\n", group_idx, group.GroupName(), - selector::Format(group.StartTime())); + Format(group.StartTime())); char instance_idx = 'a'; for (const auto& instance : group.Instances()) { fmt::print(ss, " <{}> {}-{} (id : {})\n", instance_idx++, @@ -51,13 +51,13 @@ std::string SelectionMenu( return ss.str(); } -Result PromptUserForGroup( +Result PromptUserForGroup( InstanceManager& instance_manager, const CommandRequest& request, const cvd_common::Envs& envs, const selector::SelectorOptions& selector_options) { // show the menu and let the user choose - std::vector groups = - CF_EXPECT(instance_manager.FindGroups(selector::Queries{})); + std::vector groups = + CF_EXPECT(instance_manager.FindGroups(Queries{})); auto menu = SelectionMenu(groups); std::cout << menu << "\n"; @@ -83,8 +83,7 @@ Result PromptUserForGroup( chosen_group_name = android::base::Trim(input_line); } - InstanceManager::Queries extra_queries{ - {selector::kGroupNameField, chosen_group_name}}; + Queries extra_queries{{selector::kGroupNameField, chosen_group_name}}; auto instance_group_result = instance_manager.SelectGroup(selector_options, envs, extra_queries); if (instance_group_result.ok()) { @@ -98,8 +97,8 @@ Result PromptUserForGroup( } // namespace -Result SelectGroup( - InstanceManager& instance_manager, const CommandRequest& request) { +Result SelectGroup(InstanceManager& instance_manager, + const CommandRequest& request) { auto has_groups = CF_EXPECT(instance_manager.HasInstanceGroups()); CF_EXPECT(std::move(has_groups), "No instance groups available"); const cvd_common::Envs& env = request.Env(); diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/group_selector.h b/base/cvd/cuttlefish/host/commands/cvd/cli/group_selector.h index 5c58a5c47c..2d18052c22 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/group_selector.h +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/group_selector.h @@ -17,12 +17,11 @@ #pragma once #include "common/libs/utils/result.h" +#include "host/commands/cvd/cli/command_request.h" #include "host/commands/cvd/instances/instance_group_record.h" #include "host/commands/cvd/instances/instance_manager.h" -#include "host/commands/cvd/cli/command_request.h" namespace cuttlefish { -Result SelectGroup(InstanceManager&, - const CommandRequest&); +Result SelectGroup(InstanceManager&, const CommandRequest&); } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/selector/device_selector_utils.cpp b/base/cvd/cuttlefish/host/commands/cvd/cli/selector/device_selector_utils.cpp index 218a463595..265b240bcc 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/selector/device_selector_utils.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/selector/device_selector_utils.cpp @@ -50,7 +50,7 @@ std::optional OverridenHomeDirectory(const cvd_common::Envs& env) { Result BuildQueriesFromSelectors(const SelectorOptions& selectors, const cvd_common::Envs& env) { - selector::Queries queries; + Queries queries; auto overriden_home = OverridenHomeDirectory(env); if (overriden_home.has_value()) { queries.emplace_back(kHomeField, overriden_home.value()); diff --git a/base/cvd/cuttlefish/host/commands/cvd/instances/data_viewer.cpp b/base/cvd/cuttlefish/host/commands/cvd/instances/data_viewer.cpp index b20aaaac51..8675396c83 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/instances/data_viewer.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/instances/data_viewer.cpp @@ -16,8 +16,10 @@ #include "host/commands/cvd/instances/data_viewer.h" +#include "common/libs/fs/shared_buf.h" + namespace cuttlefish { -namespace selector { + Result DataViewer::LockBackingFile(int op) const { auto fd = SharedFD::Open(backing_file_, O_CREAT | O_RDWR, 0640); CF_EXPECTF(fd->IsOpen(), "Failed to open instance database backing file: {}", @@ -60,5 +62,4 @@ DataViewer::DeadlockProtector::~DeadlockProtector() { map_[std::this_thread::get_id()] = false; } -} // namespace selector } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/instances/data_viewer.h b/base/cvd/cuttlefish/host/commands/cvd/instances/data_viewer.h index 82a225a89b..2183d68081 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/instances/data_viewer.h +++ b/base/cvd/cuttlefish/host/commands/cvd/instances/data_viewer.h @@ -22,16 +22,13 @@ #include #include #include -#include -#include "common/libs/fs/shared_buf.h" #include "common/libs/fs/shared_fd.h" #include "common/libs/utils/result.h" #include "common/libs/utils/signals.h" #include "cuttlefish/host/commands/cvd/instances/cvd_persistent_data.pb.h" namespace cuttlefish { -namespace selector { /** * Synchronizes loading and storing the instance database from and to a file. @@ -124,6 +121,5 @@ class DataViewer { std::string backing_file_; }; -} // namespace selector } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/instances/group_selector.cpp b/base/cvd/cuttlefish/host/commands/cvd/instances/group_selector.cpp index 94ce99778f..e2d78d2f61 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/instances/group_selector.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/instances/group_selector.cpp @@ -22,12 +22,12 @@ #include "host/commands/cvd/cli/selector/selector_common_parser.h" namespace cuttlefish { -namespace selector { Result GroupSelector::GetSelector( - const SelectorOptions& selector_options, const Queries& extra_queries, - const cvd_common::Envs& envs) { - Queries queries = CF_EXPECT(BuildQueriesFromSelectors(selector_options, envs)); + const selector::SelectorOptions& selector_options, + const Queries& extra_queries, const cvd_common::Envs& envs) { + Queries queries = + CF_EXPECT(BuildQueriesFromSelectors(selector_options, envs)); for (const auto& extra_query : extra_queries) { queries.push_back(extra_query); @@ -50,9 +50,8 @@ Result GroupSelector::FindGroup( Result GroupSelector::FindDefaultGroup( const InstanceDatabase& instance_database) { - auto group = CF_EXPECT(GetDefaultGroup(instance_database)); + auto group = CF_EXPECT(selector::GetDefaultGroup(instance_database)); return group; } -} // namespace selector } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/instances/group_selector.h b/base/cvd/cuttlefish/host/commands/cvd/instances/group_selector.h index 345a94cac3..acf6031ea9 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/instances/group_selector.h +++ b/base/cvd/cuttlefish/host/commands/cvd/instances/group_selector.h @@ -19,19 +19,18 @@ #include #include "common/libs/utils/result.h" -#include "host/commands/cvd/instances/instance_database.h" -#include "host/commands/cvd/instances/instance_database_types.h" #include "host/commands/cvd/cli/selector/selector_common_parser.h" #include "host/commands/cvd/cli/types.h" +#include "host/commands/cvd/instances/instance_database.h" +#include "host/commands/cvd/instances/instance_database_types.h" namespace cuttlefish { -namespace selector { class GroupSelector { public: static Result GetSelector( - const SelectorOptions& selector_options, const Queries& extra_queries, - const cvd_common::Envs& envs); + const selector::SelectorOptions& selector_options, + const Queries& extra_queries, const cvd_common::Envs& envs); /* * If default, try running single instance group. If multiple, try to find * HOME == SystemWideUserHome. If not exists, give up. @@ -52,5 +51,4 @@ class GroupSelector { const Queries queries_; }; -} // namespace selector } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_database.cpp b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_database.cpp index 24c825526c..f1a28edeef 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_database.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_database.cpp @@ -34,7 +34,6 @@ #include "host/libs/config/config_constants.h" namespace cuttlefish { -namespace selector { namespace { @@ -179,16 +178,16 @@ Result InstanceDatabase::FindParam::FromQueries( const Queries& queries) { FindParam param; for (const auto& query : queries) { - if (query.field_name_ == kHomeField) { + if (query.field_name_ == selector::kHomeField) { param.home = query.field_value_; - } else if (query.field_name_ == kInstanceIdField) { + } else if (query.field_name_ == selector::kInstanceIdField) { int id; CF_EXPECTF(android::base::ParseInt(query.field_value_, &id), "Id is not a number: {}", id); param.id = id; - } else if (query.field_name_ == kGroupNameField) { + } else if (query.field_name_ == selector::kGroupNameField) { param.group_name = query.field_value_; - } else if (query.field_name_ == kInstanceNameField) { + } else if (query.field_name_ == selector::kInstanceNameField) { param.instance_name = query.field_value_; } else { return CF_ERRF("Unrecognized field name: {}", query.field_name_); @@ -298,5 +297,4 @@ Result InstanceDatabase::GetAcloudTranslatorOptout() const { }); } -} // namespace selector } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_database.h b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_database.h index 688ccc5154..0616269ae8 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_database.h +++ b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_database.h @@ -28,7 +28,6 @@ #include "host/commands/cvd/instances/instance_group_record.h" namespace cuttlefish { -namespace selector { class InstanceDatabase { public: @@ -108,5 +107,4 @@ class InstanceDatabase { DataViewer viewer_; }; -} // namespace selector } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_database_types.cpp b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_database_types.cpp index 3ed4b5e66c..a02b0a1929 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_database_types.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_database_types.cpp @@ -24,7 +24,6 @@ #include namespace cuttlefish { -namespace selector { Query::Query(const std::string& field_name, const std::string& field_value) : field_name_(field_name), field_value_(field_value) {} @@ -54,5 +53,4 @@ std::string Format(const TimeStamp& time_point) { return ss.str(); } -} // namespace selector } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_database_types.h b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_database_types.h index a11ac28c49..887a1bb8a7 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_database_types.h +++ b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_database_types.h @@ -28,8 +28,7 @@ #include "common/libs/utils/result.h" namespace cuttlefish { -namespace selector { -namespace selector_impl { +namespace database_impl { template using ToStringTypeReturnType = @@ -41,7 +40,7 @@ struct IsToStringOk : std::false_type {}; template struct IsToStringOk> : std::true_type {}; -} // namespace selector_impl +} // namespace database_impl using FieldName = std::string; using Value = std::string; @@ -50,7 +49,7 @@ using Value = std::string; struct Query { template ::value, void>> + database_impl::IsToStringOk::value, void>> Query(const std::string& field_name, ValueType&& field_value) : field_name_(field_name), field_value_(std::to_string(std::forward(field_value))) {} @@ -75,5 +74,4 @@ std::string SerializeTimePoint(const TimeStamp&); Result DeserializeTimePoint(const Json::Value& group_json); std::string Format(const TimeStamp&); -} // namespace selector } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_database_utils.cpp b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_database_utils.cpp index 16cc2b5bc4..18aae136a3 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_database_utils.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_database_utils.cpp @@ -25,7 +25,6 @@ #include "common/libs/utils/files.h" namespace cuttlefish { -namespace selector { Result GetCuttlefishConfigPath(const std::string& home) { std::string home_realpath; @@ -95,5 +94,4 @@ std::string GenerateTooManyInstancesErrorMsg(const int n, return s.str(); } -} // namespace selector } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_database_utils.h b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_database_utils.h index d4d279aa37..0e0f667304 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_database_utils.h +++ b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_database_utils.h @@ -22,7 +22,6 @@ #include "common/libs/utils/result.h" namespace cuttlefish { -namespace selector { Result GetCuttlefishConfigPath(const std::string& home); @@ -80,5 +79,4 @@ RetSet Intersection(const RetSet& u, AnyContainer&& v, Containers&&... s) { return Intersection(first, std::forward(s)...); } -} // namespace selector } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_group_record.cpp b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_group_record.cpp index 680d111ecf..53dd828189 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_group_record.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_group_record.cpp @@ -26,7 +26,6 @@ #include "host/commands/cvd/instances/instance_database_types.h" namespace cuttlefish { -namespace selector { namespace { @@ -209,10 +208,9 @@ Result LocalInstanceGroup::FetchStatus( } Json::Value group_json; group_json["group_name"] = GroupName(); - group_json["start_time"] = selector::Format(StartTime()); + group_json["start_time"] = Format(StartTime()); group_json["instances"] = instances_json; return group_json; } -} // namespace selector } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_group_record.h b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_group_record.h index 18b61a48e4..9df28dc7aa 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_group_record.h +++ b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_group_record.h @@ -27,7 +27,6 @@ #include "host/commands/cvd/instances/instance_record.h" namespace cuttlefish { -namespace selector { class LocalInstanceGroup { public: @@ -86,5 +85,4 @@ class LocalInstanceGroup { std::vector instances_; }; -} // namespace selector } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_manager.cpp b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_manager.cpp index 48bf810c61..5ce911f020 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_manager.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_manager.cpp @@ -29,11 +29,14 @@ #include "common/libs/utils/result.h" #include "common/libs/utils/subprocess.h" #include "cuttlefish/host/commands/cvd/legacy/cvd_server.pb.h" -#include "host/commands/cvd/utils/common.h" +#include "host/commands/cvd/cli/commands/host_tool_target.h" +#include "host/commands/cvd/cli/selector/selector_constants.h" +#include "host/commands/cvd/instances/group_selector.h" #include "host/commands/cvd/instances/instance_database_types.h" #include "host/commands/cvd/instances/instance_database_utils.h" -#include "host/commands/cvd/cli/selector/selector_constants.h" -#include "host/commands/cvd/cli/commands/host_tool_target.h" +#include "host/commands/cvd/instances/instance_record.h" +#include "host/commands/cvd/instances/instance_selector.h" +#include "host/commands/cvd/utils/common.h" #include "host/libs/config/config_constants.h" #include "host/libs/config/config_utils.h" @@ -51,7 +54,7 @@ Result RunCommand(Command&& command) { return {}; } -Result RemoveGroupDirectory(const selector::LocalInstanceGroup& group) { +Result RemoveGroupDirectory(const LocalInstanceGroup& group) { std::string per_user_dir = PerUserDir(); if (!android::base::StartsWith(group.HomeDir(), per_user_dir)) { LOG(WARNING) @@ -69,11 +72,11 @@ Result RemoveGroupDirectory(const selector::LocalInstanceGroup& group) { Result InstanceManager::GetCuttlefishConfigPath( const std::string& home) { - return CF_EXPECT(selector::GetCuttlefishConfigPath(home)); + return CF_EXPECT(cuttlefish::GetCuttlefishConfigPath(home)); } InstanceManager::InstanceManager(InstanceLockFileManager& lock_manager, - selector::InstanceDatabase& instance_db) + InstanceDatabase& instance_db) : lock_manager_(lock_manager), instance_db_(instance_db) {} Result InstanceManager::SetAcloudTranslatorOptout(bool optout) { @@ -90,7 +93,7 @@ Result InstanceManager::CreationAnalyzer( return selector::CreationAnalyzer::Create(param, lock_manager_); } -Result InstanceManager::SelectGroup( +Result InstanceManager::SelectGroup( const selector::SelectorOptions& selectors, const cvd_common::Envs& envs, const Queries& extra_queries) { auto group_selector = @@ -98,7 +101,7 @@ Result InstanceManager::SelectGroup( return CF_EXPECT(group_selector.FindGroup(instance_db_)); } -Result> +Result> InstanceManager::SelectInstance( const selector::SelectorOptions& selector_options, const cvd_common::Envs& envs, const Queries& extra_queries) { @@ -107,8 +110,7 @@ InstanceManager::SelectInstance( return CF_EXPECT(instance_selector.FindInstanceWithGroup(instance_db_)); } -Result> +Result> InstanceManager::FindInstanceById(unsigned id) const { return CF_EXPECT(instance_db_.FindInstanceWithGroup( Query(selector::kInstanceIdField, id))); @@ -118,8 +120,7 @@ Result InstanceManager::HasInstanceGroups() { return !CF_EXPECT(instance_db_.IsEmpty()); } -Result -InstanceManager::CreateInstanceGroup( +Result InstanceManager::CreateInstanceGroup( const selector::GroupCreationInfo& group_info) { cvd::InstanceGroup new_group; new_group.set_name(group_info.group_name); @@ -169,7 +170,7 @@ Result InstanceManager::UpdateInstanceGroup( Result InstanceManager::IssueStopCommand( const CommandRequest& request, const std::string& config_file_path, - selector::LocalInstanceGroup& group) { + LocalInstanceGroup& group) { const auto stop_bin = CF_EXPECT(StopBin(group.HostArtifactsPath())); Command command(group.HostArtifactsPath() + "/bin/" + stop_bin); command.AddParameter("--clear_instance_dirs"); @@ -222,7 +223,7 @@ cvd::Status InstanceManager::CvdClear(const CommandRequest& request) { for (auto& group : instance_groups) { // Only stop running instances. if (group.HasActiveInstances()) { - auto config_path = selector::GetCuttlefishConfigPath(group.HomeDir()); + auto config_path = GetCuttlefishConfigPath(group.HomeDir()); if (config_path.ok()) { auto stop_result = IssueStopCommand(request, *config_path, group); if (!stop_result.ok()) { @@ -256,22 +257,22 @@ Result> InstanceManager::TryAcquireLock( return CF_EXPECT(lock_manager_.TryAcquireLock(instance_num)); } -Result> -InstanceManager::FindGroups(const Query& query) const { +Result> InstanceManager::FindGroups( + const Query& query) const { return CF_EXPECT(FindGroups(Queries{query})); } -Result> -InstanceManager::FindGroups(const Queries& queries) const { +Result> InstanceManager::FindGroups( + const Queries& queries) const { return instance_db_.FindGroups(queries); } -Result InstanceManager::FindGroup( +Result InstanceManager::FindGroup( const Query& query) const { return CF_EXPECT(FindGroup(Queries{query})); } -Result InstanceManager::FindGroup( +Result InstanceManager::FindGroup( const Queries& queries) const { auto output = CF_EXPECT(instance_db_.FindGroups(queries)); CF_EXPECT_EQ(output.size(), 1ul); diff --git a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_manager.h b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_manager.h index a9c2e0d6f7..97a3d2cf6b 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_manager.h +++ b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_manager.h @@ -26,32 +26,21 @@ #include "common/libs/utils/result.h" #include "cuttlefish/host/commands/cvd/legacy/cvd_server.pb.h" #include "host/commands/cvd/cli/command_request.h" -#include "host/commands/cvd/instances/instance_lock.h" #include "host/commands/cvd/cli/selector/creation_analyzer.h" -#include "host/commands/cvd/instances/group_selector.h" +#include "host/commands/cvd/cli/selector/selector_common_parser.h" #include "host/commands/cvd/instances/instance_database.h" #include "host/commands/cvd/instances/instance_database_types.h" #include "host/commands/cvd/instances/instance_group_record.h" +#include "host/commands/cvd/instances/instance_lock.h" #include "host/commands/cvd/instances/instance_record.h" -#include "host/commands/cvd/instances/instance_selector.h" -#include "host/commands/cvd/cli/selector/selector_common_parser.h" namespace cuttlefish { class InstanceManager { public: using GroupCreationInfo = selector::GroupCreationInfo; - using LocalInstance = selector::LocalInstance; - using LocalInstanceGroup = selector::LocalInstanceGroup; - using GroupSelector = selector::GroupSelector; - using InstanceSelector = selector::InstanceSelector; - using Queries = selector::Queries; - using Query = selector::Query; - template - using Set = selector::Set; - - InstanceManager(InstanceLockFileManager&, - selector::InstanceDatabase& instance_db); + + InstanceManager(InstanceLockFileManager&, InstanceDatabase& instance_db); // For cvd start Result CreationAnalyzer( @@ -96,7 +85,7 @@ class InstanceManager { Result StopBin(const std::string& host_android_out); InstanceLockFileManager& lock_manager_; - selector::InstanceDatabase& instance_db_; + InstanceDatabase& instance_db_; }; } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_record.cpp b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_record.cpp index 1c19ea62b2..2d4f3f5fb9 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_record.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_record.cpp @@ -23,7 +23,6 @@ #include "host/commands/cvd/instances/status_fetcher.h" namespace cuttlefish { -namespace selector { namespace { constexpr int BASE_ADB_PORT = 6520; @@ -84,5 +83,4 @@ Result LocalInstance::FetchStatus(std::chrono::seconds timeout) { return CF_EXPECT(FetchInstanceStatus(*this, timeout)); } -} // namespace selector } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_record.h b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_record.h index d4de72cd71..a043d093b9 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_record.h +++ b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_record.h @@ -25,7 +25,6 @@ #include "cuttlefish/host/commands/cvd/instances/cvd_persistent_data.pb.h" namespace cuttlefish { -namespace selector { class LocalInstance { public: @@ -72,5 +71,4 @@ class LocalInstance { friend class LocalInstanceGroup; }; -} // namespace selector } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_selector.cpp b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_selector.cpp index 998903ca1a..0327aa0976 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_selector.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_selector.cpp @@ -21,16 +21,16 @@ #include #include "host/commands/cvd/cli/selector/device_selector_utils.h" -#include "host/commands/cvd/instances/instance_database_types.h" #include "host/commands/cvd/cli/selector/selector_common_parser.h" +#include "host/commands/cvd/instances/instance_database_types.h" namespace cuttlefish { -namespace selector { Result InstanceSelector::GetSelector( - const SelectorOptions& selector_options, const Queries& extra_queries, - const cvd_common::Envs& envs) { - Queries queries = CF_EXPECT(BuildQueriesFromSelectors(selector_options, envs)); + const selector::SelectorOptions& selector_options, + const Queries& extra_queries, const cvd_common::Envs& envs) { + Queries queries = + CF_EXPECT(BuildQueriesFromSelectors(selector_options, envs)); for (const auto& extra_query : extra_queries) { queries.push_back(extra_query); @@ -53,12 +53,11 @@ InstanceSelector::FindInstanceWithGroup( Result> InstanceSelector::FindDefaultInstance( const InstanceDatabase& instance_database) { - auto group = CF_EXPECT(GetDefaultGroup(instance_database)); + auto group = CF_EXPECT(selector::GetDefaultGroup(instance_database)); const auto instances = group.Instances(); CF_EXPECT_EQ(instances.size(), 1u, "Default instance is the single instance in the default group."); return std::make_pair(*instances.cbegin(), group); } -} // namespace selector } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_selector.h b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_selector.h index 809576d91c..09080a9fe7 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/instances/instance_selector.h +++ b/base/cvd/cuttlefish/host/commands/cvd/instances/instance_selector.h @@ -21,18 +21,17 @@ #include #include "common/libs/utils/result.h" -#include "host/commands/cvd/instances/instance_database.h" #include "host/commands/cvd/cli/selector/selector_common_parser.h" #include "host/commands/cvd/cli/types.h" +#include "host/commands/cvd/instances/instance_database.h" namespace cuttlefish { -namespace selector { class InstanceSelector { public: static Result GetSelector( - const SelectorOptions& selector_options, const Queries& extra_queries, - const cvd_common::Envs& envs); + const selector::SelectorOptions& selector_options, + const Queries& extra_queries, const cvd_common::Envs& envs); /* * If default, try running single instance group. If multiple, try to find * HOME == SystemWideUserHome. If not exists, give up. @@ -53,5 +52,4 @@ class InstanceSelector { const Queries queries_; }; -} // namespace selector } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/instances/operator_client.cpp b/base/cvd/cuttlefish/host/commands/cvd/instances/operator_client.cpp index 374d56657e..c70833d30b 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/instances/operator_client.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/instances/operator_client.cpp @@ -23,8 +23,8 @@ #include #include -#include #include +#include #include "common/libs/fs/shared_buf.h" #include "common/libs/fs/shared_fd.h" @@ -36,8 +36,7 @@ namespace cuttlefish { namespace { -Result BuildPregistrationMsg( - const selector::LocalInstanceGroup& group) { +Result BuildPregistrationMsg(const LocalInstanceGroup& group) { Json::Value msg; msg["message_type"] = "pre-register"; msg["group_name"] = group.GroupName(); @@ -82,8 +81,7 @@ Result> OperatorControlConn::Create( /** * Pre-registers an instance group with the operator */ -Result OperatorControlConn::Preregister( - const selector::LocalInstanceGroup& group) { +Result OperatorControlConn::Preregister(const LocalInstanceGroup& group) { CF_EXPECT(SendMsg(conn_, CF_EXPECT(BuildPregistrationMsg(group))), "Failed to send pre-registration message to operator"); Json::Value response = diff --git a/base/cvd/cuttlefish/host/commands/cvd/instances/operator_client.h b/base/cvd/cuttlefish/host/commands/cvd/instances/operator_client.h index 6e33f878f7..bdb9babe65 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/instances/operator_client.h +++ b/base/cvd/cuttlefish/host/commands/cvd/instances/operator_client.h @@ -39,7 +39,7 @@ class OperatorControlConn { /** * Pre-registers an instance group with the operator */ - Result Preregister(const selector::LocalInstanceGroup& group); + Result Preregister(const LocalInstanceGroup& group); private: OperatorControlConn(SharedFD conn) : conn_(conn) {} diff --git a/base/cvd/cuttlefish/host/commands/cvd/instances/status_fetcher.cpp b/base/cvd/cuttlefish/host/commands/cvd/instances/status_fetcher.cpp index e7d9c4bc74..b9371c06f6 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/instances/status_fetcher.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/instances/status_fetcher.cpp @@ -74,7 +74,7 @@ std::string HumanFriendlyStateName(cvd::InstanceState state) { // Adds more information to the json object returned by cvd_internal_status, // including some that cvd_internal_status normally returns but doesn't when the // instance is not running. -void OverrideInstanceJson(const selector::LocalInstance& instance, +void OverrideInstanceJson(const LocalInstance& instance, Json::Value& instance_json) { instance_json["instance_name"] = instance.name(); instance_json["status"] = HumanFriendlyStateName(instance.state()); @@ -98,7 +98,7 @@ Result GetBin(const std::string& host_artifacts_path) { } // namespace -Result FetchInstanceStatus(selector::LocalInstance& instance, +Result FetchInstanceStatus(LocalInstance& instance, std::chrono::seconds timeout) { // Only running instances are capable of responding to status requests. An // unreachable instance is also considered running, it just didnt't reply last diff --git a/base/cvd/cuttlefish/host/commands/cvd/instances/status_fetcher.h b/base/cvd/cuttlefish/host/commands/cvd/instances/status_fetcher.h index 85af869399..1e6497229b 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/instances/status_fetcher.h +++ b/base/cvd/cuttlefish/host/commands/cvd/instances/status_fetcher.h @@ -27,7 +27,7 @@ namespace cuttlefish { // Fetches status from a single instance. Waits for each run_cvd process to // respond within the given timeout. -Result FetchInstanceStatus(selector::LocalInstance& instance, +Result FetchInstanceStatus(LocalInstance& instance, std::chrono::seconds timeout); } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/legacy/run_server.cpp b/base/cvd/cuttlefish/host/commands/cvd/legacy/run_server.cpp index 8d24ca1626..b3f2ed15ef 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/legacy/run_server.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/legacy/run_server.cpp @@ -20,13 +20,14 @@ #include #include +#include "common/libs/fs/shared_buf.h" #include "common/libs/utils/flag_parser.h" #include "common/libs/utils/json.h" #include "common/libs/utils/shared_fd_flag.h" #include "common/libs/utils/unix_sockets.h" -#include "host/commands/cvd/utils/common.h" -#include "host/commands/cvd/metrics/metrics_notice.h" #include "host/commands/cvd/instances/instance_database.h" +#include "host/commands/cvd/metrics/metrics_notice.h" +#include "host/commands/cvd/utils/common.h" namespace cuttlefish { @@ -112,7 +113,7 @@ Result ImportResourcesImpl(const ParseResult& param) { SetMinimumVerbosity(android::base::VERBOSE); LOG(INFO) << "Starting server"; signal(SIGPIPE, SIG_IGN); - selector::InstanceDatabase instance_database(InstanceDatabasePath()); + InstanceDatabase instance_database(InstanceDatabasePath()); cvd::Response response; if (param.memory_carryover_fd) { SharedFD memory_carryover_fd = std::move(*param.memory_carryover_fd); diff --git a/base/cvd/cuttlefish/host/commands/cvd/main.cc b/base/cvd/cuttlefish/host/commands/cvd/main.cc index 10bcc5b7f0..6ac4927d87 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/main.cc +++ b/base/cvd/cuttlefish/host/commands/cvd/main.cc @@ -31,9 +31,9 @@ #include "common/libs/utils/files.h" #include "common/libs/utils/flag_parser.h" #include "common/libs/utils/subprocess.h" -#include "host/commands/cvd/utils/common.h" #include "host/commands/cvd/cvd.h" #include "host/commands/cvd/legacy/client.h" +#include "host/commands/cvd/utils/common.h" // TODO(315772518) Re-enable once metrics send is reenabled // #include "host/commands/cvd/metrics/cvd_metrics_api.h" #include "host/commands/cvd/legacy/run_server.h" @@ -192,7 +192,7 @@ Result CvdMain(int argc, char** argv, char** envp, IncreaseFileLimit(); InstanceLockFileManager instance_lockfile_manager; - selector::InstanceDatabase instance_db(InstanceDatabasePath()); + InstanceDatabase instance_db(InstanceDatabasePath()); InstanceManager instance_manager(instance_lockfile_manager, instance_db); Cvd cvd(verbosity, instance_lockfile_manager, instance_manager);