Skip to content

Commit 4ef1854

Browse files
committed
[CE-70] #close Fixed background service bug
Fix create chain service Add fabric choice in chain creation for react theme Change-Id: I2d1f58e7c776cda5353c6d1fb6a6dabf07725b73 Signed-off-by: Haitao Yue <hightall@me.com>
1 parent bc94641 commit 4ef1854

File tree

6 files changed

+51
-17
lines changed

6 files changed

+51
-17
lines changed

src/agent/docker/cluster.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def create(self, cid, mapped_ports, host, user_id="",
5454
# start compose project, failed then clean and return
5555
logger.debug("Start compose project with name={}".format(cid))
5656
containers = compose_up(name=cid, mapped_ports=mapped_ports, host=host,
57-
network_type=network_type, config=None)
57+
network_type=network_type, config=config)
5858
if not containers or len(containers) != config.size:
5959
logger.warning("failed to create cluster, with container={}"
6060
.format(containers))

src/agent/docker/docker_swarm.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
CONSENSUS_PLUGINS, CONSENSUS_MODES, \
2222
CLUSTER_LOG_TYPES, CLUSTER_LOG_LEVEL, \
2323
NETWORK_SIZE_FABRIC_PRE_V1, \
24-
SERVICE_PORTS
24+
SERVICE_PORTS, NETWORK_TYPE_FABRIC_PRE_V1
2525

2626
COMPOSE_FILE_PATH = os.getenv("COMPOSE_FILE_PATH",
2727
"./agent/docker/_compose_files")
@@ -318,11 +318,11 @@ def _compose_set_env(name, worker_api, mapped_ports=SERVICE_PORTS,
318318
log_type=CLUSTER_LOG_TYPES[0], log_server="",
319319
config=None):
320320

