Skip to content

Commit

Permalink
Merge pull request #36 from dwolfson/v.5.0
Browse files Browse the repository at this point in the history
Updated the widgets and added a first cli
  • Loading branch information
dwolfson authored Jul 30, 2024
2 parents ab04bf5 + f6e3d69 commit 5f4c6cc
Show file tree
Hide file tree
Showing 41 changed files with 1,186 additions and 212 deletions.
20 changes: 11 additions & 9 deletions examples/widgets/catalog_user/get_asset_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import os
import sys

from rich import print
from rich.console import Console
from rich.markdown import Markdown
from rich.panel import Panel
Expand All @@ -35,6 +34,7 @@
EGERIA_USER_PASSWORD = os.environ.get('EGERIA_USER_PASSWORD', 'secret')

disable_ssl_warnings = True

console = Console(width=200)


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

try:

console = Console(width=200)

a_client = AssetCatalog(server_name, platform_url,
user_id=user)

Expand Down Expand Up @@ -146,6 +144,7 @@ def build_nested_elements(nested_element: dict) -> Markdown:
f"* Asset Origin: {asset_origin}\n{prop_md}\n"
)
core_md = Markdown(core_md)

p1 = Panel.fit(core_md, style = "bold bright_white")
l2 = tree.add(p1)
if asset_class_md is not None:
Expand Down Expand Up @@ -225,9 +224,9 @@ def build_nested_elements(nested_element: dict) -> Markdown:
relationship_panel = Panel.fit(Markdown(relationship_md), style="bold bright_white", title = "Asset Relationships")
tree.add(relationship_panel)


print("\n\n")
print(tree)
with console.screen():
print("\n\n")
print(tree)

