Skip to content

Commit

Permalink
Add optional OutputCapabilities to the output descriptor (DataProvider)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
bhufmann committed Jan 21, 2025
1 parent bf8bae4 commit 362cbc1
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
5 changes: 5 additions & 0 deletions test_tsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from tsp.configuration_source import ConfigurationSource
from tsp.configuration_source_set import ConfigurationSourceSet
from tsp.output_descriptor import OutputDescriptor
from tsp.output_capabilities import OutputCapabilities

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

assert isinstance(response.model.capabilities, OutputCapabilities)
assert response.model.capabilities.can_create == False
assert response.model.capabilities.can_delete == True

derived_id = response.model.id

response = self.tsp_client.fetch_experiment_outputs(experiment_uuid)
Expand Down
70 changes: 70 additions & 0 deletions tsp/output_capabilities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# The MIT License (MIT)
#
# Copyright (C) 2025 - Ericsson
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

"""OutputDescriptor class file."""

import json

CAN_CREATE_KEY = "canCreate"
CAN_DELETE_KEY = "canDelete"

# pylint: disable=too-few-public-methods,too-many-instance-attributes
class OutputCapabilities:
'''
classdocs
'''

# pylint: disable=too-many-branches
def __init__(self, params):
'''
Constructor
'''

# Capability canCreate
if CAN_CREATE_KEY in params:
# pylint: disable=invalid-name
self.can_create = params.get(CAN_CREATE_KEY)
del params[CAN_CREATE_KEY]
else: # pragma: no cover
self.can_create = None

if CAN_DELETE_KEY in params:
# pylint: disable=invalid-name
self.can_delete = params.get(CAN_DELETE_KEY)
del params[CAN_DELETE_KEY]
else: # pragma: no cover
self.can_delete = None

def __repr__(self):
return 'OutputCapabilities(canCreate={}, canDelete={})'.format(self.can_create, self.can_delete)

def to_json(self):
return json.dumps(self, cls=OutputCapabilities, indent=4)

class OutputCapabilitiesEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, OutputCapabilities):
return {
'canCreate': obj.can_create,
'canDelete': obj.can_delete
}
return super().default(obj)
15 changes: 14 additions & 1 deletion tsp/output_descriptor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The MIT License (MIT)
#
# Copyright (C) 2020 - Ericsson
# Copyright (C) 2020 - 2025 - Ericsson
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -24,6 +24,7 @@

import json
from tsp.configuration import Configuration, ConfigurationEncoder
from tsp.output_capabilities import OutputCapabilities, OutputCapabilitiesEncoder

NA = "N/A"
UNKOWN = "UNKNOWN"
Expand All @@ -38,6 +39,7 @@
IS_FINAL_KEY = "final"
COMPATIBLE_PROVIDERS_KEY = "compatibleProviders"
CONFIGURATION_KEY = "configuration"
CAPABILITES_KEY = "capabilities"


# pylint: disable=too-few-public-methods,too-many-instance-attributes
Expand Down Expand Up @@ -133,6 +135,13 @@ def __init__(self, params):
del params[CONFIGURATION_KEY]
else:
self.configuration = []

# Capabilites of this data provider.
if CAPABILITES_KEY in params:
self.capabilities = OutputCapabilities(params.get(CAPABILITES_KEY))
del params[CAPABILITES_KEY]
else:
self.capabilities = None


def __repr__(self):
Expand Down Expand Up @@ -163,5 +172,9 @@ def default(self, obj):
# optional configuration
if isinstance(obj.configuration, Configuration):
result[CONFIGURATION_KEY] = ConfigurationEncoder().default(obj.configuration)

# optional capabilities
if isinstance(obj.capabilities, OutputCapabilities):
result[CAPABILITES_KEY] = OutputCapabilitiesEncoder().default(obj.capabilities)
return result
return super().default(obj)

0 comments on commit 362cbc1

Please sign in to comment.