Skip to content

Commit

Permalink
[CE-349] Add fillup,reset,clean,update operation
Browse files Browse the repository at this point in the history
Support fillup,reset,clean,update operation.
Support json & form format for host operate & update api.

Change-Id: Ic76b807c66a813eab5f61466ef30a175f7b43aff
Signed-off-by: Haitao Yue <hightall@me.com>
  • Loading branch information
hightall committed Apr 24, 2018
1 parent 3c5d7b8 commit 250d693
Show file tree
Hide file tree
Showing 8 changed files with 279 additions and 40 deletions.
30 changes: 19 additions & 11 deletions src/resources/host_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,20 @@ def host_create():
@bp_host_api.route('/host', methods=['PUT'])
def host_update():
request_debug(r, logger)
if "id" not in r.form:
if r.content_type.startswith("application/json"):
body = dict(r.get_json(force=True, silent=True))
else:
body = r.form
if "id" not in body:
error_msg = "host PUT without enough data"
logger.warning(error_msg)
return make_fail_resp(error=error_msg,
data=r.form)
data=body)
else:
id, d = r.form["id"], {}
for k in r.form:
id, d = body["id"], {}
for k in body:
if k != "id":
d[k] = r.form.get(k)
d[k] = body.get(k)
result = host_handler.update(id, d)
if result:
logger.debug("host PUT successfully")
Expand Down Expand Up @@ -225,13 +229,17 @@ def host_delete():
def host_actions():
logger.info("/host_op, method=" + r.method)
request_debug(r, logger)
if r.content_type.startswith("application/json"):
body = dict(r.get_json(force=True, silent=True))
else:
body = r.form

host_id, action = r.form['id'], r.form['action']
host_id, action = body['id'], body['action']
if not host_id or not action:
error_msg = "host POST without enough data"
logger.warning(error_msg)
return make_fail_resp(error=error_msg,
data=r.form)
data=body)
else:
if action == "fillup":
if host_handler.fillup(host_id):
Expand All @@ -240,15 +248,15 @@ def host_actions():
else:
error_msg = "Failed to fillup the host."
logger.warning(error_msg)
return make_fail_resp(error=error_msg, data=r.form)
return make_fail_resp(error=error_msg, data=body)
elif action == "clean":
if host_handler.clean(host_id):
logger.debug("clean successfully")
return make_ok_resp()
else:
error_msg = "Failed to clean the host."
logger.warning(error_msg)
return make_fail_resp(error=error_msg, data=r.form)
return make_fail_resp(error=error_msg, data=body)
elif action == "reset":
if host_handler.reset(host_id):
logger.debug("reset successfully")
Expand All @@ -263,8 +271,8 @@ def host_actions():
else:
error_msg = "Failed to reset the host."
logger.warning(error_msg)
return make_fail_resp(error=error_msg, data=r.form)
return make_fail_resp(error=error_msg, data=body)

