Skip to content
Permalink
Browse files

fix(compose): accept parser argument only

  • Loading branch information...
hanxiao committed Jul 19, 2019
1 parent 887d89c commit 63c4515ff96fdb9f354cd935ded21b1db691a037
Showing with 13 additions and 4 deletions.
  1. +13 −4 gnes/composer/base.py
@@ -10,6 +10,9 @@
from termcolor import colored

from .. import __version__
from ..cli.parser import set_grpc_frontend_parser, \
set_router_service_parser, set_loadable_service_parser, set_preprocessor_service_parser, \
set_indexer_service_parser
from ..helper import set_logger
from ..service.base import SocketType

@@ -25,6 +28,14 @@ class YamlGraph:
'Preprocessor': 'preprocess'
}

comp2args = {
'Encoder': set_loadable_service_parser().parse_args(),
'Router': set_router_service_parser().parse_args(),
'Indexer': set_indexer_service_parser().parse_args(),
'gRPCFrontend': set_grpc_frontend_parser().parse_args(),
'Preprocessor': set_preprocessor_service_parser().parse_args()
}

class Layer:
default_values = {
'name': None,
@@ -142,13 +153,12 @@ def build_dockerswarm(all_layers: List['YamlGraph.Layer'], docker_img: str = 'gn
volumes: Dict = None, networks: Dict = None) -> str:
with resource_stream('gnes', '/'.join(('resources', 'compose', 'gnes-swarm.yml'))) as r:
swarm_lines = _yaml.load(r)
taboo = {'name', 'replicas', 'yaml_path'}
config_dict = {}
for l_idx, layer in enumerate(all_layers):
for c_idx, c in enumerate(layer.components):
c_name = '%s%d%d' % (c['name'], l_idx, c_idx)
args = ['--%s %s' % (a, str(v) if ' ' not in str(v) else ('"%s"' % str(v))) for a, v in c.items() if
a not in taboo and v]
a in YamlGraph.comp2args[c['name']] and v]
if 'yaml_path' in c and c['yaml_path'] is not None:
args.append('--yaml_path /%s_yaml' % c_name)
config_dict['%s_yaml' % c_name] = {'file': c['yaml_path']}
@@ -219,7 +229,6 @@ def build_kubernetes(all_layers: List['YamlGraph.Layer'], *args, **kwargs):
@staticmethod
def build_shell(all_layers: List['YamlGraph.Layer'], log_redirect: str = None) -> str:
shell_lines = []
taboo = {'name', 'replicas'}
for layer in all_layers:
for c in layer.components:
rep_c = YamlGraph.Layer.get_value(c, 'replicas')
@@ -229,7 +238,7 @@ def build_shell(all_layers: List['YamlGraph.Layer'], log_redirect: str = None) -
cmd = YamlGraph.comp2file[c['name']]
args = ' '.join(
['--%s %s' % (a, str(v) if ' ' not in str(v) else ('"%s"' % str(v))) for a, v in c.items() if
a not in taboo and v])
a in YamlGraph.comp2args[c['name']] and v])
shell_lines.append('gnes %s %s %s &' % (
cmd, args, '>> %s 2>&1' % log_redirect if log_redirect else ''))

0 comments on commit 63c4515

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