|
18 | 18 |
|
19 | 19 | import ai.starwhale.mlops.api.protocol.Code; |
20 | 20 | import ai.starwhale.mlops.api.protocol.ResponseMessage; |
| 21 | +import ai.starwhale.mlops.api.protocol.datastore.BackupVo; |
21 | 22 | import ai.starwhale.mlops.api.protocol.datastore.ColumnDesc; |
22 | 23 | import ai.starwhale.mlops.api.protocol.datastore.FlushRequest; |
23 | 24 | import ai.starwhale.mlops.api.protocol.datastore.ListTablesRequest; |
|
35 | 36 | import ai.starwhale.mlops.datastore.DataStoreScanRequest; |
36 | 37 | import ai.starwhale.mlops.datastore.RecordList; |
37 | 38 | import ai.starwhale.mlops.datastore.TableQueryFilter; |
| 39 | +import ai.starwhale.mlops.datastore.backup.Meta; |
38 | 40 | import ai.starwhale.mlops.datastore.exporter.RecordsStreamingExporter; |
39 | 41 | import ai.starwhale.mlops.datastore.impl.RecordDecoder; |
40 | 42 | import ai.starwhale.mlops.exception.SwProcessException; |
|
60 | 62 | import org.springframework.util.CollectionUtils; |
61 | 63 | import org.springframework.util.StringUtils; |
62 | 64 | import org.springframework.validation.annotation.Validated; |
| 65 | +import org.springframework.web.bind.annotation.DeleteMapping; |
| 66 | +import org.springframework.web.bind.annotation.GetMapping; |
63 | 67 | import org.springframework.web.bind.annotation.PostMapping; |
64 | 68 | import org.springframework.web.bind.annotation.RequestBody; |
65 | 69 | import org.springframework.web.bind.annotation.RequestMapping; |
| 70 | +import org.springframework.web.bind.annotation.RequestParam; |
66 | 71 | import org.springframework.web.bind.annotation.RestController; |
67 | 72 |
|
68 | 73 | @RestController |
@@ -293,6 +298,49 @@ void scanAndExport( |
293 | 298 | } |
294 | 299 | } |
295 | 300 |
|
| 301 | + @PostMapping(value = "/datastore/maintain/backup") |
| 302 | + @PreAuthorize("hasAnyRole('OWNER')") |
| 303 | + ResponseEntity<ResponseMessage<BackupVo>> createBackup() { |
| 304 | + try { |
| 305 | + var meta = this.dataStore.createBackup(); |
| 306 | + return ResponseEntity.ok(Code.success.asResponse(meta.toVo())); |
| 307 | + } catch (IOException e) { |
| 308 | + log.error("create backup failed", e); |
| 309 | + throw new SwProcessException(ErrorType.SYSTEM, "create backup failed", e); |
| 310 | + } |
| 311 | + } |
| 312 | + |
| 313 | + @GetMapping(value = "/datastore/maintain/backup") |
| 314 | + @PreAuthorize("hasAnyRole('OWNER')") |
| 315 | + ResponseEntity<ResponseMessage<List<BackupVo>>> listBackups() { |
| 316 | + var backups = this.dataStore.listBackups().stream().map(Meta::toVo).collect(Collectors.toList()); |
| 317 | + return ResponseEntity.ok(Code.success.asResponse(backups)); |
| 318 | + } |
| 319 | + |
| 320 | + @PostMapping(value = "/datastore/maintain/backup/restore") |
| 321 | + @PreAuthorize("hasAnyRole('OWNER')") |
| 322 | + ResponseEntity<ResponseMessage<String>> restoreBackup(@Valid @RequestParam String id) { |
| 323 | + try { |
| 324 | + this.dataStore.restoreWithBackup(id); |
| 325 | + } catch (IOException e) { |
| 326 | + log.error("restore backup failed", e); |
| 327 | + throw new SwProcessException(ErrorType.SYSTEM, "restore backup failed", e); |
| 328 | + } |
| 329 | + return ResponseEntity.ok(Code.success.asResponse("success")); |
| 330 | + } |
| 331 | + |
| 332 | + @DeleteMapping(value = "/datastore/maintain/backup") |
| 333 | + @PreAuthorize("hasAnyRole('OWNER')") |
| 334 | + ResponseEntity<ResponseMessage<String>> deleteBackup(@Valid @RequestParam String id) { |
| 335 | + try { |
| 336 | + this.dataStore.deleteBackup(id); |
| 337 | + } catch (IOException e) { |
| 338 | + log.error("delete backup failed", e); |
| 339 | + throw new SwProcessException(ErrorType.SYSTEM, "delete backup failed", e); |
| 340 | + } |
| 341 | + return ResponseEntity.ok(Code.success.asResponse("success")); |
| 342 | + } |
| 343 | + |
296 | 344 | private RecordList queryRecordList(QueryTableRequest request) { |
297 | 345 | if (request.getTableName() == null) { |
298 | 346 | throw new SwValidationException( |
|
0 commit comments