use of cn.jiangzeyin.common.PreLoadMethod in project Jpom by dromara.
the class AutoStartProject method start.
@PreLoadMethod
private static void start() {
ProjectInfoService projectInfoService = SpringUtil.getBean(ProjectInfoService.class);
List<NodeProjectInfoModel> list = projectInfoService.list();
if (CollUtil.isEmpty(list)) {
return;
}
list = list.stream().filter(nodeProjectInfoModel -> nodeProjectInfoModel.getAutoStart() != null && nodeProjectInfoModel.getAutoStart()).collect(Collectors.toList());
List<NodeProjectInfoModel> finalList = list;
ThreadUtil.execute(() -> {
AbstractProjectCommander instance = AbstractProjectCommander.getInstance();
for (NodeProjectInfoModel nodeProjectInfoModel : finalList) {
try {
if (!instance.isRun(nodeProjectInfoModel, null)) {
instance.start(nodeProjectInfoModel, null);
}
List<NodeProjectInfoModel.JavaCopyItem> javaCopyItemList = nodeProjectInfoModel.getJavaCopyItemList();
if (javaCopyItemList != null) {
for (NodeProjectInfoModel.JavaCopyItem javaCopyItem : javaCopyItemList) {
if (!instance.isRun(nodeProjectInfoModel, javaCopyItem)) {
instance.start(nodeProjectInfoModel, javaCopyItem);
}
}
}
} catch (Exception e) {
DefaultSystemLog.getLog().warn("自动启动项目失败:{} {}", nodeProjectInfoModel.getId(), e.getMessage());
}
}
});
}
use of cn.jiangzeyin.common.PreLoadMethod in project Jpom by dromara.
the class CheckPath method clearTemp.
@PreLoadMethod(4)
private static void clearTemp() {
File file = ConfigBean.getInstance().getTempPath();
/**
* @author Hotstrip
* use Hutool's FileUtil.del method just put file as param not file's path
* or else, may be return Accessdenied exception
*/
try {
FileUtil.del(file);
} catch (Exception e) {
// Try again jzy 2021-07-31
DefaultSystemLog.getLog().warn("Attempt to delete temporary folder failed, try to handle read-only permission:{}", e.getMessage());
List<File> files = FileUtil.loopFiles(file);
long count = files.stream().map(file12 -> file12.setWritable(true)).filter(aBoolean -> aBoolean).count();
DefaultSystemLog.getLog().warn("Cumulative number of files in temporary folder: {}, number of successful processing:{}", CollUtil.size(files), count);
try {
FileUtil.del(file.toPath());
} catch (Exception e1) {
e1.addSuppressed(e);
boolean causedBy = ExceptionUtil.isCausedBy(e1, AccessDeniedException.class);
if (causedBy) {
DefaultSystemLog.getLog().error("清除临时文件失败,请手动清理:" + FileUtil.getAbsolutePath(file), e);
return;
}
DefaultSystemLog.getLog().error("清除临时文件失败,请检查目录:" + FileUtil.getAbsolutePath(file), e);
}
}
}
use of cn.jiangzeyin.common.PreLoadMethod in project Jpom by dromara.
the class AutoImportLocalNode method install.
@PreLoadMethod
private static void install() {
File file = FileUtil.file(ConfigBean.getInstance().getDataPath(), ServerConfigBean.INSTALL);
if (file.exists()) {
return;
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("installId", IdUtil.fastSimpleUUID());
jsonObject.put("installTime", DateTime.now().toString());
jsonObject.put("desc", "请勿删除此文件,服务端安装id和插件端互通关联");
JsonFileUtil.saveJson(file.getAbsolutePath(), jsonObject);
}
use of cn.jiangzeyin.common.PreLoadMethod in project Jpom by dromara.
the class ConsoleStartSuccess method success.
/**
* 输出启动成功的 日志
*/
@PreLoadMethod(value = Integer.MAX_VALUE)
private static void success() {
Type type = JpomManifest.getInstance().getType();
int port = ConfigBean.getInstance().getPort();
String localhostStr = NetUtil.getLocalhostStr();
String url = StrUtil.format("http://{}:{}", localhostStr, port);
if (type == Type.Server) {
Console.log("{} Successfully started,Can use happily => {} 【The current address is for reference only】", type, url);
} else if (type == Type.Agent) {
Console.log("{} Successfully started,Please go to the server to configure and use,Current node address => {} 【The current address is for reference only】", type, url);
}
}
use of cn.jiangzeyin.common.PreLoadMethod in project Jpom by dromara.
the class AutoRegSeverNode method reg.
/**
* 向服务端注册插件端
*/
@PreLoadMethod
private static void reg() {
AgentExtConfigBean instance = AgentExtConfigBean.getInstance();
String agentId = instance.getAgentId();
String serverUrl = instance.getServerUrl();
if (StrUtil.isEmpty(agentId) || StrUtil.isEmpty(serverUrl)) {
// 如果二者缺一不注册
return;
}
String oldInstallId = null;
File file = FileUtil.file(ConfigBean.getInstance().getDataPath(), AgentConfigBean.SERVER_ID);
JSONObject serverJson = null;
if (file.exists()) {
try {
serverJson = (JSONObject) JsonFileUtil.readJson(file.getAbsolutePath());
} catch (FileNotFoundException e) {
serverJson = new JSONObject();
}
oldInstallId = serverJson.getString("installId");
}
HttpRequest installRequest = instance.createServerRequest(ServerOpenApi.INSTALL_ID);
String body1 = installRequest.execute().body();
JsonMessage jsonMessage = JSON.parseObject(body1, JsonMessage.class);
if (jsonMessage.getCode() != HttpStatus.HTTP_OK) {
DefaultSystemLog.getLog().error("获取Server 安装id失败:" + jsonMessage);
return;
}
String installId = jsonMessage.dataToString();
boolean eqInstall = StrUtil.equals(oldInstallId, installId);
//
URL url = URLUtil.toUrlForHttp(instance.getAgentUrl());
String protocol = url.getProtocol();
HttpRequest serverRequest = instance.createServerRequest(ServerOpenApi.UPDATE_NODE_INFO);
serverRequest.form("id", agentId);
serverRequest.form("name", "节点:" + agentId);
serverRequest.form("openStatus", 1);
serverRequest.form("protocol", protocol);
serverRequest.form("url", url.getHost() + CharPool.COLON + url.getPort());
AgentAuthorize agentAuthorize = AgentAuthorize.getInstance();
serverRequest.form("loginName", agentAuthorize.getAgentName());
serverRequest.form("loginPwd", agentAuthorize.getAgentPwd());
serverRequest.form("type", eqInstall ? "update" : "add");
String body = serverRequest.execute().body();
DefaultSystemLog.getLog().info("自动注册Server:" + body);
JsonMessage regJsonMessage = JSON.parseObject(body, JsonMessage.class);
if (regJsonMessage.getCode() == HttpStatus.HTTP_OK) {
if (serverJson == null) {
serverJson = new JSONObject();
}
if (!eqInstall) {
serverJson.put("installId", installId);
serverJson.put("regTime", DateTime.now().toString());
} else {
serverJson.put("updateTime", DateTime.now().toString());
}
JsonFileUtil.saveJson(file.getAbsolutePath(), serverJson);
} else {
DefaultSystemLog.getLog().error("自动注册插件端失败:{}", body);
}
}
Aggregations