feat:存储池和网络代码调用第三方
parent
837afec179
commit
e2c223b22e
|
|
@ -52,6 +52,7 @@ public class ClientController {
|
|||
deviceReq.setDeviceName("默认终端");
|
||||
deviceReq.setDeviceGroupId(3L);
|
||||
deviceReq.setDeviceGroupName("默认终端分组");
|
||||
deviceReq.setMacAddr(loginReq.getMacAddr());
|
||||
return deviceService.insert(deviceReq);
|
||||
}
|
||||
|
||||
|
|
@ -108,6 +109,4 @@ public class ClientController {
|
|||
hashMap.put("url", "https://intent-bathhouse.name");
|
||||
return Result.successResult(hashMap);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,10 +56,11 @@ public class NetworkManageController {
|
|||
return Result.successResult();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "同步状态")
|
||||
@GetMapping("/synchStatus")
|
||||
public Result<?> synchStatus() {
|
||||
return null;
|
||||
@ApiOperation(value = "同步数据和状态")
|
||||
@GetMapping("/synchData")
|
||||
public Result<?> synchData() {
|
||||
networkManageService.synchData();
|
||||
return Result.successResult();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,10 +62,10 @@ public class StoragePoolController {
|
|||
|
||||
}
|
||||
|
||||
@ApiOperation(value = "同步状态")
|
||||
@GetMapping("/synchStatus")
|
||||
public Result<?> synchStatus() {
|
||||
|
||||
@ApiOperation(value = "同步数据")
|
||||
@GetMapping("/synchData")
|
||||
public Result<?> synchData() {
|
||||
storagePoolService.synchData();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ public class NetworkManage {
|
|||
/**
|
||||
* 网络名称
|
||||
*/
|
||||
@TableField("name")
|
||||
private String name;
|
||||
@TableField("network_name")
|
||||
private String networkName;
|
||||
|
||||
/**
|
||||
* 网络类型
|
||||
|
|
|
|||
|
|
@ -31,9 +31,9 @@ public class StoragePool {
|
|||
/**
|
||||
* 存储池名称
|
||||
*/
|
||||
@TableField("name")
|
||||
@TableField("pool_name")
|
||||
@ApiModelProperty(value = "存储池名称")
|
||||
private String name;
|
||||
private String poolName;
|
||||
|
||||
/**
|
||||
* 存储池类型
|
||||
|
|
|
|||
|
|
@ -0,0 +1,150 @@
|
|||
// Network.java - 网络信息对象
|
||||
package com.unisinsight.project.entity.dto;
|
||||
|
||||
public class Network {
|
||||
private String name;
|
||||
private String uuid;
|
||||
private String state;
|
||||
private Integer autostart;
|
||||
private Integer persistent;
|
||||
private String description;
|
||||
private String type;
|
||||
private String bridge;
|
||||
private String bridgeName;
|
||||
private String ipAddress;
|
||||
private String netmask;
|
||||
private String gateway;
|
||||
private String ipRange;
|
||||
private Boolean dhcpEnabled;
|
||||
private String dhcpStart;
|
||||
private String dhcpEnd;
|
||||
|
||||
// Getters and Setters
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = 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 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 String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getBridge() {
|
||||
return bridge;
|
||||
}
|
||||
|
||||
public void setBridge(String bridge) {
|
||||
this.bridge = bridge;
|
||||
}
|
||||
|
||||
public String getBridgeName() {
|
||||
return bridgeName;
|
||||
}
|
||||
|
||||
public void setBridgeName(String bridgeName) {
|
||||
this.bridgeName = bridgeName;
|
||||
}
|
||||
|
||||
public String getIpAddress() {
|
||||
return ipAddress;
|
||||
}
|
||||
|
||||
public void setIpAddress(String ipAddress) {
|
||||
this.ipAddress = ipAddress;
|
||||
}
|
||||
|
||||
public String getNetmask() {
|
||||
return netmask;
|
||||
}
|
||||
|
||||
public void setNetmask(String netmask) {
|
||||
this.netmask = netmask;
|
||||
}
|
||||
|
||||
public String getGateway() {
|
||||
return gateway;
|
||||
}
|
||||
|
||||
public void setGateway(String gateway) {
|
||||
this.gateway = gateway;
|
||||
}
|
||||
|
||||
public String getIpRange() {
|
||||
return ipRange;
|
||||
}
|
||||
|
||||
public void setIpRange(String ipRange) {
|
||||
this.ipRange = ipRange;
|
||||
}
|
||||
|
||||
public Boolean getDhcpEnabled() {
|
||||
return dhcpEnabled;
|
||||
}
|
||||
|
||||
public void setDhcpEnabled(Boolean dhcpEnabled) {
|
||||
this.dhcpEnabled = dhcpEnabled;
|
||||
}
|
||||
|
||||
public String getDhcpStart() {
|
||||
return dhcpStart;
|
||||
}
|
||||
|
||||
public void setDhcpStart(String dhcpStart) {
|
||||
this.dhcpStart = dhcpStart;
|
||||
}
|
||||
|
||||
public String getDhcpEnd() {
|
||||
return dhcpEnd;
|
||||
}
|
||||
|
||||
public void setDhcpEnd(String dhcpEnd) {
|
||||
this.dhcpEnd = dhcpEnd;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package com.unisinsight.project.entity.dto;
|
||||
import java.util.List;
|
||||
|
||||
public class NetworkData {
|
||||
private List<Network> networks;
|
||||
private Pagination pagination;
|
||||
|
||||
// Getters and Setters
|
||||
public List<Network> getNetworks() {
|
||||
return networks;
|
||||
}
|
||||
|
||||
public void setNetworks(List<Network> networks) {
|
||||
this.networks = networks;
|
||||
}
|
||||
|
||||
public Pagination getPagination() {
|
||||
return pagination;
|
||||
}
|
||||
|
||||
public void setPagination(Pagination pagination) {
|
||||
this.pagination = pagination;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
// Pagination.java - 分页信息对象
|
||||
package com.unisinsight.project.entity.dto;
|
||||
|
||||
public class Pagination {
|
||||
private Integer currentPage;
|
||||
private Integer pageSize;
|
||||
private Integer total;
|
||||
private Integer totalPages;
|
||||
|
||||
// Getters and Setters
|
||||
public Integer getCurrentPage() {
|
||||
return currentPage;
|
||||
}
|
||||
|
||||
public void setCurrentPage(Integer currentPage) {
|
||||
this.currentPage = currentPage;
|
||||
}
|
||||
|
||||
public Integer getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(Integer pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public Integer getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(Integer total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public Integer getTotalPages() {
|
||||
return totalPages;
|
||||
}
|
||||
|
||||
public void setTotalPages(Integer totalPages) {
|
||||
this.totalPages = totalPages;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package com.unisinsight.project.entity.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class StoragePoolData {
|
||||
private List<VmStoragePool> items;
|
||||
private Integer total;
|
||||
private Integer page;
|
||||
private Integer pageSize;
|
||||
private Integer totalPages;
|
||||
|
||||
// Getters and Setters
|
||||
public List<VmStoragePool> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<VmStoragePool> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public Integer getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(Integer total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public Integer getPage() {
|
||||
return page;
|
||||
}
|
||||
|
||||
public void setPage(Integer page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
public Integer getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(Integer pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public Integer getTotalPages() {
|
||||
return totalPages;
|
||||
}
|
||||
|
||||
public void setTotalPages(Integer totalPages) {
|
||||
this.totalPages = totalPages;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
// StoragePool.java - 存储池信息对象
|
||||
package com.unisinsight.project.entity.dto;
|
||||
|
||||
public class VmStoragePool {
|
||||
private String name;
|
||||
private String uuid;
|
||||
private String state;
|
||||
private Long capacity;
|
||||
private Long allocation;
|
||||
private Long available;
|
||||
private Integer autostart;
|
||||
private Integer persistent;
|
||||
private Integer volumeCount;
|
||||
private String type;
|
||||
private String path;
|
||||
|
||||
// Getters and Setters
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -30,5 +30,10 @@ public class LoginReq {
|
|||
@JsonProperty("token")
|
||||
private String token;
|
||||
|
||||
@ApiModelProperty("mac地址")
|
||||
private String macAddr;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public class NetworkManagePageReq {
|
|||
*/
|
||||
@Size(max = 64, message = "网络名称长度不能超过64个字符")
|
||||
@ApiModelProperty(value = "网络名称", required = true)
|
||||
private String name;
|
||||
private String networkName;
|
||||
|
||||
/**
|
||||
* 网络类型
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public class NetworkManageReq {
|
|||
@NotBlank(message = "网络名称不能为空")
|
||||
@Size(max = 64, message = "网络名称长度不能超过64个字符")
|
||||
@ApiModelProperty(value = "网络名称", required = true)
|
||||
private String name;
|
||||
private String networkName;
|
||||
|
||||
/**
|
||||
* 网络类型
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public class StoragePoolReq {
|
|||
@ApiModelProperty("名称")
|
||||
@NotBlank(message = "名称不能为空")
|
||||
@Size(max = 64, message = "名称长度不能超过64个字符")
|
||||
private String name;
|
||||
private String poolName;
|
||||
|
||||
@ApiModelProperty("类型")
|
||||
@Size(max = 16, message = "类型长度不能超过16个字符")
|
||||
|
|
|
|||
|
|
@ -1,14 +1,16 @@
|
|||
package com.unisinsight.project.feign;
|
||||
|
||||
import com.unisinsight.project.config.FeignConfig;
|
||||
import com.unisinsight.project.entity.dao.NetworkManage;
|
||||
import com.unisinsight.project.entity.dto.ApiResponse;
|
||||
import com.unisinsight.project.entity.dto.NetworkData;
|
||||
import com.unisinsight.project.entity.dto.StoragePoolData;
|
||||
import com.unisinsight.project.entity.req.NetworkManageReq;
|
||||
import com.unisinsight.project.entity.req.StoragePoolReq;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 第三方API客户端
|
||||
|
|
@ -47,4 +49,9 @@ public interface ExternalApiClient {
|
|||
@DeleteMapping("/api/v1/storage/pools/{pool_name}")
|
||||
ApiResponse deleteStorage(@PathVariable("pool_name") String poolName);
|
||||
|
||||
@GetMapping("/api/v1/network/list")
|
||||
ApiResponse<NetworkData> list(@RequestParam("page")int page, @RequestParam("page_size")int pageSize);
|
||||
|
||||
@GetMapping("/api/v1/storage/pools")
|
||||
ApiResponse<StoragePoolData> listStorage(@RequestParam("page")int page, @RequestParam("page_size")int pageSize);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,4 +61,6 @@ public interface NetworkManageService {
|
|||
* @return Page<NetworkManage> 分页结果
|
||||
*/
|
||||
PageResult<NetworkManage> pageNetworkManages(NetworkManagePageReq networkManagePageReq);
|
||||
|
||||
void synchData();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,4 +50,6 @@ public interface StoragePoolService {
|
|||
* @return Page<StoragePool> 分页结果
|
||||
*/
|
||||
PageResult<StoragePool> pageStoragePools(StoragePoolReq storagePoolReq);
|
||||
|
||||
void synchData();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
package com.unisinsight.project.service.impl;
|
||||
|
||||
import cn.hutool.core.exceptions.CheckedUtil;
|
||||
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.dto.ApiResponse;
|
||||
import com.unisinsight.project.entity.dto.Network;
|
||||
import com.unisinsight.project.entity.dto.NetworkData;
|
||||
import com.unisinsight.project.entity.req.NetworkManagePageReq;
|
||||
import com.unisinsight.project.entity.req.NetworkManageReq;
|
||||
import com.unisinsight.project.entity.res.PageResult;
|
||||
|
|
@ -15,9 +16,10 @@ import com.unisinsight.project.mapper.NetworkManageMapper;
|
|||
import com.unisinsight.project.service.NetworkManageService;
|
||||
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;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -29,6 +31,7 @@ public class NetworkManageServiceImpl extends ServiceImpl<NetworkManageMapper, N
|
|||
|
||||
@Resource
|
||||
private ExternalApiClient client;
|
||||
|
||||
/**
|
||||
* 新增网络管理信息
|
||||
*
|
||||
|
|
@ -39,9 +42,9 @@ public class NetworkManageServiceImpl extends ServiceImpl<NetworkManageMapper, N
|
|||
public NetworkManage addNetworkManage(NetworkManageReq networkManageReq) {
|
||||
// 检查名称是否重复
|
||||
QueryWrapper<NetworkManage> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("name", networkManageReq.getName());
|
||||
queryWrapper.eq("name", networkManageReq.getNetworkName());
|
||||
if (this.count(queryWrapper) > 0) {
|
||||
throw new BusinessException("网络名称'" + networkManageReq.getName() + "'已存在,请使用其他名称");
|
||||
throw new BusinessException("网络名称'" + networkManageReq.getNetworkName() + "'已存在,请使用其他名称");
|
||||
}
|
||||
|
||||
// 调用虚拟机创建存储池
|
||||
|
|
@ -81,15 +84,15 @@ public class NetworkManageServiceImpl extends ServiceImpl<NetworkManageMapper, N
|
|||
// 修改名称
|
||||
existing.setUpdateTime(new Date());
|
||||
// 如果名称不为空且与原名称不同,则进行重名校验
|
||||
if (networkManageReq.getName() != null && !networkManageReq.getName().isEmpty()
|
||||
&& !networkManageReq.getName().equals(existing.getName())) {
|
||||
if (networkManageReq.getNetworkName() != null && !networkManageReq.getNetworkName().isEmpty()
|
||||
&& !networkManageReq.getNetworkName().equals(existing.getNetworkName())) {
|
||||
// 检查新名称是否重复
|
||||
QueryWrapper<NetworkManage> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("name", networkManageReq.getName());
|
||||
queryWrapper.eq("name", networkManageReq.getNetworkName());
|
||||
if (this.count(queryWrapper) > 0) {
|
||||
throw new BusinessException("网络名称'" + networkManageReq.getName() + "'已存在,请使用其他名称");
|
||||
throw new BusinessException("网络名称'" + networkManageReq.getNetworkName() + "'已存在,请使用其他名称");
|
||||
}
|
||||
existing.setName(networkManageReq.getName());
|
||||
existing.setNetworkName(networkManageReq.getNetworkName());
|
||||
}
|
||||
|
||||
// 调用虚拟机创建存储池
|
||||
|
|
@ -103,14 +106,14 @@ public class NetworkManageServiceImpl extends ServiceImpl<NetworkManageMapper, N
|
|||
}
|
||||
|
||||
// 修改状态
|
||||
if(networkManageReq.getStatus() != null ){
|
||||
if (networkManageReq.getStatus() != null) {
|
||||
try {
|
||||
networkManageReq.setName(existing.getName());
|
||||
networkManageReq.setNetworkName(existing.getNetworkName());
|
||||
ApiResponse response;
|
||||
if(1==networkManageReq.getStatus()){
|
||||
if (1 == networkManageReq.getStatus()) {
|
||||
response = client.startNetwork(networkManageReq);
|
||||
} else {
|
||||
response =client.stopNetwork(networkManageReq);
|
||||
response = client.stopNetwork(networkManageReq);
|
||||
}
|
||||
if (!"200".equals(response.getCode())) {
|
||||
throw new BusinessException("调用外部接口失败: " + response.getMessage());
|
||||
|
|
@ -136,7 +139,7 @@ public class NetworkManageServiceImpl extends ServiceImpl<NetworkManageMapper, N
|
|||
throw new BusinessException("网络管理信息不存在");
|
||||
}
|
||||
try {
|
||||
ApiResponse response = client.deleteNetwork(existing.getName());
|
||||
ApiResponse response = client.deleteNetwork(existing.getNetworkName());
|
||||
if (!"200".equals(response.getCode())) {
|
||||
throw new BusinessException("调用外部接口失败: " + response.getMessage());
|
||||
}
|
||||
|
|
@ -196,8 +199,8 @@ public class NetworkManageServiceImpl extends ServiceImpl<NetworkManageMapper, N
|
|||
QueryWrapper<NetworkManage> queryWrapper = new QueryWrapper<>();
|
||||
|
||||
// 添加查询条件
|
||||
if (pageReq.getName() != null && !pageReq.getName().isEmpty()) {
|
||||
queryWrapper.like("name", pageReq.getName());
|
||||
if (pageReq.getNetworkName() != null && !pageReq.getNetworkName().isEmpty()) {
|
||||
queryWrapper.like("network_name", pageReq.getNetworkName());
|
||||
}
|
||||
if (pageReq.getType() != null && !pageReq.getType().isEmpty()) {
|
||||
queryWrapper.eq("type", pageReq.getType());
|
||||
|
|
@ -211,5 +214,41 @@ public class NetworkManageServiceImpl extends ServiceImpl<NetworkManageMapper, N
|
|||
|
||||
// 转换为 PageResult
|
||||
return PageResult.convertPage(resultPage, NetworkManage.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从虚拟机同步网络数据
|
||||
*/
|
||||
@Override
|
||||
public void synchData() {
|
||||
ApiResponse<NetworkData> response;
|
||||
try {
|
||||
response = client.list(1, 100);
|
||||
if (!"200".equals(response.getCode())) {
|
||||
throw new BusinessException("调用外部接口失败: " + response.getMessage());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException("调用外部接口失败: " + e.getMessage());
|
||||
}
|
||||
|
||||
List<Network> networkList = response.getData().getNetworks();
|
||||
if (CollectionUtils.isEmpty(networkList)) {
|
||||
return;
|
||||
}
|
||||
List<NetworkManage> networkManageList = new ArrayList<>();
|
||||
for (Network network : networkList) {
|
||||
NetworkManage networkManage = new NetworkManage();
|
||||
BeanUtils.copyProperties(network, networkManage);
|
||||
networkManage.setNetworkName(network.getName());
|
||||
networkManage.setStatus("active".equals(network.getState()) ? 1 : 2);
|
||||
networkManageList.add(networkManage);
|
||||
}
|
||||
// 清空数据并重新插入
|
||||
this.remove(new QueryWrapper<>());
|
||||
this.saveOrUpdateBatch(networkManageList);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ 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.ApiResponse;
|
||||
import com.unisinsight.project.entity.dto.*;
|
||||
import com.unisinsight.project.entity.req.StoragePoolReq;
|
||||
import com.unisinsight.project.entity.res.PageResult;
|
||||
import com.unisinsight.project.exception.BusinessException;
|
||||
|
|
@ -15,9 +15,12 @@ import com.unisinsight.project.service.StoragePoolService;
|
|||
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;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 存储池服务实现类
|
||||
|
|
@ -38,9 +41,9 @@ public class StoragePoolServiceImpl extends ServiceImpl<StoragePoolMapper, Stora
|
|||
public StoragePool addStoragePool(StoragePoolReq storagePoolReq) {
|
||||
// 检查名称是否重复
|
||||
QueryWrapper<StoragePool> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("name", storagePoolReq.getName());
|
||||
queryWrapper.eq("name", storagePoolReq.getPoolName());
|
||||
if (this.count(queryWrapper) > 0) {
|
||||
throw new BusinessException("存储池名称'" + storagePoolReq.getName() + "'已存在,请使用其他名称");
|
||||
throw new BusinessException("存储池名称'" + storagePoolReq.getPoolName() + "'已存在,请使用其他名称");
|
||||
}
|
||||
|
||||
// 调用虚拟机创建存储池
|
||||
|
|
@ -93,12 +96,12 @@ public class StoragePoolServiceImpl extends ServiceImpl<StoragePoolMapper, Stora
|
|||
// 修改状态
|
||||
if (storagePoolReq.getStatus() != null) {
|
||||
try {
|
||||
storagePoolReq.setName(existing.getName());
|
||||
storagePoolReq.setPoolName(existing.getPoolName());
|
||||
ApiResponse response;
|
||||
if(1==storagePoolReq.getStatus()){
|
||||
if (1 == storagePoolReq.getStatus()) {
|
||||
response = client.startStorage(storagePoolReq);
|
||||
} else {
|
||||
response =client.stopStorage(storagePoolReq);
|
||||
response = client.stopStorage(storagePoolReq);
|
||||
}
|
||||
if (!"200".equals(response.getCode())) {
|
||||
throw new BusinessException("调用外部接口失败: " + response.getMessage());
|
||||
|
|
@ -127,7 +130,7 @@ public class StoragePoolServiceImpl extends ServiceImpl<StoragePoolMapper, Stora
|
|||
return false;
|
||||
}
|
||||
try {
|
||||
ApiResponse response = client.deleteStorage(existing.getName());
|
||||
ApiResponse response = client.deleteStorage(existing.getPoolName());
|
||||
if (!"200".equals(response.getCode())) {
|
||||
throw new BusinessException("调用外部接口失败: " + response.getMessage());
|
||||
}
|
||||
|
|
@ -161,8 +164,8 @@ public class StoragePoolServiceImpl extends ServiceImpl<StoragePoolMapper, Stora
|
|||
QueryWrapper<StoragePool> queryWrapper = new QueryWrapper<>();
|
||||
|
||||
// 添加查询条件
|
||||
if (storagePoolReq.getName() != null && !storagePoolReq.getName().isEmpty()) {
|
||||
queryWrapper.like("name", storagePoolReq.getName());
|
||||
if (storagePoolReq.getPoolName() != null && !storagePoolReq.getPoolName().isEmpty()) {
|
||||
queryWrapper.like("pool_name", storagePoolReq.getPoolName());
|
||||
}
|
||||
if (storagePoolReq.getType() != null && !storagePoolReq.getType().isEmpty()) {
|
||||
queryWrapper.eq("type", storagePoolReq.getType());
|
||||
|
|
@ -176,4 +179,35 @@ public class StoragePoolServiceImpl extends ServiceImpl<StoragePoolMapper, Stora
|
|||
Page<StoragePool> resultPage = this.page(page, queryWrapper);
|
||||
return PageResult.convertPage(resultPage, StoragePool.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void synchData() {
|
||||
ApiResponse<StoragePoolData> response;
|
||||
try {
|
||||
response = client.listStorage(1, 100);
|
||||
if (!"200".equals(response.getCode())) {
|
||||
throw new BusinessException("调用外部接口失败: " + response.getMessage());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException("调用外部接口失败: " + e.getMessage());
|
||||
}
|
||||
|
||||
List<VmStoragePool> vmStoragePoolList = response.getData().getItems();
|
||||
if (CollectionUtils.isEmpty(vmStoragePoolList)) {
|
||||
return;
|
||||
}
|
||||
List<StoragePool> networkManageList = new ArrayList<>();
|
||||
for (VmStoragePool vmStoragePool : vmStoragePoolList) {
|
||||
StoragePool storagePool = new StoragePool();
|
||||
BeanUtils.copyProperties(vmStoragePool, storagePool);
|
||||
storagePool.setPoolName(vmStoragePool.getName());
|
||||
storagePool.setStatus("active".equals(vmStoragePool.getState()) ? 1 : 2);
|
||||
networkManageList.add(storagePool);
|
||||
}
|
||||
// 清空数据并重新插入
|
||||
this.remove(new QueryWrapper<>());
|
||||
this.saveOrUpdateBatch(networkManageList);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue