From b40571de7d2a71558f10cfcae29ab8f5f4b63a37 Mon Sep 17 00:00:00 2001 From: xusongfu Date: Thu, 28 Jul 2022 17:21:20 +0800 Subject: [PATCH] feat: support reboot action in trove instance Support reboot database service in trove instance Change-Id: I6a831256fc1f7e20bf7cf237915f0f0534386aac --- src/locales/en.json | 2 +- src/locales/zh.json | 2 +- .../containers/Instances/actions/Reboot.jsx | 49 +++++++++++++++++++ .../containers/Instances/actions/Restart.jsx | 6 +-- .../containers/Instances/actions/index.jsx | 3 +- src/stores/trove/instances.js | 5 ++ 6 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 src/pages/database/containers/Instances/actions/Reboot.jsx diff --git a/src/locales/en.json b/src/locales/en.json index b461dee8..a9386f95 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1854,6 +1854,7 @@ "Reason: ": "Reason: ", "Reboot": "Reboot", "Reboot Container": "Reboot Container", + "Reboot Database Instance": "Reboot Database Instance", "Reboot Instance": "Reboot Instance", "Rebooting": "Rebooting", "Rebuild": "Rebuild", @@ -1909,7 +1910,6 @@ "Resource Type": "Resource Type", "Resource Types": "Resource Types", "Resources Synced": "Resources Synced", - "Restart": "Restart", "Restart Database Service": "Restart Database Service", "Restart Policy": "Restart Policy", "Restarting": "Restarting", diff --git a/src/locales/zh.json b/src/locales/zh.json index 16b633f7..ce45178e 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -1854,6 +1854,7 @@ "Reason: ": "原因:", "Reboot": "重启", "Reboot Container": "重启容器", + "Reboot Database Instance": "重启数据库实例", "Reboot Instance": "重启云主机", "Rebooting": "重启中", "Rebuild": "重建", @@ -1909,7 +1910,6 @@ "Resource Type": "资源类型", "Resource Types": "资源类型", "Resources Synced": "资源同步", - "Restart": "重启", "Restart Database Service": "重启数据库服务", "Restart Policy": "重启策略", "Restarting": "重启中", diff --git a/src/pages/database/containers/Instances/actions/Reboot.jsx b/src/pages/database/containers/Instances/actions/Reboot.jsx new file mode 100644 index 00000000..67ccda73 --- /dev/null +++ b/src/pages/database/containers/Instances/actions/Reboot.jsx @@ -0,0 +1,49 @@ +// Copyright 2021 99cloud +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { ConfirmAction } from 'containers/Action'; +import { checkStatus } from 'resources/nova/instance'; +import globalTroveInstanceStore from 'stores/trove/instances'; + +export default class RebootAction extends ConfirmAction { + get id() { + return 'reboot'; + } + + get title() { + return t('Reboot Database Instance'); + } + + get isDanger() { + return true; + } + + get actionName() { + return t('Reboot Database Instance'); + } + + get isAsyncAction() { + return true; + } + + policy = 'instance:reboot'; + + allowedCheckFunc = (item) => + checkStatus(['active', 'shutoff', 'shutdown'], item); + + onSubmit = (item) => { + const { id } = item || this.item; + return globalTroveInstanceStore.reboot({ id }); + }; +} diff --git a/src/pages/database/containers/Instances/actions/Restart.jsx b/src/pages/database/containers/Instances/actions/Restart.jsx index b66bc616..e35e1be1 100644 --- a/src/pages/database/containers/Instances/actions/Restart.jsx +++ b/src/pages/database/containers/Instances/actions/Restart.jsx @@ -16,7 +16,7 @@ import { ConfirmAction } from 'containers/Action'; import { checkStatus } from 'resources/nova/instance'; import globalTroveInstanceStore from 'stores/trove/instances'; -export default class StartAction extends ConfirmAction { +export default class RestartAction extends ConfirmAction { get id() { return 'restart'; } @@ -29,10 +29,6 @@ export default class StartAction extends ConfirmAction { return true; } - get buttonText() { - return t('Restart'); - } - get actionName() { return t('Restart Database Service'); } diff --git a/src/pages/database/containers/Instances/actions/index.jsx b/src/pages/database/containers/Instances/actions/index.jsx index b2e2a227..accaaae9 100644 --- a/src/pages/database/containers/Instances/actions/index.jsx +++ b/src/pages/database/containers/Instances/actions/index.jsx @@ -17,6 +17,7 @@ import Create from './StepCreate'; import Edit from './Edit'; import Restart from './Restart'; import Stop from './Stop'; +import Reboot from './Reboot'; const actionConfigs = { rowActions: { @@ -27,7 +28,7 @@ const actionConfigs = { }, { title: t('Database Instance Status'), - actions: [Restart, Stop], + actions: [Restart, Stop, Reboot], }, ], }, diff --git a/src/stores/trove/instances.js b/src/stores/trove/instances.js index 44f9bf95..f97c1c5e 100644 --- a/src/stores/trove/instances.js +++ b/src/stores/trove/instances.js @@ -95,6 +95,11 @@ export class InstancesStore extends Base { return this.operation({ key: 'restart', id }); } + @action + async reboot({ id }) { + return this.operation({ key: 'reboot', id }); + } + @action async stop({ id }) { return this.submitting(this.adminClient.action(id, { stop: {} }));