diff --git a/src/client/trove/index.js b/src/client/trove/index.js index d9bb706e..ccf23ea0 100644 --- a/src/client/trove/index.js +++ b/src/client/trove/index.js @@ -97,6 +97,17 @@ export class TroveClient extends Base { }, ], }, + { + name: 'instancesAdmin', + key: 'mgmt/instances', + responseKey: 'instance', + extendOperations: [ + { + key: 'action', + method: 'post', + }, + ], + }, ]; } } diff --git a/src/locales/en.json b/src/locales/en.json index 9e67eb0e..114db06f 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1905,6 +1905,7 @@ "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", @@ -2136,6 +2137,7 @@ "Status Reason": "Status Reason", "Stop": "Stop", "Stop Container": "Stop Container", + "Stop Database Service": "Stop Database Service", "Stop Instance": "Stop Instance", "Stop auto refreshing data": "Stop auto refreshing data", "Stop refreshing data every {num} seconds": "Stop refreshing data every {num} seconds", diff --git a/src/locales/zh.json b/src/locales/zh.json index bd4ef03c..7320cbb0 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -1905,6 +1905,7 @@ "Resource Type": "资源类型", "Resource Types": "资源类型", "Resources Synced": "资源同步", + "Restart": "重启", "Restart Database Service": "重启数据库服务", "Restart Policy": "重启策略", "Restarting": "重启中", @@ -2136,6 +2137,7 @@ "Status Reason": "状态原因", "Stop": "关闭", "Stop Container": "关闭容器", + "Stop Database Service": "停止数据库服务", "Stop Instance": "关闭云主机", "Stop auto refreshing data": "关闭自动刷新数据", "Stop refreshing data every {num} seconds": "关闭每{num}秒自动刷新数据", diff --git a/src/pages/database/containers/Instances/actions/Restart.jsx b/src/pages/database/containers/Instances/actions/Restart.jsx index 95ec5f1d..b66bc616 100644 --- a/src/pages/database/containers/Instances/actions/Restart.jsx +++ b/src/pages/database/containers/Instances/actions/Restart.jsx @@ -30,7 +30,7 @@ export default class StartAction extends ConfirmAction { } get buttonText() { - return t('Restart Database Service'); + return t('Restart'); } get actionName() { diff --git a/src/pages/database/containers/Instances/actions/Stop.jsx b/src/pages/database/containers/Instances/actions/Stop.jsx new file mode 100644 index 00000000..d7e7c1d3 --- /dev/null +++ b/src/pages/database/containers/Instances/actions/Stop.jsx @@ -0,0 +1,52 @@ +// 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 'stop'; + } + + get title() { + return t('Stop Database Service'); + } + + get isDanger() { + return true; + } + + get buttonText() { + return t('Stop'); + } + + get actionName() { + return t('Stop Database Service'); + } + + get isAsyncAction() { + return true; + } + + policy = 'instance:stop'; + + allowedCheckFunc = (item) => checkStatus(['active'], item); + + onSubmit = (item) => { + const { id } = item || this.item; + return globalTroveInstanceStore.stop({ id }); + }; +} diff --git a/src/pages/database/containers/Instances/actions/index.jsx b/src/pages/database/containers/Instances/actions/index.jsx index 9699e458..75d3eef6 100644 --- a/src/pages/database/containers/Instances/actions/index.jsx +++ b/src/pages/database/containers/Instances/actions/index.jsx @@ -16,6 +16,7 @@ import Delete from './Delete'; import Create from './StepCreate'; import Edit from './Edit'; import Restart from './Restart'; +import Stop from './Stop'; const actionConfigs = { rowActions: { @@ -26,7 +27,7 @@ const actionConfigs = { }, { title: t('Database Instance Status'), - actions: [Restart], + actions: [Restart, Stop], }, ], }, diff --git a/src/stores/trove/instances.js b/src/stores/trove/instances.js index 94158798..dfd680e6 100644 --- a/src/stores/trove/instances.js +++ b/src/stores/trove/instances.js @@ -32,6 +32,10 @@ export class InstancesStore extends Base { return client.trove.configurations; } + get adminClient() { + return client.trove.instancesAdmin; + } + @action async create(newbody) { return this.submitting(this.client.create(newbody)); @@ -62,6 +66,11 @@ export class InstancesStore extends Base { return this.operation({ key: 'restart', id }); } + @action + async stop({ id }) { + return this.submitting(this.adminClient.action(id, { stop: {} })); + } + @action async listDatastores() { const result = await this.clientDatastore.list();