321-
if network_type == NETWORK_SIZE_FABRIC_PRE_V1:
321+
if network_type == NETWORK_TYPE_FABRIC_PRE_V1:
322322
envs = {
323323
'DOCKER_HOST': worker_api,
324324
'COMPOSE_PROJECT_NAME': name,
325-
'COMPOSE_FILE': "cluster-{}.yml".format(config['_size']),
325+
'COMPOSE_FILE': "cluster-{}.yml".format(config['size']),
326326
'VM_ENDPOINT': worker_api,
327327
'VM_DOCKER_HOSTCONFIG_NETWORKMODE':
328328
CLUSTER_NETWORK + "_{}".format(config['consensus_plugin']),
@@ -357,23 +357,26 @@ def compose_up(name, host, mapped_ports, network_type=NETWORK_TYPES[0],
357357
"""
358358

359359
logger.debug(
360-
"Compose start: name={}, host={}, mapped_port={}, config={}".format(
361-
name, host.get("name"), mapped_ports, config.getdata()))
360+
"Compose start: name={}, host={}, mapped_port={},"
361+
"config={} network_type={}".format(
362+
name, host.get("name"), mapped_ports,
363+
config.get_data(), network_type))
362364
worker_api, log_type, log_server, log_level = \
363365
host.get("worker_api"), host.get("log_type"), host.get("log_server"), \
364366
host.get("log_level")
365367
if log_type != CLUSTER_LOG_TYPES[0]: # not local
366368
os.environ['SYSLOG_SERVER'] = log_server
367369

368370
_compose_set_env(name, worker_api, mapped_ports, network_type,
369-
config, log_level, log_type, log_server)
371+
log_level, log_type, log_server, config)
370372

371373
try:
372-
project = get_project(COMPOSE_FILE_PATH +
373-
"/{}/".format(network_type) + log_type)
374+
template_path = COMPOSE_FILE_PATH + "/{}/".\
375+
format(network_type) + log_type
376+
project = get_project(template_path)
374377
containers = project.up(detached=True, timeout=timeout)
375378
except Exception as e:
376-
logger.warning("Exception when compose start={}".format(e))
379+
logger.warning("Exception when compose start={}".format(e.message))
377380
return {}
378381
if not containers or config['size'] != len(containers):
379382
return {}

src/resources/cluster_api.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,18 @@ def cluster_create():
220220
logger.warning(error_msg)
221221
return make_fail_resp(error=error_msg, data=r.form)
222222

223-
name, host_id, network_type = \
224-
r.form['name'], r.form['host_id'], r.form['network_type']
223+
name, host_id, network_type, size = \
224+
r.form['name'], r.form['host_id'],\
225+
r.form['network_type'], int(r.form['size'])
225226

226227
if network_type == NETWORK_TYPE_FABRIC_PRE_V1:
227228
config = FabricPreNetworkConfig(
228229
consensus_plugin=r.form['consensus_plugin'],
229230
consensus_mode=r.form['consensus_mode'],
230-
size=r.form['size'])
231+
size=size)
231232
elif network_type == NETWORK_TYPE_FABRIC_V1:
232233
config = FabricV1NetworkConfig(
233-
size=r.form['size']) # TODO: add more variables
234+
size=size) # TODO: add more variables
234235
else:
235236
error_msg = "Unknown network_type={}".format(network_type)
236237
logger.warning(error_msg)

src/themes/react/static/js/models/cluster.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export default {
5858
} else {
5959
message.error('create chain failed')
6060
}
61+
yield call(payload.callback, false);
6162
},
6263
*deleteCluster({payload}, {call, put}) {
6364
const data = yield call(deleteCluster, payload)

src/themes/react/static/js/models/host.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default {
2222
subscriptions: {
2323
setup({dispatch, history}) {
2424
history.listen(location => {
25-
if (location.pathname === '/hosts' || location.pathname === '/chains/active') {
25+
if (location.pathname === '/hosts' || location.pathname === '/chains') {
2626
dispatch({type: 'getHosts'})
2727
}
2828
})

src/themes/react/static/js/routes/cluster/active/ClusterModal.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class ClusterModal extends React.Component {
2828
pluginType: value
2929
})
3030
}
31+
setPosting = (value) => {
32+
this.setState({
33+
posting: value
34+
})
35+
}
3136
handleOk() {
3237
const {
3338
onOk,
@@ -44,8 +49,13 @@ class ClusterModal extends React.Component {
4449
this.setState({
4550
posting: true
4651
});
47-
values.consensus_mode = "batch"
48-
onOk(values)
52+
values.consensus_mode = "batch";
53+
values.network_type = values.fabric_version;
54+
const data = {
55+
...values,
56+
callback: this.setPosting
57+
}
58+
onOk(data)
4959
}
5060
})
5161
}
@@ -82,6 +92,11 @@ class ClusterModal extends React.Component {
8292
const hostsOptions = hosts.map((host, i) =>
8393
<Option value={host.id}>{host.name}</Option>
8494
)
95+
const defaultHostValue = hosts.length ? hosts[0].id : '';
96+
const fabricVersions = ["fabric-0.6", "fabric-1.0"];
97+
const fabricVersionOptions = fabricVersions.map((fabricVersion, i) =>
98+
<Option value={fabricVersion}>{fabricVersion}</Option>
99+
)
85100
return (
86101
<Modal {...modalOpts}>
87102
<Form layout="horizontal">
@@ -97,6 +112,7 @@ class ClusterModal extends React.Component {
97112
</FormItem>
98113
<FormItem label="Host" hasFeedback {...formItemLayout}>
99114
{getFieldDecorator('host_id', {
115+
initialValue: defaultHostValue,
100116
rules: [
101117
{
102118
required: true,
@@ -107,6 +123,19 @@ class ClusterModal extends React.Component {
107123
{hostsOptions}
108124
</Select>)}
109125
</FormItem>
126+
<FormItem label="Fabric Version" hasFeedback {...formItemLayout}>
127+
{getFieldDecorator('fabric_version', {
128+
initialValue: fabricVersions[0],
129+
rules: [
130+
{
131+
required: true,
132+
message: 'Must select fabric version',
133+
},
134+
],
135+
})(<Select>
136+
{fabricVersionOptions}
137+
</Select>)}
138+
</FormItem>
110139
<FormItem label="Chain Size" hasFeedback {...formItemLayout}>
111140
{getFieldDecorator('size', {
112141
initialValue: 7,

0 commit comments

Comments
 (0)