Skip to content

Commit

Permalink
[CE-69] Let network config support more types
Browse files Browse the repository at this point in the history
Now we use a nework config class to wrap all the network related
configurations.

This new design will help support multiple network types like fabric
v0.6 and fabric v1.0.

This patchset also makes other related changes.

Change-Id: Idd9661ea3dc90515ea9be1262fc736fc2713c9d9
Signed-off-by: Baohua Yang <yangbaohua@gmail.com>
  • Loading branch information
yeasy committed Jun 26, 2017
1 parent 8f3a042 commit 269c7e2
Show file tree
Hide file tree
Showing 27 changed files with 686 additions and 549 deletions.
10 changes: 5 additions & 5 deletions api/dashboard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ paths:
and other details about each cluster, and lists the clusters in the
proper display order.
parameters:
- name: daemon_url
- name: worker_api
in: query
description: Filter clusters with specific daemon_url.
description: Filter clusters with specific worker_api.
required: false
type: string
- name: user_id
Expand Down Expand Up @@ -88,9 +88,9 @@ paths:
The endpoint create a specific cluster
The response includes necessary info.
parameters:
- name: daemon_url
- name: worker_api
in: query
description: Given the daemon_url to create at
description: Given the worker_api to create at
required: true
type: string
- name: cluster_name
Expand Down Expand Up @@ -144,7 +144,7 @@ definitions:
api_url:
type: string
description: Cluster REST URL representing the cluster.
daemon_url:
worker_api:
type: string
description: Docker host daemon url
name:
Expand Down
2 changes: 1 addition & 1 deletion api/restserver_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Accordingly, the server will return a json response (succeed or fail).
"api_url": "http://192.168.7.62:5004",
"consensus_mode": "batch",
"consensus_plugin": "pbft",
"daemon_url": "tcp://192.168.7.62:2375",
"worker_api": "tcp://192.168.7.62:2375",
"id": "576ba021414b0502864d0306",
"name": "compute2_4",
"size": 4,
Expand Down
8 changes: 4 additions & 4 deletions docs/db.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ Track the information of a Host.

A typical host may look like:

id | name | daemon_url | create_ts | capacity | status | clusters | type | log_level | log_type | log_server | autofill | schedulable
id | name | worker_api | create_ts | capacity | status | clusters | type | log_level | log_type | log_server | autofill | schedulable
---| ------ | ------------------- | -------------- | -------- | -------- | ------- | ------- | --------- | -------- | ----------- | -------- | -----------
xxx | host_0 | tcp://10.0.0.1:2375 | 20160430101010 | 20 | active | [c1,c2,c3] | single | debug | syslog | udp://10.0.0.2:5000 | true | true

* id (str): uuid of the host instance
* name (str): human-readable name
* daemon_url (str): Through which url to access the Docker/Swarm Daemon
* worker_api (str): Through which url to access the Docker/Swarm Daemon
* create_ts (datetime): When to add the host
* capacity (int): Maximum number of chains on that host
* status (str): 'active' (Can access daemon service) or 'inactive' (disconnected from daemon service)
Expand All @@ -30,7 +30,7 @@ Track information of one blockchain.

A typical cluster may look like:

id | service_url | name | user_id | host_id | daemon_url | consensus_plugin | consensus_mode | create_ts | apply_ts | release_ts | duration | size | containers | health
id | service_url | name | user_id | host_id | worker_api | consensus_plugin | consensus_mode | create_ts | apply_ts | release_ts | duration | size | containers | health
--- | --------------- | --------- | -------- | ------- | ------------------- | ---------------- | -------------- | ------------- | -------- | ---------- | ------- | ------- | ------- | ------
xxx | {} | cluster_A | "" | host_xx | tcp://10.0.0.1:2375 | pbft | batch | 20160430101010 | 20160430101010 | | | 4 | [vp0,vp1,vp2,vp3] | OK

Expand All @@ -39,7 +39,7 @@ xxx | {} | cluster_A | "" | host_xx | tcp://10.0.0.1:2375 | pbft
* name (str): human-readable name
* user_id (str): Which user occupies this chain, empty for no occupation
* host_id (str): Where the chain exists
* daemon_url (str): Through which url to access the Docker/Swarm Daemon
* worker_api (str): Through which url to access the Docker/Swarm Daemon
* consensus_plugin (str): Consensus plugin name
* consensus_mode (str): Consensus plugin mode name
* create_ts (datetime): When to create the chain
Expand Down
12 changes: 6 additions & 6 deletions scripts/update_docker_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
# SPDX-License-Identifier: Apache-2.0
#

echo "Pull yeasy/hyperledger:latest and retagging"
docker pull yeasy/hyperledger:latest && \
docker rmi hyperledger/fabric-baseimage:latest && \
docker tag yeasy/hyperledger:latest hyperledger/fabric-baseimage:latest
echo "This script will setup the docker images for master node"
echo "Pull python:3.5, mongo:3.2, mongo-express:0.30 and yeasy/nginx"

echo "Pull yeasy/hyperledger-peer:latest"
docker pull yeasy/hyperledger-peer:latest
docker pull python:3.5 \
&& docker pull mongo:3.2 \
&& docker pull mongo-express:0.30 \
&& docker pull yeasy/nginx:latest
65 changes: 26 additions & 39 deletions src/agent/docker/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
compose_restart

from common import NETWORK_TYPES, CONSENSUS_PLUGINS, \
CONSENSUS_MODES, CLUSTER_SIZES
CONSENSUS_MODES, NETWORK_SIZE_FABRIC_PRE_V1

from ..cluster_base import ClusterBase

Expand All @@ -32,9 +32,8 @@ def __init__(self):
pass

def create(self, cid, mapped_ports, host, user_id="",
fabric_version=NETWORK_TYPES[0],
consensus_plugin=CONSENSUS_PLUGINS[0],
consensus_mode=CONSENSUS_MODES[0], size=CLUSTER_SIZES[0]):
network_type=NETWORK_TYPES[0],
config=None):
""" Create a cluster based on given data
TODO: maybe need other id generation mechanism
Expand All @@ -44,54 +43,42 @@ def create(self, cid, mapped_ports, host, user_id="",
:param start_port: first service port for cluster, will generate
if not given
:param user_id: user_id of the cluster if start to be applied
:param fabric_version: fabric images version
:param consensus_plugin: type of the consensus type
:param size: size of the cluster, int type
:param network_type: fabric images version
:param config: network config
:return: Id of the created cluster or None
"""

# from now on, we should be safe

# 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=fabric_version,
consensus_plugin=consensus_plugin, consensus_mode=consensus_mode,
cluster_size=size)
if not containers or len(containers) != size:
containers = compose_up(name=cid, mapped_ports=mapped_ports, host=host,
network_type=network_type, config=None)
if not containers or len(containers) != config.size:
logger.warning("failed to create cluster, with container={}"
.format(containers))
return []
else:
return containers

def delete(self, id, daemon_url, fabric_version, consensus_plugin,
cluster_size):
return compose_clean(id, daemon_url, fabric_version,
consensus_plugin, cluster_size)

def start(self, name, daemon_url, mapped_ports, fabric_version,
consensus_plugin,
consensus_mode, log_type, log_level, log_server, cluster_size):
return compose_start(name, daemon_url, mapped_ports, fabric_version,
consensus_plugin, consensus_mode, log_type,
log_level, log_server, cluster_size)

def restart(self, name, daemon_url, mapped_ports, fabric_version,
consensus_plugin, consensus_mode, log_type, log_level,
log_server, cluster_size):
return compose_restart(name, daemon_url, mapped_ports, fabric_version,
consensus_plugin, consensus_mode, log_type,
log_level, log_server, cluster_size)

def stop(self, name, daemon_url, mapped_ports, fabric_version,
consensus_plugin, consensus_mode, log_type, log_level,
log_server, cluster_size):
return compose_stop(name, daemon_url, mapped_ports, fabric_version,
consensus_plugin,
consensus_mode, log_type, log_level, log_server,
cluster_size)
def delete(self, id, worker_api, network_type, config):
return compose_clean(id, worker_api, network_type, config)

def start(self, name, worker_api, mapped_ports, network_type,
log_type, log_level, log_server, config):
return compose_start(name, worker_api, mapped_ports, network_type,
log_type, log_level, log_server, config)

def restart(self, name, worker_api, mapped_ports, network_type,
log_type, log_level, log_server, config):
return compose_restart(name, worker_api, mapped_ports, network_type,
log_type, log_level, log_server, config)

def stop(self, name, worker_api, mapped_ports, network_type,
log_type, log_level, log_server, config):
return compose_stop(name, worker_api, mapped_ports, network_type,
log_type, log_level, log_server, config)


cluster_on_docker = ClusterOnDocker()
Loading

0 comments on commit 269c7e2

Please sign in to comment.