diff --git a/src/client/trove/index.js b/src/client/trove/index.js index f0758d52..d9bb706e 100644 --- a/src/client/trove/index.js +++ b/src/client/trove/index.js @@ -61,6 +61,10 @@ export class TroveClient extends Base { ); }, }, + { + key: 'action', + method: 'post', + }, ], }, { diff --git a/src/locales/en.json b/src/locales/en.json index 97da7ab6..9e67eb0e 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -586,6 +586,7 @@ "Database": "Database", "Database Instance": "Database Instance", "Database Instance Detail": "Database Instance Detail", + "Database Instance Status": "Database Instance Status", "Database Name": "Database Name", "Database Port": "Database Port", "Database Service": "Database Service", @@ -1904,6 +1905,7 @@ "Resource Type": "Resource Type", "Resource Types": "Resource Types", "Resources Synced": "Resources Synced", + "Restart Database Service": "Restart Database Service", "Restart Policy": "Restart Policy", "Restarting": "Restarting", "Restore Backup": "Restore Backup", diff --git a/src/locales/zh.json b/src/locales/zh.json index c7cb04ac..bd4ef03c 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -586,6 +586,7 @@ "Database": "数据库", "Database Instance": "数据库实例", "Database Instance Detail": "数据库实例详情", + "Database Instance Status": "数据库实例状态", "Database Name": "数据库名称", "Database Port": "数据库端口", "Database Service": "数据库服务", @@ -1904,6 +1905,7 @@ "Resource Type": "资源类型", "Resource Types": "资源类型", "Resources Synced": "资源同步", + "Restart Database Service": "重启数据库服务", "Restart Policy": "重启策略", "Restarting": "重启中", "Restore Backup": "恢复备份", diff --git a/src/pages/database/containers/Instances/actions/Restart.jsx b/src/pages/database/containers/Instances/actions/Restart.jsx new file mode 100644 index 00000000..95ec5f1d --- /dev/null +++ b/src/pages/database/containers/Instances/actions/Restart.jsx @@ -0,0 +1,53 @@ +// 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 StartAction extends ConfirmAction { + get id() { + return 'restart'; + } + + get title() { + return t('Restart Database Service'); + } + + get isDanger() { + return true; + } + + get buttonText() { + return t('Restart Database Service'); + } + + get actionName() { + return t('Restart Database Service'); + } + + get isAsyncAction() { + return true; + } + + policy = 'instance:restart'; + + allowedCheckFunc = (item) => + checkStatus(['active', 'shutoff', 'shutdown'], item); + + onSubmit = (item) => { + const { id } = item || this.item; + return globalTroveInstanceStore.restart({ id }); + }; +} diff --git a/src/pages/database/containers/Instances/actions/index.jsx b/src/pages/database/containers/Instances/actions/index.jsx index 7f531fea..9699e458 100644 --- a/src/pages/database/containers/Instances/actions/index.jsx +++ b/src/pages/database/containers/Instances/actions/index.jsx @@ -15,6 +15,7 @@ import Delete from './Delete'; import Create from './StepCreate'; import Edit from './Edit'; +import Restart from './Restart'; const actionConfigs = { rowActions: { @@ -23,6 +24,10 @@ const actionConfigs = { { action: Edit, }, + { + title: t('Database Instance Status'), + actions: [Restart], + }, ], }, primaryActions: [Create], diff --git a/src/resources/skyline/policy.js b/src/resources/skyline/policy.js index a7d9d06a..8da54a50 100644 --- a/src/resources/skyline/policy.js +++ b/src/resources/skyline/policy.js @@ -79,6 +79,7 @@ export const policyMap = { 'instance:delete', 'instance:update', 'instance:backups', + 'instance:restart', 'instance:resize', 'instance:extension', 'instance:guest_log_list', diff --git a/src/stores/trove/instances.js b/src/stores/trove/instances.js index 61105cad..94158798 100644 --- a/src/stores/trove/instances.js +++ b/src/stores/trove/instances.js @@ -42,6 +42,26 @@ export class InstancesStore extends Base { return this.client.delete(params, newbody); } + @action + update(id, body) { + return this.submitting(this.client.action(id, body)); + } + + @action + async operation({ body, id, key = '' }) { + let requestBody = body; + if (!requestBody) { + requestBody = {}; + requestBody[key] = {}; + } + return this.update(id, requestBody); + } + + @action + async restart({ id }) { + return this.operation({ key: 'restart', id }); + } + @action async listDatastores() { const result = await this.clientDatastore.list();