Skip to content

Commit 1e73eec

Browse files
Vlad Aramabhufmann
authored andcommitted
Implement identifier service
Signed-off-by: Vlad Arama <[email protected]>
1 parent 9bb682a commit 1e73eec

File tree

5 files changed

+157
-0
lines changed

5 files changed

+157
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ usage: tsp_cli_client [-h] [--ip IP] [--port PORT]
8888
[--config-id CONFIG_ID]
8989
[--params PARAMS]
9090
[--get-health]
91+
[--get-identifier]
9192

9293
CLI client to send Trace Server Protocol commands to a Trace Server.
9394

@@ -158,6 +159,7 @@ optional arguments:
158159
id of configuration
159160
--params PARAMS comma separated key value pairs (key1=val1,key2=val2)
160161
--get-health Get the health status of the server
162+
--get-identifier Identify important information regarding the server and the system
161163
```
162164

163165
Examples:
@@ -188,6 +190,7 @@ Examples:
188190
./tsp_cli_client --update-configuration --type-id TYPE_ID --config-id CONFIG_ID --params key1=value1,key2=value2
189191
./tsp_cli_client --delete-configuration CONFIGURATION_ID --type-id TYPE_ID
190192
./tsp_cli_client --get-health
193+
./tsp_cli_client --get-identifier
191194
```
192195

193196
[agc]: https://kislyuk.github.io/argcomplete/#activating-global-completion

test_tsp.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,20 @@ def test_fetch_health(self):
579579
assert response.model
580580
assert response.model.status == HealthStatus.UP
581581

582+
def test_fetch_identifier(self):
583+
"""Expect a successful identifier response"""
584+
response = self.tsp_client.fetch_identifier()
585+
assert response.status_code == 200
586+
assert response.model
587+
assert response.model.server_version
588+
assert response.model.build_time
589+
assert response.model.os_name
590+
assert response.model.os_arch
591+
assert response.model.os_version
592+
assert response.model.cpu_count
593+
assert response.model.max_memory
594+
assert response.model.product_id
595+
582596
@staticmethod
583597
def __requested_parameters(response):
584598
parameters = {}

tsp/identifier.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (C) 2024 - Ericsson
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
"""Identifier Service Class"""
24+
25+
SERVER_VERSION = "version"
26+
BUILD_TIME = "buildTime"
27+
OS_NAME = "os"
28+
OS_ARCH = "osArch"
29+
OS_VERSION = "osVersion"
30+
CPU_COUNT = "cpuCount"
31+
MAX_MEMORY = "maxMemory"
32+
LAUNCHER_NAME = "launcherName"
33+
PRODUCT_ID = "productId"
34+
35+
36+
class Identifier:
37+
'''
38+
Model of the Identifier Service. This is a Service used to identify important information
39+
regarding the trace server and the system it is running on.
40+
'''
41+
def __init__(self, params):
42+
'''
43+
Constructor
44+
'''
45+
46+
# Server Version
47+
if SERVER_VERSION in params:
48+
self.server_version = params.get(SERVER_VERSION)
49+
del params[SERVER_VERSION]
50+
else:
51+
self.server_version = None
52+
53+
# Build Time
54+
if BUILD_TIME in params:
55+
self.build_time = params.get(BUILD_TIME)
56+
del params[BUILD_TIME]
57+
else:
58+
self.build_time = None
59+
60+
# OS Name
61+
if OS_NAME in params:
62+
self.os_name = params.get(OS_NAME)
63+
del params[OS_NAME]
64+
else:
65+
self.os_name = None
66+
67+
# OS Arch
68+
if OS_ARCH in params:
69+
self.os_arch = params.get(OS_ARCH)
70+
del params[OS_ARCH]
71+
else:
72+
self.os_arch = None
73+
74+
# OS Version
75+
if OS_VERSION in params:
76+
self.os_version = params.get(OS_VERSION)
77+
del params[OS_VERSION]
78+
else:
79+
self.os_version = None
80+
81+
# CPU Count
82+
if CPU_COUNT in params:
83+
self.cpu_count = params.get(CPU_COUNT)
84+
del params[CPU_COUNT]
85+
else:
86+
self.cpu_count = None
87+
88+
# Max Memory
89+
if MAX_MEMORY in params:
90+
self.max_memory = params.get(MAX_MEMORY)
91+
del params[MAX_MEMORY]
92+
else:
93+
self.max_memory = None
94+
95+
# Product ID
96+
if PRODUCT_ID in params:
97+
self.product_id = params.get(PRODUCT_ID)
98+
del params[PRODUCT_ID]
99+
else:
100+
self.product_id = None
101+
102+
# Launcher Name
103+
if LAUNCHER_NAME in params:
104+
self.launcher_name = params.get(LAUNCHER_NAME)
105+
del params[LAUNCHER_NAME]
106+
else:
107+
self.launcher_name = None
108+
109+
def to_string(self):
110+
'''
111+
to_string method
112+
'''
113+
return f"Identifier[version={self.server_version}, buildTime={self.build_time}, os={self.os_name}, osArch={self.os_arch}, osVersion={self.os_version}, cpuCount={self.cpu_count}, maxMemory={self.max_memory}, productId={self.product_id}, launcherName={self.launcher_name}]"

tsp/tsp_client.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from tsp.experiment import Experiment
3939
from tsp.output_descriptor import OutputDescriptor
4040
from tsp.health import Health
41+
from tsp.identifier import Identifier
4142

4243
APPLICATION_JSON = 'application/json'
4344

@@ -535,3 +536,20 @@ def fetch_health(self):
535536
else: # pragma: no cover
536537
print("get health failed: {0}".format(response.status_code))
537538
return TspClientResponse(None, response.status_code, response.text)
539+
540+
def fetch_identifier(self):
541+
'''
542+
Fetch the identifier service to obtain important information regarding the trace server
543+
and the system it is running on.
544+
545+
:return: :class:`TspClientResponse <Identifier> object
546+
:rtype: TspClientResponse
547+
'''
548+
api_url = '{0}identifier'.format(self.base_url)
549+
response = requests.get(api_url, headers=headers)
550+
if response.status_code == 200:
551+
return TspClientResponse(Identifier(json.loads(response.content.decode('utf-8'))),
552+
response.status_code, response.text)
553+
else: # pragma: no cover
554+
print("get identifiers failed: {0}".format(response.status_code))
555+
return TspClientResponse(None, response.status_code, response.text)

tsp_cli_client

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ if __name__ == "__main__":
239239
parser.add_argument("--config-id", dest="config_id", help="id of configuration")
240240
parser.add_argument("--params", dest="params", help="semicolon separated key value pairs (key1=val1;key2=val2)")
241241
parser.add_argument("--get-health", dest="get_health", action='store_true', help="Get the health status of the server")
242+
parser.add_argument("--get-identifier", dest="get_identifier", action='store_true', help="Get important information regarding the trace server and the system")
242243

243244
argcomplete.autocomplete(parser)
244245
options = parser.parse_args()
@@ -590,6 +591,14 @@ if __name__ == "__main__":
590591
else:
591592
sys.exit(1)
592593

594+
if options.get_identifier:
595+
response = tsp_client.fetch_identifier()
596+
if response.status_code == 200:
597+
print(' {0}'.format(response.model.to_string()))
598+
sys.exit(0)
599+
else:
600+
sys.exit(1)
601+
593602
except requests.exceptions.ConnectionError as e:
594603
print('Unexpected error: {0}'.format(e))
595604
sys.exit(1)

0 commit comments

Comments
 (0)