pyegeria 1.5.1.1.36__py3-none-any.whl → 1.5.1.1.37__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pyegeria/_client.py CHANGED
@@ -654,32 +654,33 @@ class Client:
654
654
  integration_guids[display_name] = resource_guid
655
655
  # print(f"Added {display_name} integration connector with GUID {integration_guids[display_name]}")
656
656
 
657
- async def __async__get_guid__(
657
+ async def __async_get_guid__(
658
658
  self,
659
659
  guid: str = None,
660
- name: str = None,
660
+ display_name: str = None,
661
661
  property_name: str = "qualifiedName",
662
+ qualified_name: str = None,
662
663
  tech_type: str = None,
663
664
  ) -> str:
664
- """Helper function to return a server_guid - one of server_guid or server_name should
665
- contain information. If both are None, an exception will be thrown. If both contain
666
- values, server_guid will be used. If the tech_type is supplied and the property_name is qualifiedName
667
- then the name will be pre-pended with the tech_type name to form a qualifiedName.
665
+ """Helper function to return a server_guid - one of server_guid, qualified_name or display_name should
666
+ contain information. If all are None, an exception will be thrown. If all contain
667
+ values, server_guid will be used first, followed by qualified_name. If the tech_type is supplied and the
668
+ property_name is qualifiedName then the display_name will be pre-pended with the tech_type name to form a
669
+ qualifiedName.
668
670
 
669
671
  An InvalidParameter Exception is thrown if multiple matches
670
672
  are found for the given property name. If this occurs, use a qualified name for the property name.
671
673
  Async version.
672
674
  """
675
+
673
676
  if guid:
674
677
  return guid
675
- if name:
676
- if (tech_type) and (property_name == "qualifiedName"):
677
- name = f"{tech_type}:{name}"
678
678
 
679
+ if qualified_name:
679
680
  body = {
680
681
  "class": "NameRequestBody",
681
- "name": name,
682
- "namePropertyName": property_name,
682
+ "name": qualified_name,
683
+ "namePropertyName": "qualifiedName",
683
684
  "forLineage": False,
684
685
  "forDuplicateProcessing": False,
685
686
  "effectiveTime": None,
@@ -689,11 +690,43 @@ class Client:
689
690
  f"elements/guid-by-unique-name?forLineage=false&forDuplicateProcessing=false"
690
691
  )
691
692
 
692
- response: Response = await self._async_make_request(
693
- "POST", url, body_slimmer(body), time_out=self.time_out
694
- )
693
+ result = await self._async_make_request("POST", url, body_slimmer(body))
694
+ return result.json().get("guid", "No elements found")
695
+
696
+ if (not qualified_name) and display_name:
697
+ if (tech_type) and (property_name == "qualifiedName"):
698
+ name = f"{tech_type}:{display_name}"
699
+ body = {
700
+ "class": "NameRequestBody",
701
+ "name": name,
702
+ "namePropertyName": property_name,
703
+ "forLineage": False,
704
+ "forDuplicateProcessing": False,
705
+ "effectiveTime": None,
706
+ }
707
+ url = (
708
+ f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/classification-manager/"
709
+ f"elements/guid-by-unique-name?forLineage=false&forDuplicateProcessing=false"
710
+ )
695
711
 
696
- return response.json().get("guid", "No elements found")
712
+ result = await self._async_make_request("POST", url, body_slimmer(body))
713
+ return result.json().get("guid", "No elements found")
714
+ else:
715
+ body = {
716
+ "class": "NameRequestBody",
717
+ "name": display_name,
718
+ "namePropertyName": property_name,
719
+ "forLineage": False,
720
+ "forDuplicateProcessing": False,
721
+ "effectiveTime": None,
722
+ }
723
+ url = (
724
+ f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/classification-manager/"
725
+ f"elements/guid-by-unique-name?forLineage=false&forDuplicateProcessing=false"
726
+ )
727
+
728
+ result = await self._async_make_request("POST", url, body_slimmer(body))
729
+ return result.json().get("guid", "No elements found")
697
730
  else:
698
731
  raise InvalidParameterException(
699
732
  "Neither server_guid nor server_name were provided - please provide."
@@ -702,21 +735,26 @@ class Client:
702
735
  def __get_guid__(
703
736
  self,
704
737
  guid: str = None,
705
- name: str = None,
738
+ display_name: str = None,
706
739
  property_name: str = "qualifiedName",
740
+ qualified_name: str = None,
707
741
  tech_type: str = None,
708
742
  ) -> str:
709
- """Helper function to return a server_guid - one of server_guid or server_name should
710
- contain information. If both are None, an exception will be thrown. If both contain
711
- values, server_guid will be used. If the tech_type is supplied and the property_name is qualifiedName
712
- then the name will be pre-pended with the tech_type name to form a qualifiedName.
743
+ """Helper function to return a server_guid - one of server_guid, qualified_name or display_name should
744
+ contain information. If all are None, an exception will be thrown. If all contain
745
+ values, server_guid will be used first, followed by qualified_name. If the tech_type is supplied and the
746
+ property_name is qualifiedName then the display_name will be pre-pended with the tech_type name to form a
747
+ qualifiedName.
713
748
 
714
749
  An InvalidParameter Exception is thrown if multiple matches
715
750
  are found for the given property name. If this occurs, use a qualified name for the property name.
751
+ Async version.
716
752
  """
717
753
  loop = asyncio.get_event_loop()
718
754
  result = loop.run_until_complete(
719
- self.__async__get_guid__(guid, name, property_name, tech_type)
755
+ self.__async_get_guid__(
756
+ guid, display_name, property_name, qualified_name, tech_type
757
+ )
720
758
  )
721
759
  return result
722
760
 
@@ -0,0 +1,152 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ SPDX-License-Identifier: Apache-2.0
4
+ Copyright Contributors to the ODPi Egeria project.
5
+
6
+ Display by deployed implementation type.
7
+
8
+ Note: This implementation is using the runtime manager.
9
+
10
+
11
+
12
+ A simple server status display
13
+ """
14
+ import argparse
15
+ import os
16
+ import sys
17
+ import time
18
+
19
+ from rich.console import Console
20
+ from rich.markdown import Markdown
21
+ from rich.prompt import Prompt
22
+ from rich.table import Table
23
+ from rich.text import Text
24
+
25
+ from pyegeria import (
26
+ InvalidParameterException,
27
+ PropertyServerException,
28
+ UserNotAuthorizedException,
29
+ print_exception_response,
30
+ RuntimeManager,
31
+ )
32
+
33
+ EGERIA_METADATA_STORE = os.environ.get("EGERIA_METADATA_STORE", "active-metadata-store")
34
+ EGERIA_KAFKA_ENDPOINT = os.environ.get("KAFKA_ENDPOINT", "localhost:9092")
35
+ EGERIA_PLATFORM_URL = os.environ.get("EGERIA_PLATFORM_URL", "https://localhost:9443")
36
+ EGERIA_VIEW_SERVER = os.environ.get("VIEW_SERVER", "view-server")
37
+ EGERIA_VIEW_SERVER_URL = os.environ.get(
38
+ "EGERIA_VIEW_SERVER_URL", "https://localhost:9443"
39
+ )
40
+ EGERIA_INTEGRATION_DAEMON = os.environ.get("INTEGRATION_DAEMON", "integration-daemon")
41
+ EGERIA_INTEGRATION_DAEMON_URL = os.environ.get(
42
+ "EGERIA_INTEGRATION_DAEMON_URL", "https://localhost:9443"
43
+ )
44
+ EGERIA_ADMIN_USER = os.environ.get("ADMIN_USER", "garygeeke")
45
+ EGERIA_ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD", "secret")
46
+ EGERIA_USER = os.environ.get("EGERIA_USER", "erinoverview")
47
+ EGERIA_USER_PASSWORD = os.environ.get("EGERIA_USER_PASSWORD", "secret")
48
+ EGERIA_JUPYTER = bool(os.environ.get("EGERIA_JUPYTER", "False"))
49
+ EGERIA_WIDTH = int(os.environ.get("EGERIA_WIDTH", "200"))
50
+
51
+
52
+ def display_servers_by_dep_imp(
53
+ filter: str = "*",
54
+ view_server: str = EGERIA_VIEW_SERVER,
55
+ view_url: str = EGERIA_VIEW_SERVER_URL,
56
+ user: str = EGERIA_USER,
57
+ user_pass: str = EGERIA_USER_PASSWORD,
58
+ jupyter: bool = EGERIA_JUPYTER,
59
+ width: int = EGERIA_WIDTH,
60
+ ):
61
+ p_client = RuntimeManager(view_server, view_url, user, user_pass)
62
+ token = p_client.create_egeria_bearer_token()
63
+
64
+ def generate_table() -> Table:
65
+ """Make a new table."""
66
+ table = Table(
67
+ title=f"Servers by Deployed Implementation Type - {time.asctime()}",
68
+ style="bold white on black",
69
+ row_styles=["bold white on black"],
70
+ header_style="white on dark_blue",
71
+ title_style="bold white on black",
72
+ caption_style="white on black",
73
+ caption=f"Platform - '{view_url}'",
74
+ show_lines=True,
75
+ )
76
+
77
+ table.add_column("Server")
78
+ table.add_column("Deployed Impl Type")
79
+ table.add_column("Zones")
80
+
81
+ table.add_column("Description")
82
+ table.add_column("Qualified Name & GUID", no_wrap=True)
83
+
84
+ server_list = p_client.get_servers_by_dep_impl_type(filter)
85
+ if type(server_list) is str:
86
+ print("No matching Software Servers found?")
87
+ sys.exit(1)
88
+
89
+ for server in server_list:
90
+ display_name = server["properties"].get("displayName", "---")
91
+ qualified_name = server["properties"].get("qualifiedName", "---")
92
+ classifications = server["elementHeader"].get("classifications", None)
93
+ zones = ""
94
+ if classifications:
95
+ for clas in classifications:
96
+ if clas["classificationName"] == "AssetZoneMembership":
97
+ classification_props = clas["classificationProperties"]
98
+ zone_membership = classification_props.get(
99
+ "zoneMembership", None
100
+ )
101
+ if zone_membership:
102
+ for z in zone_membership.keys():
103
+ zones += f"{zone_membership[z]}, "
104
+ zones = zones[:-2]
105
+
106
+ impl_type = server["properties"].get("deployedImplementationType", "---")
107
+ server_guid = server["elementHeader"]["guid"]
108
+ server_desc = server["properties"].get("resourceDescription", "---")
109
+
110
+ server_id = Text(f"{qualified_name}\n&\n{server_guid}", justify="center")
111
+
112
+ table.add_row(display_name, impl_type, zones, server_desc, server_id)
113
+
114
+ return table
115
+
116
+ try:
117
+ console = Console(width=width, force_terminal=not jupyter)
118
+
119
+ with console.pager(styles=True):
120
+ console.print(generate_table())
121
+
122
+ except (
123
+ InvalidParameterException,
124
+ PropertyServerException,
125
+ UserNotAuthorizedException,
126
+ ) as e:
127
+ print_exception_response(e)
128
+ except KeyboardInterrupt:
129
+ pass
130
+ finally:
131
+ p_client.close_session()
132
+
133
+
134
+ def main():
135
+ parser = argparse.ArgumentParser()
136
+
137
+ parser.add_argument("--server", help="Name of the server to display status for")
138
+ parser.add_argument("--url", help="URL Platform to connect to")
139
+ parser.add_argument("--userid", help="User Id")
140
+ parser.add_argument("--password", help="User Password")
141
+ args = parser.parse_args()
142
+
143
+ server = args.server if args.server is not None else EGERIA_VIEW_SERVER
144
+ url = args.url if args.url is not None else EGERIA_PLATFORM_URL
145
+ userid = args.userid if args.userid is not None else EGERIA_ADMIN_USER
146
+ user_pass = args.password if args.password is not None else EGERIA_USER_PASSWORD
147
+ filter = Prompt.ask("Search string", default="*")
148
+ display_servers_by_dep_imp(filter, server, url, userid, user_pass)
149
+
150
+
151
+ if __name__ == "__main__":
152
+ main()
@@ -27,6 +27,7 @@ from pyegeria.commands.cat.list_tech_types import display_tech_types
27
27
  from pyegeria.commands.cat.list_todos import display_to_dos as list_todos
28
28
  from pyegeria.commands.cat.list_user_ids import list_user_ids
29
29
  from pyegeria.commands.cat.list_archives import display_archive_list
30
+ from pyegeria.commands.cat.list_servers_deployed_imp import display_servers_by_dep_imp
30
31
  from pyegeria.commands.cli.ops_config import Config
31
32
  from pyegeria.commands.my.list_my_profile import display_my_profile
32
33
  from pyegeria.commands.my.list_my_roles import display_my_roles
@@ -933,12 +934,30 @@ def archives(ctx):
933
934
  )
934
935
 
935
936
 
937
+ @show.command("deployed-servers")
938
+ @click.option(
939
+ "--search-string", default="*", help="Filter deployed servers by search string"
940
+ )
941
+ @click.pass_context
942
+ def show_deployed_servers(ctx, search_string):
943
+ c = ctx.obj
944
+ display_servers_by_dep_imp(
945
+ search_string,
946
+ c.view_server,
947
+ c.view_server_url,
948
+ c.userid,
949
+ c.password,
950
+ c.jupyter,
951
+ c.width,
952
+ )
953
+
954
+
936
955
  @show.command("deployed-schemas")
937
956
  @click.option(
938
957
  "--search_catalog", default="*", help="What database or catalog to search"
939
958
  )
940
959
  @click.pass_context
941
- def deployed_schemas(search_catalog, ctx):
960
+ def deployed_schemas(ctx, search_catalog):
942
961
  """Display a tree graph of information about an asset"""
943
962
  c = ctx.obj
944
963
  list_deployed_database_schemas(
@@ -955,7 +974,7 @@ def deployed_schemas(search_catalog, ctx):
955
974
  @show.command("catalogs")
956
975
  @click.option("--search_server", default="*", help="Server to search for catalogs")
957
976
  @click.pass_context
958
- def catalogs(search_server, ctx):
977
+ def catalogs(ctx, search_server):
959
978
  """Display a tree graph of information about an asset"""
960
979
  c = ctx.obj
961
980
  list_deployed_catalogs(
@@ -25,6 +25,7 @@ from pyegeria.commands.cat.glossary_actions import (
25
25
  load_terms,
26
26
  export_terms,
27
27
  )
28
+ from pyegeria.commands.cat.list_servers_deployed_imp import display_servers_by_dep_imp
28
29
  from pyegeria.commands.cat.list_glossaries import display_glossaries
29
30
  from pyegeria.commands.cat.list_archives import display_archive_list
30
31
  from pyegeria.commands.cat.list_assets import display_assets
@@ -516,6 +517,24 @@ def list_archives(ctx):
516
517
  )
517
518
 
518
519
 
520
+ @show.command("deployed-servers")
521
+ @click.option(
522
+ "--search-string", default="*", help="Filter deployed servers by search string"
523
+ )
524
+ @click.pass_context
525
+ def show_deployed_servers(ctx, search_string):
526
+ c = ctx.obj
527
+ display_servers_by_dep_imp(
528
+ search_string,
529
+ c.view_server,
530
+ c.view_server_url,
531
+ c.userid,
532
+ c.password,
533
+ c.jupyter,
534
+ c.width,
535
+ )
536
+
537
+
519
538
  @show.command("deployed-schemas")
520
539
  @click.option("--catalog", default="*", help="What database or catalog to search")
521
540
  @click.pass_context
@@ -104,9 +104,13 @@ def update_catalog_target(ctx, relationship_guid: str, catalog_target_name: str)
104
104
  print_exception_response(e)
105
105
 
106
106
 
107
+ #
108
+ # This method will be updated based on forthcoming changes on the Egeria server side
109
+ #
107
110
  @click.command("refresh")
111
+ @click.option("-engine-host-guid", help="GUID of engine host to refresh.")
108
112
  @click.pass_context
109
- def refresh_gov_eng_config(ctx):
113
+ def refresh_gov_eng_config(ctx, engine_host_guid: str):
110
114
  """Start or restart an engine-host from its known configuration"""
111
115
  c = ctx.obj
112
116
  p_client = EgeriaTech(c.view_server, c.view_server_url, c.userid, c.password)
@@ -263,7 +263,7 @@ def main_live():
263
263
  view_url=view_url,
264
264
  user=userid,
265
265
  user_pass=user_pass,
266
- paging=True,
266
+ paging=False,
267
267
  )
268
268
 
269
269
 
@@ -64,11 +64,11 @@ def display_status(
64
64
  header_style="white on dark_blue",
65
65
  title_style="bold white on black",
66
66
  caption_style="white on black",
67
- caption=f"Status of Platforms - '{url}'",
67
+ caption=f"Status of Platforms - '{view_url}'",
68
68
  show_lines=True,
69
69
  # expand=True
70
70
  )
71
- table.add_column("Platform Name")
71
+ table.add_column("Platform Name & GUID")
72
72
  # table.add_column("Platform GUID")
73
73
  table.add_column("Platform URL")
74
74
  table.add_column("Platform Origin")
@@ -98,7 +98,7 @@ def display_status(
98
98
  platform_url = platform_report.get("platformURLRoot", " ")
99
99
  platform_origin = platform_report.get("platformOrigin", " ")
100
100
  platform_started = platform_report.get("platformStartTime", " ")
101
-
101
+ platform_id = f"{platform_name}\n\n\t\t&\n\n{platform_guid}"
102
102
  servers = platform_report.get("omagservers", None)
103
103
 
104
104
  if servers is not None:
@@ -120,7 +120,7 @@ def display_status(
120
120
  # server_list = server_list + serv
121
121
 
122
122
  table.add_row(
123
- platform_name,
123
+ platform_id,
124
124
  platform_url,
125
125
  platform_origin,
126
126
  platform_desc,
@@ -70,12 +70,14 @@ def display_status(
70
70
  title_style="bold white on black",
71
71
  caption_style="white on black",
72
72
  caption=f"Server Status from Platform - '{url}'",
73
- # show_lines=True,
73
+ show_lines=True,
74
74
  )
75
75
 
76
76
  table.add_column("Known Server")
77
77
  table.add_column("Status")
78
78
  if extended:
79
+ table.add_column("GUID", no_wrap=True)
80
+ table.add_column("Qualified Name")
79
81
  table.add_column("Description")
80
82
  table.add_column("Server Type")
81
83
  table.add_column("Last Started")
@@ -102,15 +104,31 @@ def display_status(
102
104
  server_status = p_server.get("serverActiveStatus", "UNKNOWN")
103
105
  if server_status in ("RUNNING", "STARTING"):
104
106
  status = "Active"
105
- elif server_status in ("INACTIVE", "STOPPING"):
107
+ elif server_status in ("INACTIVE", "STOPPING", "UNKNOWN"):
106
108
  status = "Inactive"
107
109
  else:
108
110
  status = "UNKNOWN"
109
111
 
110
112
  if extended:
113
+ #
114
+ # get the qualified name and guid from get_server_by_name?
115
+ #
116
+ server_info = p_client.get_servers_by_name(server_name)
117
+ if type(server_info) is str:
118
+ guid = "---"
119
+ qualified_name = "---"
120
+ else:
121
+ guid = ""
122
+ qualified_name = ""
123
+ for i in server_info:
124
+ guid += f"{i["elementHeader"]["guid"]} "
125
+ qualified_name += f"{i["properties"]["qualifiedName"]} "
126
+
111
127
  table.add_row(
112
128
  server_name,
113
129
  "[red]Inactive" if status == "Inactive" else "[green]Active",
130
+ guid,
131
+ qualified_name,
114
132
  server_desc,
115
133
  server_type,
116
134
  last_start_time,
@@ -144,7 +162,7 @@ def display_status(
144
162
 
145
163
  def main():
146
164
  parser = argparse.ArgumentParser()
147
- parser.add_argument("--extended", help="Extended Information?")
165
+ parser.add_argument("--extended", default = True, help="Extended Information?")
148
166
  parser.add_argument("--server", help="Name of the server to display status for")
149
167
  parser.add_argument("--url", help="URL Platform to connect to")
150
168
  parser.add_argument("--userid", help="User Id")
@@ -47,7 +47,7 @@ def refresh_connector(
47
47
  server = "integration-daemon" if server is None else server
48
48
 
49
49
  s_client.refresh_integration_connectors(
50
- connector_name=connector, server_guid=None, server_name=server
50
+ connector_name=connector, server_guid=None, display_name=server
51
51
  )
52
52
 
53
53
  print(f"\n===> Integration Daemon '{server}' refreshed {statement}.")