diff --git a/src/main/java/neatlogic/module/tenant/api/util/GetNeatLogicConcurrentSafeCacheLockKeyApi.java b/src/main/java/neatlogic/module/tenant/api/util/GetNeatLogicConcurrentSafeCacheLockKeyApi.java new file mode 100644 index 0000000000000000000000000000000000000000..d9e7652112e66c8ebdb223f5564716a534108609 --- /dev/null +++ b/src/main/java/neatlogic/module/tenant/api/util/GetNeatLogicConcurrentSafeCacheLockKeyApi.java @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2025 深圳极向量科技有限公司 All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package neatlogic.module.tenant.api.util; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.asynchronization.threadlocal.RequestContext; +import neatlogic.framework.asynchronization.threadlocal.TenantContext; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.auth.label.ADMIN; +import neatlogic.framework.common.config.Config; +import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.dao.cache.NeatLogicConcurrentSafeCache; +import neatlogic.framework.exception.core.ApiRuntimeException; +import neatlogic.framework.heartbeat.dao.mapper.ServerMapper; +import neatlogic.framework.heartbeat.dto.ServerClusterVo; +import neatlogic.framework.integration.authentication.enums.AuthenticateType; +import neatlogic.framework.restful.annotation.Description; +import neatlogic.framework.restful.annotation.Input; +import neatlogic.framework.restful.annotation.OperationType; +import neatlogic.framework.restful.annotation.Param; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.framework.util.HttpRequestUtil; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Objects; + +@Service +@AuthAction(action = ADMIN.class) +@OperationType(type = OperationTypeEnum.SEARCH) +public class GetNeatLogicConcurrentSafeCacheLockKeyApi extends PrivateApiComponentBase { + + @Resource + private ServerMapper serverMapper; + + @Override + public String getName() { + return "获取Mybaties二级缓存NeatLogicConcurrentSafeCache中lockKey列表"; + } + + @Input({ + @Param(name = "serverId", type = ApiParamType.INTEGER, desc = "服务器ID") + }) + @Description(desc = "获取Mybaties二级缓存NeatLogicConcurrentSafeCache中lockKey列表") + @Override + public Object myDoService(JSONObject paramObj) throws Exception { + JSONObject resultObj = new JSONObject(new LinkedHashMap<>()); + Integer serverId = paramObj.getInteger("serverId"); + if (serverId == null) { + serverId = Config.SCHEDULE_SERVER_ID; + } + if (Objects.equals(serverId, Config.SCHEDULE_SERVER_ID)) { + List lockKeyList = NeatLogicConcurrentSafeCache.getAllLockKeyList(); + resultObj.put("lockKeyList", lockKeyList); + resultObj.put("serverId", serverId); + } else { + TenantContext.get().setUseMasterDatabase(true); + ServerClusterVo serverClusterVo = serverMapper.getServerByServerId(serverId); + TenantContext.get().setUseMasterDatabase(false); + if (serverClusterVo != null) { + String host = serverClusterVo.getHost(); + if (StringUtils.isNotBlank(host)) { + HttpServletRequest request = RequestContext.get().getRequest(); + String url = host + request.getRequestURI(); + HttpRequestUtil httpRequestUtil = HttpRequestUtil.post(url) + .setPayload(paramObj.toJSONString()) + .setAuthType(AuthenticateType.BUILDIN) + .setConnectTimeout(5000) + .setReadTimeout(5000) + .sendRequest(); + String error = httpRequestUtil.getError(); + if (StringUtils.isNotBlank(error)) { + throw new ApiRuntimeException(error); + } + JSONObject resultJson = httpRequestUtil.getResultJson(); + if (MapUtils.isNotEmpty(resultJson)) { + String status = resultJson.getString("Status"); + if (!"OK".equals(status)) { + throw new RuntimeException(resultJson.getString("Message")); + } + resultObj = resultJson.getJSONObject("Return"); + } + } else { + resultObj.put("message", "serverId为" + serverId + "的应用服务器的`server_status`表中对应数据没有配置host"); + } + } else { + resultObj.put("message", "找不到serverId为" + serverId + "的应用服务器"); + } + } + return resultObj; + } + + @Override + public String getToken() { + return "util/neatlogicconcurrentsafecache/lockkeylist"; + } +} diff --git a/src/main/java/neatlogic/module/tenant/api/util/GetServerInfoApi.java b/src/main/java/neatlogic/module/tenant/api/util/GetServerInfoApi.java index 7145900a98126b011ff26488fb6904d3cbb4e21d..e84fca31007172df6c4fb35c222750c7d0c99ed1 100644 --- a/src/main/java/neatlogic/module/tenant/api/util/GetServerInfoApi.java +++ b/src/main/java/neatlogic/module/tenant/api/util/GetServerInfoApi.java @@ -44,9 +44,8 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.lang.management.ManagementFactory; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Objects; +import java.util.*; +import java.util.stream.Collectors; @Service @AuthAction(action = ADMIN.class) @@ -88,8 +87,22 @@ public class GetServerInfoApi extends PrivateApiComponentBase { JSONArray array = new JSONArray(); array.addAll(args); resultObj.put("命令行参数", array); - resultObj.put("Java虚拟机的系统属性", System.getProperties()); - resultObj.put("操作系统的环境变量", System.getenv()); + { + Properties prop = System.getProperties(); + Map map = new LinkedHashMap<>(); + for (Map.Entry entry : prop.entrySet()) { + map.put(entry.getKey().toString(), entry.getValue()); + } + Map sortedMap = map.entrySet().stream().sorted(Map.Entry.comparingByKey()) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); + resultObj.put("Java虚拟机的系统属性", sortedMap); + } + { + Map map = System.getenv(); + Map sortedMap = map.entrySet().stream().sorted(Map.Entry.comparingByKey()) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); + resultObj.put("操作系统的环境变量", sortedMap); + } resultObj.put("serverId", serverId); } else { TenantContext.get().setUseMasterDatabase(true); diff --git a/src/main/java/neatlogic/module/tenant/api/util/RefreshConfigApi.java b/src/main/java/neatlogic/module/tenant/api/util/RefreshConfigApi.java index 7433b4bab4031329d20d8dea0c3bab15c9a679b9..1526259e42a6dbda82c832f873a220051beb64ce 100644 --- a/src/main/java/neatlogic/module/tenant/api/util/RefreshConfigApi.java +++ b/src/main/java/neatlogic/module/tenant/api/util/RefreshConfigApi.java @@ -41,8 +41,11 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import java.util.LinkedHashMap; +import java.util.Map; import java.util.Objects; import java.util.Properties; +import java.util.stream.Collectors; @Service @AuthAction(action = ADMIN.class) @@ -79,7 +82,13 @@ public class RefreshConfigApi extends PrivateApiComponentBase { } else { resultObj.put("数据来源", "config.properties"); } - resultObj.put("config", prop); + Map map = new LinkedHashMap<>(); + for (Map.Entry entry : prop.entrySet()) { + map.put(entry.getKey().toString(), entry.getValue()); + } + Map sortedMap = map.entrySet().stream().sorted(Map.Entry.comparingByKey()) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); + resultObj.put("config", sortedMap); resultObj.put("serverId", serverId); } else { TenantContext.get().setUseMasterDatabase(true);