/
githubmirror
/
nbs
Обзор
Документация
Войти
/
githubmirror
/
nbs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
cloud/blockstore/apps/client/lib/stop_endpoint.cpp
111 строк
3 KB
Vladislav Stepanyuk
issue-4519: added DiskId and ClientId params to stop endpoint command (#4521)
21 окт 2025, 12:05
Не верифицирован
21 окт 2025, 12:05
d30aba6
Код
Авторство
О чём код?
#include "stop_endpoint.h" #include <cloud/blockstore/libs/service/context.h> #include <cloud/blockstore/libs/service/request_helpers.h> #include <cloud/blockstore/libs/service/service.h> #include <cloud/storage/core/libs/common/error.h> #include <cloud/storage/core/libs/diagnostics/logging.h> #include <library/cpp/protobuf/util/pb_io.h> namespace NCloud::NBlockStore::NClient { namespace { //////////////////////////////////////////////////////////////////////////////// class TStopEndpointCommand final : public TCommand { private: TString UnixSocketPath; TString DiskId; TString ClientId; public: TStopEndpointCommand(IBlockStorePtr client) : TCommand(std::move(client)) { Opts.AddLongOption("socket", "unix socket path") .RequiredArgument("STR") .StoreResult(&UnixSocketPath); Opts.AddLongOption("disk-id", "volume identifier") .RequiredArgument("STR") .StoreResult(&DiskId); Opts.AddLongOption("client-id", "client identifier") .RequiredArgument("STR") .StoreResult(&ClientId); } protected: bool DoExecute() override { if (!Proto && !CheckOpts()) { return false; } auto& input = GetInputStream(); auto& output = GetOutputStream(); STORAGE_DEBUG("Reading StopEndpoint request"); auto request = std::make_shared<NProto::TStopEndpointRequest>(); if (Proto) { ParseFromTextFormat(input, *request); } else { request->SetUnixSocketPath(UnixSocketPath); request->SetDiskId(DiskId); request->MutableHeaders()->SetClientId(ClientId); } STORAGE_DEBUG("Sending StopEndpoint request"); const auto requestId = GetRequestId(*request); auto result = WaitFor(ClientEndpoint->StopEndpoint( MakeIntrusive<TCallContext>(requestId), std::move(request))); STORAGE_DEBUG("Received StopEndpoint response"); if (Proto) { SerializeToTextFormat(result, output); return true; } if (HasError(result)) { output << FormatError(result.GetError()) << Endl; return false; } output << "OK" << Endl; return true; } private: bool CheckOpts() const { if (!UnixSocketPath) { STORAGE_ERROR("Unix socket path is required"); return false; } if (DiskId.empty() != ClientId.empty()) { const auto* passedArgument = DiskId ? "DiskId" : "ClientId"; const auto* otherArgument = DiskId ? "ClientId" : "DiskId"; STORAGE_ERROR( "There is no sense to pass " << passedArgument << " without " << otherArgument); return false; } return true; } }; } // namespace //////////////////////////////////////////////////////////////////////////////// TCommandPtr NewStopEndpointCommand(IBlockStorePtr client) { return MakeIntrusive<TStopEndpointCommand>(std::move(client)); } } // namespace NCloud::NBlockStore::NClient