Skip to content

Commit cef26b7

Browse files
authored
Rwh cxl agent fabric merge (#42)
I think this fabric_merge branch is ready to pull to main
2 parents a798300 + b3acaec commit cef26b7

File tree

6 files changed

+1239
-70
lines changed

6 files changed

+1239
-70
lines changed

sunfish/lib/core.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,24 +232,28 @@ def replace_object(self, path: str, payload: dict):
232232
str|exception: return the replaced resource or an exception in case of fault.
233233
"""
234234
object_type = self._get_type(payload, path=path)
235+
payload_to_write = payload
235236
# we assume no changes can be done on collections
236237
if "Collection" in object_type:
237238
raise CollectionNotSupported()
238239
try:
239240
# 1. check the path target of the operation exists
240241
self.storage_backend.read(path)
241242
# 2. is needed first forward the request to the agent managing the object
242-
self.objects_manager.forward_to_manager(SunfishRequestType.REPLACE, path, payload=payload)
243+
#self.objects_manager.forward_to_manager(SunfishRequestType.REPLACE, path, payload=payload)
244+
agent_response = self.objects_manager.forward_to_manager(SunfishRequestType.REPLACE, path, payload=payload)
245+
if agent_response:
246+
payload_to_write = agent_response
243247
# 3. Execute any custom handler for this object type
244-
self.objects_handler.dispatch(object_type, path, SunfishRequestType.REPLACE, payload=payload)
248+
self.objects_handler.dispatch(object_type, path, SunfishRequestType.REPLACE, payload=payload_to_write)
245249
except ResourceNotFound:
246250
logger.error(logger.error(f"The resource to be replaced ({path}) does not exist."))
247251
except AttributeError:
248252
# The object does not have a handler.
249253
logger.debug(f"The object {object_type} does not have a custom handler")
250254
pass
251255
# 4. persist change in Sunfish tree
252-
return self.storage_backend.replace(payload)
256+
return self.storage_backend.replace(payload_to_write)
253257

254258
def patch_object(self, path: str, payload: dict):
255259
"""Calls the correspondent patch function from the backend implementation.
@@ -261,6 +265,7 @@ def patch_object(self, path: str, payload: dict):
261265
str|exception: return the updated resource or an exception in case of fault.
262266
"""
263267
# we assume no changes can be done on collections
268+
payload_to_write = payload
264269
obj = self.storage_backend.read(path)
265270
object_type = self._get_type(obj, path=path)
266271
if "Collection" in object_type:
@@ -269,7 +274,10 @@ def patch_object(self, path: str, payload: dict):
269274
# 1. check the path target of the operation exists
270275
self.storage_backend.read(path)
271276
# 2. is needed first forward the request to the agent managing the object
272-
self.objects_manager.forward_to_manager(SunfishRequestType.PATCH, path, payload=payload)
277+
#self.objects_manager.forward_to_manager(SunfishRequestType.PATCH, path, payload=payload)
278+
agent_response = self.objects_manager.forward_to_manager(SunfishRequestType.PATCH, path, payload=payload)
279+
if agent_response:
280+
payload_to_write = agent_response
273281
# 3. Execute any custom handler for this object type
274282
self.objects_handler.dispatch(object_type, path, SunfishRequestType.PATCH, payload=payload)
275283
except ResourceNotFound:
@@ -280,7 +288,7 @@ def patch_object(self, path: str, payload: dict):
280288
pass
281289

282290
# 4. persist change in Sunfish tree
283-
return self.storage_backend.patch(path, payload)
291+
return self.storage_backend.patch(path, payload_to_write)
284292

285293
def delete_object(self, path: string):
286294
"""Calls the correspondent remove function from the backend implementation. Checks that the path is valid.

sunfish/storage/backend_interface.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright IBM Corp. 2023
2+
# Copyright Hewlett Packard Enterprise Development LP 2024
23
# This software is available to you under a BSD 3-Clause License.
34
# The full license terms are available here: https://github.com/OpenFabrics/sunfish_library_reference/blob/main/LICENSE
45

@@ -22,4 +23,8 @@ def patch():
2223

2324
@abstractmethod
2425
def remove():
25-
pass
26+
pass
27+
28+
@abstractmethod
29+
def reset_resources():
30+
pass

0 commit comments

Comments
 (0)