feat:bug修改
parent
70f6ade5db
commit
b69a3ae3d4
|
|
@ -59,8 +59,7 @@ public class NetworkManageController {
|
||||||
@ApiOperation(value = "同步数据和状态")
|
@ApiOperation(value = "同步数据和状态")
|
||||||
@GetMapping("/synchData")
|
@GetMapping("/synchData")
|
||||||
public Result<?> synchData() {
|
public Result<?> synchData() {
|
||||||
networkManageService.synchData();
|
return Result.successResult(networkManageService.synchData());
|
||||||
return Result.successResult();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,8 +65,7 @@ public class StoragePoolController {
|
||||||
@ApiOperation(value = "同步数据")
|
@ApiOperation(value = "同步数据")
|
||||||
@GetMapping("/synchData")
|
@GetMapping("/synchData")
|
||||||
public Result<?> synchData() {
|
public Result<?> synchData() {
|
||||||
storagePoolService.synchData();
|
return Result.successResult(storagePoolService.synchData());
|
||||||
return Result.successResult();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,4 +76,25 @@ public class StoragePool {
|
||||||
@TableField("create_user")
|
@TableField("create_user")
|
||||||
@ApiModelProperty(value = "创建用户")
|
@ApiModelProperty(value = "创建用户")
|
||||||
private String createUser;
|
private String createUser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 总容量
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
@ApiModelProperty(value = "总容量")
|
||||||
|
private Long capacity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 已分配容量
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
@ApiModelProperty(value = "已分配容量")
|
||||||
|
private Long allocation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 可用容量
|
||||||
|
*/
|
||||||
|
@TableField(exist = false)
|
||||||
|
@ApiModelProperty(value = "可用容量")
|
||||||
|
private Long available;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
package com.unisinsight.project.entity.dto;
|
package com.unisinsight.project.entity.dto;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonSetter;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
|
@ -51,4 +52,21 @@ public class Network {
|
||||||
|
|
||||||
@JsonProperty("vlan_id")
|
@JsonProperty("vlan_id")
|
||||||
private Integer vlanId;
|
private Integer vlanId;
|
||||||
|
|
||||||
|
// 自定义 setter,在设置 name 时同步到 networkName
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
if (name != null) {
|
||||||
|
this.networkName = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 自定义 setter,在设置 poolName 时同步到 name
|
||||||
|
@JsonSetter("network_name")
|
||||||
|
public void setPoolName(String poolName) {
|
||||||
|
this.networkName = poolName;
|
||||||
|
if (poolName != null) {
|
||||||
|
this.name = poolName;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,8 +1,15 @@
|
||||||
// StoragePool.java - 存储池信息对象
|
// StoragePool.java - 存储池信息对象
|
||||||
package com.unisinsight.project.entity.dto;
|
package com.unisinsight.project.entity.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonSetter;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
public class VmStoragePool {
|
public class VmStoragePool {
|
||||||
private String name;
|
private String name;
|
||||||
|
@JsonProperty("pool_name")
|
||||||
|
private String poolName;
|
||||||
private String uuid;
|
private String uuid;
|
||||||
private String state;
|
private String state;
|
||||||
private Long capacity;
|
private Long capacity;
|
||||||
|
|
@ -10,96 +17,25 @@ public class VmStoragePool {
|
||||||
private Long available;
|
private Long available;
|
||||||
private Integer autostart;
|
private Integer autostart;
|
||||||
private Integer persistent;
|
private Integer persistent;
|
||||||
|
@JsonProperty("volume_count")
|
||||||
private Integer volumeCount;
|
private Integer volumeCount;
|
||||||
private String type;
|
private String type;
|
||||||
private String path;
|
private String path;
|
||||||
|
|
||||||
// Getters and Setters
|
// 自定义 setter,在设置 name 时同步到 poolName
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
if (name != null) {
|
||||||
|
this.poolName = name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUuid() {
|
// 自定义 setter,在设置 poolName 时同步到 name
|
||||||
return uuid;
|
@JsonSetter("pool_name")
|
||||||
}
|
public void setPoolName(String poolName) {
|
||||||
|
this.poolName = poolName;
|
||||||
public void setUuid(String uuid) {
|
if (poolName != null) {
|
||||||
this.uuid = uuid;
|
this.name = poolName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getState() {
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setState(String state) {
|
|
||||||
this.state = state;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getCapacity() {
|
|
||||||
return capacity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCapacity(Long capacity) {
|
|
||||||
this.capacity = capacity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getAllocation() {
|
|
||||||
return allocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAllocation(Long allocation) {
|
|
||||||
this.allocation = allocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getAvailable() {
|
|
||||||
return available;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAvailable(Long available) {
|
|
||||||
this.available = available;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getAutostart() {
|
|
||||||
return autostart;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAutostart(Integer autostart) {
|
|
||||||
this.autostart = autostart;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getPersistent() {
|
|
||||||
return persistent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPersistent(Integer persistent) {
|
|
||||||
this.persistent = persistent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getVolumeCount() {
|
|
||||||
return volumeCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVolumeCount(Integer volumeCount) {
|
|
||||||
this.volumeCount = volumeCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setType(String type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPath() {
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPath(String path) {
|
|
||||||
this.path = path;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,5 +62,5 @@ public interface NetworkManageService {
|
||||||
*/
|
*/
|
||||||
PageResult<NetworkManage> pageNetworkManages(NetworkManagePageReq networkManagePageReq);
|
PageResult<NetworkManage> pageNetworkManages(NetworkManagePageReq networkManagePageReq);
|
||||||
|
|
||||||
void synchData();
|
String synchData();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,5 +51,5 @@ public interface StoragePoolService {
|
||||||
*/
|
*/
|
||||||
PageResult<StoragePool> pageStoragePools(StoragePoolReq storagePoolReq);
|
PageResult<StoragePool> pageStoragePools(StoragePoolReq storagePoolReq);
|
||||||
|
|
||||||
void synchData();
|
String synchData();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -242,7 +242,8 @@ public class NetworkManageServiceImpl extends ServiceImpl<NetworkManageMapper, N
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
// @Transactional
|
// @Transactional
|
||||||
public void synchData() {
|
public String synchData() {
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
ApiResponse<NetworkData> response;
|
ApiResponse<NetworkData> response;
|
||||||
try {
|
try {
|
||||||
response = client.list(1, 100);
|
response = client.list(1, 100);
|
||||||
|
|
@ -255,7 +256,7 @@ public class NetworkManageServiceImpl extends ServiceImpl<NetworkManageMapper, N
|
||||||
|
|
||||||
List<Network> networkList = response.getData().getNetworks();
|
List<Network> networkList = response.getData().getNetworks();
|
||||||
if (CollectionUtils.isEmpty(networkList)) {
|
if (CollectionUtils.isEmpty(networkList)) {
|
||||||
return;
|
return "同步成功,无数据更新";
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("开始同步网络数据,共{}条记录", networkList.size());
|
log.info("开始同步网络数据,共{}条记录", networkList.size());
|
||||||
|
|
@ -294,10 +295,12 @@ public class NetworkManageServiceImpl extends ServiceImpl<NetworkManageMapper, N
|
||||||
// 执行批量操作,分批处理避免大数据量问题
|
// 执行批量操作,分批处理避免大数据量问题
|
||||||
if (!toUpdate.isEmpty()) {
|
if (!toUpdate.isEmpty()) {
|
||||||
updateBatch(toUpdate);
|
updateBatch(toUpdate);
|
||||||
|
sb.append("更新 ").append(toUpdate.size()).append(" 条存储池数据\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!toInsert.isEmpty()) {
|
if (!toInsert.isEmpty()) {
|
||||||
insertBatch(toInsert);
|
insertBatch(toInsert);
|
||||||
|
sb.append("插入 ").append(toInsert.size()).append(" 条存储池数据\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除不存在的记录
|
// 删除不存在的记录
|
||||||
|
|
@ -313,7 +316,9 @@ public class NetworkManageServiceImpl extends ServiceImpl<NetworkManageMapper, N
|
||||||
if (!idsToDelete.isEmpty()) {
|
if (!idsToDelete.isEmpty()) {
|
||||||
log.info("需要删除{}条记录", idsToDelete.size());
|
log.info("需要删除{}条记录", idsToDelete.size());
|
||||||
this.removeByIds(idsToDelete);
|
this.removeByIds(idsToDelete);
|
||||||
|
sb.append("删除 ").append(idsToDelete.size()).append(" 条存储池数据\n");
|
||||||
}
|
}
|
||||||
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateBatch(List<NetworkManage> list) {
|
private void updateBatch(List<NetworkManage> list) {
|
||||||
|
|
|
||||||
|
|
@ -187,7 +187,8 @@ public class StoragePoolServiceImpl extends ServiceImpl<StoragePoolMapper, Stora
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void synchData() {
|
public String synchData() {
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
ApiResponse<StoragePoolData> response;
|
ApiResponse<StoragePoolData> response;
|
||||||
try {
|
try {
|
||||||
response = client.listStorage(1, 100);
|
response = client.listStorage(1, 100);
|
||||||
|
|
@ -220,7 +221,7 @@ public class StoragePoolServiceImpl extends ServiceImpl<StoragePoolMapper, Stora
|
||||||
StoragePool storagePool = new StoragePool();
|
StoragePool storagePool = new StoragePool();
|
||||||
BeanUtils.copyProperties(remotePool, storagePool);
|
BeanUtils.copyProperties(remotePool, storagePool);
|
||||||
storagePool.setPoolName(remotePool.getName());
|
storagePool.setPoolName(remotePool.getName());
|
||||||
storagePool.setStatus("active".equals(remotePool.getState()) ? 1 : 2);
|
storagePool.setStatus("active".equals(remotePool.getState()) ? 1 : 0);
|
||||||
|
|
||||||
if (localPool == null) {
|
if (localPool == null) {
|
||||||
// 新增项
|
// 新增项
|
||||||
|
|
@ -248,11 +249,13 @@ public class StoragePoolServiceImpl extends ServiceImpl<StoragePoolMapper, Stora
|
||||||
if (!toAdd.isEmpty()) {
|
if (!toAdd.isEmpty()) {
|
||||||
this.saveBatch(toAdd);
|
this.saveBatch(toAdd);
|
||||||
log.info("新增 {} 条存储池数据", toAdd.size());
|
log.info("新增 {} 条存储池数据", toAdd.size());
|
||||||
|
sb.append("新增 ").append(toAdd.size()).append(" 条存储池数据\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!toUpdate.isEmpty()) {
|
if (!toUpdate.isEmpty()) {
|
||||||
this.updateBatchById(toUpdate);
|
this.updateBatchById(toUpdate);
|
||||||
log.info("更新 {} 条存储池数据", toUpdate.size());
|
log.info("更新 {} 条存储池数据", toUpdate.size());
|
||||||
|
sb.append("更新 ").append(toUpdate.size()).append(" 条存储池数据\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!toRemoveNames.isEmpty()) {
|
if (!toRemoveNames.isEmpty()) {
|
||||||
|
|
@ -260,7 +263,9 @@ public class StoragePoolServiceImpl extends ServiceImpl<StoragePoolMapper, Stora
|
||||||
deleteWrapper.in("pool_name", toRemoveNames);
|
deleteWrapper.in("pool_name", toRemoveNames);
|
||||||
this.remove(deleteWrapper);
|
this.remove(deleteWrapper);
|
||||||
log.info("删除 {} 条存储池数据", toRemoveNames.size());
|
log.info("删除 {} 条存储池数据", toRemoveNames.size());
|
||||||
|
sb.append("删除 ").append(toRemoveNames.size()).append(" 条存储池数据\n");
|
||||||
}
|
}
|
||||||
|
return sb.toString() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue