Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
fix(compose): fix router logic in compose
Browse files Browse the repository at this point in the history
  • Loading branch information
hanhxiao committed Jul 17, 2019
1 parent c8f9635 commit 8030feb
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 20 deletions.
35 changes: 22 additions & 13 deletions gnes/composer/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ def build_dockerswarm(all_layers: List['YamlGraph.Layer'], docker_img: str = 'gn
host_in_name = '%s%d%d' % (_c['name'], _l_idx, _c_idx)
break

args += ['--host_in %s' % host_in_name,
'--host_out %s' % host_out_name]
args += ['--host_in %s' % host_in_name]
# '--host_out %s' % host_out_name]

cmd = '%s %s' % (YamlGraph.comp2file[c['name']], ' '.join(args))
swarm_lines['services'][c_name] = {
Expand Down Expand Up @@ -266,7 +266,7 @@ def build_mermaid(all_layers: List['YamlGraph.Layer'], mermaid_leftright: bool =
# if len(last_layer.components) > 1:
# self.mermaid_graph.append('\tend')

style = ['classDef FrontendCLS fill:#FFFFCB,stroke:#277CE8,stroke-width:1px,stroke-dasharray:5;',
style = ['classDef FrontendCLS fill:#ffb347,stroke:#277CE8,stroke-width:1px,stroke-dasharray:5;',
'classDef EncoderCLS fill:#27E1E8,stroke:#277CE8,stroke-width:1px;',
'classDef IndexerCLS fill:#27E1E8,stroke:#277CE8,stroke-width:1px;',
'classDef RouterCLS fill:#2BFFCB,stroke:#277CE8,stroke-width:1px;',
Expand Down Expand Up @@ -417,20 +417,29 @@ def rule8():
'port_out': self._get_random_port()})

for c in last_layer.components:
c['socket_out'] = str(SocketType.PUSH_CONNECT)
r_c = CommentedMap({'name': 'Router',
'yaml_path': None,
'socket_in': str(SocketType.PULL_BIND),
'socket_out': str(SocketType.PUSH_CONNECT),
'port_in': self._get_random_port(),
'port_out': r['port_in']})
c['port_out'] = r_c['port_in']
router_layer.append(r_c)
last_income = self.Layer.get_value(c, 'income')
if last_income == 'sub':
c['socket_out'] = str(SocketType.PUSH_CONNECT)
r_c = CommentedMap({'name': 'Router',
'yaml_path': None,
'socket_in': str(SocketType.PULL_BIND),
'socket_out': str(SocketType.PUSH_CONNECT),
'port_in': self._get_random_port(),
'port_out': r['port_in']})
c['port_out'] = r_c['port_in']
router_layer.append(r_c)
elif last_income == 'pull':
c['socket_out'] = str(SocketType.PUSH_CONNECT)
c['port_out'] = r['port_in']

for c in layer.components:
c['socket_in'] = str(SocketType.PULL_CONNECT)
c['port_in'] = r['port_out']
router_layers.append(router_layer)

if router_layer.components:
router_layers.append(router_layer)
else:
self._num_layer -= 1

router_layer = YamlGraph.Layer(layer_id=self._num_layer)
self._num_layer += 1
Expand Down
4 changes: 2 additions & 2 deletions gnes/resources/static/gnes-board.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
</nav>
<div class="container container-wide">
<div class="row">
<div class="col-4">
<div class="col-3">
<div class="card sticky-card">
<div class="card-header">
YAML config
Expand All @@ -211,7 +211,7 @@
</div>
</div>
</div>
<div class="col-8">
<div class="col-9">
<div class="tab-content" id="pills-tabContent">

<div class="tab-pane fade show active" id="pills-flow" role="tabpanel" aria-labelledby="pills-home-tab">
Expand Down
10 changes: 5 additions & 5 deletions tests/test_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def setUp(self):
self.html_path = os.path.join(self.dirname, 'test.html')

def test_all(self):
paths = [os.path.join(self.dirname, 'yaml', 'topology%d.yml' % j) for j in range(1, 7)]
b_a = [(3, 3), (4, 4), (4, 5), (4, 7), (4, 7), (4, 9)]
paths = [os.path.join(self.dirname, 'yaml', 'topology%d.yml' % j) for j in range(1, 8)]
b_a = [(3, 3), (4, 4), (4, 5), (4, 7), (4, 6), (4, 8), (4, 9)]
for p, j in zip(paths, b_a):
self._test_topology(p, *j)

Expand All @@ -32,6 +32,6 @@ def _test_topology(self, yaml_path: str, num_layer_before: int, num_layer_after:
os.path.exists(self.html_path)
print(a.build_dockerswarm(r))

def tearDown(self):
if os.path.exists(self.html_path):
os.remove(self.html_path)
# def tearDown(self):
# if os.path.exists(self.html_path):
# os.remove(self.html_path)
15 changes: 15 additions & 0 deletions tests/yaml/topology7.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
port: 5566
services:
- name: Preprocessor
replicas: 2
- name: Encoder
replicas: 3
-
- name: Indexer
yaml_path: indexer-binary.yml
replicas: 4
income: sub
- name: Indexer
yaml_path: indexer-fulltext.yml
replicas: 3
income: sub

0 comments on commit 8030feb

Please sign in to comment.