error_msg = "unknown host action={}".format(action)
logger.warning(error_msg)
return make_fail_resp(error=error_msg, data=r.form)
return make_fail_resp(error=error_msg, data=body)
4 changes: 4 additions & 0 deletions src/themes/react/static/dashboard/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
"prop": "ignore"
}
],
"no-param-reassign": [
"error",
{ "props": false }
],
"no-else-return": [0],
"no-restricted-syntax": [0],
"import/no-extraneous-dependencies": [0],
Expand Down
12 changes: 12 additions & 0 deletions src/themes/react/static/dashboard/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,17 @@
"Host.Label.CreateTime": "Create Time",
"Host.Label.Type": "Type",
"Host.Label.Capacity": "Capacity",
"Host.Label.RunningChains": "Running Chains",
"Host.Messages.Operate.Success.FillUp": "Fill Up host {name} successfully.",
"Host.Messages.Operate.Success.Clean": "Clean host {name} successfully.",
"Host.Messages.Operate.Success.Reset": "Reset host {name} successfully.",
"Host.Messages.Operate.Success.Update": "Update host successfully",
"Host.Button.Add": "Add",
"Host.Button.Delete": "Delete",
"Host.Button.FillUp": "Fill Up",
"Host.Button.Clean": "Clean",
"Host.Button.Reset": "Reset",
"Host.Button.Edit": "Edit",
"Host.Button.More": "More",
"Host.Message.Confirm.DeleteHost": "Do you want to delete host {name}?",
"Messages.RequestError": "Request Error",
Expand All @@ -32,6 +41,9 @@
"Messages.HttpStatus.502": "Bad gateway.",
"Messages.HttpStatus.503": "The service is unavailable and the server is temporarily overloaded or maintained.",
"Messages.HttpStatus.504": "Gateway timeout.",
"Host.Create.Title": "Create New Host",
"Host.Create.UpdateTitle": "Update Host",
"Host.Create.SubTitle": "Here you can create multiple type host, for creating fabric cluster.",
"Host.Create.Validate.Error.WorkerApi": "Please input validate daemon url.",
"Host.Create.Validate.Required.Name": "Please input name.",
"Host.Create.Validate.Required.DaemonUrl": "Please input daemon url.",
Expand Down
12 changes: 12 additions & 0 deletions src/themes/react/static/dashboard/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,17 @@
"Host.Label.CreateTime": "创建时间",
"Host.Label.Type": "类型",
"Host.Label.Capacity": "容量",
"Host.Label.RunningChains": "已运行链",
"Host.Messages.Operate.Success.FillUp": "填充主机 {name} 成功。",
"Host.Messages.Operate.Success.Clean": "清空主机 {name} 成功。",
"Host.Messages.Operate.Success.Reset": "重置主机 {name} 成功。",
"Host.Messages.Operate.Success.Update": "更新主机成功。",
"Host.Button.Add": "添加",
"Host.Button.Delete": "删除",
"Host.Button.FillUp": "填充",
"Host.Button.Clean": "清空",
"Host.Button.Reset": "重置",
"Host.Button.Edit": "编辑",
"Host.Button.More": "更多",
"Host.Message.Confirm.DeleteHost": "是否确认删除主机 {name}?",
"Messages.RequestError": "请求错误",
Expand All @@ -32,6 +41,9 @@
"Messages.HttpStatus.502": "网关错误。",
"Messages.HttpStatus.503": "服务不可用,服务器暂时过载或维护。",
"Messages.HttpStatus.504": "网关超时。",
"Host.Create.UpdateTitle": "更新主机",
"Host.Create.Title": "创建新的主机",
"Host.Create.SubTitle": "在这里你可以创建多种类型的主机, 用来创建Fabric集群。",
"Host.Create.Validate.Error.WorkerApi": "请输入有效的地址。",
"Host.Create.Validate.Required.Name": "请输入名称。",
"Host.Create.Validate.Required.DaemonUrl": "请输入地址。",
Expand Down
57 changes: 56 additions & 1 deletion src/themes/react/static/dashboard/src/models/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,40 @@
SPDX-License-Identifier: Apache-2.0
*/
import { routerRedux } from 'dva/router';
import { queryHosts, createHost, deleteHost } from '../services/host';
import { IntlProvider, defineMessages } from 'react-intl';
import { message } from 'antd';
import { queryHosts, createHost, deleteHost, operateHost, updateHost } from '../services/host';
import { getLocale } from '../utils/utils';

const currentLocale = getLocale();
const intlProvider = new IntlProvider(
{ locale: currentLocale.locale, messages: currentLocale.messages },
{}
);
const { intl } = intlProvider.getChildContext();

const messages = defineMessages({
operate: {
success: {
fillup: {
id: 'Host.Messages.Operate.Success.FillUp',
defaultMessage: '填充主机 {name} 成功。',
},
clean: {
id: 'Host.Messages.Operate.Success.Clean',
defaultMessage: '清空主机 {name} 成功。',
},
reset: {
id: 'Host.Messages.Operate.Success.Reset',
defaultMessage: '重置主机 {name} 成功。',
},
update: {
id: 'Host.Messages.Operate.Success.Update',
defaultMessage: '更新主机成功。',
},
},
},
});

export default {
namespace: 'host',
Expand Down Expand Up @@ -36,6 +69,28 @@ export default {
type: 'fetchHosts',
});
},
*operateHost({ payload }, { call, put }) {
const response = yield call(operateHost, payload);
yield put({
type: 'fetchHosts',
});
if (response.code === 200) {
const values = { name: payload.name };
message.success(intl.formatMessage(messages.operate.success[payload.action], values));
}
},
*updateHost({ payload }, { call, put }) {
const response = yield call(updateHost, payload);
if (response.code === 200) {
message.success(intl.formatMessage(messages.operate.success.update));
yield put(
routerRedux.push({
pathname: '/host',
})
);
}
yield call(payload.callback);
},
},

reducers: {
Expand Down
Loading

0 comments on commit 250d693

Please sign in to comment.