Skip to content

Commit 8f0d2ab

Browse files
committed
cvd: Decouple CvdCreateCommandHandler from CommandSequenceExecutor
Bypass CommandSequenceExecutor in CvdCreateCommandHandler and instead directly instantiate and invoke NewLoadConfigsCommand and NewCvdStartCommandHandler. - Removed CommandSequenceExecutor dependency from CvdCreateCommandHandler and NewCvdCreateCommandHandler. Assisted-by: Jetski Bug: b/324653441
1 parent cf379d8 commit 8f0d2ab

3 files changed

Lines changed: 17 additions & 16 deletions

File tree

base/cvd/cuttlefish/host/commands/cvd/cli/commands/create.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@
4040
#include "cuttlefish/common/libs/utils/flag_parser.h"
4141
#include "cuttlefish/common/libs/utils/users.h"
4242
#include "cuttlefish/host/commands/cvd/cli/command_request.h"
43-
#include "cuttlefish/host/commands/cvd/cli/command_sequence.h"
4443
#include "cuttlefish/host/commands/cvd/cli/commands/command_handler.h"
4544
#include "cuttlefish/host/commands/cvd/cli/commands/host_tool_target.h"
45+
#include "cuttlefish/host/commands/cvd/cli/commands/load_configs.h"
46+
#include "cuttlefish/host/commands/cvd/cli/commands/start.h"
4647
#include "cuttlefish/host/commands/cvd/cli/selector/creation_analyzer.h"
4748
#include "cuttlefish/host/commands/cvd/cli/types.h"
4849
#include "cuttlefish/host/commands/cvd/instances/cvd_persistent_data.pb.h"
@@ -205,10 +206,8 @@ Result<bool> IsDefaultGroup(const CommandRequest& request) {
205206

206207
class CvdCreateCommandHandler : public CvdCommandHandler {
207208
public:
208-
CvdCreateCommandHandler(InstanceManager& instance_manager,
209-
CommandSequenceExecutor& command_executor)
210-
: instance_manager_(instance_manager),
211-
command_executor_(command_executor) {}
209+
CvdCreateCommandHandler(InstanceManager& instance_manager)
210+
: instance_manager_(instance_manager) {}
212211

213212
Result<void> Handle(const CommandRequest& request) override;
214213
std::vector<std::string> CmdList() const override { return {"create"}; }
@@ -223,7 +222,6 @@ class CvdCreateCommandHandler : public CvdCommandHandler {
223222
Result<void> CreateSymlinks(const LocalInstanceGroup& group);
224223

225224
InstanceManager& instance_manager_;
226-
CommandSequenceExecutor& command_executor_;
227225
};
228226

229227
Result<LocalInstanceGroup> CvdCreateCommandHandler::CreateGroup(
@@ -301,9 +299,11 @@ Result<void> CvdCreateCommandHandler::Handle(const CommandRequest& request) {
301299
CreateFlags flags = CF_EXPECT(ParseCommandFlags(envs, subcmd_args));
302300

303301
if (!flags.config_file.empty()) {
304-
auto subrequest =
302+
CommandRequest subrequest =
305303
CF_EXPECT(CreateLoadCommand(request, subcmd_args, flags.config_file));
306-
CF_EXPECT(command_executor_.ExecuteOne(subrequest));
304+
std::unique_ptr<CvdCommandHandler> load_handler =
305+
NewLoadConfigsCommand(instance_manager_);
306+
CF_EXPECT(load_handler->Handle(subrequest));
307307
return {};
308308
}
309309

@@ -327,8 +327,11 @@ Result<void> CvdCreateCommandHandler::Handle(const CommandRequest& request) {
327327
CF_EXPECT(instance_manager_.UpdateInstanceGroup(group));
328328

329329
if (flags.start) {
330-
auto start_cmd = CF_EXPECT(CreateStartCommand(group, subcmd_args, envs));
331-
CF_EXPECT(command_executor_.ExecuteOne(start_cmd));
330+
CommandRequest start_cmd =
331+
CF_EXPECT(CreateStartCommand(group, subcmd_args, envs));
332+
std::unique_ptr<CvdCommandHandler> start_handler =
333+
NewCvdStartCommandHandler(instance_manager_);
334+
CF_EXPECT(start_handler->Handle(start_cmd));
332335

333336
if (CF_EXPECT(IsDefaultGroup(request))) {
334337
// For backward compatibility, we add extra symlink in system wide home
@@ -356,8 +359,8 @@ Result<std::string> CvdCreateCommandHandler::DetailedHelp(
356359
}
357360

358361
std::unique_ptr<CvdCommandHandler> NewCvdCreateCommandHandler(
359-
InstanceManager& instance_manager, CommandSequenceExecutor& executor) {
360-
return std::make_unique<CvdCreateCommandHandler>(instance_manager, executor);
362+
InstanceManager& instance_manager) {
363+
return std::make_unique<CvdCreateCommandHandler>(instance_manager);
361364
}
362365

363366
} // namespace cuttlefish

base/cvd/cuttlefish/host/commands/cvd/cli/commands/create.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@
1818

1919
#include <memory>
2020

21-
#include "cuttlefish/host/commands/cvd/cli/command_sequence.h"
2221
#include "cuttlefish/host/commands/cvd/cli/commands/command_handler.h"
2322
#include "cuttlefish/host/commands/cvd/instances/instance_manager.h"
2423

2524
namespace cuttlefish {
2625

2726
std::unique_ptr<CvdCommandHandler> NewCvdCreateCommandHandler(
28-
InstanceManager& instance_manager, CommandSequenceExecutor& executor);
27+
InstanceManager& instance_manager);
2928

3029
} // namespace cuttlefish
3130

base/cvd/cuttlefish/host/commands/cvd/cli/request_context.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ RequestContext::RequestContext(InstanceManager& instance_manager,
8484
: command_sequence_executor_(this->request_handlers_) {
8585
request_handlers_.emplace_back(NewCvdCacheCommandHandler());
8686

87-
request_handlers_.emplace_back(
88-
NewCvdCreateCommandHandler(instance_manager, command_sequence_executor_));
87+
request_handlers_.emplace_back(NewCvdCreateCommandHandler(instance_manager));
8988
request_handlers_.emplace_back(NewCvdDisplayCommandHandler(instance_manager));
9089
request_handlers_.emplace_back(NewCvdEnvCommandHandler(instance_manager));
9190
request_handlers_.emplace_back(NewCvdFetchCommandHandler());

0 commit comments

Comments
 (0)