Skip to content

Commit a885ed1

Browse files
committed
Add live find-slot with use_live_data flag
When use_live_data is true, compute find-slot using the cached resource summary for capacity data and live orchestrator DB reservations for allocation data instead of proxying to the Reports API. - Add use_live_data boolean to find-slot swagger spec - Add _find_slot_live() with sliding window search in orchestrator_handler - Add get_link_allocations() and get_component_allocations() DB methods through the full management actor chain for lightweight reservation queries
1 parent ef16d33 commit a885ed1

9 files changed

Lines changed: 623 additions & 4 deletions

File tree

fabric_cf/actor/core/apis/abc_actor_management_object.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,20 @@ def get_links(self, *, node_id: str, rsv_type: list[str], states: list[int], sta
294294
@return Dictionary with link node id as key and cumulative bandwidth.
295295
"""
296296

297+
def get_link_allocations(self, *, rsv_type: list[str], states: list[int],
298+
start: datetime = None, end: datetime = None) -> list[dict]:
299+
"""
300+
Return per-reservation link allocation data with lease times.
301+
@return list of dicts with keys: link_node_id, bw, lease_start, lease_end, site
302+
"""
303+
304+
def get_component_allocations(self, *, states: list[int],
305+
start: datetime = None, end: datetime = None) -> list[dict]:
306+
"""
307+
Return per-reservation component allocation data with lease times and host info.
308+
@return list of dicts with keys: host, site, lease_start, lease_end, component, bdf
309+
"""
310+
297311
def get_slices(self, *, slice_id: ID, caller: AuthToken, slice_name: str = None, email: str = None,
298312
states: List[int] = None, project: str = None, limit: int = None,
299313
offset: int = None, user_id: str = None, search: str = None,

fabric_cf/actor/core/apis/abc_database.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,29 @@ def get_links(self, *, node_id: str, states: list[int], rsv_type: list[str], sta
205205
@return Dictionary with link node id as the key and value cumulative bw.
206206
"""
207207

208+
@abstractmethod
209+
def get_link_allocations(self, *, states: list[int], rsv_type: list[str],
210+
start: datetime = None, end: datetime = None) -> list[dict]:
211+
"""
212+
Return per-reservation link allocation data with lease times.
213+
@param states: list of reservation states to include
214+
@param rsv_type: list of reservation types (ServiceType strings)
215+
@param start: start of time range
216+
@param end: end of time range
217+
@return list of dicts with keys: link_node_id, bw, lease_start, lease_end, site
218+
"""
219+
220+
@abstractmethod
221+
def get_component_allocations(self, *, states: list[int],
222+
start: datetime = None, end: datetime = None) -> list[dict]:
223+
"""
224+
Return per-reservation component allocation data with lease times and host info.
225+
@param states: list of reservation states to include
226+
@param start: start of time range
227+
@param end: end of time range
228+
@return list of dicts with keys: host, site, lease_start, lease_end, component, bdf
229+
"""
230+
208231
@abstractmethod
209232
def get_client_reservations(self, *, slice_id: ID = None) -> List[ABCReservationMixin]:
210233
"""

fabric_cf/actor/core/apis/abc_mgmt_actor.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,22 @@ def get_links(self, *, node_id: str, rsv_type: list[str], states: list[int], sta
208208
"""
209209
raise NotImplementedError
210210

211+
def get_link_allocations(self, *, rsv_type: list[str], states: list[int],
212+
start: datetime = None, end: datetime = None) -> list[dict]:
213+
"""
214+
Return per-reservation link allocation data with lease times.
215+
@return list of dicts with keys: link_node_id, bw, lease_start, lease_end, site
216+
"""
217+
raise NotImplementedError
218+
219+
def get_component_allocations(self, *, states: list[int],
220+
start: datetime = None, end: datetime = None) -> list[dict]:
221+
"""
222+
Return per-reservation component allocation data with lease times and host info.
223+
@return list of dicts with keys: host, site, lease_start, lease_end, component, bdf
224+
"""
225+
raise NotImplementedError
226+
211227
@abstractmethod
212228
def get_sites(self, *, site: str) -> List[SiteAvro] or None:
213229
"""

fabric_cf/actor/core/manage/actor_management_object.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,14 @@ def get_links(self, *, node_id: str, rsv_type: list[str], states: list[int], sta
441441
return self.db.get_links(node_id=node_id, rsv_type=rsv_type, states=states, start=start,
442442
end=end, excludes=excludes)
443443

444+
def get_link_allocations(self, *, rsv_type: list[str], states: list[int],
445+
start: datetime = None, end: datetime = None) -> list[dict]:
446+
return self.db.get_link_allocations(states=states, rsv_type=rsv_type, start=start, end=end)
447+
448+
def get_component_allocations(self, *, states: list[int],
449+
start: datetime = None, end: datetime = None) -> list[dict]:
450+
return self.db.get_component_allocations(states=states, start=start, end=end)
451+
444452
def get_reservations(self, *, caller: AuthToken, states: List[int] = None,
445453
slice_id: ID = None, rid: ID = None, oidc_claim_sub: str = None,
446454
email: str = None, rid_list: List[str] = None, type: str = None,

fabric_cf/actor/core/manage/local/local_actor.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,23 @@ def get_links(self, *, node_id: str, rsv_type: list[str], states: list[int], sta
145145
except Exception as e:
146146
self.on_exception(e=e, traceback_str=traceback.format_exc())
147147

148+
def get_link_allocations(self, *, rsv_type: list[str], states: list[int],
149+
start: datetime = None, end: datetime = None) -> list[dict]:
150+
try:
151+
return self.manager.get_link_allocations(rsv_type=rsv_type, states=states,
152+
start=start, end=end)
153+
except Exception as e:
154+
self.on_exception(e=e, traceback_str=traceback.format_exc())
155+
return []
156+
157+
def get_component_allocations(self, *, states: list[int],
158+
start: datetime = None, end: datetime = None) -> list[dict]:
159+
try:
160+
return self.manager.get_component_allocations(states=states, start=start, end=end)
161+
except Exception as e:
162+
self.on_exception(e=e, traceback_str=traceback.format_exc())
163+
return []
164+
148165
def get_sites(self, *, site: str) -> List[SiteAvro] or None:
149166
self.clear_last()
150167
try:

fabric_cf/actor/core/plugins/db/actor_database.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,28 @@ def get_links(self, *, node_id: str, states: list[int], rsv_type: list[str], sta
631631
if self.lock.locked():
632632
self.lock.release()
633633

634+
def get_link_allocations(self, *, states: list[int], rsv_type: list[str],
635+
start: datetime = None, end: datetime = None) -> list[dict]:
636+
try:
637+
return self.db.get_link_allocations(states=states, rsv_type=rsv_type, start=start, end=end)
638+
except Exception as e:
639+
self.logger.error(e)
640+
finally:
641+
if self.lock.locked():
642+
self.lock.release()
643+
return []
644+
645+
def get_component_allocations(self, *, states: list[int],
646+
start: datetime = None, end: datetime = None) -> list[dict]:
647+
try:
648+
return self.db.get_component_allocations(states=states, start=start, end=end)
649+
except Exception as e:
650+
self.logger.error(e)
651+
finally:
652+
if self.lock.locked():
653+
self.lock.release()
654+
return []
655+
634656
def get_reservations(self, *, slice_id: ID = None, graph_node_id: str = None, project_id: str = None,
635657
email: str = None, oidc_sub: str = None, rid: ID = None, states: list[int] = None,
636658
site: str = None, rsv_type: list[str] = None, start: datetime = None,

fabric_cf/actor/db/psql_database.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,122 @@ def get_links(self, *, node_id: str, states: list[int], rsv_type: list[str],
10501050
raise e
10511051
return result
10521052

1053+
def get_link_allocations(self, *, states: list[int], rsv_type: list[str],
1054+
start: datetime = None, end: datetime = None) -> list[dict]:
1055+
"""
1056+
Return per-reservation link allocation data with lease times.
1057+
1058+
Each dict contains: link_node_id, bw, lease_start, lease_end.
1059+
This avoids deserializing full slivers for network service reservations.
1060+
1061+
@param states: list of reservation states to include
1062+
@param rsv_type: list of reservation types (ServiceType strings)
1063+
@param start: start of time range
1064+
@param end: end of time range
1065+
@return list of dicts with link allocation data
1066+
"""
1067+
result = []
1068+
session = self.get_session()
1069+
try:
1070+
lease_end_filter = True
1071+
if start is not None or end is not None:
1072+
if start is not None and end is not None:
1073+
lease_end_filter = or_(
1074+
and_(start <= Reservations.lease_end, Reservations.lease_end <= end),
1075+
and_(start <= Reservations.lease_start, Reservations.lease_start <= end),
1076+
and_(Reservations.lease_start <= start, Reservations.lease_end >= end)
1077+
)
1078+
elif start is not None:
1079+
lease_end_filter = start <= Reservations.lease_end
1080+
elif end is not None:
1081+
lease_end_filter = Reservations.lease_end <= end
1082+
1083+
rows = (
1084+
session.query(
1085+
Links.node_id,
1086+
Links.bw,
1087+
Reservations.lease_start,
1088+
Reservations.lease_end,
1089+
Reservations.site,
1090+
)
1091+
.join(Reservations, Links.reservation_id == Reservations.rsv_id)
1092+
.filter(Reservations.rsv_type.in_(rsv_type))
1093+
.filter(Reservations.rsv_state.in_(states))
1094+
.filter(lease_end_filter)
1095+
.all()
1096+
)
1097+
1098+
for row in rows:
1099+
result.append({
1100+
"link_node_id": row[0],
1101+
"bw": row[1] or 0,
1102+
"lease_start": row[2],
1103+
"lease_end": row[3],
1104+
"site": row[4],
1105+
})
1106+
except Exception as e:
1107+
self.logger.error(Constants.EXCEPTION_OCCURRED.format(e))
1108+
raise e
1109+
return result
1110+
1111+
def get_component_allocations(self, *, states: list[int],
1112+
start: datetime = None, end: datetime = None) -> list[dict]:
1113+
"""
1114+
Return per-reservation component allocation data with lease times and host info.
1115+
1116+
Each dict contains: host, site, lease_start, lease_end, component (name), bdf.
1117+
This avoids deserializing full slivers for component counting.
1118+
1119+
@param states: list of reservation states to include
1120+
@param start: start of time range
1121+
@param end: end of time range
1122+
@return list of dicts with component allocation data
1123+
"""
1124+
result = []
1125+
session = self.get_session()
1126+
try:
1127+
lease_end_filter = True
1128+
if start is not None or end is not None:
1129+
if start is not None and end is not None:
1130+
lease_end_filter = or_(
1131+
and_(start <= Reservations.lease_end, Reservations.lease_end <= end),
1132+
and_(start <= Reservations.lease_start, Reservations.lease_start <= end),
1133+
and_(Reservations.lease_start <= start, Reservations.lease_end >= end)
1134+
)
1135+
elif start is not None:
1136+
lease_end_filter = start <= Reservations.lease_end
1137+
elif end is not None:
1138+
lease_end_filter = Reservations.lease_end <= end
1139+
1140+
rows = (
1141+
session.query(
1142+
Reservations.host,
1143+
Reservations.site,
1144+
Reservations.lease_start,
1145+
Reservations.lease_end,
1146+
Components.component,
1147+
Components.bdf,
1148+
)
1149+
.join(Components, Components.reservation_id == Reservations.rsv_id)
1150+
.filter(Reservations.rsv_state.in_(states))
1151+
.filter(lease_end_filter)
1152+
.all()
1153+
)
1154+
1155+
for row in rows:
1156+
result.append({
1157+
"host": row[0],
1158+
"site": row[1],
1159+
"lease_start": row[2],
1160+
"lease_end": row[3],
1161+
"component": row[4],
1162+
"bdf": row[5],
1163+
})
1164+
except Exception as e:
1165+
self.logger.error(Constants.EXCEPTION_OCCURRED.format(e))
1166+
raise e
1167+
return result
1168+
10531169
def get_reservations_by_rids(self, *, rsv_resid_list: list) -> list:
10541170
"""
10551171
Get Reservations for an actor by reservation ids

0 commit comments

Comments
 (0)