Skip to content

Commit 5f4c6cc

Browse files
authored
Merge pull request #36 from dwolfson/v.5.0
Updated the widgets and added a first cli
2 parents ab04bf5 + f6e3d69 commit 5f4c6cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1186
-212
lines changed

examples/widgets/catalog_user/get_asset_graph.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import os
1010
import sys
1111

12-
from rich import print
1312
from rich.console import Console
1413
from rich.markdown import Markdown
1514
from rich.panel import Panel
@@ -35,6 +34,7 @@
3534
EGERIA_USER_PASSWORD = os.environ.get('EGERIA_USER_PASSWORD', 'secret')
3635

3736
disable_ssl_warnings = True
37+
3838
console = Console(width=200)
3939

4040

@@ -89,8 +89,6 @@ def build_nested_elements(nested_element: dict) -> Markdown:
8989

9090
try:
9191

92-
console = Console(width=200)
93-
9492
a_client = AssetCatalog(server_name, platform_url,
9593
user_id=user)
9694

@@ -146,6 +144,7 @@ def build_nested_elements(nested_element: dict) -> Markdown:
146144
f"* Asset Origin: {asset_origin}\n{prop_md}\n"
147145
)
148146
core_md = Markdown(core_md)
147+
149148
p1 = Panel.fit(core_md, style = "bold bright_white")
150149
l2 = tree.add(p1)
151150
if asset_class_md is not None:
@@ -225,9 +224,9 @@ def build_nested_elements(nested_element: dict) -> Markdown:
225224
relationship_panel = Panel.fit(Markdown(relationship_md), style="bold bright_white", title = "Asset Relationships")
226225
tree.add(relationship_panel)
227226

228-
229-
print("\n\n")
230-
print(tree)
227+
with console.screen():
228+
print("\n\n")
229+
print(tree)
231230

