Skip to content
Permalink
Browse files

fix(compose): fix composer logic

  • Loading branch information...
hanxiao committed Jul 17, 2019
1 parent 7f3b2fb commit 599a3c3dc4558bc34901189e54561e0f74bc2c19
Showing with 37 additions and 8 deletions.
  1. +33 −4 gnes/composer/base.py
  2. +4 −4 tests/test_compose.py
@@ -177,7 +177,7 @@ def build_dockerswarm(all_layers: List['YamlGraph.Layer'], docker_img: str = 'gn
break

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

cmd = '%s %s' % (YamlGraph.comp2file[c['name']], ' '.join(args))
swarm_lines['services'][c_name] = {
@@ -366,13 +366,15 @@ def rule6():
router_layer = YamlGraph.Layer(layer_id=self._num_layer)
self._num_layer += 1
for c in layer.components:
income = self.Layer.get_value(c, 'income')
r = CommentedMap({'name': 'Router',
'yaml_path': None,
'socket_in': str(SocketType.SUB_CONNECT),
'socket_out': str(SocketType.PUSH_BIND),
'socket_out': str(SocketType.PUSH_BIND) if income == 'pull' else str(
SocketType.PUB_BIND),
'port_in': last_layer.components[0]['port_out'],
'port_out': self._get_random_port()})
c['socket_in'] = str(SocketType.PULL_CONNECT)
c['socket_in'] = str(SocketType.PULL_CONNECT) if income == 'pull' else str(SocketType.SUB_CONNECT)
c['port_in'] = r['port_out']
router_layer.append(r)
router_layers.append(router_layer)
@@ -395,6 +397,8 @@ def rule7():
router_layer = YamlGraph.Layer(layer_id=self._num_layer)
self._num_layer += 1
for c in layer.components:
income = self.Layer.get_value(c, 'income')

r = CommentedMap({'name': 'Router',
'yaml_path': None,
'socket_in': str(SocketType.SUB_CONNECT),
@@ -406,6 +410,25 @@ def rule7():
router_layer.append(r)
router_layers.append(router_layer)

def rule10():
last_layer.components[0]['socket_out'] = str(SocketType.PUSH_CONNECT)

router_layer = YamlGraph.Layer(layer_id=self._num_layer)
self._num_layer += 1
r0 = CommentedMap({'name': 'Router',
'yaml_path': None,
'socket_in': str(SocketType.PULL_BIND),
'socket_out': str(SocketType.PUB_BIND),
'port_in': self._get_random_port(),
'port_out': self._get_random_port()})
router_layer.append(r0)
router_layers.append(router_layer)
last_layer.components[0]['port_out'] = r0['port_in']

for c in layer.components:
c['socket_in'] = str(SocketType.SUB_CONNECT)
c['port_in'] = r0['port_out']

def rule8():
last_layer.components[0]['socket_out'] = str(SocketType.PUSH_CONNECT)
router_layer = YamlGraph.Layer(layer_id=self._num_layer)
@@ -501,7 +524,13 @@ def rule9():
# (N)-to-(1)&(1)&(1)
rule5()
else:
rule7()
income = self.Layer.get_value(layer.components[0], 'income')
if income == 'pull':
rule7()
elif income == 'sub':
rule10()
else:
raise NotImplementedError('replica type: %s is not recognized!' % last_income)
elif last_layer.is_heto_single_component:
rule3()
else:
@@ -12,7 +12,7 @@ def setUp(self):

def test_all(self):
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)]
b_a = [(3, 3), (4, 4), (4, 5), (4, 7), (4, 6), (4, 8), (4, 8)]
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 comments on commit 599a3c3

Please sign in to comment.
You can’t perform that action at this time.