( ctx context.Context, req *apiv1.PatchCheckpointsRequest, )
| 251 | } |
| 252 | |
| 253 | func (a *apiServer) PatchCheckpoints( |
| 254 | ctx context.Context, |
| 255 | req *apiv1.PatchCheckpointsRequest, |
| 256 | ) (*apiv1.PatchCheckpointsResponse, error) { |
| 257 | var uuidStrings []string |
| 258 | for _, c := range req.Checkpoints { |
| 259 | uuidStrings = append(uuidStrings, c.Uuid) |
| 260 | } |
| 261 | |
| 262 | conv := &protoconverter.ProtoConverter{} |
| 263 | uuids := conv.ToUUIDList(uuidStrings) |
| 264 | if cErr := conv.Error(); cErr != nil { |
| 265 | return nil, status.Errorf(codes.InvalidArgument, "converting checkpoint: %s", cErr) |
| 266 | } |
| 267 | |
| 268 | if _, _, err := a.checkpointsRBACEditCheck(ctx, uuids); err != nil { |
| 269 | return nil, err |
| 270 | } |
| 271 | |
| 272 | registeredCheckpointUUIDs, err := checkpoints.GetRegisteredCheckpoints(ctx, uuids) |
| 273 | if err != nil { |
| 274 | return nil, err |
| 275 | } |
| 276 | if len(registeredCheckpointUUIDs) > 0 { |
| 277 | errMsg, err := makeRegisteredCheckpointErrorMessage( |
| 278 | ctx, |
| 279 | "this subset of checkpoints provided are in the model registry and cannot be patched: %v.", |
| 280 | registeredCheckpointUUIDs, |
| 281 | ) |
| 282 | if err != nil { |
| 283 | return nil, err |
| 284 | } |
| 285 | return nil, status.Errorf(codes.InvalidArgument, *errMsg) |
| 286 | } |
| 287 | |
| 288 | err = internaldb.Bun().RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error { |
| 289 | var updatedCheckpointSizes []uuid.UUID |
| 290 | for i, c := range req.Checkpoints { |
| 291 | if c.Resources != nil { |
| 292 | size := int64(0) |
| 293 | for _, v := range c.Resources.Resources { |
| 294 | size += v |
| 295 | } |
| 296 | |
| 297 | v2Update := tx.NewUpdate().Model(&model.CheckpointV2{}). |
| 298 | Where("uuid = ?", c.Uuid) |
| 299 | |
| 300 | if len(c.Resources.Resources) == 0 { // Full delete case. |
| 301 | v2Update = v2Update.Set("state = ?", model.DeletedState) |
| 302 | } else { // Partial delete case. |
| 303 | v2Update = v2Update. |
| 304 | Set("resources = ?", c.Resources.Resources). |
| 305 | Set("size = ?", size) |
| 306 | |
| 307 | oldResources := struct { |
| 308 | bun.BaseModel `bun:"table:checkpoints_view"` |
| 309 | Resources map[string]int64 |
| 310 | }{} |
nothing calls this directly
no test coverage detected