|
| 1 | +// Copyright 2025 The Ray Authors. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#pragma once |
| 16 | + |
| 17 | +#include <memory> |
| 18 | +#include <string> |
| 19 | +#include <utility> |
| 20 | +#include <vector> |
| 21 | + |
| 22 | +#include "ray/raylet/worker.h" |
| 23 | +#include "ray/raylet_ipc_client/client_connection.h" |
| 24 | + |
| 25 | +namespace ray { |
| 26 | +namespace raylet { |
| 27 | + |
| 28 | +class FakeWorker : public WorkerInterface { |
| 29 | + public: |
| 30 | + FakeWorker(WorkerID worker_id, int port, instrumented_io_context &io_context) |
| 31 | + : worker_id_(worker_id), |
| 32 | + port_(port), |
| 33 | + proc_(Process::CreateNewDummy()), |
| 34 | + connection_([&io_context]() { |
| 35 | + local_stream_socket socket(io_context); |
| 36 | + return ClientConnection::Create( |
| 37 | + [](std::shared_ptr<ClientConnection>, |
| 38 | + int64_t, |
| 39 | + const std::vector<uint8_t> &) {}, |
| 40 | + [](std::shared_ptr<ClientConnection>, const boost::system::error_code &) {}, |
| 41 | + std::move(socket), |
| 42 | + "fake_worker_connection", |
| 43 | + {}); |
| 44 | + }()) {} |
| 45 | + |
| 46 | + WorkerID WorkerId() const override { return worker_id_; } |
| 47 | + rpc::WorkerType GetWorkerType() const override { return rpc::WorkerType::WORKER; } |
| 48 | + int Port() const override { return port_; } |
| 49 | + void SetOwnerAddress(const rpc::Address &address) override {} |
| 50 | + void GrantLease(const RayLease &granted_lease) override {} |
| 51 | + void GrantLeaseId(const LeaseID &lease_id) override { lease_id_ = lease_id; } |
| 52 | + const RayLease &GetGrantedLease() const override { return granted_lease_; } |
| 53 | + absl::Time GetGrantedLeaseTime() const override { return absl::InfiniteFuture(); } |
| 54 | + std::optional<bool> GetIsGpu() const override { return std::nullopt; } |
| 55 | + std::optional<bool> GetIsActorWorker() const override { return std::nullopt; } |
| 56 | + const std::string IpAddress() const override { return "127.0.0.1"; } |
| 57 | + void AsyncNotifyGCSRestart() override {} |
| 58 | + void SetAllocatedInstances( |
| 59 | + const std::shared_ptr<TaskResourceInstances> &allocated_instances) override {} |
| 60 | + void SetLifetimeAllocatedInstances( |
| 61 | + const std::shared_ptr<TaskResourceInstances> &allocated_instances) override {} |
| 62 | + std::shared_ptr<TaskResourceInstances> GetAllocatedInstances() override { |
| 63 | + return nullptr; |
| 64 | + } |
| 65 | + std::shared_ptr<TaskResourceInstances> GetLifetimeAllocatedInstances() override { |
| 66 | + return nullptr; |
| 67 | + } |
| 68 | + void MarkDead() override {} |
| 69 | + bool IsDead() const override { return false; } |
| 70 | + void KillAsync(instrumented_io_context &io_service, bool force) override {} |
| 71 | + void MarkBlocked() override {} |
| 72 | + void MarkUnblocked() override {} |
| 73 | + bool IsBlocked() const override { return false; } |
| 74 | + Process GetProcess() const override { return proc_; } |
| 75 | + StartupToken GetStartupToken() const override { return 0; } |
| 76 | + void SetProcess(Process proc) override {} |
| 77 | + Language GetLanguage() const override { return Language::PYTHON; } |
| 78 | + void Connect(int port) override {} |
| 79 | + void Connect(std::shared_ptr<rpc::CoreWorkerClientInterface> rpc_client) override {} |
| 80 | + int AssignedPort() const override { return -1; } |
| 81 | + void SetAssignedPort(int port) override {} |
| 82 | + const LeaseID &GetGrantedLeaseId() const override { return lease_id_; } |
| 83 | + const JobID &GetAssignedJobId() const override { return job_id_; } |
| 84 | + int GetRuntimeEnvHash() const override { return 0; } |
| 85 | + void AssignActorId(const ActorID &actor_id) override {} |
| 86 | + const ActorID &GetActorId() const override { return actor_id_; } |
| 87 | + const std::string GetLeaseIdAsDebugString() const override { return ""; } |
| 88 | + bool IsDetachedActor() const override { return false; } |
| 89 | + const std::shared_ptr<ClientConnection> Connection() const override { |
| 90 | + return connection_; |
| 91 | + } |
| 92 | + const rpc::Address &GetOwnerAddress() const override { return owner_address_; } |
| 93 | + std::optional<pid_t> GetSavedProcessGroupId() const override { return std::nullopt; } |
| 94 | + void SetSavedProcessGroupId(pid_t pgid) override {} |
| 95 | + void ActorCallArgWaitComplete(int64_t tag) override {} |
| 96 | + void ClearAllocatedInstances() override {} |
| 97 | + void ClearLifetimeAllocatedInstances() override {} |
| 98 | + const BundleID &GetBundleId() const override { return bundle_id_; } |
| 99 | + void SetBundleId(const BundleID &bundle_id) override { bundle_id_ = bundle_id; } |
| 100 | + RayLease &GetGrantedLease() override { return granted_lease_; } |
| 101 | + bool IsRegistered() override { return false; } |
| 102 | + rpc::CoreWorkerClientInterface *rpc_client() override { return nullptr; } |
| 103 | + bool IsAvailableForScheduling() const override { return true; } |
| 104 | + void SetJobId(const JobID &job_id) override {} |
| 105 | + const ActorID &GetRootDetachedActorId() const override { |
| 106 | + return root_detached_actor_id_; |
| 107 | + } |
| 108 | + |
| 109 | + protected: |
| 110 | + void SetStartupToken(StartupToken startup_token) override {} |
| 111 | + |
| 112 | + private: |
| 113 | + WorkerID worker_id_; |
| 114 | + int port_; |
| 115 | + LeaseID lease_id_; |
| 116 | + BundleID bundle_id_; |
| 117 | + Process proc_; |
| 118 | + std::shared_ptr<ClientConnection> connection_; |
| 119 | + RayLease granted_lease_; |
| 120 | + JobID job_id_; |
| 121 | + ActorID actor_id_; |
| 122 | + rpc::Address owner_address_; |
| 123 | + ActorID root_detached_actor_id_; |
| 124 | +}; |
| 125 | + |
| 126 | +} // namespace raylet |
| 127 | +} // namespace ray |
0 commit comments