@@ -221,7 +221,7 @@ def prepare(self, *, callback: ABCCallbackProxy, logger):
221
221
222
222
self .set_dirty ()
223
223
224
- def reserve (self , * , policy : ABCPolicy ):
224
+ def reserve (self , * , policy : ABCPolicy ) -> bool :
225
225
# These handlers may need to be slightly more sophisticated, since a
226
226
# client may bid multiple times on a ticket as part of an auction
227
227
# protocol: so we may receive a reserve or extend when there is already
@@ -232,12 +232,13 @@ def reserve(self, *, policy: ABCPolicy):
232
232
self .pending_state != ReservationPendingStates .Ticketing :
233
233
# We do not want to fail the reservation simply log a warning and exit from reserve
234
234
self .logger .warning ("Duplicate ticket request" )
235
- return
235
+ return False
236
236
237
237
self .policy = policy
238
238
self .approved = False
239
239
self .bid_pending = True
240
240
self .map_and_update (ticketed = False )
241
+ return True
241
242
242
243
def service_reserve (self ):
243
244
# resources is null initially. It becomes non-null once the
@@ -276,13 +277,13 @@ def service_extend_ticket(self):
276
277
pending = ReservationPendingStates .None_ )
277
278
self .generate_update ()
278
279
279
- def close (self ):
280
+ def close (self , force : bool = False ):
280
281
send_notification = False
281
282
if self .state == ReservationStates .Nascent or self .pending_state != ReservationPendingStates .None_ :
282
283
self .logger .warning ("Closing a reservation in progress" )
283
284
send_notification = True
284
285
285
- if self .state != ReservationStates .Closed :
286
+ if self .state not in [ ReservationStates .Closed , ReservationStates . CloseFail ] or force :
286
287
if self .pending_state == ReservationPendingStates .Priming or \
287
288
(self .pending_state == ReservationPendingStates .Ticketing and not self .bid_pending ):
288
289
# Close in Priming is a special case: when processing the close
@@ -296,7 +297,11 @@ def close(self):
296
297
self .logger .debug ("closing reservation #{} while in Priming" .format (self .rid ))
297
298
self .closed_in_priming = True
298
299
299
- self .transition (prefix = "closed" , state = ReservationStates .Closed , pending = ReservationPendingStates .None_ )
300
+ if not self .update_data .is_failed ():
301
+ self .transition (prefix = "closed" , state = ReservationStates .Closed , pending = ReservationPendingStates .None_ )
302
+ else :
303
+ self .transition (prefix = "closed-failed" , state = ReservationStates .CloseFail ,
304
+ pending = ReservationPendingStates .None_ )
300
305
self .policy .closed (reservation = self )
301
306
302
307
if send_notification :
@@ -536,7 +541,16 @@ def set_authority(self, *, authority: ABCAuthorityProxy):
536
541
def update_lease (self , * , incoming : ABCReservationMixin , update_data ):
537
542
self .logger .info (f"Received Update Lease: { incoming } at Broker" )
538
543
# TODO add any processing if needed
539
- self .logger .info (f"Do Nothing!" )
544
+ if incoming .get_resources () and incoming .get_resources ().get_sliver () and incoming .get_resources ().get_sliver ().get_reservation_info ():
545
+ incoming_state = incoming .get_resources ().get_sliver ().get_reservation_info ().reservation_state
546
+ else :
547
+ incoming_state = None
548
+ self .logger .info (f"Update Lease from authority in state: { self .get_state ()} "
549
+ f"Incoming: { incoming_state } |{ incoming .get_notices ()} update_data: { update_data } !" )
550
+ if incoming_state and incoming_state == str (ReservationStates .CloseFail ):
551
+ self .update_data .absorb (other = update_data )
552
+ self .logger .info ("Closing a reservation which failed to delete at the authority" )
553
+ self .close ()
540
554
541
555
def handle_failed_rpc (self , * , failed : FailedRPC ):
542
556
if failed .get_request_type () == RPCRequestType .UpdateTicket and \
0 commit comments