@@ -339,49 +339,52 @@ func (cibph CreateNVLinkLogicalPartitionHandler) Handle(c echo.Context) error {
339339
340340 logger .Info ().Str ("Workflow ID" , wid ).Msg ("completed NVLink Logical Partition creation workflow" )
341341
342+ // commit transaction - must commit once NVLink Logical Partition has been created
343+ // If we have an error while updating the status, we'll rollback REST layer cache
344+ // but object will remain on Site
345+ err = tx .Commit ()
346+ if err != nil {
347+ logger .Error ().Err (err ).Msg ("error committing NVLink Logical Partition transaction to DB" )
348+ return cerr .NewAPIErrorResponse (c , http .StatusInternalServerError , "Failed to create NVLink Logical Partition, DB error" , nil )
349+ }
350+
351+ // set committed so, deferred cleanup functions will do nothing
352+ txCommitted = true
353+
342354 // update the db record for NVLink Logical Partition with the status from the workflow
355+ // If we run into an error, we'll log it but won't return error
343356 unvllp := nvllp
357+ ussd := ssd // Use original status detail by default
344358 if workflowResult != nil {
345359 logger .Info ().Str ("Workflow ID" , wid ).Msg ("received NVLink Logical Partition info from workflow" )
346360
347361 status , statusMessage := common .GetNVLinkLogicalPartitionStatus (workflowResult .Status .State )
348362 // if status is nil, then default is pending and inventory will be updating status from workflow
349363 if status != nil {
350- // update the db record for NVLink Logical Partition
351- unvllp , err = nvllpDAO .Update (ctx , tx , cdbm.NVLinkLogicalPartitionUpdateInput {
364+ // update the db record for NVLink Logical Partition (using new transaction/nil since tx is committed)
365+ unvllp , err = nvllpDAO .Update (ctx , nil , cdbm.NVLinkLogicalPartitionUpdateInput {
352366 NVLinkLogicalPartitionID : nvllp .ID ,
353367 Status : status ,
354368 })
355369
356370 if err != nil {
357- logger .Error ().Err (err ).Msg ("unable to update NVLink Logical Partition record in DB" )
358- return cerr .NewAPIErrorResponse (c , http .StatusInternalServerError , "Failed to update NVLink Logical Partition, DB error" , nil )
359- }
360-
361- ssd , err := sdDAO .CreateFromParams (ctx , tx , nvllp .ID .String (), * status , statusMessage )
362- if err != nil {
363- logger .Error ().Err (err ).Msg ("error creating Status Detail DB entry" )
364- return cerr .NewAPIErrorResponse (c , http .StatusInternalServerError , "Failed to create Status Detail for NVLink Logical Partition, DB error" , nil )
365- }
366- if ssd == nil {
367- logger .Error ().Msg ("Status Detail DB entry not returned from CreateFromParams" )
368- return cerr .NewAPIErrorResponse (c , http .StatusInternalServerError , "Failed to get new Status Detail for NVLink Logical Partition, DB error" , nil )
371+ logger .Error ().Err (err ).Msg ("unable to update NVLink Logical Partition record in DB, but object already exists on Site" )
372+ // Continue with original nvllp and ssd - don't return error
373+ } else {
374+ newSSD , err := sdDAO .CreateFromParams (ctx , nil , nvllp .ID .String (), * status , statusMessage )
375+ if err != nil {
376+ logger .Error ().Err (err ).Msg ("error creating Status Detail DB entry, but object already exists on Site" )
377+ // Continue with original ssd - don't return error
378+ } else if newSSD != nil {
379+ // Use the new status detail if successfully created
380+ ussd = newSSD
381+ }
369382 }
370383 }
371384 }
372385
373- // commit transaction
374- err = tx .Commit ()
375- if err != nil {
376- logger .Error ().Err (err ).Msg ("error committing NVLink Logical Partition transaction to DB" )
377- return cerr .NewAPIErrorResponse (c , http .StatusInternalServerError , "Failed to create NVLink Logical Partition, DB error" , nil )
378- }
379-
380- // set committed so, deferred cleanup functions will do nothing
381- txCommitted = true
382-
383386 // create response
384- apiNVLinkLogicalPartition := model .NewAPINVLinkLogicalPartition (unvllp , nil , nil , []cdbm.StatusDetail {* ssd })
387+ apiNVLinkLogicalPartition := model .NewAPINVLinkLogicalPartition (unvllp , nil , nil , []cdbm.StatusDetail {* ussd })
385388 logger .Info ().Msg ("finishing API handler" )
386389 return c .JSON (http .StatusCreated , apiNVLinkLogicalPartition )
387390}
0 commit comments