232231
except (
233232
InvalidParameterException,
@@ -250,9 +249,12 @@ def main():
250249
url = args.url if args.url is not None else EGERIA_PLATFORM_URL
251250
userid = args.userid if args.userid is not None else EGERIA_USER
252251
user_pass = args.password if args.password is not None else EGERIA_USER_PASSWORD
253-
254-
asset_guid = Prompt.ask("Enter the Asset GUID to view:", default="")
255-
asset_viewer(asset_guid,server, url, userid, user_pass)
252+
try:
253+
asset_guid = Prompt.ask("Enter the Asset GUID to view:", default="")
254+
asset_viewer(asset_guid,server, url, userid, user_pass)
255+
except (KeyboardInterrupt) as e:
256+
# console.print_exception()
257+
pass
256258

257259
if __name__ == "__main__":
258260
main()

examples/widgets/catalog_user/get_collection.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ def main():
8787
userid = args.userid if args.userid is not None else EGERIA_USER
8888
user_pass = args.password if args.password is not None else EGERIA_USER_PASSWORD
8989

90-
root_collection = Prompt.ask("Enter the Root Collection to start from:", default="Root Sustainability Collection")
91-
collection_viewer(root_collection, server, url, userid, user_pass)
92-
90+
try:
91+
root_collection = Prompt.ask("Enter the Root Collection to start from:", default="Root Sustainability Collection")
92+
collection_viewer(root_collection, server, url, userid, user_pass)
93+
except (KeyboardInterrupt):
94+
pass
9395
if __name__ == "__main__":
9496
main()

examples/widgets/operational/get_tech_type_elements.py renamed to examples/widgets/catalog_user/get_tech_type_elements.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,12 @@ def main():
142142
url = args.url if args.url is not None else EGERIA_PLATFORM_URL
143143
userid = args.userid if args.userid is not None else EGERIA_USER
144144
user_pass = args.password if args.password is not None else EGERIA_USER_PASSWORD
145+
try:
146+
tech_name = Prompt.ask("Enter the Asset Name to view:", default="Apache Kafka Server")
147+
tech_viewer(tech_name,server, url, userid, user_pass)
148+
except (KeyboardInterrupt):
149+
pass
145150

146-
tech_name = Prompt.ask("Enter the Asset Name to view:", default="Apache Kafka Server")
147-
tech_viewer(tech_name,server, url, userid, user_pass)
148151

149152
if __name__ == "__main__":
150153
main()

examples/widgets/operational/get_tech_type_template.py renamed to examples/widgets/catalog_user/get_tech_type_template.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,12 @@ def main():
135135
userid = args.userid if args.userid is not None else EGERIA_USER
136136
user_pass = args.password if args.password is not None else EGERIA_USER_PASSWORD
137137

138-
tech_name = Prompt.ask("Enter the Asset Name to view:", default="Apache Kafka Server")
139-
tech_viewer(tech_name,server, url, userid, user_pass)
138+
try:
139+
tech_name = Prompt.ask("Enter the Asset Name to view:", default="Apache Kafka Server")
140+
tech_viewer(tech_name,server, url, userid, user_pass)
141+
except(KeyboardInterrupt):
142+
pass
143+
140144

141145
if __name__ == "__main__":
142146
main()

examples/widgets/catalog_user/list_assets.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,10 @@ def main():
139139
userid = args.userid if args.userid is not None else EGERIA_USER
140140
user_pass = args.password if args.password is not None else EGERIA_USER_PASSWORD
141141
time_out = args.time_out if args.time_out is not None else 60
142-
143-
search_string = Prompt.ask("Enter an asset search string:", default="")
144-
display_assets(search_string, server, url, userid, user_pass, time_out)
145-
142+
try:
143+
search_string = Prompt.ask("Enter an asset search string:", default="")
144+
display_assets(search_string, server, url, userid, user_pass, time_out)
145+
except(KeyboardInterrupt):
146+
pass
146147
if __name__ == "__main__":
147148
main()

examples/widgets/catalog_user/list_glossary.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,10 @@ def main():
125125
guid = args.guid if args.guid is not None else None
126126
guid = sus_guid if args.sustainability else None
127127

128-
search_string = Prompt.ask("Enter the term you are searching for:", default="*")
129-
display_glossary_terms(search_string, guid,server, url, userid, user_pass)
130-
128+
try:
129+
search_string = Prompt.ask("Enter the term you are searching for:", default="*")
130+
display_glossary_terms(search_string, guid,server, url, userid, user_pass)
131+
except(KeyboardInterrupt):
132+
pass
131133
if __name__ == "__main__":
132134
main()

examples/widgets/cli/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .ops_config import Config

examples/widgets/cli/egeria_ops.py

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
#!/usr/bin/env python3
2+
"""
3+
SPDX-License-Identifier: Apache-2.0
4+
Copyright Contributors to the ODPi Egeria project.
5+
6+
7+
A command line interface for Egeria operations.
8+
9+
This is an emerging capability based on the **click** package. Feedback welcome!
10+
11+
"""
12+
import click
13+
from trogon import tui
14+
# from pyegeria import ServerOps
15+
from examples.widgets.cli.ops_config import Config
16+
from examples.widgets.operational.monitor_gov_eng_status import display_gov_eng_status
17+
from examples.widgets.operational.monitor_server_status import display_status as s_display_status
18+
from examples.widgets.operational.monitor_server_list import display_status as display_list
19+
from examples.widgets.operational.monitor_integ_daemon_status import display_integration_daemon_status
20+
from examples.widgets.operational.monitor_platform_status import display_status as p_display_status
21+
from examples.widgets.operational.monitor_engine_activity import display_engine_activity
22+
from examples.widgets.operational.refresh_integration_daemon import refresh_connector
23+
from examples.widgets.operational.restart_integration_daemon import restart_connector
24+
from examples.widgets.operational.integration_daemon_actions import (add_catalog_target,remove_catalog_target,
25+
update_catalog_target, stop_server, start_server)
26+
27+
from examples.widgets.operational.list_catalog_targets import display_catalog_targets
28+
# class Config(object):
29+
# def __init__(self, server: str = None, url: str = None, userid:str = None, password:str = None,
30+
# timeout:int = 30, paging: bool = False):
31+
# self.server = server
32+
# self.url = url
33+
# self.userid = userid
34+
# self.password = password
35+
# self.timeout = timeout
36+
# self.paging = paging
37+
#
38+
#
39+
# pass_config = click.make_pass_decorator(Config)
40+
41+
# @tui
42+
@tui()
43+
@click.version_option("0.0.1", prog_name="egeria_ops")
44+
@click.group()
45+
@click.option('--server', default = 'active-metadata-store', envvar = 'EGERIA_METADATA_STORE',
46+
help='Egeria metadata store to work with')
47+
@click.option('--url', default = 'https://localhost:9443', envvar= 'EGERIA_PLATFORM_URL',
48+
help='URL of Egeria metadata store platform to connect to')
49+
@click.option('--integration-daemon', default = 'integration-daemon', envvar = 'EGERIA_INTEGRATION_DAEMON',
50+
help='Egeria integration daemon to work with')
51+
@click.option('--integration_daemon_url', default = 'https://localhost:9443', envvar= 'EGERIA_INTEGRATION_DAEMON_URL',
52+
help='URL of Egeria integration daemon platform to connect to')
53+
@click.option('--view_server', default = 'view-server', envvar = 'EGERIA_VIEW_SERVER',
54+
help='Egeria view server to work with')
55+
@click.option('--view_server_url', default = 'https://localhost:9443', envvar= 'EGERIA_VIEW_SERVER_URL',
56+
help='URL of Egeria view server platform to connect to')
57+
@click.option('--engine_host', default = 'engine-host', envvar = 'EGERIA_ENGINE_HOST',
58+
help='Egeria engine host to work with')
59+
@click.option('--engine_host_url', default = 'https://localhost:9443', envvar= 'EGERIA_ENGINE_HOST_URL',
60+
help='URL of Egeria engine host platform to connect to')
61+
@click.option('--admin_user', default = 'garygeeke', envvar = 'EGERIA_ADMIN_USER', help='Egeria admin user')
62+
@click.option('--admin_user_password', default = 'secret', envvar = 'EGERIA_ADMIN_PASSWORD',
63+
help='Egeria admin password')
64+
@click.option('--userid', default = 'garygeeke', envvar = 'EGERIA_USER', help='Egeria user')
65+
@click.option('--password', default = 'secret', envvar = 'EGERIA_PASSWORD',
66+
help='Egeria user password')
67+
@click.option('--timeout', default = 60, help = 'Number of seconds to wait')
68+
@click.option('--verbose', is_flag = True, default = False, help = 'Enable verbose mode')
69+
@click.option('--paging', is_flag = True, default = False, help = 'Enable paging snapshots vs live updates')
70+
@click.pass_context
71+
def cli(ctx, server, url, view_server, view_server_url, integration_daemon, integration_daemon_url,
72+
engine_host, engine_host_url, admin_user, admin_user_password, userid, password, timeout, paging, verbose):
73+
"""An Egeria Command Line interface for Operations """
74+
ctx.obj = Config(server, url, view_server, view_server_url, integration_daemon,
75+
integration_daemon_url, engine_host, engine_host_url,
76+
admin_user, admin_user_password,userid, password,
77+
timeout, paging, verbose)
78+
ctx.max_content_width = 200
79+
ctx.ensure_object(Config)
80+
if verbose:
81+
click.echo(f"we are in verbose mode - server is {server}")
82+
83+
84+
@cli.group("show")
85+
@click.pass_context
86+
def show(ctx):
87+
"""Display an Egeria Object"""
88+
pass
89+
90+
@show.group('platforms')
91+
@click.pass_context
92+
def show_platform(ctx):
93+
"""Group of commands to show information about Egeria platforms"""
94+
pass
95+
96+
@show_platform.command('status')
97+
@click.pass_context
98+
def show_platform_status(ctx):
99+
"""Display a live status view of known platforms"""
100+
c = ctx.obj
101+
p_display_status(c.view_server,c.view_server_url,
102+
c.admin_user,c.admin_user_password)
103+
104+
105+
@show.group("servers")
106+
@click.pass_context
107+
def show_server(ctx):
108+
"""Group of commands to show information about Egeria servers"""
109+
pass
110+
111+
@show_server.command('status')
112+
@click.option('--full', is_flag=True, default = False, help='If True, full server descriptions will be shown')
113+
@click.pass_context
114+
def show_server_status(ctx, full):
115+
"""Display a live status view of Egeria servers for the specified Egeria platform"""
116+
c = ctx.obj
117+
if full:
118+
display_list(c.metadata_store, c.metadata_store_url, c.admin_user,c.admin_user_password)
119+
else:
120+
s_display_status(c.metadata_store, c.metadata_store_url, c.admin_user,c.admin_user_password)
121+
122+
@show.group("engines")
123+
@click.pass_context
124+
def engine_host(ctx):
125+
"""Group of commands to show information about Egeria engines"""
126+
pass
127+
128+
@engine_host.command("status")
129+
@click.option('--list', is_flag=True, default = False, help='If True, a paged list will be shown')
130+
@click.pass_context
131+
def gov_eng_status(ctx,list):
132+
"""Display engine-host status information"""
133+
c = ctx.obj
134+
display_gov_eng_status(c.engine_host, c.engine_host_url,
135+
c.userid, c.password,
136+
list)
137+
138+
@engine_host.command('activity')
139+
@click.option('--list', is_flag=True, default = False, help='If True, a paged list will be shown')
140+
@click.pass_context
141+
def eng_activity_status(ctx,list):
142+
"""Show Governance Activity in engine-host"""
143+
c = ctx.obj
144+
display_engine_activity(c.view_server, c.view_server_url,
145+
c.userid, c.password,
146+
list)
147+
148+
149+
@show.group('integrations')
150+
@click.pass_context
151+
def integrations(ctx):
152+
"""Group of commands to show information about Egeria integrations"""
153+
pass
154+
155+
@integrations.command("status")
156+
@click.option('--list', is_flag=True, default = False, help='If True, a paged list will be shown')
157+
@click.pass_context
158+
def integrations_status(ctx,list):
159+
"""Display integration-daemon status information"""
160+
c = ctx.obj
161+
display_integration_daemon_status(c.integration_daemon, c.integration_daemon_url,
162+
c.view_server, c.view_server_url,
163+
c.userid, c.password, list)
164+
165+
@integrations.command("targets")
166+
@click.pass_context
167+
@click.argument('connector',nargs=1)
168+
def integrations_status(ctx,connector):
169+
"""Display Catalog Targets for a connector"""
170+
c = ctx.obj
171+
display_catalog_targets(connector, c.view_server, c.view_server_url,
172+
c.userid, c.password)
173+
174+
#
175+
# Tell
176+
#
177+
178+
@cli.group('tell')
179+
@click.pass_context
180+
def tell(ctx):
181+
"""Perform actions an Egeria Objects"""
182+
pass
183+
184+
@tell.group('integration_daemon')
185+
@click.pass_context
186+
def integration_daemon(ctx):
187+
"""Group of commands to an integration-daemon"""
188+
pass
189+
190+
@integration_daemon.command('refresh')
191+
@click.pass_context
192+
@click.option('--connector', default = 'all', help="Name of connector to refresh or 'all' to refresh all")
193+
def refresh_connectors(ctx,connector):
194+
"""Refresh the specified integration connector or ALL connectors if not specified"""
195+
c = ctx.obj
196+
refresh_connector(connector,c.integration_daemon, c.integration_daemon_url,
197+
c.userid, c.password)
198+
199+
@integration_daemon.command('restart')
200+
@click.pass_context
201+
@click.option('--connector', default = 'all', help="Name of connector to restart or 'all' to restart all")
202+
def restart_connectors(ctx,connector):
203+
"""Restart the specified integration connector or ALL connectors if not specified"""
204+
c = ctx.obj
205+
restart_connector(connector,c.integration_daemon, c.integration_daemon_url,
206+
c.userid, c.password)
207+
208+
209+
integration_daemon.add_command(add_catalog_target)
210+
integration_daemon.add_command(remove_catalog_target)
211+
integration_daemon.add_command(update_catalog_target)
212+
integration_daemon.add_command(stop_server)
213+
integration_daemon.add_command(start_server)
214+
215+
216+
if __name__ == '__main__':
217+
cli()

examples/widgets/cli/ops_config.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import click
2+
3+
4+
class Config(object):
5+
def __init__(self, server: str = None, url: str = None,
6+
view_server: str = 'view-server', view_server_url: str = 'https://localhost:9443',
7+
integration_daemon: str = 'integration-daemon', integration_daemon_url: str = 'https://localhost:9443',
8+
engine_host: str = 'engine-host', engine_host_url: str = 'https://localhost:9443',
9+
admin_user: str = 'garygeeke', admin_user_password: str = 'secret',
10+
userid: str = None, password: str = None,
11+
timeout: int = 30, paging: bool = False, verbose: bool = False):
12+
self.metadata_store = server
13+
self.metadata_store_url = url
14+
self.view_server = view_server
15+
self.view_server_url = view_server_url
16+
self.integration_daemon = integration_daemon
17+
self.integration_daemon_url = integration_daemon_url
18+
self.engine_host = engine_host
19+
self.engine_host_url = engine_host_url
20+
self.admin_user = admin_user
21+
self.admin_user_password = admin_user_password
22+
self.userid = userid
23+
self.password = password
24+
self.timeout = timeout
25+
self.paging = paging
26+
self.verbose = verbose
27+
28+
29+
pass_config = click.make_pass_decorator(Config)

0 commit comments

Comments
 (0)