17 changed files with 513 additions and 226 deletions
@ -0,0 +1,12 @@ |
|||
package com.yvan.entity; |
|||
|
|||
import com.yvan.workbench.autoconfigure.LccConfigProperties; |
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
public class ServerAuthorizationConfigVo { |
|||
private String serverId; |
|||
private String authorizationCode; |
|||
private Long expirationTime; |
|||
private LccConfigProperties.FrontendMqtt frontendMqtt; |
|||
} |
|||
@ -0,0 +1,96 @@ |
|||
package com.yvan.entity; |
|||
|
|||
import com.yvan.logisticsEnv.EnvConfig; |
|||
import com.yvan.logisticsModel.SystemMetricsStore; |
|||
import org.clever.core.mapper.JacksonMapper; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 服务器状态信息 |
|||
*/ |
|||
public class ServerStatusVo { |
|||
public String projectUuid; |
|||
public Long envId; |
|||
public Boolean isVirtual; |
|||
public String serverId; |
|||
public Boolean isRunning; |
|||
|
|||
public Long startTime; |
|||
public Long stopTime; |
|||
public Float timeRate; |
|||
public String[] subSystemList; |
|||
|
|||
public Float cpuUsage; |
|||
public Float memoryUsage; |
|||
public Float diskIoLoad; |
|||
/** |
|||
* 空闲内存,单位GB |
|||
*/ |
|||
public Float freeMemory; |
|||
/** |
|||
* 磁盘剩余空间,单位GB |
|||
*/ |
|||
public Float diskFreeSpace; |
|||
|
|||
public EnvConfig envConfig; |
|||
public String projectLabel; |
|||
|
|||
public void fillSystemInfos() { |
|||
this.cpuUsage = SystemMetricsStore.cpuUsage; |
|||
this.memoryUsage = SystemMetricsStore.memoryUsage; |
|||
this.freeMemory = SystemMetricsStore.freeMemory; |
|||
this.diskIoLoad = SystemMetricsStore.diskIoLoad; |
|||
this.diskFreeSpace = SystemMetricsStore.diskFreeSpace; |
|||
} |
|||
|
|||
public Map<String, Object> toMap() { |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("projectUuid", projectUuid); |
|||
map.put("envId", envId); |
|||
map.put("isVirtual", isVirtual); |
|||
map.put("serverId", serverId); |
|||
map.put("isRunning", isRunning); |
|||
|
|||
map.put("startTime", startTime); |
|||
map.put("stopTime", stopTime); |
|||
map.put("timeRate", timeRate); |
|||
map.put("subSystemList", subSystemList); |
|||
map.put("cpuUsage", cpuUsage); |
|||
|
|||
map.put("memoryUsage", memoryUsage); |
|||
map.put("diskIoLoad", diskIoLoad); |
|||
map.put("freeMemory", freeMemory); |
|||
map.put("diskFreeSpace", diskFreeSpace); |
|||
map.put("envConfig", envConfig != null ? JacksonMapper.getInstance().toJson(envConfig) : null); |
|||
|
|||
map.put("projectLabel", projectLabel); |
|||
return map; |
|||
} |
|||
|
|||
public void copyFrom(ServerStatusVo state) { |
|||
if (state == null) { |
|||
return; |
|||
} |
|||
this.projectUuid = state.projectUuid; |
|||
this.envId = state.envId; |
|||
this.isVirtual = state.isVirtual; |
|||
this.serverId = state.serverId; |
|||
this.isRunning = state.isRunning; |
|||
|
|||
this.startTime = state.startTime; |
|||
this.stopTime = state.stopTime; |
|||
this.timeRate = state.timeRate; |
|||
this.subSystemList = state.subSystemList; |
|||
|
|||
this.cpuUsage = state.cpuUsage; |
|||
this.memoryUsage = state.memoryUsage; |
|||
this.diskIoLoad = state.diskIoLoad; |
|||
this.freeMemory = state.freeMemory; |
|||
this.diskFreeSpace = state.diskFreeSpace; |
|||
|
|||
this.envConfig = state.envConfig; |
|||
this.projectLabel = state.projectLabel; |
|||
} |
|||
} |
|||
@ -1,56 +0,0 @@ |
|||
package com.yvan.logisticsModel; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
public class RuntimeState { |
|||
public String projectUuid; |
|||
public long envId; |
|||
public boolean isVirtual; |
|||
public String serverId; |
|||
public boolean isRunning; |
|||
|
|||
public long startTime; |
|||
public long stopTime; |
|||
public float timeRate; |
|||
public String[] subSystemList; |
|||
|
|||
public float cpuUsage; |
|||
public float memoryUsage; |
|||
public float diskIoLoad; |
|||
/** |
|||
* 空闲内存,单位GB |
|||
*/ |
|||
public float freeMemory; |
|||
/** |
|||
* 磁盘剩余空间,单位GB |
|||
*/ |
|||
public float diskFreeSpace; |
|||
|
|||
public void fillSystemInfos() { |
|||
this.cpuUsage = SystemMetricsStore.cpuUsage; |
|||
this.memoryUsage = SystemMetricsStore.memoryUsage; |
|||
this.freeMemory = SystemMetricsStore.freeMemory; |
|||
this.diskIoLoad = SystemMetricsStore.diskIoLoad; |
|||
this.diskFreeSpace = SystemMetricsStore.diskFreeSpace; |
|||
} |
|||
|
|||
public Map<String, Object> toMap() { |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("projectUuid", projectUuid); |
|||
map.put("envId", envId); |
|||
map.put("isVirtual", isVirtual); |
|||
map.put("serverId", serverId); |
|||
map.put("isRunning", isRunning); |
|||
map.put("startTime", startTime); |
|||
map.put("stopTime", stopTime); |
|||
map.put("timeRate", timeRate); |
|||
map.put("subSystemList", subSystemList); |
|||
map.put("cpuUsage", cpuUsage); |
|||
map.put("memoryUsage", memoryUsage); |
|||
map.put("diskIoLoad", diskIoLoad); |
|||
map.put("freeMemory", freeMemory); |
|||
map.put("diskFreeSpace", diskFreeSpace); |
|||
return map; |
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
package com.yvan.workbench.controller; |
|||
|
|||
import com.yvan.entity.ServerAuthorizationConfigVo; |
|||
import com.yvan.workbench.SpringContext; |
|||
import com.yvan.workbench.autoconfigure.LccConfigProperties; |
|||
import com.yvan.workbench.service.LccMapService; |
|||
import lombok.SneakyThrows; |
|||
import org.clever.core.model.response.R; |
|||
import org.clever.web.mvc.annotation.RequestBody; |
|||
|
|||
import java.net.InetAddress; |
|||
import java.util.Map; |
|||
|
|||
public class AuthController { |
|||
|
|||
@SneakyThrows |
|||
public static R<ServerAuthorizationConfigVo> getAuthorizationConfig(@RequestBody Map<String, Object> params) { |
|||
var lccMapService = SpringContext.HOLDER.getBean(LccMapService.class); |
|||
LccConfigProperties lccConfigProperties = lccMapService.config; |
|||
|
|||
ServerAuthorizationConfigVo vo = new ServerAuthorizationConfigVo(); |
|||
vo.setServerId(InetAddress.getLocalHost().getHostName()); |
|||
vo.setAuthorizationCode("N/A"); |
|||
vo.setExpirationTime(0L); |
|||
vo.setFrontendMqtt(lccConfigProperties.getFrontendMqtt()); |
|||
|
|||
return R.success(vo); |
|||
} |
|||
} |
|||
@ -0,0 +1,151 @@ |
|||
package com.yvan.workbench.controller; |
|||
|
|||
import com.galaxis.rcs.RCSService; |
|||
import com.google.common.base.Strings; |
|||
import com.google.common.collect.Lists; |
|||
import com.yvan.entity.ServerStatusVo; |
|||
import com.yvan.logisticsModel.LogisticsRuntimeService; |
|||
import com.yvan.workbench.SpringContext; |
|||
import com.yvan.workbench.service.LccMapService; |
|||
import org.clever.core.Conv; |
|||
import org.clever.core.mapper.BeanCopyUtils; |
|||
import org.clever.core.model.response.R; |
|||
import org.clever.web.mvc.annotation.RequestBody; |
|||
|
|||
import java.util.Comparator; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
public class ServerController { |
|||
public static R<?> queryServerState(@RequestBody Map<String, Object> params) { |
|||
String projectUuid = Conv.asString(params.get("projectUUID")); |
|||
long envId = Conv.asLong(params.get("envId")); |
|||
|
|||
var mapService = SpringContext.HOLDER.getBean(LccMapService.class); |
|||
|
|||
// 从文件夹读取全部 项目+环境
|
|||
List<ServerStatusVo> list = Lists.newArrayList(); |
|||
if (!Strings.isNullOrEmpty(projectUuid)) { |
|||
var proj = mapService.getProjectById(projectUuid); |
|||
if (proj == null) { |
|||
throw new IllegalArgumentException("Project not found: " + projectUuid); |
|||
} |
|||
if (envId > 0) { |
|||
// 读取指定项目+环境
|
|||
var env = mapService.getEnvById(projectUuid, envId); |
|||
if (env == null) { |
|||
throw new IllegalArgumentException("Environment not found: " + envId + " for project: " + projectUuid); |
|||
} |
|||
ServerStatusVo serverStatus = new ServerStatusVo(); |
|||
list.add(serverStatus); |
|||
|
|||
serverStatus.projectUuid = proj.getProjectUuid(); |
|||
serverStatus.projectLabel = proj.getProjectLabel(); |
|||
serverStatus.subSystemList = proj.getSubSystemList(); |
|||
serverStatus.envId = env.getEnvId(); |
|||
serverStatus.isVirtual = env.getIsVirtual(); |
|||
serverStatus.envConfig = env.getEnvConfig(); |
|||
serverStatus.isRunning = false; |
|||
|
|||
} else { |
|||
// 读取指定项目全部环境
|
|||
for (var env : mapService.getAllEnv(projectUuid)) { |
|||
if (envId > 0 && env.getEnvId() != envId) { |
|||
// 读取指定环境
|
|||
continue; |
|||
} |
|||
|
|||
ServerStatusVo serverStatus = new ServerStatusVo(); |
|||
list.add(serverStatus); |
|||
|
|||
serverStatus.projectUuid = proj.getProjectUuid(); |
|||
serverStatus.projectLabel = proj.getProjectLabel(); |
|||
serverStatus.subSystemList = proj.getSubSystemList(); |
|||
serverStatus.envId = env.getEnvId(); |
|||
serverStatus.isVirtual = env.getIsVirtual(); |
|||
serverStatus.envConfig = env.getEnvConfig(); |
|||
serverStatus.isRunning = false; |
|||
} |
|||
} |
|||
|
|||
} else { |
|||
// 全部项目+环境
|
|||
for (var proj : mapService.getAllProjects()) { |
|||
for (var env : mapService.getAllEnv(proj.getProjectUuid())) { |
|||
ServerStatusVo serverStatus = new ServerStatusVo(); |
|||
list.add(serverStatus); |
|||
|
|||
serverStatus.projectUuid = proj.getProjectUuid(); |
|||
serverStatus.projectLabel = proj.getProjectLabel(); |
|||
serverStatus.subSystemList = proj.getSubSystemList(); |
|||
serverStatus.envId = env.getEnvId(); |
|||
serverStatus.isVirtual = env.getIsVirtual(); |
|||
serverStatus.envConfig = env.getEnvConfig(); |
|||
serverStatus.isRunning = false; |
|||
} |
|||
} |
|||
} |
|||
|
|||
// 从运行时获取详情数据
|
|||
for (var runtime : LogisticsRuntimeService.INSTANCE.getAllRuntimeList()) { |
|||
if (Strings.isNullOrEmpty(runtime.projectUuid)) { |
|||
continue; // 跳过没有项目UUID的运行时
|
|||
} |
|||
if (runtime.envId < 0) { |
|||
continue; // 跳过没有环境ID的运行时
|
|||
} |
|||
ServerStatusVo serverStatus = null; |
|||
for (ServerStatusVo status : list) { |
|||
if (status.projectUuid.equals(runtime.projectUuid) && status.envId.equals(runtime.envId)) { |
|||
serverStatus = status; |
|||
break; |
|||
} |
|||
} |
|||
if (serverStatus != null) { |
|||
serverStatus.copyFrom(runtime.getState()); |
|||
} |
|||
} |
|||
|
|||
// list 根据 envId 排序
|
|||
list.sort(Comparator.comparingLong(a -> a.envId)); |
|||
|
|||
return R.success(list); |
|||
} |
|||
|
|||
public static R<String> startServer(@RequestBody Map<String, Object> params) { |
|||
String projectUuid = Conv.asString(params.get("projectUUID")); |
|||
Long envId = Conv.asLong(params.get("envId")); |
|||
|
|||
if (Strings.isNullOrEmpty(projectUuid)) { |
|||
return R.fail("projectUUID Must not be empty"); |
|||
} |
|||
if (envId == null || envId < 0) { |
|||
return R.fail("envId Must not be empty"); |
|||
} |
|||
|
|||
// 启动 RCS 服务器
|
|||
RCSService.serverStart(projectUuid, envId); |
|||
|
|||
// 启动MFC服务器 / 启动WCS服务器 / 启动PES服务器 等等
|
|||
|
|||
return R.success("Project started successfully"); |
|||
} |
|||
|
|||
public static R<String> stopServer(@RequestBody Map<String, Object> params) { |
|||
String projectUuid = Conv.asString(params.get("projectUUID")); |
|||
Long envId = Conv.asLong(params.get("envId")); |
|||
|
|||
if (Strings.isNullOrEmpty(projectUuid)) { |
|||
return R.fail("projectUUID Must not be empty"); |
|||
} |
|||
if (envId == null || envId < 0) { |
|||
return R.fail("envId Must not be empty"); |
|||
} |
|||
|
|||
// 停止RCS服务器
|
|||
RCSService.serverStop(projectUuid, envId); |
|||
|
|||
// 停止MFC服务器 / 停止WCS服务器 / 停止PES服务器 等等
|
|||
return R.success("Project stopped successfully"); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue