Skip to content

Commit 86d2b5b

Browse files
authored
scheme (schema) operations (#5617)
1 parent eeb0728 commit 86d2b5b

File tree

7 files changed

+216
-0
lines changed

7 files changed

+216
-0
lines changed

ydb/core/grpc_services/rpc_describe_path.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ void DoListDirectoryRequest(std::unique_ptr<IRequestOpCtx> p, const IFacilityPro
162162
f.RegisterActor(new TListDirectoryRPC(p.release()));
163163
}
164164

165+
template<>
166+
IActor* TEvListDirectoryRequest::CreateRpcActor(NKikimr::NGRpcService::IRequestOpCtx* msg) {
167+
return new TListDirectoryRPC(msg);
168+
}
169+
165170
void DoDescribePathRequest(std::unique_ptr<IRequestOpCtx> p, const IFacilityProvider& f) {
166171
f.RegisterActor(new TDescribePathRPC(p.release()));
167172
}

ydb/core/grpc_services/rpc_make_directory.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ void DoMakeDirectoryRequest(std::unique_ptr<IRequestOpCtx> p, const IFacilityPro
6363
f.RegisterActor(new TMakeDirectoryRPC(p.release()));
6464
}
6565

66+
template<>
67+
IActor* TEvMakeDirectoryRequest::CreateRpcActor(NKikimr::NGRpcService::IRequestOpCtx* msg) {
68+
return new TMakeDirectoryRPC(msg);
69+
}
70+
6671
} // namespace NGRpcService
6772
} // namespace NKikimr
6873

ydb/core/grpc_services/rpc_remove_directory.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ void DoRemoveDirectoryRequest(std::unique_ptr<IRequestOpCtx> p, const IFacilityP
6262
f.RegisterActor(new TRemoveDirectoryRPC(p.release()));
6363
}
6464

65+
template<>
66+
IActor* TEvRemoveDirectoryRequest::CreateRpcActor(NKikimr::NGRpcService::IRequestOpCtx* msg) {
67+
return new TRemoveDirectoryRPC(msg);
68+
}
69+
6570
} // namespace NGRpcService
6671
} // namespace NKikimr
6772

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "json_handlers.h"
2+
3+
#include "scheme_directory.h"
4+
5+
namespace NKikimr::NViewer {
6+
7+
void InitSchemeJsonHandlers(TJsonHandlers& jsonHandlers) {
8+
jsonHandlers.AddHandler("/scheme/directory", new TJsonSchemeDirectoryHandler());
9+
}
10+
11+
}

ydb/core/viewer/scheme_directory.h

