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 17b4f37..07f193a 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 @@ -3,6 +3,7 @@ package com.unisinsight.project.entity.dao; import com.baomidou.mybatisplus.annotation.*; import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.util.Date; 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 e0eba0b..adf281d 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 @@ -80,21 +80,28 @@ public class StoragePool { /** * 总容量 */ - @TableField(exist = false) + @TableField("capacity") @ApiModelProperty(value = "总容量") private Long capacity; /** * 已分配容量 */ - @TableField(exist = false) + @TableField("allocation") @ApiModelProperty(value = "已分配容量") private Long allocation; /** * 可用容量 */ - @TableField(exist = false) + @TableField("available") @ApiModelProperty(value = "可用容量") private Long available; + + /** + * 可用容量 + */ + @TableField("path") + @ApiModelProperty(value = "路劲") + private String path; } 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 9b06942..419a798 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 @@ -71,7 +71,7 @@ public class NetworkManageReq { */ @ApiModelProperty(value = "DHCP启用状态:1 启用 0 不启用") @JsonProperty("dhcp_enabled") - private Short dhcpEnabled; + private Integer dhcpEnabled; /** * DHCP起始地址 @@ -123,6 +123,6 @@ public class NetworkManageReq { * 开机自启动 */ @ApiModelProperty(value = "开机自启动:1是,0否") - private Short autostart; + private Integer autostart; } \ 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 index eae61dc..b1c5dc9 100644 --- a/nex-be/src/main/java/com/unisinsight/project/feign/ExternalApiClient.java +++ b/nex-be/src/main/java/com/unisinsight/project/feign/ExternalApiClient.java @@ -26,8 +26,8 @@ public interface ExternalApiClient { @DeleteMapping("/api/v1/network/{network_name}") ApiResponse deleteNetwork(@PathVariable("network_name") String networkName); - @PostMapping("/api/v1/network/update") - ApiResponse updateNetwork(@RequestBody NetworkManageReq networkManageReq); + @PutMapping("/api/v1/network/update") + ApiResponse updateNetwork(@RequestBody Network network); @PostMapping("/api/v1/network/start") ApiResponse startNetwork(@RequestBody NetworkManageReq networkManageReq); 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 7765a67..ba6690c 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 @@ -18,9 +18,7 @@ import com.unisinsight.project.util.StringUtil; 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 org.springframework.util.StringUtils; import javax.annotation.Resource; import java.util.ArrayList; @@ -75,7 +73,7 @@ public class NetworkManageServiceImpl extends ServiceImpl 网络管理列表 */ @Override @@ -273,10 +321,10 @@ public class NetworkManageServiceImpl extends ServiceImpl { + try { + logProcessOutput(process); + } catch (IOException e) { + e.printStackTrace(); + } + }).start(); + // 对于start命令,只要进程启动成功就返回true + + // 稍微等待一下看初始输出是否有错误 + Thread.sleep(WAIT_START_TIME); + return process.isAlive(); // 如果进程还在运行,认为启动成功 + + + } catch (IOException | InterruptedException e) { + e.printStackTrace(); + return false; + } + } + + /** + * 打印进程输出 + */ + private static void logProcessOutput(Process process) throws IOException { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) { + String line; + while ((line = reader.readLine()) != null) { + System.out.println("[BT输出] " + line); + } + } + } + + public static boolean createImage(String srcFile, String detFile, String name, String type) { + // 验证文件是否存在 + if (!new File(srcFile).exists()) { + System.err.println("源文件不存在: " + srcFile); + return false; + } + // 确保目标目录存在 + new File(detFile).getParentFile().mkdirs(); + return executeCommand(srcFile, detFile, name, type); + } + + public static Map progress(String name) { + + try { + // 检查文件是否存在 + File jsonFile = new File(JSON_PATH+name); + if (!jsonFile.exists()) { + System.err.println("JSON文件不存在: " + JSON_PATH+name); + return null; + } + + // 读取文件内容 + String content = new String(Files.readAllBytes(Paths.get(JSON_PATH+name))); + + // 使用Jackson将JSON转换为Map + ObjectMapper objectMapper = new ObjectMapper(); + return objectMapper.readValue(content, Map.class); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } +}