Skip to content

Commit

Permalink
Use selector namespace for selectors only
Browse files Browse the repository at this point in the history
  • Loading branch information
jemoreira committed Oct 28, 2024
1 parent 776ac99 commit 620f9ef
Show file tree
Hide file tree
Showing 35 changed files with 163 additions and 208 deletions.
2 changes: 1 addition & 1 deletion base/cvd/cuttlefish/host/commands/cvd/acloud/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ Result<ConvertedAcloudCreateCommand> 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 = "--";
Expand Down
38 changes: 19 additions & 19 deletions base/cvd/cuttlefish/host/commands/cvd/cli/commands/create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -156,9 +156,10 @@ Result<CommandRequest> CreateLoadCommand(const CommandRequest& request,
.Build());
}

Result<CommandRequest> CreateStartCommand(
const CommandRequest& request, const selector::LocalInstanceGroup& group,
const cvd_common::Args& args, const cvd_common::Envs& envs) {
Result<CommandRequest> CreateStartCommand(const CommandRequest& request,
const LocalInstanceGroup& group,
const cvd_common::Args& args,
const cvd_common::Envs& envs) {
return CF_EXPECT(
CommandRequestBuilder()
.SetEnv(envs)
Expand Down Expand Up @@ -192,8 +193,7 @@ Result<cvd_common::Envs> 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()) {
Expand Down Expand Up @@ -241,10 +241,10 @@ class CvdCreateCommandHandler : public CvdServerHandler {
Result<std::string> DetailedHelp(std::vector<std::string>&) const override;

private:
Result<selector::LocalInstanceGroup> GetOrCreateGroup(
Result<LocalInstanceGroup> GetOrCreateGroup(
const cvd_common::Args& subcmd_args, const cvd_common::Envs& envs,
const CommandRequest& request, bool acquire_file_locks);
Result<void> CreateSymlinks(const selector::LocalInstanceGroup& group);
Result<void> CreateSymlinks(const LocalInstanceGroup& group);

static void MarkLockfiles(std::vector<InstanceLockFile>& lock_files,
const InUseState state);
Expand Down Expand Up @@ -272,7 +272,7 @@ Result<bool> CvdCreateCommandHandler::CanHandle(
return Contains(CmdList(), invocation.command);
}

Result<selector::LocalInstanceGroup> CvdCreateCommandHandler::GetOrCreateGroup(
Result<LocalInstanceGroup> CvdCreateCommandHandler::GetOrCreateGroup(
const std::vector<std::string>& subcmd_args, const cvd_common::Envs& envs,
const CommandRequest& request, bool acquire_file_locks) {
using CreationAnalyzerParam =
Expand All @@ -291,8 +291,8 @@ Result<selector::LocalInstanceGroup> 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);
Expand Down Expand Up @@ -322,7 +322,7 @@ Result<selector::LocalInstanceGroup> CvdCreateCommandHandler::GetOrCreateGroup(

// For backward compatibility, we add extra symlink in home dir
Result<void> 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<unsigned>::max();
Expand Down Expand Up @@ -385,7 +385,7 @@ Result<cvd::Response> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class CvdDisplayCommandHandler : public CvdServerHandler {
CvdFlag<std::int32_t> 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);
}
Expand Down
23 changes: 11 additions & 12 deletions base/cvd/cuttlefish/host/commands/cvd/cli/commands/load_configs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -143,8 +143,7 @@ class LoadConfigsCommand : public CvdServerHandler {
}

Result<void> 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 */ "");
Expand Down Expand Up @@ -195,9 +194,9 @@ class LoadConfigsCommand : public CvdServerHandler {
.Build());
}

Result<CommandRequest> BuildLaunchCmd(
const CommandRequest& request, const CvdFlags& cvd_flags,
const selector::LocalInstanceGroup& group) {
Result<CommandRequest> 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={}",
Expand Down Expand Up @@ -228,7 +227,7 @@ class LoadConfigsCommand : public CvdServerHandler {
}

private:
Result<selector::LocalInstanceGroup> CreateGroup(const CvdFlags& cvd_flags) {
Result<LocalInstanceGroup> CreateGroup(const CvdFlags& cvd_flags) {
selector::GroupCreationInfo group_info{
.home = cvd_flags.load_directories.launch_home_directory,
.host_artifacts_path =
Expand Down
12 changes: 6 additions & 6 deletions base/cvd/cuttlefish/host/commands/cvd/cli/commands/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -155,7 +155,7 @@ class CvdDevicePowerCommandHandler : public CvdServerHandler {
CvdFlag<std::int32_t> 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);
}
Expand Down
4 changes: 2 additions & 2 deletions base/cvd/cuttlefish/host/commands/cvd/cli/commands/remove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ class RemoveCvdCommandHandler : public CvdServerHandler {
}

private:
Result<void> StopGroup(selector::LocalInstanceGroup& group,
Result<void> 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 {};
}
Expand Down
Loading

0 comments on commit 620f9ef

Please sign in to comment.