+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
#pragma once
2+
#include <ydb/public/api/grpc/ydb_scheme_v1.grpc.pb.h>
3+
#include <ydb/core/grpc_services/rpc_calls.h>
4+
#include "json_local_rpc.h"
5+
#include "json_handlers.h"
6+
7+
namespace NKikimr {
8+
namespace NViewer {
9+
10+
class TSchemeDirectory : public IActor {
11+
public:
12+
TSchemeDirectory(IViewer*, NMon::TEvHttpInfo::TPtr&) {}
13+
};
14+
15+
using TSchemeDirectoryGetRpc = TJsonLocalRpc<Ydb::Scheme::ListDirectoryRequest,
16+
Ydb::Scheme::ListDirectoryResponse,
17+
Ydb::Scheme::ListDirectoryResult,
18+
Ydb::Scheme::V1::SchemeService,
19+
NKikimr::NGRpcService::TGrpcRequestOperationCall<Ydb::Scheme::ListDirectoryRequest, Ydb::Scheme::ListDirectoryResponse>>;
20+
21+
using TSchemeDirectoryPostRpc = TJsonLocalRpc<Ydb::Scheme::MakeDirectoryRequest,
22+
Ydb::Scheme::MakeDirectoryResponse,
23+
Ydb::Scheme::MakeDirectoryResponse,
24+
Ydb::Scheme::V1::SchemeService,
25+
NKikimr::NGRpcService::TGrpcRequestOperationCall<Ydb::Scheme::MakeDirectoryRequest, Ydb::Scheme::MakeDirectoryResponse>>;
26+
27+
using TSchemeDirectoryDeleteRpc = TJsonLocalRpc<Ydb::Scheme::RemoveDirectoryRequest,
28+
Ydb::Scheme::RemoveDirectoryResponse,
29+
Ydb::Scheme::RemoveDirectoryResponse,
30+
Ydb::Scheme::V1::SchemeService,
31+
NKikimr::NGRpcService::TGrpcRequestOperationCall<Ydb::Scheme::RemoveDirectoryRequest, Ydb::Scheme::RemoveDirectoryResponse>>;
32+
33+
34+
template<typename LocalRpcType>
35+
class TSchemeDirectoryRequest : public LocalRpcType {
36+
public:
37+
using TBase = LocalRpcType;
38+
39+
TSchemeDirectoryRequest(IViewer* viewer, NMon::TEvHttpInfo::TPtr& ev)
40+
: TBase(viewer, ev)
41+
{}
42+
43+
void Bootstrap() override {
44+
if (!TBase::PostToRequest()) {
45+
return;
46+
}
47+
48+
const auto& params(TBase::Event->Get()->Request.GetParams());
49+
if (params.Has("database")) {
50+
TBase::Database = params.Get("database");
51+
}
52+
if (TBase::Database.empty()) {
53+
return TBase::ReplyAndPassAway(TBase::Viewer->GetHTTPBADREQUEST(TBase::Event->Get(), "text/plain", "field 'database' is required"));
54+
}
55+
56+
if (params.Has("path")) {
57+
TBase::Request.set_path(params.Get("path"));
58+
}
59+
if (TBase::Request.path().empty()) {
60+
return TBase::ReplyAndPassAway(TBase::Viewer->GetHTTPBADREQUEST(TBase::Event->Get(), "text/plain", "field 'path' is required"));
61+
}
62+
63+
TBase::Bootstrap();
64+
}
65+
};
66+
67+
class TJsonSchemeDirectoryHandler : public TJsonHandler<TSchemeDirectory> {
68+
public:
69+
IActor* CreateRequestActor(IViewer* viewer, NMon::TEvHttpInfo::TPtr& event) override {
70+
switch (event->Get()->Request.GetMethod()) {
71+
case HTTP_METHOD_GET:
72+
return new TSchemeDirectoryRequest<TSchemeDirectoryGetRpc>(viewer, event);
73+
case HTTP_METHOD_POST:
74+
return new TSchemeDirectoryRequest<TSchemeDirectoryPostRpc>(viewer, event);
75+
case HTTP_METHOD_DELETE:
76+
return new TSchemeDirectoryRequest<TSchemeDirectoryDeleteRpc>(viewer, event);
77+
default:
78+
throw std::logic_error("Bad request method");
79+
}
80+
}
81+
};
82+
83+
template<>
84+
YAML::Node TJsonRequestSwagger<TSchemeDirectory>::GetSwagger() {
85+
YAML::Node node = YAML::Load(R"___(
86+
get:
87+
tags:
88+
- scheme
89+
summary: List directory
90+
description: Returns information about given directory and objects inside it
91+
parameters:
92+
- name: database
93+
in: query
94+
description: database name
95+
required: true
96+
type: string
97+
- name: path
98+
in: query
99+
description: path to directory
100+
required: true
101+
type: string
102+
responses:
103+
200:
104+
description: OK
105+
content:
106+
application/json:
107+
schema: {}
108+
400:
109+
description: Bad Request
110+
403:
111+
description: Forbidden
112+
504:
113+
description: Gateway Timeout
114+
post:
115+
tags:
116+
- scheme
117+
summary: Make directory
118+
description: Makes directory
119+
parameters:
120+
- name: database
121+
in: query
122+
description: database name
123+
required: true
124+
type: string
125+
- name: path
126+
in: query
127+
description: path to directory
128+
required: true
129+
type: string
130+
responses:
131+
200:
132+
description: OK
133+
content:
134+
application/json:
135+
schema: {}
136+
400:
137+
description: Bad Request
138+
403:
139+
description: Forbidden
140+
504:
141+
description: Gateway Timeout
142+
delete:
143+
tags:
144+
- scheme
145+
summary: Remove directory
146+
description: Removes directory
147+
parameters:
148+
- name: database
149+
in: query
150+
description: database name
151+
required: true
152+
type: string
153+
- name: path
154+
in: query
155+
description: path to directory
156+
required: true
157+
type: string
158+
responses:
159+
200:
160+
description: OK
161+
content:
162+
application/json:
163+
schema: {}
164+
400:
165+
description: Bad Request
166+
403:
167+
description: Forbidden
168+
504:
169+
description: Gateway Timeout
170+
)___");
171+
172+
node["get"]["responses"]["200"]["content"]["application/json"]["schema"] = TProtoToYaml::ProtoToYamlSchema<Ydb::Scheme::ListDirectoryResult>();
173+
node["post"]["responses"]["200"]["content"]["application/json"]["schema"] = TProtoToYaml::ProtoToYamlSchema<Ydb::Scheme::MakeDirectoryResponse>();
174+
node["delete"]["responses"]["200"]["content"]["application/json"]["schema"] = TProtoToYaml::ProtoToYamlSchema<Ydb::Scheme::RemoveDirectoryResponse>();
175+
return node;
176+
}
177+
178+
}
179+
}

