Merge remote-tracking branch 'orgin/master'
commit
4cc564c554
|
|
@ -10,7 +10,7 @@ WORKDIR /app
|
|||
COPY target/*.jar app.jar
|
||||
|
||||
# 暴露应用端口
|
||||
EXPOSE 8112
|
||||
EXPOSE 8113
|
||||
|
||||
# 启动应用
|
||||
ENTRYPOINT ["java", "-jar", "app.jar"]
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
services:
|
||||
app:
|
||||
build: .
|
||||
image: nex-be:1.0.3
|
||||
image: nex-be:1.0.0
|
||||
container_name: nex-be
|
||||
ports:
|
||||
- "8113:8113"
|
||||
- "50051:50051"
|
||||
volumes:
|
||||
- /var/lib/vdi/:/var/lib/vdi/
|
||||
environment:
|
||||
|
|
|
|||
|
|
@ -59,8 +59,7 @@ public class NetworkManageController {
|
|||
@ApiOperation(value = "同步数据和状态")
|
||||
@GetMapping("/synchData")
|
||||
public Result<?> synchData() {
|
||||
networkManageService.synchData();
|
||||
return Result.successResult();
|
||||
return Result.successResult(networkManageService.synchData());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,8 +65,7 @@ public class StoragePoolController {
|
|||
@ApiOperation(value = "同步数据")
|
||||
@GetMapping("/synchData")
|
||||
public Result<?> synchData() {
|
||||
storagePoolService.synchData();
|
||||
return Result.successResult();
|
||||
return Result.successResult(storagePoolService.synchData());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,4 +76,25 @@ public class StoragePool {
|
|||
@TableField("create_user")
|
||||
@ApiModelProperty(value = "创建用户")
|
||||
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;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonSetter;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
|
|
@ -51,4 +52,21 @@ public class Network {
|
|||
|
||||
@JsonProperty("vlan_id")
|
||||
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 - 存储池信息对象
|
||||
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 {
|
||||
private String name;
|
||||
@JsonProperty("pool_name")
|
||||
private String poolName;
|
||||
private String uuid;
|
||||
private String state;
|
||||
private Long capacity;
|
||||
|
|
@ -10,96 +17,25 @@ public class VmStoragePool {
|
|||
private Long available;
|
||||
private Integer autostart;
|
||||
private Integer persistent;
|
||||
@JsonProperty("volume_count")
|
||||
private Integer volumeCount;
|
||||
private String type;
|
||||
private String path;
|
||||
|
||||
// Getters and Setters
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
// 自定义 setter,在设置 name 时同步到 poolName
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
if (name != null) {
|
||||
this.poolName = name;
|
||||
}
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
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;
|
||||
// 自定义 setter,在设置 poolName 时同步到 name
|
||||
@JsonSetter("pool_name")
|
||||
public void setPoolName(String poolName) {
|
||||
this.poolName = poolName;
|
||||
if (poolName != null) {
|
||||
this.name = poolName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,8 +69,8 @@ public class NetworkManageReq {
|
|||
/**
|
||||
* DHCP启用状态
|
||||
*/
|
||||
@ApiModelProperty(value = "DHCP启用状态")
|
||||
@JsonProperty("dhcp_enabled:1 启用 0 不启用")
|
||||
@ApiModelProperty(value = "DHCP启用状态:1 启用 0 不启用")
|
||||
@JsonProperty("dhcp_enabled")
|
||||
private Short dhcpEnabled;
|
||||
|
||||
/**
|
||||
|
|
@ -100,8 +100,8 @@ public class NetworkManageReq {
|
|||
/**
|
||||
* 状态
|
||||
*/
|
||||
@ApiModelProperty(value = "状态,新增时不传")
|
||||
@JsonProperty("status:1,活跃,0,非活跃")
|
||||
@ApiModelProperty(value = "状态,新增时不传:1,活跃,0,非活跃")
|
||||
@JsonProperty("status")
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -31,6 +31,20 @@ public class StoragePoolReq {
|
|||
@JsonProperty("pool_name")
|
||||
private String poolName;
|
||||
|
||||
@ApiModelProperty("名称,用于传给虚拟机的时候用的")
|
||||
@JsonProperty("storage_pool_name")
|
||||
private String storagePoolName;
|
||||
|
||||
|
||||
public String getStoragePoolName() {
|
||||
return this.poolName;
|
||||
}
|
||||
|
||||
public void setPoolName(String poolName) {
|
||||
this.poolName = poolName;
|
||||
this.storagePoolName = poolName; // 同步值
|
||||
}
|
||||
|
||||
@ApiModelProperty("类型")
|
||||
@Size(max = 16, message = "类型长度不能超过16个字符")
|
||||
@JsonProperty("type")
|
||||
|
|
|
|||
|
|
@ -62,5 +62,5 @@ public interface NetworkManageService {
|
|||
*/
|
||||
PageResult<NetworkManage> pageNetworkManages(NetworkManagePageReq networkManagePageReq);
|
||||
|
||||
void synchData();
|
||||
String synchData();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,5 +51,5 @@ public interface StoragePoolService {
|
|||
*/
|
||||
PageResult<StoragePool> pageStoragePools(StoragePoolReq storagePoolReq);
|
||||
|
||||
void synchData();
|
||||
String synchData();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public class NetworkManageServiceImpl extends ServiceImpl<NetworkManageMapper, N
|
|||
public NetworkManage addNetworkManage(NetworkManageReq networkManageReq) {
|
||||
// 检查名称是否重复
|
||||
QueryWrapper<NetworkManage> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("name", networkManageReq.getNetworkName());
|
||||
queryWrapper.eq("network_name", networkManageReq.getNetworkName());
|
||||
if (this.count(queryWrapper) > 0) {
|
||||
throw new BusinessException("网络名称'" + networkManageReq.getNetworkName() + "'已存在,请使用其他名称");
|
||||
}
|
||||
|
|
@ -242,7 +242,8 @@ public class NetworkManageServiceImpl extends ServiceImpl<NetworkManageMapper, N
|
|||
*/
|
||||
@Override
|
||||
// @Transactional
|
||||
public void synchData() {
|
||||
public String synchData() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
ApiResponse<NetworkData> response;
|
||||
try {
|
||||
response = client.list(1, 100);
|
||||
|
|
@ -255,7 +256,7 @@ public class NetworkManageServiceImpl extends ServiceImpl<NetworkManageMapper, N
|
|||
|
||||
List<Network> networkList = response.getData().getNetworks();
|
||||
if (CollectionUtils.isEmpty(networkList)) {
|
||||
return;
|
||||
return "同步成功,无数据更新";
|
||||
}
|
||||
|
||||
log.info("开始同步网络数据,共{}条记录", networkList.size());
|
||||
|
|
@ -294,10 +295,12 @@ public class NetworkManageServiceImpl extends ServiceImpl<NetworkManageMapper, N
|
|||
// 执行批量操作,分批处理避免大数据量问题
|
||||
if (!toUpdate.isEmpty()) {
|
||||
updateBatch(toUpdate);
|
||||
sb.append("更新 ").append(toUpdate.size()).append(" 条存储池数据\n");
|
||||
}
|
||||
|
||||
if (!toInsert.isEmpty()) {
|
||||
insertBatch(toInsert);
|
||||
sb.append("插入 ").append(toInsert.size()).append(" 条存储池数据\n");
|
||||
}
|
||||
|
||||
// 删除不存在的记录
|
||||
|
|
@ -313,7 +316,9 @@ public class NetworkManageServiceImpl extends ServiceImpl<NetworkManageMapper, N
|
|||
if (!idsToDelete.isEmpty()) {
|
||||
log.info("需要删除{}条记录", idsToDelete.size());
|
||||
this.removeByIds(idsToDelete);
|
||||
sb.append("删除 ").append(idsToDelete.size()).append(" 条存储池数据\n");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private void updateBatch(List<NetworkManage> list) {
|
||||
|
|
|
|||
|
|
@ -3,9 +3,10 @@ package com.unisinsight.project.service.impl;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.unisinsight.project.entity.dao.NetworkManage;
|
||||
import com.unisinsight.project.entity.dao.StoragePool;
|
||||
import com.unisinsight.project.entity.dto.*;
|
||||
import com.unisinsight.project.entity.dto.ApiResponse;
|
||||
import com.unisinsight.project.entity.dto.StoragePoolData;
|
||||
import com.unisinsight.project.entity.dto.VmStoragePool;
|
||||
import com.unisinsight.project.entity.req.StoragePoolReq;
|
||||
import com.unisinsight.project.entity.res.PageResult;
|
||||
import com.unisinsight.project.exception.BusinessException;
|
||||
|
|
@ -16,7 +17,6 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -46,7 +46,7 @@ public class StoragePoolServiceImpl extends ServiceImpl<StoragePoolMapper, Stora
|
|||
public StoragePool addStoragePool(StoragePoolReq storagePoolReq) {
|
||||
// 检查名称是否重复
|
||||
QueryWrapper<StoragePool> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("name", storagePoolReq.getPoolName());
|
||||
queryWrapper.eq("pool_name", storagePoolReq.getPoolName());
|
||||
if (this.count(queryWrapper) > 0) {
|
||||
throw new BusinessException("存储池名称'" + storagePoolReq.getPoolName() + "'已存在,请使用其他名称");
|
||||
}
|
||||
|
|
@ -187,7 +187,8 @@ public class StoragePoolServiceImpl extends ServiceImpl<StoragePoolMapper, Stora
|
|||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void synchData() {
|
||||
public String synchData() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
ApiResponse<StoragePoolData> response;
|
||||
try {
|
||||
response = client.listStorage(1, 100);
|
||||
|
|
@ -220,7 +221,7 @@ public class StoragePoolServiceImpl extends ServiceImpl<StoragePoolMapper, Stora
|
|||
StoragePool storagePool = new StoragePool();
|
||||
BeanUtils.copyProperties(remotePool, storagePool);
|
||||
storagePool.setPoolName(remotePool.getName());
|
||||
storagePool.setStatus("active".equals(remotePool.getState()) ? 1 : 2);
|
||||
storagePool.setStatus("active".equals(remotePool.getState()) ? 1 : 0);
|
||||
|
||||
if (localPool == null) {
|
||||
// 新增项
|
||||
|
|
@ -248,11 +249,13 @@ public class StoragePoolServiceImpl extends ServiceImpl<StoragePoolMapper, Stora
|
|||
if (!toAdd.isEmpty()) {
|
||||
this.saveBatch(toAdd);
|
||||
log.info("新增 {} 条存储池数据", toAdd.size());
|
||||
sb.append("新增 ").append(toAdd.size()).append(" 条存储池数据\n");
|
||||
}
|
||||
|
||||
if (!toUpdate.isEmpty()) {
|
||||
this.updateBatchById(toUpdate);
|
||||
log.info("更新 {} 条存储池数据", toUpdate.size());
|
||||
sb.append("更新 ").append(toUpdate.size()).append(" 条存储池数据\n");
|
||||
}
|
||||
|
||||
if (!toRemoveNames.isEmpty()) {
|
||||
|
|
@ -260,7 +263,9 @@ public class StoragePoolServiceImpl extends ServiceImpl<StoragePoolMapper, Stora
|
|||
deleteWrapper.in("pool_name", toRemoveNames);
|
||||
this.remove(deleteWrapper);
|
||||
log.info("删除 {} 条存储池数据", toRemoveNames.size());
|
||||
sb.append("删除 ").append(toRemoveNames.size()).append(" 条存储池数据\n");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,4 +81,4 @@ logging:
|
|||
com.unisinsight.project.feign.ExternalApiClient: debug
|
||||
external:
|
||||
api:
|
||||
url: http://10.100.51.118:8000
|
||||
url: http://10.100.51.178:8000
|
||||
Loading…
Reference in New Issue