Skip to content

Commit ae35e29

Browse files
committed
Add optional OutputCapabilities to the output descriptor (DataProvider)
OutputCapabilities indicate capabilities of am output, such as "canCreate" and "canDelete". "canCreate" indicates that a given output can create a derived outputs. "canDelete" indicates that a given output can be deleted. Signed-off-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
1 parent bf8bae4 commit ae35e29

File tree

3 files changed

+89
-1
lines changed

3 files changed

+89
-1
lines changed

test_tsp.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from tsp.configuration_source import ConfigurationSource
3737
from tsp.configuration_source_set import ConfigurationSourceSet
3838
from tsp.output_descriptor import OutputDescriptor
39+
from tsp.output_capabilities import OutputCapabilities
3940

4041
STATISTICS_DP_ID = (
4142
"org.eclipse.tracecompass.analysis.timing.core.segmentstore.SegmentStoreStatisticsDataProvider:"
@@ -757,6 +758,10 @@ def test_create_delete_derived_output(self, kernel):
757758
assert isinstance(response.model, OutputDescriptor)
758759
assert response.model.parent_id == INANDOUT_DP_ID
759760

761+
assert isinstance(response.model.capabilities, OutputCapabilities)
762+
assert response.model.capabilities.can_create == False
763+
assert response.model.capabilities.can_delete == True
764+
760765
derived_id = response.model.id
761766

762767
response = self.tsp_client.fetch_experiment_outputs(experiment_uuid)

tsp/output_capabilities.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (C) 2025 - 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+
"""OutputDescriptor class file."""
24+
25+
import json
26+
27+
CAN_CREATE_KEY = "canCreate"
28+
CAN_DELETE_KEY = "canDelete"
29+
30+
# pylint: disable=too-few-public-methods,too-many-instance-attributes
31+
class OutputCapabilities:
32+
'''
33+
classdocs
34+
'''
35+
36+
# pylint: disable=too-many-branches
37+
def __init__(self, params):
38+
'''
39+
Constructor
40+
'''
41+
42+
# Capability canCreate
43+
if CAN_CREATE_KEY in params:
44+
# pylint: disable=invalid-name
45+
self.can_create = params.get(CAN_CREATE_KEY)
46+
del params[CAN_CREATE_KEY]
47+
else: # pragma: no cover
48+
self.can_create = None
49+
50+
if CAN_DELETE_KEY in params:
51+
# pylint: disable=invalid-name
52+
self.can_delete = params.get(CAN_DELETE_KEY)
53+
del params[CAN_DELETE_KEY]
54+
else: # pragma: no cover
55+
self.can_delete = None
56+
57+
def __repr__(self):
58+
return 'OutputCapabilities(canCreate={}, canDelete={})'.format(self.can_create, self.can_delete)
59+
60+
def to_json(self):
61+
return json.dumps(self, cls=OutputCapabilities, indent=4)
62+
63+
class OutputCapabilitiesEncoder(json.JSONEncoder):
64+
def default(self, obj):
65+
if isinstance(obj, OutputCapabilities):
66+
return {
67+
'canCreate': obj.can_create,
68+
'canDelete': obj.can_delete
69+
}
70+
return super().default(obj)

tsp/output_descriptor.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The MIT License (MIT)
22
#
3-
# Copyright (C) 2020 - Ericsson
3+
# Copyright (C) 2020 - 2025 - Ericsson
44
#
55
# Permission is hereby granted, free of charge, to any person obtaining a copy
66
# of this software and associated documentation files (the "Software"), to deal
@@ -24,6 +24,7 @@
2424

2525
import json
2626
from tsp.configuration import Configuration, ConfigurationEncoder
27+
from tsp.output_capabilities import OutputCapabilities, OutputCapabilitiesEncoder
2728

2829
NA = "N/A"
2930
UNKOWN = "UNKNOWN"
@@ -38,6 +39,7 @@
3839
IS_FINAL_KEY = "final"
3940
COMPATIBLE_PROVIDERS_KEY = "compatibleProviders"
4041
CONFIGURATION_KEY = "configuration"
42+
CAPABILITES_KEY = "capabilities"
4143

4244

4345
# pylint: disable=too-few-public-methods,too-many-instance-attributes
@@ -133,6 +135,13 @@ def __init__(self, params):
133135
del params[CONFIGURATION_KEY]
134136
else:
135137
self.configuration = []
138+
139+
# Capabilites of this data provider.
140+
if CAPABILITES_KEY in params:
141+
self.capabilities = OutputCapabilities(params.get(CAPABILITES_KEY))
142+
del params[CAPABILITES_KEY]
143+
else:
144+
self.capabilities = None
136145

137146

138147
def __repr__(self):
@@ -163,5 +172,9 @@ def default(self, obj):
163172
# optional configuration
164173
if isinstance(obj.configuration, Configuration):
165174
result[CONFIGURATION_KEY] = ConfigurationEncoder().default(obj.configuration)
175+
176+
# optional capabilities
177+
if isinstance(obj.capabilities, OutputCapabilities):
178+
result[CAPABILITES_KEY] = OutputCapabilitiesEncoder().default(obj.capabilities)
166179
return result
167180
return super().default(obj)

0 commit comments

Comments
 (0)