summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorinnokentii <[email protected]>2023-06-13 20:01:24 +0300
committerinnokentii <[email protected]>2023-06-13 20:01:24 +0300
commitfd2c598b1689747c9080c05b9984d3a59602e22a (patch)
tree62c495dfdecfae692258f1ae1121123a4aa94509
parentf28b700a96d0e08b8e348ccb836df27b270795de (diff)
Fix webui
fix webui
-rw-r--r--ydb/core/cms/json_proxy.h35
-rw-r--r--ydb/core/cms/ui/yaml_config.js46
2 files changed, 58 insertions, 23 deletions
diff --git a/ydb/core/cms/json_proxy.h b/ydb/core/cms/json_proxy.h
index fffee941336..a8db8632876 100644
--- a/ydb/core/cms/json_proxy.h
+++ b/ydb/core/cms/json_proxy.h
@@ -17,6 +17,8 @@
#include <library/cpp/protobuf/json/json2proto.h>
#include <library/cpp/protobuf/json/proto2json.h>
+#include <library/cpp/json/json_writer.h>
+
#include <iostream>
namespace NKikimr::NCms {
@@ -87,6 +89,9 @@ protected:
STFUNC(StateWork) {
switch (ev->GetTypeRewrite()) {
HFunc(TResponseEvent, Handle);
+ HFunc(NConsole::TEvConsole::TEvUnauthorized, HandleError);
+ HFunc(NConsole::TEvConsole::TEvDisabled, HandleError);
+ HFunc(NConsole::TEvConsole::TEvGenericError, HandleError);
CFunc(TEvents::TSystem::Wakeup, Timeout);
CFunc(TEvTabletPipe::TEvClientDestroyed::EventType, Disconnect);
HFunc(TEvTabletPipe::TEvClientConnected, Handle);
@@ -129,6 +134,36 @@ protected:
ReplyAndDie(ev->Get()->Record, ctx);
}
+ void HandleError(NConsole::TEvConsole::TEvUnauthorized::TPtr &, const TActorContext &ctx) {
+ ReplyAndDieImpl(TString(NMonitoring::HTTPUNAUTHORIZED), ctx);
+ }
+
+ void HandleError(NConsole::TEvConsole::TEvDisabled::TPtr &, const TActorContext &ctx) {
+ ReplyAndDieImpl(TString("HTTP/1.1 400 Bad Request\r\nContent-Type: application/json\r\nConnection: Close\r\n\r\n{\"code\":400, \"message\":\"Feature is disabled\"}\r\n"), ctx);
+ }
+
+ void HandleError(NConsole::TEvConsole::TEvGenericError::TPtr &ev, const TActorContext &ctx) {
+ TStringStream issues;
+ for (auto& issue : ev->Get()->Record.GetIssues()) {
+ issues << issue.ShortDebugString() + ", ";
+ }
+
+ TString res;
+ TStringOutput ss(res);
+
+ NJson::TJsonWriter writer(&ss, true);
+
+ writer.OpenMap();
+ writer.Write("code", (ui64)ev->Get()->Record.GetYdbStatus());
+ writer.Write("issues", issues.Str());
+ writer.CloseMap();
+
+ writer.Flush();
+ ss.Flush();
+
+ ReplyAndDieImpl(TString("HTTP/1.1 400 Bad Request\r\nContent-Type: application/json\r\nConnection: Close\r\n\r\n") + res + "\r\n", ctx);
+ }
+
void SetTempError(NKikimrCms::TStatus &status, const TString &error) {
status.SetCode(NKikimrCms::TStatus::ERROR_TEMP);
status.SetReason(error);
diff --git a/ydb/core/cms/ui/yaml_config.js b/ydb/core/cms/ui/yaml_config.js
index 9377021217c..b86c7a8bb91 100644
--- a/ydb/core/cms/ui/yaml_config.js
+++ b/ydb/core/cms/ui/yaml_config.js
@@ -168,16 +168,16 @@ class YamlConfigState {
loadYaml() {
clearTimeout(this.loadYamlTimeout);
- $.get(this.url).done(this.onYamlLoaded.bind(this)).fail(this.onYamlLoaded.bind(this));
+ $.get(this.url).done(this.onYamlLoaded.bind(this, true)).fail(this.onYamlLoaded.bind(this, false));
}
- onYamlLoaded(data) {
- if (data?.Response?.operation?.status === "SUCCESS") {
- this.cluster = data.Response.cluster;
- $('#yaml-cluster').text(data.Response.cluster);
+ onYamlLoaded(success, data) {
+ if (success) {
+ this.cluster = data.Response.identity.cluster;
+ $('#yaml-cluster').text(data.Response.identity.cluster);
- this.version = data.Response.version;
- $('#yaml-version').text(data.Response.version);
+ this.version = data.Response.identity.version;
+ $('#yaml-version').text(data.Response.identity.version);
if (this.config !== data.Response.config) {
this.codeMirror.setValue((data.Response.config !== undefined) ? data.Response.config : "");
@@ -246,11 +246,11 @@ class YamlConfigState {
this.loadYamlTimeout = setTimeout(this.loadYaml.bind(this), this.fetchInterval);
}
- onVolatileConfigChanged(data) {
- if (data?.Response?.operation?.status === "SUCCESS") {
+ onVolatileConfigChanged(success, data) {
+ if (success) {
this.loadYaml();
} else {
- showToast("Error", "Invalid volatile config\n" + data.Response.operation.issues[0].message, 15000);
+ showToast("Error", "Invalid volatile config\n" + data.responseJSON.issues, 15000);
}
}
@@ -265,8 +265,8 @@ class YamlConfigState {
};
$.post(this.applyUrl, JSON.stringify(cmd))
- .done(this.onVolatileConfigChanged.bind(this))
- .fail(this.onVolatileConfigChanged.bind(this));
+ .done(this.onVolatileConfigChanged.bind(this, true))
+ .fail(this.onVolatileConfigChanged.bind(this, false));
this.volatileCodeMirror.setValue("");
@@ -284,8 +284,8 @@ class YamlConfigState {
};
$.post(this.removeVolatileUrl, JSON.stringify(cmd))
- .done(this.onVolatileConfigChanged.bind(this))
- .fail(this.onVolatileConfigChanged.bind(this));
+ .done(this.onVolatileConfigChanged.bind(this, true))
+ .fail(this.onVolatileConfigChanged.bind(this, false));
}
removeVolatileConfig(id) {
@@ -298,15 +298,15 @@ class YamlConfigState {
};
$.post(this.removeVolatileUrl, JSON.stringify(cmd))
- .done(this.onVolatileConfigChanged.bind(this))
- .fail(this.onVolatileConfigChanged.bind(this));
+ .done(this.onVolatileConfigChanged.bind(this, true))
+ .fail(this.onVolatileConfigChanged.bind(this, false));
}
- onResolved(data) {
- if (data?.Response?.operation?.status === "SUCCESS") {
+ onResolved(success, data) {
+ if (success) {
this.resolvedCodeMirror.setValue(data.Response.config);
} else {
- showToast("Error", "Config resolution error\n" + data.Response.operation.issues[0].message, 15000);
+ showToast("Error", "Config resolution error\n" + data.responseJSON.issues, 15000);
}
}
@@ -320,8 +320,8 @@ class YamlConfigState {
};
$.post(this.resolveAllUrl, JSON.stringify(cmd))
- .done(this.onResolved.bind(this))
- .fail(this.onResolved.bind(this));
+ .done(this.onResolved.bind(this, true))
+ .fail(this.onResolved.bind(this, false));
}
resolveForLabels() {
@@ -342,8 +342,8 @@ class YamlConfigState {
};
$.post(this.resolveUrl, JSON.stringify(cmd))
- .done(this.onResolved.bind(this))
- .fail(this.onResolved.bind(this));
+ .done(this.onResolved.bind(this, true))
+ .fail(this.onResolved.bind(this, false));
}
initTab() {