diff --git a/nex-be/pom.xml b/nex-be/pom.xml
index a712c52..41a08e1 100644
--- a/nex-be/pom.xml
+++ b/nex-be/pom.xml
@@ -23,6 +23,7 @@
1.8
3.23.4
+ 2021.0.5
@@ -32,6 +33,11 @@
spring-boot-starter-web
+
+ org.springframework.cloud
+ spring-cloud-starter-openfeign
+
+
org.springframework.boot
@@ -124,7 +130,19 @@
spring-boot-starter-test
test
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-dependencies
+ ${spring-cloud.version}
+ pom
+ import
+
+
+
diff --git a/nex-be/src/main/java/com/unisinsight/project/Application.java b/nex-be/src/main/java/com/unisinsight/project/Application.java
index b1fdf4d..96f6660 100644
--- a/nex-be/src/main/java/com/unisinsight/project/Application.java
+++ b/nex-be/src/main/java/com/unisinsight/project/Application.java
@@ -3,12 +3,14 @@ package com.unisinsight.project;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* 分片上传应用启动类
*/
@SpringBootApplication
@MapperScan(basePackages = "com.unisinsight.project.mapper")
+@EnableFeignClients(basePackages = "com.unisinsight.project.feign")
public class Application {
public static void main(String[] args) {
diff --git a/nex-be/src/main/java/com/unisinsight/project/config/FeignConfig.java b/nex-be/src/main/java/com/unisinsight/project/config/FeignConfig.java
new file mode 100644
index 0000000..2154752
--- /dev/null
+++ b/nex-be/src/main/java/com/unisinsight/project/config/FeignConfig.java
@@ -0,0 +1,35 @@
+package com.unisinsight.project.config;
+
+import feign.Logger;
+import feign.Request;
+import feign.Retryer;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class FeignConfig {
+
+ /**
+ * 配置请求日志级别
+ */
+ @Bean
+ public Logger.Level feignLoggerLevel() {
+ return Logger.Level.FULL;
+ }
+
+ /**
+ * 配置超时时间
+ */
+ @Bean
+ public Request.Options options() {
+ return new Request.Options(5000, 10000); // 连接超时5秒,读取超时10秒
+ }
+
+ /**
+ * 配置重试机制
+ */
+ @Bean
+ public Retryer retryer() {
+ return new Retryer.Default(1000, 2000, 3); // 初始间隔1秒,最大间隔2秒,最多重试3次
+ }
+}
diff --git a/nex-be/src/main/java/com/unisinsight/project/controller/ClientController.java b/nex-be/src/main/java/com/unisinsight/project/controller/ClientController.java
index 9f9b772..4b89816 100644
--- a/nex-be/src/main/java/com/unisinsight/project/controller/ClientController.java
+++ b/nex-be/src/main/java/com/unisinsight/project/controller/ClientController.java
@@ -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);
}
-
-
}
diff --git a/nex-be/src/main/java/com/unisinsight/project/controller/NetworkManageController.java b/nex-be/src/main/java/com/unisinsight/project/controller/NetworkManageController.java
index 412e506..0d9e2c7 100644
--- a/nex-be/src/main/java/com/unisinsight/project/controller/NetworkManageController.java
+++ b/nex-be/src/main/java/com/unisinsight/project/controller/NetworkManageController.java
@@ -2,12 +2,9 @@ package com.unisinsight.project.controller;
import com.unisinsight.project.entity.dao.NetworkManage;
-import com.unisinsight.project.entity.req.DeleteIdReq;
import com.unisinsight.project.entity.req.NetworkManagePageReq;
import com.unisinsight.project.entity.req.NetworkManageReq;
-import com.unisinsight.project.entity.req.StoragePoolReq;
import com.unisinsight.project.entity.res.PageResult;
-import com.unisinsight.project.entity.res.StoragePoolRes;
import com.unisinsight.project.exception.Result;
import com.unisinsight.project.service.NetworkManageService;
import io.swagger.annotations.Api;
@@ -30,17 +27,19 @@ public class NetworkManageController {
@Resource
private NetworkManageService networkManageService;
- @ApiOperation(value = "分页查询镜像")
+ @ApiOperation(value = "分页查询")
@PostMapping("/select/page")
public Result> selectPage(@RequestBody NetworkManagePageReq networkManagePageReq) {
return Result.successResult(networkManageService.pageNetworkManages(networkManagePageReq));
}
+
@ApiOperation(value = "新增")
@PostMapping("/add")
public Result> addNetworkManage(@Valid @RequestBody NetworkManageReq networkManageReq) {
networkManageService.addNetworkManage(networkManageReq);
return Result.successResult();
}
+
@ApiOperation(value = "修改状态")
@PostMapping("/update")
public Result> updateNetworkManage(@RequestBody NetworkManageReq networkManageReq) {
@@ -57,11 +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();
}
}
diff --git a/nex-be/src/main/java/com/unisinsight/project/controller/StoragePoolController.java b/nex-be/src/main/java/com/unisinsight/project/controller/StoragePoolController.java
index 212018d..fe35d27 100644
--- a/nex-be/src/main/java/com/unisinsight/project/controller/StoragePoolController.java
+++ b/nex-be/src/main/java/com/unisinsight/project/controller/StoragePoolController.java
@@ -1,23 +1,19 @@
package com.unisinsight.project.controller;
-import cn.hutool.json.JSONUtil;
-import com.unisinsight.project.entity.req.DeleteIdReq;
-import com.unisinsight.project.entity.req.ImageVirtualMachinesReq;
+import com.unisinsight.project.entity.dao.StoragePool;
import com.unisinsight.project.entity.req.StoragePoolReq;
-import com.unisinsight.project.entity.res.ImageVirtualMachinesRes;
import com.unisinsight.project.entity.res.PageResult;
-import com.unisinsight.project.entity.res.StoragePoolRes;
import com.unisinsight.project.exception.BaseErrorCode;
import com.unisinsight.project.exception.Result;
-import com.unisinsight.project.service.ImageVirtualMachinesService;
+import com.unisinsight.project.service.StoragePoolService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
-import java.util.Objects;
+import javax.validation.Valid;
/**
* 存储池管理
@@ -28,34 +24,48 @@ import java.util.Objects;
@Api(tags = "存储池类")
public class StoragePoolController {
- @ApiOperation(value = "分页查询镜像")
+ @Resource
+ private StoragePoolService storagePoolService;
+
+ @ApiOperation(value = "分页查询")
@PostMapping("/select/page")
- public Result> selectPage(@RequestBody StoragePoolReq storagePoolReq) {
- return null;
+ public Result> selectPage(@RequestBody StoragePoolReq storagePoolReq) {
+ return Result.successResult(storagePoolService.pageStoragePools(storagePoolReq));
}
+
@ApiOperation(value = "新增")
@PostMapping("/add")
- public Result> insertImageVirtualMachines(@RequestBody StoragePoolReq storagePoolReq) {
- return null;
+ public Result> insertStoragePool(@Valid @RequestBody StoragePoolReq storagePoolReq) {
+ storagePoolService.addStoragePool(storagePoolReq);
+ return Result.successResult();
}
- @ApiOperation(value = "修改状态")
+
+ @ApiOperation(value = "修改")
@PostMapping("/update")
- public Result> updateUser(@RequestBody StoragePoolReq storagePoolReq) {
- return null;
+ public Result> updateStoragePool(@RequestBody StoragePoolReq storagePoolReq) {
+ if (storagePoolService.updateStoragePool(storagePoolReq)) {
+ return Result.successResult();
+ } else {
+ return Result.errorResult(BaseErrorCode.DATABASE_OPERATION_FAILED);
+ }
}
@ApiOperation(value = "删除")
- @PostMapping("/delete")
- public Result> delete(@RequestBody DeleteIdReq deleteIdReq) {
+ @DeleteMapping("/{id}")
+ public Result> delete(@PathVariable Long id) {
+ if (storagePoolService.deleteStoragePool(id)) {
+ return Result.successResult();
+ } else {
+ return Result.errorResult(BaseErrorCode.DATABASE_OPERATION_FAILED);
+ }
- return null;
}
- @ApiOperation(value = "同步状态")
- @GetMapping("/synchStatus")
- public Result> synchStatus() {
-
+ @ApiOperation(value = "同步数据")
+ @GetMapping("/synchData")
+ public Result> synchData() {
+ storagePoolService.synchData();
return null;
}
diff --git a/nex-be/src/main/java/com/unisinsight/project/entity/dao/NetworkManage.java b/nex-be/src/main/java/com/unisinsight/project/entity/dao/NetworkManage.java
index 1e9a975..5a3d190 100644
--- a/nex-be/src/main/java/com/unisinsight/project/entity/dao/NetworkManage.java
+++ b/nex-be/src/main/java/com/unisinsight/project/entity/dao/NetworkManage.java
@@ -23,8 +23,8 @@ public class NetworkManage {
/**
* 网络名称
*/
- @TableField("name")
- private String name;
+ @TableField("network_name")
+ private String networkName;
/**
* 网络类型
diff --git a/nex-be/src/main/java/com/unisinsight/project/entity/dao/StoragePool.java b/nex-be/src/main/java/com/unisinsight/project/entity/dao/StoragePool.java
index 17e5c38..3872265 100644
--- a/nex-be/src/main/java/com/unisinsight/project/entity/dao/StoragePool.java
+++ b/nex-be/src/main/java/com/unisinsight/project/entity/dao/StoragePool.java
@@ -31,9 +31,9 @@ public class StoragePool {
/**
* 存储池名称
*/
- @TableField("name")
+ @TableField("pool_name")
@ApiModelProperty(value = "存储池名称")
- private String name;
+ private String poolName;
/**
* 存储池类型
@@ -47,7 +47,7 @@ public class StoragePool {
*/
@TableField("status")
@ApiModelProperty(value = "状态")
- private Short status;
+ private Integer status;
/**
* 描述信息
diff --git a/nex-be/src/main/java/com/unisinsight/project/entity/dto/ApiResponse.java b/nex-be/src/main/java/com/unisinsight/project/entity/dto/ApiResponse.java
new file mode 100644
index 0000000..34a1839
--- /dev/null
+++ b/nex-be/src/main/java/com/unisinsight/project/entity/dto/ApiResponse.java
@@ -0,0 +1,91 @@
+
+package com.unisinsight.project.entity.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * 通用API响应结果类
+ */
+@Data
+@ApiModel(description = "API响应结果")
+public class ApiResponse implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ @ApiModelProperty(value = "响应码")
+ private String code;
+
+ @ApiModelProperty(value = "响应消息")
+ private String message;
+
+ @ApiModelProperty(value = "响应数据")
+ private T data;
+
+ public ApiResponse() {}
+
+ public ApiResponse(String code, String message) {
+ this.code = code;
+ this.message = message;
+ }
+
+ public ApiResponse(String code, String message, T data) {
+ this.code = code;
+ this.message = message;
+ this.data = data;
+ }
+
+ /**
+ * 成功响应
+ */
+ public static ApiResponse success() {
+ return new ApiResponse<>("200", "操作成功");
+ }
+
+ public static ApiResponse success(T data) {
+ return new ApiResponse<>("200", "操作成功", data);
+ }
+
+ public static ApiResponse success(String message, T data) {
+ return new ApiResponse<>("200", message, data);
+ }
+
+ /**
+ * 失败响应
+ */
+ public static ApiResponse error(String message) {
+ return new ApiResponse<>("500", message);
+ }
+
+ public static ApiResponse error(String code, String message) {
+ return new ApiResponse<>(code, message);
+ }
+
+ public static ApiResponse error(String code, String message, T data) {
+ return new ApiResponse<>(code, message, data);
+ }
+
+ /**
+ * 参数校验错误
+ */
+ public static ApiResponse badRequest(String message) {
+ return new ApiResponse<>("400", message);
+ }
+
+ /**
+ * 权限错误
+ */
+ public static ApiResponse forbidden(String message) {
+ return new ApiResponse<>("403", message);
+ }
+
+ /**
+ * 未找到
+ */
+ public static ApiResponse notFound(String message) {
+ return new ApiResponse<>("404", message);
+ }
+}
\ No newline at end of file
diff --git a/nex-be/src/main/java/com/unisinsight/project/entity/dto/Network.java b/nex-be/src/main/java/com/unisinsight/project/entity/dto/Network.java
new file mode 100644
index 0000000..9b3564c
--- /dev/null
+++ b/nex-be/src/main/java/com/unisinsight/project/entity/dto/Network.java
@@ -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;
+ }
+}
diff --git a/nex-be/src/main/java/com/unisinsight/project/entity/dto/NetworkData.java b/nex-be/src/main/java/com/unisinsight/project/entity/dto/NetworkData.java
new file mode 100644
index 0000000..f6492ce
--- /dev/null
+++ b/nex-be/src/main/java/com/unisinsight/project/entity/dto/NetworkData.java
@@ -0,0 +1,24 @@
+package com.unisinsight.project.entity.dto;
+import java.util.List;
+
+public class NetworkData {
+ private List networks;
+ private Pagination pagination;
+
+ // Getters and Setters
+ public List getNetworks() {
+ return networks;
+ }
+
+ public void setNetworks(List networks) {
+ this.networks = networks;
+ }
+
+ public Pagination getPagination() {
+ return pagination;
+ }
+
+ public void setPagination(Pagination pagination) {
+ this.pagination = pagination;
+ }
+}
diff --git a/nex-be/src/main/java/com/unisinsight/project/entity/dto/Pagination.java b/nex-be/src/main/java/com/unisinsight/project/entity/dto/Pagination.java
new file mode 100644
index 0000000..42ead4a
--- /dev/null
+++ b/nex-be/src/main/java/com/unisinsight/project/entity/dto/Pagination.java
@@ -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;
+ }
+}
diff --git a/nex-be/src/main/java/com/unisinsight/project/entity/dto/StoragePoolData.java b/nex-be/src/main/java/com/unisinsight/project/entity/dto/StoragePoolData.java
new file mode 100644
index 0000000..e22db25
--- /dev/null
+++ b/nex-be/src/main/java/com/unisinsight/project/entity/dto/StoragePoolData.java
@@ -0,0 +1,52 @@
+package com.unisinsight.project.entity.dto;
+
+import java.util.List;
+
+public class StoragePoolData {
+ private List items;
+ private Integer total;
+ private Integer page;
+ private Integer pageSize;
+ private Integer totalPages;
+
+ // Getters and Setters
+ public List getItems() {
+ return items;
+ }
+
+ public void setItems(List 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;
+ }
+}
diff --git a/nex-be/src/main/java/com/unisinsight/project/entity/dto/VmStoragePool.java b/nex-be/src/main/java/com/unisinsight/project/entity/dto/VmStoragePool.java
new file mode 100644
index 0000000..1709af9
--- /dev/null
+++ b/nex-be/src/main/java/com/unisinsight/project/entity/dto/VmStoragePool.java
@@ -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;
+ }
+}
diff --git a/nex-be/src/main/java/com/unisinsight/project/entity/req/LoginReq.java b/nex-be/src/main/java/com/unisinsight/project/entity/req/LoginReq.java
index 04ea9dc..5d81906 100644
--- a/nex-be/src/main/java/com/unisinsight/project/entity/req/LoginReq.java
+++ b/nex-be/src/main/java/com/unisinsight/project/entity/req/LoginReq.java
@@ -30,5 +30,10 @@ public class LoginReq {
@JsonProperty("token")
private String token;
+ @ApiModelProperty("mac地址")
+ private String macAddr;
+
+
+
}
diff --git a/nex-be/src/main/java/com/unisinsight/project/entity/req/NetworkManagePageReq.java b/nex-be/src/main/java/com/unisinsight/project/entity/req/NetworkManagePageReq.java
index d0d6948..d309ff0 100644
--- a/nex-be/src/main/java/com/unisinsight/project/entity/req/NetworkManagePageReq.java
+++ b/nex-be/src/main/java/com/unisinsight/project/entity/req/NetworkManagePageReq.java
@@ -17,7 +17,7 @@ public class NetworkManagePageReq {
*/
@Size(max = 64, message = "网络名称长度不能超过64个字符")
@ApiModelProperty(value = "网络名称", required = true)
- private String name;
+ private String networkName;
/**
* 网络类型
diff --git a/nex-be/src/main/java/com/unisinsight/project/entity/req/NetworkManageReq.java b/nex-be/src/main/java/com/unisinsight/project/entity/req/NetworkManageReq.java
index b3ecb2f..0dc22da 100644
--- a/nex-be/src/main/java/com/unisinsight/project/entity/req/NetworkManageReq.java
+++ b/nex-be/src/main/java/com/unisinsight/project/entity/req/NetworkManageReq.java
@@ -22,7 +22,7 @@ public class NetworkManageReq {
@NotBlank(message = "网络名称不能为空")
@Size(max = 64, message = "网络名称长度不能超过64个字符")
@ApiModelProperty(value = "网络名称", required = true)
- private String name;
+ private String networkName;
/**
* 网络类型
diff --git a/nex-be/src/main/java/com/unisinsight/project/entity/req/StoragePoolReq.java b/nex-be/src/main/java/com/unisinsight/project/entity/req/StoragePoolReq.java
index 8854a92..9ce0af3 100644
--- a/nex-be/src/main/java/com/unisinsight/project/entity/req/StoragePoolReq.java
+++ b/nex-be/src/main/java/com/unisinsight/project/entity/req/StoragePoolReq.java
@@ -1,14 +1,14 @@
+
package com.unisinsight.project.entity.req;
-
import com.fasterxml.jackson.annotation.JsonProperty;
-import com.unisinsight.project.entity.dao.StoragePool;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
+import javax.validation.constraints.*;
/**
- * 存储池
+ * 存储池请求参数
*
* @author ch
* @since 2025-08-25 11:42:52
@@ -17,34 +17,45 @@ import lombok.Data;
@ApiModel("存储池")
public class StoragePoolReq {
+ @ApiModelProperty(value = "id")
+ private Integer id;
+
+ @ApiModelProperty("自动启动,默认是")
+ private boolean autostart = true;
@ApiModelProperty("名称")
- private String name;
+ @NotBlank(message = "名称不能为空")
+ @Size(max = 64, message = "名称长度不能超过64个字符")
+ private String poolName;
@ApiModelProperty("类型")
+ @Size(max = 16, message = "类型长度不能超过16个字符")
private String type;
- @ApiModelProperty("路劲")
+ @ApiModelProperty("路径")
+ @Size(max = 128, message = "路径长度不能超过128个字符")
private String path;
/**
* 状态: 1-活跃,2-关闭
**/
@ApiModelProperty("状态")
- private String status;
+ private Integer status;
/**
* 查询页
*/
@ApiModelProperty(value = "查询页", notes = "分页查询时再传")
@JsonProperty("page_num")
- private Integer pageNum;
+ @Min(value = 1, message = "页码必须大于0")
+ private Integer pageNum = 1;
/**
* 每页数量
*/
@ApiModelProperty(value = "每页数量", notes = "分页查询时再传")
@JsonProperty("page_size")
- private Integer pageSize;
-}
-
+ @Min(value = 1, message = "每页数量必须大于0")
+ @Max(value = 100, message = "每页数量不能超过100")
+ private Integer pageSize = 10;
+}
\ No newline at end of file
diff --git a/nex-be/src/main/java/com/unisinsight/project/feign/ExternalApiClient.java b/nex-be/src/main/java/com/unisinsight/project/feign/ExternalApiClient.java
new file mode 100644
index 0000000..5ff4ed4
--- /dev/null
+++ b/nex-be/src/main/java/com/unisinsight/project/feign/ExternalApiClient.java
@@ -0,0 +1,57 @@
+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.*;
+
+import java.util.List;
+
+/**
+ * 第三方API客户端
+ */
+@FeignClient(
+ name = "external-api-client",
+ url = "${external.api.url:http://10.100.51.118:8000}",
+ configuration = FeignConfig.class
+)
+public interface ExternalApiClient {
+
+ @PostMapping("/api/v1/network/create")
+ ApiResponse createNetwork(@RequestBody NetworkManageReq networkManageReq);
+
+ @DeleteMapping("/api/v1/network/{network_name}")
+ ApiResponse deleteNetwork(@PathVariable("network_name") String networkName);
+
+ @PostMapping("/api/v1/network/update")
+ ApiResponse updateNetwork(@RequestBody NetworkManageReq networkManageReq);
+
+ @PostMapping("/api/v1/network/start")
+ ApiResponse startNetwork(@RequestBody NetworkManageReq networkManageReq);
+
+ @PostMapping("/api/v1/network/stop")
+ ApiResponse stopNetwork(@RequestBody NetworkManageReq networkManageReq);
+
+ @PostMapping("/api/v1/storage/pools")
+ ApiResponse createStorage(@RequestBody StoragePoolReq storagePoolReq);
+
+ @PostMapping("/api/v1/storage/pools/start")
+ ApiResponse startStorage(@RequestBody StoragePoolReq storagePoolReq);
+
+ @PostMapping("/api/v1/storage/pools/stop")
+ ApiResponse stopStorage(@RequestBody StoragePoolReq storagePoolReq);
+
+ @DeleteMapping("/api/v1/storage/pools/{pool_name}")
+ ApiResponse deleteStorage(@PathVariable("pool_name") String poolName);
+
+ @GetMapping("/api/v1/network/list")
+ ApiResponse list(@RequestParam("page")int page, @RequestParam("page_size")int pageSize);
+
+ @GetMapping("/api/v1/storage/pools")
+ ApiResponse listStorage(@RequestParam("page")int page, @RequestParam("page_size")int pageSize);
+}
diff --git a/nex-be/src/main/java/com/unisinsight/project/service/NetworkManageService.java b/nex-be/src/main/java/com/unisinsight/project/service/NetworkManageService.java
index ad26a8e..5760d35 100644
--- a/nex-be/src/main/java/com/unisinsight/project/service/NetworkManageService.java
+++ b/nex-be/src/main/java/com/unisinsight/project/service/NetworkManageService.java
@@ -61,4 +61,6 @@ public interface NetworkManageService {
* @return Page 分页结果
*/
PageResult pageNetworkManages(NetworkManagePageReq networkManagePageReq);
+
+ void synchData();
}
diff --git a/nex-be/src/main/java/com/unisinsight/project/service/StoragePoolService.java b/nex-be/src/main/java/com/unisinsight/project/service/StoragePoolService.java
index 2090d6a..25841b8 100644
--- a/nex-be/src/main/java/com/unisinsight/project/service/StoragePoolService.java
+++ b/nex-be/src/main/java/com/unisinsight/project/service/StoragePoolService.java
@@ -3,6 +3,8 @@ package com.unisinsight.project.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.unisinsight.project.entity.dao.StoragePool;
import com.unisinsight.project.entity.req.StoragePoolReq;
+import com.unisinsight.project.entity.res.PageResult;
+import com.unisinsight.project.entity.res.StoragePoolRes;
/**
* 存储池服务接口
@@ -12,18 +14,18 @@ public interface StoragePoolService {
/**
* 新增存储池
*
- * @param storagePool 存储池对象
+ * @param storagePoolReq
* @return StoragePool 返回新增的存储池对象
*/
- StoragePool addStoragePool(StoragePool storagePool);
+ StoragePool addStoragePool(StoragePoolReq storagePoolReq);
/**
* 根据ID更新存储池信息
*
- * @param storagePool 存储池对象
+ * @param storagePoolReq
* @return boolean 是否更新成功
*/
- boolean updateStoragePool(StoragePool storagePool);
+ boolean updateStoragePool(StoragePoolReq storagePoolReq);
/**
* 根据ID删除存储池
@@ -44,12 +46,10 @@ public interface StoragePoolService {
/**
* 分页查询存储池列表
*
- * @param currentPage 当前页码
- * @param pageSize 每页大小
- * @param name 存储池名称(可选查询条件)
- * @param type 存储池类型(可选查询条件)
- * @param status 存储池状态(可选查询条件)
+ * @param storagePoolReq
* @return Page 分页结果
*/
- Page pageStoragePools(StoragePoolReq storagePoolReq);
+ PageResult pageStoragePools(StoragePoolReq storagePoolReq);
+
+ void synchData();
}
diff --git a/nex-be/src/main/java/com/unisinsight/project/service/impl/NetworkManageServiceImpl.java b/nex-be/src/main/java/com/unisinsight/project/service/impl/NetworkManageServiceImpl.java
index cfe34f1..4641f17 100644
--- a/nex-be/src/main/java/com/unisinsight/project/service/impl/NetworkManageServiceImpl.java
+++ b/nex-be/src/main/java/com/unisinsight/project/service/impl/NetworkManageServiceImpl.java
@@ -1,20 +1,25 @@
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;
import com.unisinsight.project.exception.BusinessException;
+import com.unisinsight.project.feign.ExternalApiClient;
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;
@@ -24,19 +29,32 @@ import java.util.List;
@Service
public class NetworkManageServiceImpl extends ServiceImpl implements NetworkManageService {
+ @Resource
+ private ExternalApiClient client;
+
/**
* 新增网络管理信息
*
- * @param networkManageReq
+ * @param networkManageReq
* @return NetworkManage 返回新增的网络管理对象
*/
@Override
public NetworkManage addNetworkManage(NetworkManageReq networkManageReq) {
// 检查名称是否重复
QueryWrapper 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() + "'已存在,请使用其他名称");
+ }
+
+ // 调用虚拟机创建存储池
+ try {
+ ApiResponse response = client.createNetwork(networkManageReq);
+ if (!"200".equals(response.getCode())) {
+ throw new BusinessException("调用外部接口失败: " + response.getMessage());
+ }
+ } catch (Exception e) {
+ throw new BusinessException("调用外部接口失败: " + e.getMessage());
}
// 设置创建时间和更新时间
NetworkManage networkManage = new NetworkManage();
@@ -53,7 +71,7 @@ public class NetworkManageServiceImpl extends ServiceImpl 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());
}
+
+ // 调用虚拟机创建存储池
+ try {
+ ApiResponse response = client.updateNetwork(networkManageReq);
+ if (!"200".equals(response.getCode())) {
+ throw new BusinessException("调用外部接口失败: " + response.getMessage());
+ }
+ } catch (Exception e) {
+ throw new BusinessException("调用外部接口失败: " + e.getMessage());
+ }
+
// 修改状态
- if(networkManageReq.getStatus() != null ){
+ if (networkManageReq.getStatus() != null) {
+ try {
+ networkManageReq.setNetworkName(existing.getNetworkName());
+ ApiResponse response;
+ if (1 == networkManageReq.getStatus()) {
+ response = client.startNetwork(networkManageReq);
+ } else {
+ response = client.stopNetwork(networkManageReq);
+ }
+ if (!"200".equals(response.getCode())) {
+ throw new BusinessException("调用外部接口失败: " + response.getMessage());
+ }
+ } catch (Exception e) {
+ throw new BusinessException("调用外部接口失败: " + e.getMessage());
+ }
existing.setStatus(networkManageReq.getStatus());
}
return this.updateById(existing);
@@ -90,8 +133,19 @@ public class NetworkManageServiceImpl extends ServiceImpl 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());
@@ -160,5 +214,41 @@ public class NetworkManageServiceImpl extends ServiceImpl 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 networkList = response.getData().getNetworks();
+ if (CollectionUtils.isEmpty(networkList)) {
+ return;
+ }
+ List 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);
+
+
+
+
}
}
diff --git a/nex-be/src/main/java/com/unisinsight/project/service/impl/StoragePoolServiceImpl.java b/nex-be/src/main/java/com/unisinsight/project/service/impl/StoragePoolServiceImpl.java
index 4d1f765..f19dfc9 100644
--- a/nex-be/src/main/java/com/unisinsight/project/service/impl/StoragePoolServiceImpl.java
+++ b/nex-be/src/main/java/com/unisinsight/project/service/impl/StoragePoolServiceImpl.java
@@ -3,14 +3,24 @@ 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.req.StoragePoolReq;
+import com.unisinsight.project.entity.res.PageResult;
+import com.unisinsight.project.exception.BusinessException;
+import com.unisinsight.project.feign.ExternalApiClient;
import com.unisinsight.project.mapper.StoragePoolMapper;
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;
/**
* 存储池服务实现类
@@ -18,17 +28,40 @@ import java.util.Date;
@Service
public class StoragePoolServiceImpl extends ServiceImpl implements StoragePoolService {
+ @Resource
+ private ExternalApiClient client;
+
/**
* 新增存储池
*
- * @param storagePool 存储池对象
+ * @param storagePoolReq
* @return StoragePool 返回新增的存储池对象
*/
@Override
- @Transactional(rollbackFor = Exception.class)
- public StoragePool addStoragePool(StoragePool storagePool) {
+ public StoragePool addStoragePool(StoragePoolReq storagePoolReq) {
+ // 检查名称是否重复
+ QueryWrapper queryWrapper = new QueryWrapper<>();
+ queryWrapper.eq("name", storagePoolReq.getPoolName());
+ if (this.count(queryWrapper) > 0) {
+ throw new BusinessException("存储池名称'" + storagePoolReq.getPoolName() + "'已存在,请使用其他名称");
+ }
+
+ // 调用虚拟机创建存储池
+ try {
+ ApiResponse response = client.createStorage(storagePoolReq);
+ if (!"200".equals(response.getCode())) {
+ throw new BusinessException("调用外部接口失败: " + response.getMessage());
+ }
+ } catch (Exception e) {
+ throw new BusinessException("调用外部接口失败: " + e.getMessage());
+ }
+
+ // 本地保存
+ StoragePool storagePool = new StoragePool();
+ BeanUtils.copyProperties(storagePoolReq, storagePool);
storagePool.setCreateTime(new Date());
storagePool.setUpdateTime(new Date());
+ storagePool.setStatus(1);
this.save(storagePool);
return storagePool;
}
@@ -36,18 +69,51 @@ public class StoragePoolServiceImpl extends ServiceImpl queryWrapper = new QueryWrapper<>();
+// queryWrapper.eq("name", storagePoolReq.getName());
+// if (this.count(queryWrapper) > 0) {
+// throw new BusinessException("存储池名称'" + storagePoolReq.getName() + "'已存在,请使用其他名称");
+// }
+// existing.setName(storagePoolReq.getName());
+// }
+
+ // 调用虚拟机创建存储池
+ // 修改状态
+ if (storagePoolReq.getStatus() != null) {
+ try {
+ storagePoolReq.setPoolName(existing.getPoolName());
+ ApiResponse response;
+ if (1 == storagePoolReq.getStatus()) {
+ response = client.startStorage(storagePoolReq);
+ } else {
+ response = client.stopStorage(storagePoolReq);
+ }
+ if (!"200".equals(response.getCode())) {
+ throw new BusinessException("调用外部接口失败: " + response.getMessage());
+ }
+ } catch (Exception e) {
+ throw new BusinessException("调用外部接口失败: " + e.getMessage());
+ }
+ existing.setStatus(storagePoolReq.getStatus());
+ }
+
+ existing.setUpdateTime(new Date());
+ return this.updateById(existing);
}
/**
@@ -59,6 +125,19 @@ public class StoragePoolServiceImpl extends ServiceImpl 分页结果
*/
@Override
- public Page pageStoragePools(StoragePoolReq storagePoolReq) {
+ public PageResult pageStoragePools(StoragePoolReq storagePoolReq) {
Page page = new Page<>(storagePoolReq.getPageNum(), storagePoolReq.getPageSize());
QueryWrapper 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());
@@ -100,6 +175,39 @@ public class StoragePoolServiceImpl extends ServiceImpl resultPage = this.page(page, queryWrapper);
+ return PageResult.convertPage(resultPage, StoragePool.class);
+ }
+
+ @Override
+ public void synchData() {
+ ApiResponse 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 vmStoragePoolList = response.getData().getItems();
+ if (CollectionUtils.isEmpty(vmStoragePoolList)) {
+ return;
+ }
+ List 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);
+
+
}
}
diff --git a/nex-be/src/main/resources/application.yml b/nex-be/src/main/resources/application.yml
index 842287a..e65a9dc 100644
--- a/nex-be/src/main/resources/application.yml
+++ b/nex-be/src/main/resources/application.yml
@@ -55,4 +55,19 @@ mybatis-plus:
grpc:
server:
# 指定Grpc暴露的端口,后续客户端通过这个端口访问
- port: 51051
\ No newline at end of file
+ port: 51051
+
+# Feign 配置
+feign:
+ client:
+ config:
+ external-api-client: # 对应 FeignClient 的 name
+ logger-level: full # 完整日志级别
+ default: # 全局默认配置
+ logger-level: basic
+
+# 日志配置
+logging:
+ level:
+ com.unisinsight.project.feign: debug # Feign 客户端包路径
+ com.unisinsight.project.feign.ExternalApiClient: debug
\ No newline at end of file