diff options
author | danilalexeev <danilalexeev@yandex-team.com> | 2024-04-21 17:43:09 +0300 |
---|---|---|
committer | danilalexeev <danilalexeev@yandex-team.com> | 2024-04-21 17:55:19 +0300 |
commit | f66bba5f5878c08d7dde25e3d1a44d6972684f88 (patch) | |
tree | a419a25c632d042082da87561febb7f063579bee | |
parent | d8640df74c20a8add7bf6ce47079ea3599cd7fba (diff) | |
download | ydb-f66bba5f5878c08d7dde25e3d1a44d6972684f88.tar.gz |
YT-21382: Implement ISequoiaService & ISequoiaServiceContext
9303c9ef0d39f044b047781a42505e79ba4ccbb9
-rw-r--r-- | yt/yt/core/ytree/helpers-inl.h | 15 | ||||
-rw-r--r-- | yt/yt/core/ytree/helpers.h | 7 | ||||
-rw-r--r-- | yt/yt/core/ytree/ypath_detail.cpp | 58 | ||||
-rw-r--r-- | yt/yt/core/ytree/ypath_detail.h | 67 |
4 files changed, 68 insertions, 79 deletions
diff --git a/yt/yt/core/ytree/helpers-inl.h b/yt/yt/core/ytree/helpers-inl.h index 4f19dc1814..e0d177fd55 100644 --- a/yt/yt/core/ytree/helpers-inl.h +++ b/yt/yt/core/ytree/helpers-inl.h @@ -56,19 +56,4 @@ IYPathServicePtr IYPathService::FromMethod( //////////////////////////////////////////////////////////////////////////////// -template <class TReq, class TRsp> -TIntrusivePtr<TTypedYPathServiceContext<TReq, TRsp>> DeserializeAsTypedOrThrow( - const IYPathServiceContextPtr& context, - const NRpc::THandlerInvocationOptions& options) -{ - auto typedContext = New<TTypedYPathServiceContext<TReq, TRsp>>(context, options); - if (!typedContext->DeserializeRequest()) { - THROW_ERROR_EXCEPTION("Error deserializing request"); - } - - return typedContext; -} - -//////////////////////////////////////////////////////////////////////////////// - } // namespace NYT::NYTree diff --git a/yt/yt/core/ytree/helpers.h b/yt/yt/core/ytree/helpers.h index cc7c736c51..b7308f30de 100644 --- a/yt/yt/core/ytree/helpers.h +++ b/yt/yt/core/ytree/helpers.h @@ -55,13 +55,6 @@ void ValidateYPathResolutionDepth(const NYPath::TYPath& path, int depth); //! of providing a custom efficient implementation. std::vector<std::pair<TString, NYson::TYsonString>> ListAttributesPairs(const IAttributeDictionary& attributes); -//////////////////////////////////////////////////////////////////////////////// - -//! Creates typed context and deserializes it. Throws if deserialization fails. -template <class TReq, class TRsp> -TIntrusivePtr<TTypedYPathServiceContext<TReq, TRsp>> DeserializeAsTypedOrThrow( - const IYPathServiceContextPtr& context, - const NRpc::THandlerInvocationOptions& options); //////////////////////////////////////////////////////////////////////////////// diff --git a/yt/yt/core/ytree/ypath_detail.cpp b/yt/yt/core/ytree/ypath_detail.cpp index 0e15508993..0ccbe25b7c 100644 --- a/yt/yt/core/ytree/ypath_detail.cpp +++ b/yt/yt/core/ytree/ypath_detail.cpp @@ -145,65 +145,19 @@ bool TYPathServiceBase::ShouldHideAttributes() //////////////////////////////////////////////////////////////////////////////// -#define IMPLEMENT_SUPPORTS_VERB_RESOLVE(method, onPathError) \ - DEFINE_RPC_SERVICE_METHOD(TSupports##method, method) \ - { \ - NYPath::TTokenizer tokenizer(GetRequestTargetYPath(context->RequestHeader())); \ - if (tokenizer.Advance() == NYPath::ETokenType::EndOfStream) { \ - method##Self(request, response, context); \ - return; \ - } \ - tokenizer.Skip(NYPath::ETokenType::Ampersand); \ - if (tokenizer.GetType() != NYPath::ETokenType::Slash) { \ - onPathError \ - return; \ - } \ - if (tokenizer.Advance() == NYPath::ETokenType::At) { \ - method##Attribute(TYPath(tokenizer.GetSuffix()), request, response, context); \ - } else { \ - method##Recursive(TYPath(tokenizer.GetInput()), request, response, context); \ - } \ - } - -#define IMPLEMENT_SUPPORTS_VERB(method) \ - IMPLEMENT_SUPPORTS_VERB_RESOLVE( \ - method, \ - { \ - tokenizer.ThrowUnexpected(); \ - } \ - ) \ - \ - void TSupports##method::method##Attribute(const TYPath& /*path*/, TReq##method* /*request*/, TRsp##method* /*response*/, const TCtx##method##Ptr& context) \ - { \ - ThrowMethodNotSupported(context->GetMethod(), TString("attribute")); \ - } \ - \ - void TSupports##method::method##Self(TReq##method* /*request*/, TRsp##method* /*response*/, const TCtx##method##Ptr& context) \ - { \ - ThrowMethodNotSupported(context->GetMethod(), TString("self")); \ - } \ - \ - void TSupports##method::method##Recursive(const TYPath& /*path*/, TReq##method* /*request*/, TRsp##method* /*response*/, const TCtx##method##Ptr& context) \ - { \ - ThrowMethodNotSupported(context->GetMethod(), TString("recursive")); \ - } +IMPLEMENT_SUPPORTS_METHOD(GetKey) +IMPLEMENT_SUPPORTS_METHOD(Get) +IMPLEMENT_SUPPORTS_METHOD(Set) +IMPLEMENT_SUPPORTS_METHOD(List) +IMPLEMENT_SUPPORTS_METHOD(Remove) -IMPLEMENT_SUPPORTS_VERB(GetKey) -IMPLEMENT_SUPPORTS_VERB(Get) -IMPLEMENT_SUPPORTS_VERB(Set) -IMPLEMENT_SUPPORTS_VERB(List) -IMPLEMENT_SUPPORTS_VERB(Remove) - -IMPLEMENT_SUPPORTS_VERB_RESOLVE( +IMPLEMENT_SUPPORTS_METHOD_RESOLVE( Exists, { context->SetRequestInfo(); Reply(context, /*exists*/ false); }) -#undef IMPLEMENT_SUPPORTS_VERB -#undef IMPLEMENT_SUPPORTS_VERB_RESOLVE - void TSupportsExists::ExistsAttribute( const TYPath& /*path*/, TReqExists* /*request*/, diff --git a/yt/yt/core/ytree/ypath_detail.h b/yt/yt/core/ytree/ypath_detail.h index e52b8cd929..b952736463 100644 --- a/yt/yt/core/ytree/ypath_detail.h +++ b/yt/yt/core/ytree/ypath_detail.h @@ -62,13 +62,13 @@ DEFINE_REFCOUNTED_TYPE(TYPathServiceContextWrapper) //////////////////////////////////////////////////////////////////////////////// #define DECLARE_YPATH_SERVICE_METHOD(ns, method) \ - using TCtx##method = ::NYT::NYTree::TTypedYPathServiceContext<ns::TReq##method, ns::TRsp##method>; \ + using TCtx##method = TYPathTypedServiceContextImpl<ns::TReq##method, ns::TRsp##method>; \ using TCtx##method##Ptr = ::NYT::TIntrusivePtr<TCtx##method>; \ using TReq##method = TCtx##method::TTypedRequest; \ using TRsp##method = TCtx##method::TTypedResponse; \ \ void method##Thunk( \ - const ::NYT::NYTree::IYPathServiceContextPtr& context, \ + const ::NYT::TIntrusivePtr<IYPathServiceContextImpl>& context, \ const ::NYT::NRpc::THandlerInvocationOptions& options) \ { \ auto typedContext = ::NYT::New<TCtx##method>(context, options); \ @@ -102,6 +102,16 @@ DEFINE_REFCOUNTED_TYPE(TYPathServiceContextWrapper) //////////////////////////////////////////////////////////////////////////////// +//! These aliases provide an option to replace default typed service context class +//! with a custom one which may be richer in some way. +#define DEFINE_YPATH_CONTEXT_IMPL(serviceContext, typedServiceContext) \ + using IYPathServiceContextImpl = serviceContext; \ + \ + template <class RequestMessage, class ResponseMessage> \ + using TYPathTypedServiceContextImpl = typedServiceContext<RequestMessage, ResponseMessage>; + +//////////////////////////////////////////////////////////////////////////////// + class TYPathServiceBase : public virtual IYPathService { @@ -115,6 +125,8 @@ public: bool ShouldHideAttributes() override; protected: + DEFINE_YPATH_CONTEXT_IMPL(IYPathServiceContext, TTypedYPathServiceContext); + virtual void BeforeInvoke(const IYPathServiceContextPtr& context); virtual bool DoInvoke(const IYPathServiceContextPtr& context); virtual void AfterInvoke(const IYPathServiceContextPtr& context); @@ -131,12 +143,59 @@ protected: : public base \ { \ protected: \ - DECLARE_YPATH_SERVICE_METHOD(NProto, method); \ + DECLARE_YPATH_SERVICE_METHOD(::NYT::NYTree::NProto, method); \ virtual void method##Self(TReq##method* request, TRsp##method* response, const TCtx##method##Ptr& context); \ virtual void method##Recursive(const TYPath& path, TReq##method* request, TRsp##method* response, const TCtx##method##Ptr& context); \ virtual void method##Attribute(const TYPath& path, TReq##method* request, TRsp##method* response, const TCtx##method##Ptr& context); \ } +#define IMPLEMENT_SUPPORTS_METHOD_RESOLVE(method, onPathError) \ + DEFINE_RPC_SERVICE_METHOD(TSupports##method, method) \ + { \ + NYPath::TTokenizer tokenizer(GetRequestTargetYPath(context->RequestHeader())); \ + if (tokenizer.Advance() == NYPath::ETokenType::EndOfStream) { \ + method##Self(request, response, context); \ + return; \ + } \ + tokenizer.Skip(NYPath::ETokenType::Ampersand); \ + if (tokenizer.GetType() != NYPath::ETokenType::Slash) { \ + onPathError \ + return; \ + } \ + if (tokenizer.Advance() == NYPath::ETokenType::At) { \ + method##Attribute(TYPath(tokenizer.GetSuffix()), request, response, context); \ + } else { \ + method##Recursive(TYPath(tokenizer.GetInput()), request, response, context); \ + } \ + } + +#define IMPLEMENT_SUPPORTS_METHOD(method) \ + IMPLEMENT_SUPPORTS_METHOD_RESOLVE( \ + method, \ + { \ + tokenizer.ThrowUnexpected(); \ + } \ + ) \ + \ + void TSupports##method::method##Attribute(const TYPath& /*path*/, TReq##method* /*request*/, TRsp##method* /*response*/, const TCtx##method##Ptr& context) \ + { \ + ThrowMethodNotSupported(context->GetMethod(), TString("attribute")); \ + } \ + \ + void TSupports##method::method##Self(TReq##method* /*request*/, TRsp##method* /*response*/, const TCtx##method##Ptr& context) \ + { \ + ThrowMethodNotSupported(context->GetMethod(), TString("self")); \ + } \ + \ + void TSupports##method::method##Recursive(const TYPath& /*path*/, TReq##method* /*request*/, TRsp##method* /*response*/, const TCtx##method##Ptr& context) \ + { \ + ThrowMethodNotSupported(context->GetMethod(), TString("recursive")); \ + } + +//////////////////////////////////////////////////////////////////////////////// + +DEFINE_YPATH_CONTEXT_IMPL(IYPathServiceContext, TTypedYPathServiceContext); + class TSupportsExistsBase : public virtual TRefCounted { @@ -174,8 +233,6 @@ DECLARE_SUPPORTS_METHOD(List, virtual TRefCounted); DECLARE_SUPPORTS_METHOD(Remove, virtual TRefCounted); DECLARE_SUPPORTS_METHOD(Exists, TSupportsExistsBase); -#undef DECLARE_SUPPORTS_METHOD - //////////////////////////////////////////////////////////////////////////////// class TSupportsPermissions |