-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
Copy pathexporter.py
89 lines (68 loc) · 2.57 KB
/
exporter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import json
from jina.orchestrate.flow.base import Flow
from jina.orchestrate.deployments import Deployment
from jina.jaml import JAML
from jina.logging.predefined import default_logger
from jina.schemas import get_full_schema
from jina_cli.export import api_to_dict
def export_kubernetes(args):
"""Export to k8s yaml files
:param args: args from CLI
"""
from jina.jaml import JAMLCompatible
obj = JAMLCompatible.load_config(args.config_path)
if isinstance(obj, (Flow, Deployment)):
obj.to_kubernetes_yaml(
output_base_path=args.outpath, k8s_namespace=args.k8s_namespace
)
else:
raise NotImplementedError(
f'Object of class {obj.__class__.__name__} cannot be exported to Kubernetes'
)
def export_docker_compose(args):
"""Export to Docker compose yaml files
:param args: args from CLI
"""
from jina.jaml import JAMLCompatible
obj = JAMLCompatible.load_config(args.config_path)
if isinstance(obj, (Flow, Deployment)):
obj.to_docker_compose_yaml(
output_path=args.outpath, network_name=args.network_name
)
else:
raise NotImplementedError(
f'Object of class {obj.__class__.__name__} cannot be exported to Docker Compose'
)
def export_flowchart(args):
"""Export to flowchart file
:param args: args from CLI
"""
Flow.load_config(args.config_path).plot(
args.outpath, vertical_layout=args.vertical_layout
)
def export_schema(args):
"""Export to JSON Schemas
:param args: args from CLI
"""
from jina import __version__
if args.yaml_path:
dump_api = api_to_dict()
for yp in args.yaml_path:
f_name = (yp % __version__) if '%s' in yp else yp
with open(f_name, 'w', encoding='utf-8') as fp:
JAML.dump(dump_api, fp)
default_logger.info(f'API is exported to {f_name}')
if args.json_path:
dump_api = api_to_dict()
for jp in args.json_path:
f_name = (jp % __version__) if '%s' in jp else jp
with open(f_name, 'w', encoding='utf-8') as fp:
json.dump(dump_api, fp, sort_keys=True)
default_logger.info(f'API is exported to {f_name}')
if args.schema_path:
dump_api = get_full_schema()
for jp in args.schema_path:
f_name = (jp % __version__) if '%s' in jp else jp
with open(f_name, 'w', encoding='utf-8') as fp:
json.dump(dump_api, fp, sort_keys=True)
default_logger.info(f'API is exported to {f_name}')