From f7b4a06ea04705c65703237ef22166629b7f8f00 Mon Sep 17 00:00:00 2001 From: innokentii Date: Tue, 28 Nov 2023 17:20:26 +0300 Subject: [PATCH] Add edit main config in ui feature add edit main config in ui feature --- ydb/core/cms/console/configs_dispatcher.cpp | 1 + ydb/core/cms/console/console.h | 9 +++ .../cms/console/console_configs_manager.cpp | 22 ++++++ .../cms/console/console_configs_manager.h | 7 ++ ydb/core/cms/console/console_impl.h | 1 + ydb/core/cms/http.cpp | 6 ++ ydb/core/cms/ui/index.html | 6 +- ydb/core/cms/ui/yaml_config.js | 72 +++++++++++++++++-- ydb/core/protos/config.proto | 1 + ydb/core/protos/console_config.proto | 9 +++ 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 9f0a23a681c5..ad5f120335e4 100644 --- a/ydb/core/cms/console/configs_dispatcher.cpp +++ b/ydb/core/cms/console/configs_dispatcher.cpp @@ -56,6 +56,7 @@ const THashSet DYNAMIC_KINDS({ (ui32)NKikimrConsole::TConfigItem::TableServiceConfigItem, (ui32)NKikimrConsole::TConfigItem::TenantPoolConfigItem, (ui32)NKikimrConsole::TConfigItem::TenantSlotBrokerConfigItem, + (ui32)NKikimrConsole::TConfigItem::AllowEditYamlInUiItem, }); const THashSet NON_YAML_KINDS({ diff --git a/ydb/core/cms/console/console.h b/ydb/core/cms/console/console.h index 8d0e172372f3..35fba0dc0172 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 {}; + + struct TEvIsYamlReadOnlyRequest : public TEventShortDebugPB { + using TResponse = TEvIsYamlReadOnlyResponse; + }; + struct TEvGetAllMetadataResponse : public TEventShortDebugPB {}; struct TEvGetAllMetadataRequest : public TEventShortDebugPB { diff --git a/ydb/core/cms/console/console_configs_manager.cpp b/ydb/core/cms/console/console_configs_manager.cpp index 033054bf5014..b9495819e6f6 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(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(); + 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 c05519b51df1..4b8bde044e12 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 #include @@ -133,6 +134,7 @@ class TConfigsManager : public TActorBootstrapped { 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 @@ class TConfigsManager : public TActorBootstrapped { 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 @@ class TConfigsManager : public TActorBootstrapped { 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 @@ class TConfigsManager : public TActorBootstrapped { 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 @@ class TConfigsManager : public TActorBootstrapped { ui32 YamlVersion = 0; TString YamlConfig; bool YamlDropped = false; + bool YamlReadOnly = true; TMap VolatileYamlConfigs; }; diff --git a/ydb/core/cms/console/console_impl.h b/ydb/core/cms/console/console_impl.h index dbbeec8fc1d9..15d748be0da2 100644 --- a/ydb/core/cms/console/console_impl.h +++ b/ydb/core/cms/console/console_impl.h @@ -89,6 +89,7 @@ class TConsole : public TActor 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 466dfdead386..a615965ecc4c 100644 --- a/ydb/core/cms/http.cpp +++ b/ydb/core/cms/http.cpp @@ -65,9 +65,15 @@ class TCmsHttp : public TActorBootstrapped { ApiHandlers["/api/console/yamlconfig"] = new TApiMethodHandler>; + ApiHandlers["/api/console/readonly"] = new TApiMethodHandler>; + ApiHandlers["/api/console/removevolatileyamlconfig"] = new TApiMethodHandler>; + ApiHandlers["/api/console/configureyamlconfig"] = new TApiMethodHandler>; + ApiHandlers["/api/console/configurevolatileyamlconfig"] = new TApiMethodHandler>; diff --git a/ydb/core/cms/ui/index.html b/ydb/core/cms/ui/index.html index da2563f683cc..9a9737a0be3a 100644 --- a/ydb/core/cms/ui/index.html +++ b/ydb/core/cms/ui/index.html @@ -305,8 +305,8 @@
-
-
+
+ @@ -321,6 +321,8 @@
+
diff --git a/ydb/core/cms/ui/yaml_config.js b/ydb/core/cms/ui/yaml_config.js index b86c7a8bb91e..95ba548d487c 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 207cfaa511b3..54416e0e007c 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 5c2ae8a49e56..c2cbefa2b438 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;