except (
InvalidParameterException,
Expand All @@ -250,9 +249,12 @@ def main():
url = args.url if args.url is not None else EGERIA_PLATFORM_URL
userid = args.userid if args.userid is not None else EGERIA_USER
user_pass = args.password if args.password is not None else EGERIA_USER_PASSWORD

asset_guid = Prompt.ask("Enter the Asset GUID to view:", default="")
asset_viewer(asset_guid,server, url, userid, user_pass)
try:
asset_guid = Prompt.ask("Enter the Asset GUID to view:", default="")
asset_viewer(asset_guid,server, url, userid, user_pass)
except (KeyboardInterrupt) as e:
# console.print_exception()
pass

if __name__ == "__main__":
main()
8 changes: 5 additions & 3 deletions examples/widgets/catalog_user/get_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ def main():
userid = args.userid if args.userid is not None else EGERIA_USER
user_pass = args.password if args.password is not None else EGERIA_USER_PASSWORD

root_collection = Prompt.ask("Enter the Root Collection to start from:", default="Root Sustainability Collection")
collection_viewer(root_collection, server, url, userid, user_pass)

try:
root_collection = Prompt.ask("Enter the Root Collection to start from:", default="Root Sustainability Collection")
collection_viewer(root_collection, server, url, userid, user_pass)
except (KeyboardInterrupt):
pass
if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,12 @@ def main():
url = args.url if args.url is not None else EGERIA_PLATFORM_URL
userid = args.userid if args.userid is not None else EGERIA_USER
user_pass = args.password if args.password is not None else EGERIA_USER_PASSWORD
try:
tech_name = Prompt.ask("Enter the Asset Name to view:", default="Apache Kafka Server")
tech_viewer(tech_name,server, url, userid, user_pass)
except (KeyboardInterrupt):
pass

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

if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,12 @@ def main():
userid = args.userid if args.userid is not None else EGERIA_USER
user_pass = args.password if args.password is not None else EGERIA_USER_PASSWORD

tech_name = Prompt.ask("Enter the Asset Name to view:", default="Apache Kafka Server")
tech_viewer(tech_name,server, url, userid, user_pass)
try:
tech_name = Prompt.ask("Enter the Asset Name to view:", default="Apache Kafka Server")
tech_viewer(tech_name,server, url, userid, user_pass)
except(KeyboardInterrupt):
pass


if __name__ == "__main__":
main()
9 changes: 5 additions & 4 deletions examples/widgets/catalog_user/list_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ def main():
userid = args.userid if args.userid is not None else EGERIA_USER
user_pass = args.password if args.password is not None else EGERIA_USER_PASSWORD
time_out = args.time_out if args.time_out is not None else 60

search_string = Prompt.ask("Enter an asset search string:", default="")
display_assets(search_string, server, url, userid, user_pass, time_out)

try:
search_string = Prompt.ask("Enter an asset search string:", default="")
display_assets(search_string, server, url, userid, user_pass, time_out)
except(KeyboardInterrupt):
pass
if __name__ == "__main__":
main()
8 changes: 5 additions & 3 deletions examples/widgets/catalog_user/list_glossary.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ def main():
guid = args.guid if args.guid is not None else None
guid = sus_guid if args.sustainability else None

search_string = Prompt.ask("Enter the term you are searching for:", default="*")
display_glossary_terms(search_string, guid,server, url, userid, user_pass)

try:
search_string = Prompt.ask("Enter the term you are searching for:", default="*")
display_glossary_terms(search_string, guid,server, url, userid, user_pass)
except(KeyboardInterrupt):
pass
if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions examples/widgets/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .ops_config import Config
217 changes: 217 additions & 0 deletions examples/widgets/cli/egeria_ops.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
#!/usr/bin/env python3
"""
SPDX-License-Identifier: Apache-2.0
Copyright Contributors to the ODPi Egeria project.
A command line interface for Egeria operations.
This is an emerging capability based on the **click** package. Feedback welcome!
"""
import click
from trogon import tui
# from pyegeria import ServerOps
from examples.widgets.cli.ops_config import Config
from examples.widgets.operational.monitor_gov_eng_status import display_gov_eng_status
from examples.widgets.operational.monitor_server_status import display_status as s_display_status
from examples.widgets.operational.monitor_server_list import display_status as display_list
from examples.widgets.operational.monitor_integ_daemon_status import display_integration_daemon_status
from examples.widgets.operational.monitor_platform_status import display_status as p_display_status
from examples.widgets.operational.monitor_engine_activity import display_engine_activity
from examples.widgets.operational.refresh_integration_daemon import refresh_connector
from examples.widgets.operational.restart_integration_daemon import restart_connector
from examples.widgets.operational.integration_daemon_actions import (add_catalog_target,remove_catalog_target,
update_catalog_target, stop_server, start_server)

from examples.widgets.operational.list_catalog_targets import display_catalog_targets
# class Config(object):
# def __init__(self, server: str = None, url: str = None, userid:str = None, password:str = None,
# timeout:int = 30, paging: bool = False):
# self.server = server
# self.url = url
# self.userid = userid
# self.password = password
# self.timeout = timeout
# self.paging = paging
#
#
# pass_config = click.make_pass_decorator(Config)

# @tui
@tui()
@click.version_option("0.0.1", prog_name="egeria_ops")
@click.group()
@click.option('--server', default = 'active-metadata-store', envvar = 'EGERIA_METADATA_STORE',
help='Egeria metadata store to work with')
@click.option('--url', default = 'https://localhost:9443', envvar= 'EGERIA_PLATFORM_URL',
help='URL of Egeria metadata store platform to connect to')
@click.option('--integration-daemon', default = 'integration-daemon', envvar = 'EGERIA_INTEGRATION_DAEMON',
help='Egeria integration daemon to work with')
@click.option('--integration_daemon_url', default = 'https://localhost:9443', envvar= 'EGERIA_INTEGRATION_DAEMON_URL',
help='URL of Egeria integration daemon platform to connect to')
@click.option('--view_server', default = 'view-server', envvar = 'EGERIA_VIEW_SERVER',
help='Egeria view server to work with')
@click.option('--view_server_url', default = 'https://localhost:9443', envvar= 'EGERIA_VIEW_SERVER_URL',
help='URL of Egeria view server platform to connect to')
@click.option('--engine_host', default = 'engine-host', envvar = 'EGERIA_ENGINE_HOST',
help='Egeria engine host to work with')
@click.option('--engine_host_url', default = 'https://localhost:9443', envvar= 'EGERIA_ENGINE_HOST_URL',
help='URL of Egeria engine host platform to connect to')
@click.option('--admin_user', default = 'garygeeke', envvar = 'EGERIA_ADMIN_USER', help='Egeria admin user')
@click.option('--admin_user_password', default = 'secret', envvar = 'EGERIA_ADMIN_PASSWORD',
help='Egeria admin password')
@click.option('--userid', default = 'garygeeke', envvar = 'EGERIA_USER', help='Egeria user')
@click.option('--password', default = 'secret', envvar = 'EGERIA_PASSWORD',
help='Egeria user password')
@click.option('--timeout', default = 60, help = 'Number of seconds to wait')
@click.option('--verbose', is_flag = True, default = False, help = 'Enable verbose mode')
@click.option('--paging', is_flag = True, default = False, help = 'Enable paging snapshots vs live updates')
@click.pass_context
def cli(ctx, server, url, view_server, view_server_url, integration_daemon, integration_daemon_url,
engine_host, engine_host_url, admin_user, admin_user_password, userid, password, timeout, paging, verbose):
"""An Egeria Command Line interface for Operations """
ctx.obj = Config(server, url, view_server, view_server_url, integration_daemon,
integration_daemon_url, engine_host, engine_host_url,
admin_user, admin_user_password,userid, password,
timeout, paging, verbose)
ctx.max_content_width = 200
ctx.ensure_object(Config)
if verbose:
click.echo(f"we are in verbose mode - server is {server}")


@cli.group("show")
@click.pass_context
def show(ctx):
"""Display an Egeria Object"""
pass

@show.group('platforms')
@click.pass_context
def show_platform(ctx):
"""Group of commands to show information about Egeria platforms"""
pass

@show_platform.command('status')
@click.pass_context
def show_platform_status(ctx):
"""Display a live status view of known platforms"""
c = ctx.obj
p_display_status(c.view_server,c.view_server_url,
c.admin_user,c.admin_user_password)


@show.group("servers")
@click.pass_context
def show_server(ctx):
"""Group of commands to show information about Egeria servers"""
pass

@show_server.command('status')
@click.option('--full', is_flag=True, default = False, help='If True, full server descriptions will be shown')
@click.pass_context
def show_server_status(ctx, full):
"""Display a live status view of Egeria servers for the specified Egeria platform"""
c = ctx.obj
if full:
display_list(c.metadata_store, c.metadata_store_url, c.admin_user,c.admin_user_password)
else:
s_display_status(c.metadata_store, c.metadata_store_url, c.admin_user,c.admin_user_password)

@show.group("engines")
@click.pass_context
def engine_host(ctx):
"""Group of commands to show information about Egeria engines"""
pass

@engine_host.command("status")
@click.option('--list', is_flag=True, default = False, help='If True, a paged list will be shown')
@click.pass_context
def gov_eng_status(ctx,list):
"""Display engine-host status information"""
c = ctx.obj
display_gov_eng_status(c.engine_host, c.engine_host_url,
c.userid, c.password,
list)

@engine_host.command('activity')
@click.option('--list', is_flag=True, default = False, help='If True, a paged list will be shown')
@click.pass_context
def eng_activity_status(ctx,list):
"""Show Governance Activity in engine-host"""
c = ctx.obj
display_engine_activity(c.view_server, c.view_server_url,
c.userid, c.password,
list)


@show.group('integrations')
@click.pass_context
def integrations(ctx):
"""Group of commands to show information about Egeria integrations"""
pass

@integrations.command("status")
@click.option('--list', is_flag=True, default = False, help='If True, a paged list will be shown')
@click.pass_context
def integrations_status(ctx,list):
"""Display integration-daemon status information"""
c = ctx.obj
display_integration_daemon_status(c.integration_daemon, c.integration_daemon_url,
c.view_server, c.view_server_url,
c.userid, c.password, list)

@integrations.command("targets")
@click.pass_context
@click.argument('connector',nargs=1)
def integrations_status(ctx,connector):
"""Display Catalog Targets for a connector"""
c = ctx.obj
display_catalog_targets(connector, c.view_server, c.view_server_url,
c.userid, c.password)

#
# Tell
#

@cli.group('tell')
@click.pass_context
def tell(ctx):
"""Perform actions an Egeria Objects"""
pass

@tell.group('integration_daemon')
@click.pass_context
def integration_daemon(ctx):
"""Group of commands to an integration-daemon"""
pass

@integration_daemon.command('refresh')
@click.pass_context
@click.option('--connector', default = 'all', help="Name of connector to refresh or 'all' to refresh all")
def refresh_connectors(ctx,connector):
"""Refresh the specified integration connector or ALL connectors if not specified"""
c = ctx.obj
refresh_connector(connector,c.integration_daemon, c.integration_daemon_url,
c.userid, c.password)

@integration_daemon.command('restart')
@click.pass_context
@click.option('--connector', default = 'all', help="Name of connector to restart or 'all' to restart all")
def restart_connectors(ctx,connector):
"""Restart the specified integration connector or ALL connectors if not specified"""
c = ctx.obj
restart_connector(connector,c.integration_daemon, c.integration_daemon_url,
c.userid, c.password)


integration_daemon.add_command(add_catalog_target)
integration_daemon.add_command(remove_catalog_target)
integration_daemon.add_command(update_catalog_target)
integration_daemon.add_command(stop_server)
integration_daemon.add_command(start_server)


if __name__ == '__main__':
cli()
29 changes: 29 additions & 0 deletions examples/widgets/cli/ops_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import click


class Config(object):
def __init__(self, server: str = None, url: str = None,
view_server: str = 'view-server', view_server_url: str = 'https://localhost:9443',
integration_daemon: str = 'integration-daemon', integration_daemon_url: str = 'https://localhost:9443',
engine_host: str = 'engine-host', engine_host_url: str = 'https://localhost:9443',
admin_user: str = 'garygeeke', admin_user_password: str = 'secret',
userid: str = None, password: str = None,
timeout: int = 30, paging: bool = False, verbose: bool = False):
self.metadata_store = server
self.metadata_store_url = url
self.view_server = view_server
self.view_server_url = view_server_url
self.integration_daemon = integration_daemon
self.integration_daemon_url = integration_daemon_url
self.engine_host = engine_host
self.engine_host_url = engine_host_url
self.admin_user = admin_user
self.admin_user_password = admin_user_password
self.userid = userid
self.password = password
self.timeout = timeout
self.paging = paging
self.verbose = verbose


pass_config = click.make_pass_decorator(Config)
Loading

0 comments on commit 5f4c6cc

Please sign in to comment.