Skip to content
Permalink
Browse files

fix(compose): fix router logic in compose

  • Loading branch information...
hanxiao committed Jul 17, 2019
1 parent c8f9635 commit 8030feb2d975460aa17c9cd1da56f69fba7f56c1
Showing with 44 additions and 20 deletions.
  1. +22 −13 gnes/composer/base.py
  2. +2 −2 gnes/resources/static/gnes-board.html
  3. +5 −5 tests/test_compose.py
  4. +15 −0 tests/yaml/topology7.yml
@@ -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] = {
@@ -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;',
@@ -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
@@ -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
@@ -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">
@@ -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)

@@ -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)
@@ -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.
You can’t perform that action at this time.