aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorinnokentii <innokentii@yandex-team.com>2023-11-28 17:20:26 +0300
committerinnokentii <innokentii@yandex-team.com>2023-11-28 18:29:20 +0300
commitf7b4a06ea04705c65703237ef22166629b7f8f00 (patch)
tree3fe1922f8a577e1bf7e14dbcb22b4b03598870b4
parent5e35ed89257fa2a1d06f1100c05ad41bcb7ef441 (diff)
downloadydb-f7b4a06ea04705c65703237ef22166629b7f8f00.tar.gz
Add edit main config in ui feature
add edit main config in ui feature
-rw-r--r--ydb/core/cms/console/configs_dispatcher.cpp1
-rw-r--r--ydb/core/cms/console/console.h9
-rw-r--r--ydb/core/cms/console/console_configs_manager.cpp22
-rw-r--r--ydb/core/cms/console/console_configs_manager.h7
-rw-r--r--ydb/core/cms/console/console_impl.h1
-rw-r--r--ydb/core/cms/http.cpp6
-rw-r--r--ydb/core/cms/ui/index.html6
-rw-r--r--ydb/core/cms/ui/yaml_config.js72
-rw-r--r--ydb/core/protos/config.proto1
-rw-r--r--ydb/core/protos/console_config.proto9
10 files changed, 127 insertions, 7 deletions
diff --git a/ydb/core/cms/console/configs_dispatcher.cpp b/ydb/core/cms/console/configs_dispatcher.cpp
index 9f0a23a681..ad5f120335 100644
--- a/ydb/core/cms/console/configs_dispatcher.cpp
+++ b/ydb/core/cms/console/configs_dispatcher.cpp
@@ -56,6 +56,7 @@ const THashSet<ui32> DYNAMIC_KINDS({
(ui32)NKikimrConsole::TConfigItem::TableServiceConfigItem,
(ui32)NKikimrConsole::TConfigItem::TenantPoolConfigItem,
(ui32)NKikimrConsole::TConfigItem::TenantSlotBrokerConfigItem,
+ (ui32)NKikimrConsole::TConfigItem::AllowEditYamlInUiItem,
});
const THashSet<ui32> NON_YAML_KINDS({
diff --git a/ydb/core/cms/console/console.h b/ydb/core/cms/console/console.h
index 8d0e172372..35fba0dc01 100644
--- a/ydb/core/cms/console/console.h
+++ b/ydb/core/cms/console/console.h
@@ -55,6 +55,7 @@ struct TEvConsole {
EvReplaceYamlConfigRequest,
EvGetAllMetadataRequest,
EvGetNodeLabelsRequest,
+ EvIsYamlReadOnlyRequest,
// responses
EvCreateTenantResponse = EvCreateTenantRequest + 1024,
@@ -100,6 +101,8 @@ struct TEvConsole {
EvDisabled,
EvGenericError,
+ EvIsYamlReadOnlyResponse,
+
EvEnd
};
@@ -196,6 +199,12 @@ struct TEvConsole {
using TResponse = TEvGetAllConfigsResponse;
};
+ struct TEvIsYamlReadOnlyResponse : public TEventShortDebugPB<TEvIsYamlReadOnlyResponse, NKikimrConsole::TIsYamlReadOnlyResponse, EvIsYamlReadOnlyResponse> {};
+
+ struct TEvIsYamlReadOnlyRequest : public TEventShortDebugPB<TEvIsYamlReadOnlyRequest, NKikimrConsole::TIsYamlReadOnlyRequest, EvIsYamlReadOnlyRequest> {
+ using TResponse = TEvIsYamlReadOnlyResponse;
+ };
+
struct TEvGetAllMetadataResponse : public TEventShortDebugPB<TEvGetAllMetadataResponse, NKikimrConsole::TGetAllMetadataResponse, EvGetAllMetadataResponse> {};
struct TEvGetAllMetadataRequest : public TEventShortDebugPB<TEvGetAllMetadataRequest, NKikimrConsole::TGetAllMetadataRequest, EvGetAllMetadataRequest> {
diff --git a/ydb/core/cms/console/console_configs_manager.cpp b/ydb/core/cms/console/console_configs_manager.cpp
index 033054bf50..b9495819e6 100644
--- a/ydb/core/cms/console/console_configs_manager.cpp
+++ b/ydb/core/cms/console/console_configs_manager.cpp
@@ -77,6 +77,21 @@ void TConfigsManager::Bootstrap(const TActorContext &ctx)
false,
NKikimrServices::CMS_CONFIGS);
ConfigsProvider = ctx.Register(new TConfigsProvider(ctx.SelfID));
+
+ ui32 item = (ui32)NKikimrConsole::TConfigItem::AllowEditYamlInUiItem;
+ ctx.Send(MakeConfigsDispatcherID(SelfId().NodeId()),
+ new TEvConfigsDispatcher::TEvSetConfigSubscriptionRequest(item));
+}
+
+void TConfigsManager::Handle(TEvConsole::TEvConfigNotificationRequest::TPtr &ev,
+ const TActorContext &ctx)
+{
+ auto &rec = ev->Get()->Record;
+
+ YamlReadOnly = !rec.GetConfig().GetAllowEditYamlInUi();
+
+ auto resp = MakeHolder<TEvConsole::TEvConfigNotificationResponse>(rec);
+ ctx.Send(ev->Sender, resp.Release(), 0, ev->Cookie);
}
void TConfigsManager::Detach()
@@ -627,6 +642,13 @@ void TConfigsManager::Handle(TEvConsole::TEvDropConfigRequest::TPtr &ev, const T
TxProcessor->ProcessTx(CreateTxDropYamlConfig(ev), ctx);
}
+void TConfigsManager::Handle(TEvConsole::TEvIsYamlReadOnlyRequest::TPtr &ev, const TActorContext &ctx)
+{
+ auto response = MakeHolder<TEvConsole::TEvIsYamlReadOnlyResponse>();
+ response->Record.SetReadOnly(YamlReadOnly);
+ ctx.Send(ev->Sender, response.Release());
+}
+
void TConfigsManager::Handle(TEvConsole::TEvGetAllConfigsRequest::TPtr &ev, const TActorContext &ctx)
{
TxProcessor->ProcessTx(CreateTxGetYamlConfig(ev), ctx);
diff --git a/ydb/core/cms/console/console_configs_manager.h b/ydb/core/cms/console/console_configs_manager.h
index c05519b51d..4b8bde044e 100644
--- a/ydb/core/cms/console/console_configs_manager.h
+++ b/ydb/core/cms/console/console_configs_manager.h
@@ -7,6 +7,7 @@
#include "logger.h"
#include "tx_processor.h"
#include "console_configs_provider.h"
+#include "configs_dispatcher.h"
#include <ydb/core/actorlib_impl/long_timer.h>
#include <ydb/core/base/tablet_pipe.h>
@@ -133,6 +134,7 @@ private:
void Handle(TEvConsole::TEvAddConfigSubscriptionRequest::TPtr &ev, const TActorContext &ctx);
void Handle(TEvConsole::TEvConfigNotificationResponse::TPtr &ev, const TActorContext &ctx);
void Handle(TEvConsole::TEvConfigureRequest::TPtr &ev, const TActorContext &ctx);
+ void Handle(TEvConsole::TEvConfigNotificationRequest::TPtr &ev, const TActorContext &ctx);
void Handle(TEvConsole::TEvListConfigValidatorsRequest::TPtr &ev, const TActorContext &ctx);
void Handle(TEvConsole::TEvRemoveConfigSubscriptionRequest::TPtr &ev, const TActorContext &ctx);
void Handle(TEvConsole::TEvRemoveConfigSubscriptionsRequest::TPtr &ev, const TActorContext &ctx);
@@ -142,6 +144,7 @@ private:
void Handle(TEvConsole::TEvGetNodeLabelsRequest::TPtr &ev, const TActorContext &ctx);
void Handle(TEvConsole::TEvResolveConfigRequest::TPtr &ev, const TActorContext &ctx);
void Handle(TEvConsole::TEvResolveAllConfigRequest::TPtr &ev, const TActorContext &ctx);
+ void Handle(TEvConsole::TEvIsYamlReadOnlyRequest::TPtr &ev, const TActorContext &ctx);
void Handle(TEvConsole::TEvGetAllConfigsRequest::TPtr &ev, const TActorContext &ctx);
void Handle(TEvConsole::TEvGetAllMetadataRequest::TPtr &ev, const TActorContext &ctx);
void Handle(TEvConsole::TEvAddVolatileConfigRequest::TPtr &ev, const TActorContext &ctx);
@@ -182,6 +185,8 @@ private:
HFuncTraced(TEvConsole::TEvConfigureRequest, Handle);
HFunc(TEvConsole::TEvResolveConfigRequest, Handle);
HFunc(TEvConsole::TEvResolveAllConfigRequest, Handle);
+ HFunc(TEvConsole::TEvConfigNotificationRequest, Handle);
+ HFunc(TEvConsole::TEvIsYamlReadOnlyRequest, Handle);
HFunc(TEvConsole::TEvGetAllConfigsRequest, HandleWithRights);
HFunc(TEvConsole::TEvGetNodeLabelsRequest, HandleWithRights);
HFunc(TEvConsole::TEvGetAllMetadataRequest, HandleWithRights);
@@ -206,6 +211,7 @@ private:
FFunc(TEvConsole::EvConfigSubscriptionRequest, ForwardToConfigsProvider);
FFunc(TEvConsole::EvConfigSubscriptionCanceled, ForwardToConfigsProvider);
CFunc(TEvPrivate::EvCleanupLog, CleanupLog);
+ IgnoreFunc(TEvConfigsDispatcher::TEvSetConfigSubscriptionResponse);
default:
Y_ABORT("TConfigsManager::StateWork unexpected event type: %" PRIx32 " event: %s",
@@ -257,6 +263,7 @@ private:
ui32 YamlVersion = 0;
TString YamlConfig;
bool YamlDropped = false;
+ bool YamlReadOnly = true;
TMap<ui64, TString> VolatileYamlConfigs;
};
diff --git a/ydb/core/cms/console/console_impl.h b/ydb/core/cms/console/console_impl.h
index dbbeec8fc1..15d748be0d 100644
--- a/ydb/core/cms/console/console_impl.h
+++ b/ydb/core/cms/console/console_impl.h
@@ -89,6 +89,7 @@ private:
FFunc(TEvConsole::EvAlterTenantRequest, ForwardToTenantsManager);
FFunc(TEvConsole::EvCheckConfigUpdatesRequest, ForwardToConfigsManager);
FFunc(TEvConsole::EvConfigNotificationResponse, ForwardToConfigsManager);
+ FFunc(TEvConsole::EvIsYamlReadOnlyRequest, ForwardToConfigsManager);
FFunc(TEvConsole::EvConfigureRequest, ForwardToConfigsManager);
FFunc(TEvConsole::EvGetAllConfigsRequest, ForwardToConfigsManager);
FFunc(TEvConsole::EvGetAllMetadataRequest, ForwardToConfigsManager);
diff --git a/ydb/core/cms/http.cpp b/ydb/core/cms/http.cpp
index 466dfdead3..a615965ecc 100644
--- a/ydb/core/cms/http.cpp
+++ b/ydb/core/cms/http.cpp
@@ -65,9 +65,15 @@ public:
ApiHandlers["/api/console/yamlconfig"] = new TApiMethodHandler<TJsonProxyConsole<NConsole::TEvConsole::TEvGetAllConfigsRequest,
NConsole::TEvConsole::TEvGetAllConfigsResponse, true, true>>;
+ ApiHandlers["/api/console/readonly"] = new TApiMethodHandler<TJsonProxyConsole<NConsole::TEvConsole::TEvIsYamlReadOnlyRequest,
+ NConsole::TEvConsole::TEvIsYamlReadOnlyResponse, true, true>>;
+
ApiHandlers["/api/console/removevolatileyamlconfig"] = new TApiMethodHandler<TJsonProxyConsole<NConsole::TEvConsole::TEvRemoveVolatileConfigRequest,
NConsole::TEvConsole::TEvRemoveVolatileConfigResponse, true, true>>;
+ ApiHandlers["/api/console/configureyamlconfig"] = new TApiMethodHandler<TJsonProxyConsole<NConsole::TEvConsole::TEvReplaceYamlConfigRequest,
+ NConsole::TEvConsole::TEvReplaceYamlConfigResponse, true, true>>;
+
ApiHandlers["/api/console/configurevolatileyamlconfig"] = new TApiMethodHandler<TJsonProxyConsole<NConsole::TEvConsole::TEvAddVolatileConfigRequest,
NConsole::TEvConsole::TEvAddVolatileConfigResponse, true, true>>;
diff --git a/ydb/core/cms/ui/index.html b/ydb/core/cms/ui/index.html
index da2563f683..9a9737a0be 100644
--- a/ydb/core/cms/ui/index.html
+++ b/ydb/core/cms/ui/index.html
@@ -305,8 +305,8 @@
</h5>
</div>
<div id="yaml-collapse-one" class="collapse show" aria-labelledby="yaml-heading-one">
- <div class="card-body">
- <form style="flex:1 1 auto; margin-bottom: 0px;">
+ <div class="card-body clearfix">
+ <form style="flex:1 1 auto;">
<div class="yaml-sticky-btn-wrap link-yaml-config yaml-btn-4" id="link-yaml-config" title="copy to resolver">
<div class="yaml-sticky-btn"></div>
</div>
@@ -321,6 +321,8 @@
</div>
<div id="main-editor-container"></div>
</form>
+ <button type="button" class="btn btn-success float-right disabled" id="yaml-apply-button"
+ title="Set config field 'allow_edit_yaml_in_ui' to 'true' to enable this button">Apply</button>
</div>
</div>
</div>
diff --git a/ydb/core/cms/ui/yaml_config.js b/ydb/core/cms/ui/yaml_config.js
index b86c7a8bb9..95ba548d48 100644
--- a/ydb/core/cms/ui/yaml_config.js
+++ b/ydb/core/cms/ui/yaml_config.js
@@ -156,19 +156,81 @@ class YamlConfigState {
constructor() {
this.fetchInterval = 5000;
this.url = 'cms/api/console/yamlconfig';
- this.resolveUrl = 'cms/api/console/resolveyamlconfig'
- this.resolveAllUrl = 'cms/api/console/resolveallyamlconfig'
+ this.readOnlyUrl = 'cms/api/console/readonly';
+ this.resolveUrl = 'cms/api/console/resolveyamlconfig';
+ this.resolveAllUrl = 'cms/api/console/resolveallyamlconfig';
this.removeVolatileUrl = 'cms/api/console/removevolatileyamlconfig';
- this.applyUrl = 'cms/api/console/configurevolatileyamlconfig';
+ this.applyUrl = 'cms/api/console/configureyamlconfig';
+ this.applyVolatileUrl = 'cms/api/console/configurevolatileyamlconfig';
+ this.readOnly = true;
this.maxVolatileId = -1;
this.volatileConfigs = [];
this.codeMirrors = [];
this.initTab();
}
+ changeReadOnlyState(state) {
+ if (this.readOnly == state)
+ return;
+
+ this.readOnly = state;
+ var btn = $('#yaml-apply-button');
+
+ if (this.readOnly) {
+ btn.addClass("disabled");
+ btn.prop("onclick", null).off("click");
+ btn.attr("title", "Set config field 'allow_edit_yaml_in_ui' to 'true' to enable this button");
+ } else {
+ btn.removeClass("disabled");
+ btn.removeAttr("title");
+ var self = this;
+ btn.on('click', function(event) {
+ event.preventDefault();
+ showAck("Apply new config?", " ", "Yes", "No", self.setConfig.bind(self));
+ });
+ }
+
+ if (this.codeMirror) {
+ this.codeMirror.updateOptions({ readOnly: this.readOnly });
+ }
+ }
+
+ setConfig() {
+ var cmd = {
+ Request: {
+ config: this.codeMirror.getValue(),
+ },
+ };
+
+ $.post(this.applyUrl, JSON.stringify(cmd))
+ .done(this.onSetConfig.bind(this, true))
+ .fail(this.onSetConfig.bind(this, false));
+ }
+
+ onSetConfig(success, data) {
+ if (success) {
+ // ok, do nothing
+ } else {
+ var message = "";
+ if (data.hasOwnProperty('responseJSON')) {
+ message = data.responseJSON.issues;
+ } else {
+ message = data.responseText;
+ }
+ showToast("Error", "Can't set config\n" + message, 15000);
+ }
+ }
+
loadYaml() {
clearTimeout(this.loadYamlTimeout);
$.get(this.url).done(this.onYamlLoaded.bind(this, true)).fail(this.onYamlLoaded.bind(this, false));
+ $.get(this.readOnlyUrl).done(this.onReadOnlyLoaded.bind(this, true)).fail(this.onReadOnlyLoaded.bind(this, false));
+ }
+
+ onReadOnlyLoaded(success, data) {
+ if (success && data.hasOwnProperty('ReadOnly')) {
+ this.changeReadOnlyState(data.ReadOnly);
+ }
}
onYamlLoaded(success, data) {
@@ -264,7 +326,7 @@ class YamlConfigState {
},
};
- $.post(this.applyUrl, JSON.stringify(cmd))
+ $.post(this.applyVolatileUrl, JSON.stringify(cmd))
.done(this.onVolatileConfigChanged.bind(this, true))
.fail(this.onVolatileConfigChanged.bind(this, false));
@@ -348,7 +410,7 @@ class YamlConfigState {
initTab() {
var self = this;
- this.codeMirror = createEditor($("#main-editor-container").get(0), true, 1068);
+ this.codeMirror = createEditor($("#main-editor-container").get(0), this.readOnly, 1068);
this.config = "";
this.codeMirror.setValue(this.config);
diff --git a/ydb/core/protos/config.proto b/ydb/core/protos/config.proto
index 207cfaa511..54416e0e00 100644
--- a/ydb/core/protos/config.proto
+++ b/ydb/core/protos/config.proto
@@ -1669,6 +1669,7 @@ message TAppConfig {
optional TConveyorConfig CompConveyorConfig = 72;
optional TQueryServiceConfig QueryServiceConfig = 73;
optional TConveyorConfig InsertConveyorConfig = 74;
+ optional bool AllowEditYamlInUi = 75;
repeated TNamedConfig NamedConfigs = 100;
optional string ClusterYamlConfig = 101;
diff --git a/ydb/core/protos/console_config.proto b/ydb/core/protos/console_config.proto
index 5c2ae8a49e..c2cbefa2b4 100644
--- a/ydb/core/protos/console_config.proto
+++ b/ydb/core/protos/console_config.proto
@@ -128,6 +128,7 @@ message TConfigItem {
CompConveyorConfigItem = 72;
QueryServiceConfigItem = 73;
InsertConveyorConfigItem = 74;
+ AllowEditYamlInUiItem = 75;
NamedConfigsItem = 100;
ClusterYamlConfigItem = 101;
@@ -285,6 +286,14 @@ message TGetAllConfigsResponse {
optional Ydb.DynamicConfig.GetConfigResult Response = 2;
}
+message TIsYamlReadOnlyRequest {
+ optional bytes UserToken = 1;
+}
+
+message TIsYamlReadOnlyResponse {
+ optional bool ReadOnly = 1;
+}
+
message TGetNodeLabelsRequest {
optional Ydb.DynamicConfig.GetNodeLabelsRequest Request = 1;
optional bytes UserToken = 2;