feat(imageVirtualMachines):增加快照列表分页功能并优化快照操作
- 在快照列表接口中添加分页参数 page 和 page_size -优化创建快照、删除快照和还原快照的错误处理- 修改外部 API 客户端以支持新的分页参数master
parent
7b3a4c6a6a
commit
75e960c2ca
|
|
@ -160,11 +160,11 @@ public class ImageVirtualMachinesController {
|
||||||
return service.getVncData(vmName);
|
return service.getVncData(vmName);
|
||||||
}
|
}
|
||||||
@ApiOperation(value = "获取快照列表")
|
@ApiOperation(value = "获取快照列表")
|
||||||
@GetMapping("/snapshot/list/{vmName}")
|
@GetMapping("/snapshot/list")
|
||||||
public Result<?> snapshotList(@PathVariable("vmName") String vmName) {
|
public Result<?> snapshotList(@RequestParam("vmName") String vmName,@RequestParam("page") Integer page,@RequestParam("page_size") Integer pageSize) {
|
||||||
|
|
||||||
log.info("获取快照列表请求参数为:{}", vmName);
|
log.info("获取快照列表请求参数为:{},{},{}", vmName,page,pageSize);
|
||||||
return service.snapshotList(vmName);
|
return service.snapshotList(vmName,page,pageSize);
|
||||||
}
|
}
|
||||||
@ApiOperation(value = "创建快照")
|
@ApiOperation(value = "创建快照")
|
||||||
@PostMapping("/snapshot/create")
|
@PostMapping("/snapshot/create")
|
||||||
|
|
@ -181,7 +181,7 @@ public class ImageVirtualMachinesController {
|
||||||
return service.deleteSnapshot(snapShotCreateReq);
|
return service.deleteSnapshot(snapShotCreateReq);
|
||||||
}
|
}
|
||||||
@ApiOperation(value = "还原快照")
|
@ApiOperation(value = "还原快照")
|
||||||
@GetMapping("/snapshot/revert")
|
@PostMapping("/snapshot/revert")
|
||||||
public Result<?> revertSnapshot(@RequestBody SnapShotReq snapShotCreateReq) {
|
public Result<?> revertSnapshot(@RequestBody SnapShotReq snapShotCreateReq) {
|
||||||
|
|
||||||
log.info("还原快照请求参数为:{}", snapShotCreateReq);
|
log.info("还原快照请求参数为:{}", snapShotCreateReq);
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ public interface ExternalApiClient {
|
||||||
@GetMapping("/api/v1/vm/{vmName}/vnc")
|
@GetMapping("/api/v1/vm/{vmName}/vnc")
|
||||||
ApiResponse<VncData> getVncData(@PathVariable("vmName") String vmName);
|
ApiResponse<VncData> getVncData(@PathVariable("vmName") String vmName);
|
||||||
@GetMapping("/api/v1/snapshot/list/{vm_name}")
|
@GetMapping("/api/v1/snapshot/list/{vm_name}")
|
||||||
ApiResponse<SnapshotsResponseDTO> snapshotList(@PathVariable("vm_name") String vmName);
|
ApiResponse<SnapshotsResponseDTO> snapshotList(@PathVariable("vm_name") String vmName, @RequestParam("page") Integer page, @RequestParam("page_size") Integer pageSize);
|
||||||
@PostMapping("/api/v1/snapshot/create/{vm_name}")
|
@PostMapping("/api/v1/snapshot/create/{vm_name}")
|
||||||
ApiResponse createSnapshot(@PathVariable("vm_name") String vmName,@RequestBody SnapShotCreateReq snapshotCreateReq);
|
ApiResponse createSnapshot(@PathVariable("vm_name") String vmName,@RequestBody SnapShotCreateReq snapshotCreateReq);
|
||||||
@PostMapping("/api/v1/snapshot/revert/{vm_name}/{snapshot_name}")
|
@PostMapping("/api/v1/snapshot/revert/{vm_name}/{snapshot_name}")
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ public interface ImageVirtualMachinesService extends IService<ImageVirtualMachin
|
||||||
|
|
||||||
Result<?> getVncData(String vmName);
|
Result<?> getVncData(String vmName);
|
||||||
|
|
||||||
Result<?> snapshotList(String vmName);
|
Result<?> snapshotList(String vmName, Integer page, Integer pageSize);
|
||||||
|
|
||||||
Result<?> createSnapshot(SnapShotCreateReq snapShotCreateReq);
|
Result<?> createSnapshot(SnapShotCreateReq snapShotCreateReq);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -591,8 +591,8 @@ public class ImageVirtualMachinesServiceImpl extends ServiceImpl<ImageVirtualMac
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<?> snapshotList(String vmName) {
|
public Result<?> snapshotList(String vmName, Integer page, Integer pageSize) {
|
||||||
ApiResponse<SnapshotsResponseDTO> response = externalApiClient.snapshotList(vmName);
|
ApiResponse<SnapshotsResponseDTO> response = externalApiClient.snapshotList(vmName,page,pageSize);
|
||||||
if ( !"200".equals(response.getCode()) ||response.getData() == null) {
|
if ( !"200".equals(response.getCode()) ||response.getData() == null) {
|
||||||
return Result.errorResult(BaseErrorCode.HTTP_ERROR_CODE_500, response.getMessage());
|
return Result.errorResult(BaseErrorCode.HTTP_ERROR_CODE_500, response.getMessage());
|
||||||
}
|
}
|
||||||
|
|
@ -608,8 +608,11 @@ public class ImageVirtualMachinesServiceImpl extends ServiceImpl<ImageVirtualMac
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<?> createSnapshot(SnapShotCreateReq snapShotCreateReq) {
|
public Result<?> createSnapshot(SnapShotCreateReq snapShotCreateReq) {
|
||||||
externalApiClient.createSnapshot(snapShotCreateReq.getVmName(), snapShotCreateReq);
|
ApiResponse snapshot = externalApiClient.createSnapshot(snapShotCreateReq.getVmName(), snapShotCreateReq);
|
||||||
return Result.successResult();
|
if (!"200".equals(snapshot.getCode())){
|
||||||
|
return Result.errorResultMessage(BaseErrorCode.HTTP_ERROR_CODE_500, snapshot.getMessage());
|
||||||
|
}
|
||||||
|
return Result.successResult(snapshot.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -618,6 +621,9 @@ public class ImageVirtualMachinesServiceImpl extends ServiceImpl<ImageVirtualMac
|
||||||
return Result.errorResult(BaseErrorCode.HTTP_ERROR_CODE_500, "参数错误");
|
return Result.errorResult(BaseErrorCode.HTTP_ERROR_CODE_500, "参数错误");
|
||||||
}
|
}
|
||||||
ApiResponse apiResponse = externalApiClient.deleteSnapshot(snapShotCreateReq.getVmName(), snapShotCreateReq.getSnapshotName());
|
ApiResponse apiResponse = externalApiClient.deleteSnapshot(snapShotCreateReq.getVmName(), snapShotCreateReq.getSnapshotName());
|
||||||
|
if (!"200".equals(apiResponse.getCode())){
|
||||||
|
return Result.errorResultMessage(BaseErrorCode.HTTP_ERROR_CODE_500, apiResponse.getMessage());
|
||||||
|
}
|
||||||
return Result.successResult(apiResponse.getData());
|
return Result.successResult(apiResponse.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -627,6 +633,9 @@ public class ImageVirtualMachinesServiceImpl extends ServiceImpl<ImageVirtualMac
|
||||||
return Result.errorResult(BaseErrorCode.HTTP_ERROR_CODE_500, "参数错误");
|
return Result.errorResult(BaseErrorCode.HTTP_ERROR_CODE_500, "参数错误");
|
||||||
}
|
}
|
||||||
ApiResponse apiResponse = externalApiClient.revertSnapshot(snapShotCreateReq.getVmName(), snapShotCreateReq.getSnapshotName());
|
ApiResponse apiResponse = externalApiClient.revertSnapshot(snapShotCreateReq.getVmName(), snapShotCreateReq.getSnapshotName());
|
||||||
|
if (!"200".equals(apiResponse.getCode())){
|
||||||
|
return Result.errorResultMessage(BaseErrorCode.HTTP_ERROR_CODE_500, apiResponse.getMessage());
|
||||||
|
}
|
||||||
return Result.successResult(apiResponse.getData());
|
return Result.successResult(apiResponse.getData());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue