Skip to content

Commit

Permalink
[CE-70] #close Fixed background service bug
Browse files Browse the repository at this point in the history
Fix create chain service
Add fabric choice in chain creation for react theme

Change-Id: I2d1f58e7c776cda5353c6d1fb6a6dabf07725b73
Signed-off-by: Haitao Yue <hightall@me.com>
  • Loading branch information
hightall committed Jun 29, 2017
1 parent bc94641 commit 4ef1854
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/agent/docker/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def create(self, cid, mapped_ports, host, user_id="",
# start compose project, failed then clean and return
logger.debug("Start compose project with name={}".format(cid))
containers = compose_up(name=cid, mapped_ports=mapped_ports, host=host,
network_type=network_type, config=None)
network_type=network_type, config=config)
if not containers or len(containers) != config.size:
logger.warning("failed to create cluster, with container={}"
.format(containers))
Expand Down
21 changes: 12 additions & 9 deletions src/agent/docker/docker_swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
CONSENSUS_PLUGINS, CONSENSUS_MODES, \
CLUSTER_LOG_TYPES, CLUSTER_LOG_LEVEL, \
NETWORK_SIZE_FABRIC_PRE_V1, \
SERVICE_PORTS
SERVICE_PORTS, NETWORK_TYPE_FABRIC_PRE_V1

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

if network_type == NETWORK_SIZE_FABRIC_PRE_V1:
if network_type == NETWORK_TYPE_FABRIC_PRE_V1:
envs = {
'DOCKER_HOST': worker_api,
'COMPOSE_PROJECT_NAME': name,
'COMPOSE_FILE': "cluster-{}.yml".format(config['_size']),
'COMPOSE_FILE': "cluster-{}.yml".format(config['size']),
'VM_ENDPOINT': worker_api,
'VM_DOCKER_HOSTCONFIG_NETWORKMODE':
CLUSTER_NETWORK + "_{}".format(config['consensus_plugin']),
Expand Down Expand Up @@ -357,23 +357,26 @@ def compose_up(name, host, mapped_ports, network_type=NETWORK_TYPES[0],
"""

logger.debug(
"Compose start: name={}, host={}, mapped_port={}, config={}".format(
name, host.get("name"), mapped_ports, config.getdata()))
"Compose start: name={}, host={}, mapped_port={},"
"config={} network_type={}".format(
name, host.get("name"), mapped_ports,
config.get_data(), network_type))
worker_api, log_type, log_server, log_level = \
host.get("worker_api"), host.get("log_type"), host.get("log_server"), \
host.get("log_level")
if log_type != CLUSTER_LOG_TYPES[0]: # not local
os.environ['SYSLOG_SERVER'] = log_server

_compose_set_env(name, worker_api, mapped_ports, network_type,
config, log_level, log_type, log_server)
log_level, log_type, log_server, config)

try:
project = get_project(COMPOSE_FILE_PATH +
"/{}/".format(network_type) + log_type)
template_path = COMPOSE_FILE_PATH + "/{}/".\
format(network_type) + log_type
project = get_project(template_path)
containers = project.up(detached=True, timeout=timeout)
except Exception as e:
logger.warning("Exception when compose start={}".format(e))
logger.warning("Exception when compose start={}".format(e.message))
return {}
if not containers or config['size'] != len(containers):
return {}
Expand Down
9 changes: 5 additions & 4 deletions src/resources/cluster_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,18 @@ def cluster_create():
logger.warning(error_msg)
return make_fail_resp(error=error_msg, data=r.form)

name, host_id, network_type = \
r.form['name'], r.form['host_id'], r.form['network_type']
name, host_id, network_type, size = \
r.form['name'], r.form['host_id'],\
r.form['network_type'], int(r.form['size'])

if network_type == NETWORK_TYPE_FABRIC_PRE_V1:
config = FabricPreNetworkConfig(
consensus_plugin=r.form['consensus_plugin'],
consensus_mode=r.form['consensus_mode'],
size=r.form['size'])
size=size)
elif network_type == NETWORK_TYPE_FABRIC_V1:
config = FabricV1NetworkConfig(
size=r.form['size']) # TODO: add more variables
size=size) # TODO: add more variables
else:
error_msg = "Unknown network_type={}".format(network_type)
logger.warning(error_msg)
Expand Down
1 change: 1 addition & 0 deletions src/themes/react/static/js/models/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export default {
} else {
message.error('create chain failed')
}
yield call(payload.callback, false);
},
*deleteCluster({payload}, {call, put}) {
const data = yield call(deleteCluster, payload)
Expand Down
2 changes: 1 addition & 1 deletion src/themes/react/static/js/models/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default {
subscriptions: {
setup({dispatch, history}) {
history.listen(location => {
if (location.pathname === '/hosts' || location.pathname === '/chains/active') {
if (location.pathname === '/hosts' || location.pathname === '/chains') {
dispatch({type: 'getHosts'})
}
})
Expand Down
33 changes: 31 additions & 2 deletions src/themes/react/static/js/routes/cluster/active/ClusterModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class ClusterModal extends React.Component {
pluginType: value
})
}
setPosting = (value) => {
this.setState({
posting: value
})
}
handleOk() {
const {
onOk,
Expand All @@ -44,8 +49,13 @@ class ClusterModal extends React.Component {
this.setState({
posting: true
});
values.consensus_mode = "batch"
onOk(values)
values.consensus_mode = "batch";
values.network_type = values.fabric_version;
const data = {
...values,
callback: this.setPosting
}
onOk(data)
}
})
}
Expand Down Expand Up @@ -82,6 +92,11 @@ class ClusterModal extends React.Component {
const hostsOptions = hosts.map((host, i) =>
<Option value={host.id}>{host.name}</Option>
)
const defaultHostValue = hosts.length ? hosts[0].id : '';
const fabricVersions = ["fabric-0.6", "fabric-1.0"];
const fabricVersionOptions = fabricVersions.map((fabricVersion, i) =>
<Option value={fabricVersion}>{fabricVersion}</Option>
)
return (
<Modal {...modalOpts}>
<Form layout="horizontal">
Expand All @@ -97,6 +112,7 @@ class ClusterModal extends React.Component {
</FormItem>
<FormItem label="Host" hasFeedback {...formItemLayout}>
{getFieldDecorator('host_id', {
initialValue: defaultHostValue,
rules: [
{
required: true,
Expand All @@ -107,6 +123,19 @@ class ClusterModal extends React.Component {
{hostsOptions}
</Select>)}
</FormItem>
<FormItem label="Fabric Version" hasFeedback {...formItemLayout}>
{getFieldDecorator('fabric_version', {
initialValue: fabricVersions[0],
rules: [
{
required: true,
message: 'Must select fabric version',
},
],
})(<Select>
{fabricVersionOptions}
</Select>)}
</FormItem>
<FormItem label="Chain Size" hasFeedback {...formItemLayout}>
{getFieldDecorator('size', {
initialValue: 7,
Expand Down

0 comments on commit 4ef1854

Please sign in to comment.