ydb/core/viewer/viewer.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ extern void InitViewerJsonHandlers(TJsonHandlers& jsonHandlers);
4343
extern void InitPDiskJsonHandlers(TJsonHandlers& jsonHandlers);
4444
extern void InitVDiskJsonHandlers(TJsonHandlers& jsonHandlers);
4545
extern void InitOperationJsonHandlers(TJsonHandlers& jsonHandlers);
46+
extern void InitSchemeJsonHandlers(TJsonHandlers& jsonHandlers);
4647

4748
void SetupPQVirtualHandlers(IViewer* viewer) {
4849
viewer->RegisterVirtualHandler(
@@ -160,6 +161,13 @@ class TViewer : public TActorBootstrapped<TViewer>, public IViewer {
160161
.UseAuth = true,
161162
.AllowedSIDs = monitoringAllowedSIDs,
162163
});
164+
mon->RegisterActorPage({
165+
.RelPath = "scheme",
166+
.ActorSystem = ctx.ExecutorThread.ActorSystem,
167+
.ActorId = ctx.SelfID,
168+
.UseAuth = true,
169+
.AllowedSIDs = viewerAllowedSIDs,
170+
});
163171
auto whiteboardServiceId = NNodeWhiteboard::MakeNodeWhiteboardServiceId(ctx.SelfID.NodeId());
164172
ctx.Send(whiteboardServiceId, new NNodeWhiteboard::TEvWhiteboard::TEvSystemStateAddEndpoint(
165173
"http-mon", Sprintf(":%d", KikimrRunConfig.AppConfig.GetMonitoringConfig().GetMonitoringPort())));
@@ -170,6 +178,7 @@ class TViewer : public TActorBootstrapped<TViewer>, public IViewer {
170178
InitPDiskJsonHandlers(JsonHandlers);
171179
InitVDiskJsonHandlers(JsonHandlers);
172180
InitOperationJsonHandlers(JsonHandlers);
181+
InitSchemeJsonHandlers(JsonHandlers);
173182

174183
for (const auto& handler : JsonHandlers.JsonHandlersList) {
175184
// temporary handling of old paths

ydb/core/viewer/ya.make

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ SRCS(
2929
json_graph.h
3030
json_handlers_operation.cpp
3131
json_handlers_pdisk.cpp
32+
json_handlers_scheme.cpp
3233
json_handlers_vdisk.cpp
3334
json_handlers_viewer.cpp
3435
json_healthcheck.h
@@ -65,6 +66,7 @@ SRCS(
6566
operation_list.h
6667
pdisk_info.h
6768
pdisk_status.h
69+
scheme_directory.h
6870
query_autocomplete_helper.h
6971
viewer_request.cpp
7072
viewer_request.h

0 commit comments

Comments
 (0)