use of io.jpom.system.JpomRuntimeException in project Jpom by dromara.
the class JpomManifest method getScriptFile.
/**
* 获取当前的管理名文件
*
* @return file
*/
public static File getScriptFile() {
File runPath = getRunPath().getParentFile().getParentFile();
String type = JpomApplication.getAppType().name();
File scriptFile = FileUtil.file(runPath, StrUtil.format("{}.{}", type, CommandUtil.SUFFIX));
if (!scriptFile.exists() || scriptFile.isDirectory()) {
throw new JpomRuntimeException("当前服务中没有命令脚本:" + StrUtil.format("{}.{}", type, CommandUtil.SUFFIX));
}
return scriptFile;
}
use of io.jpom.system.JpomRuntimeException in project Jpom by dromara.
the class JpomManifest method releaseJar.
/**
* 发布包到对应运行路径
*
* @param path 文件路径
* @param version 新版本号
*/
public static void releaseJar(String path, String version) {
File runFile = getRunPath();
File runPath = runFile.getParentFile();
if (!runPath.isDirectory()) {
throw new JpomRuntimeException(runPath.getAbsolutePath() + " error");
}
String upgrade = FileUtil.file(runPath, ConfigBean.UPGRADE).getAbsolutePath();
JSONObject jsonObject = null;
try {
jsonObject = (JSONObject) JsonFileUtil.readJson(upgrade);
} catch (FileNotFoundException ignored) {
}
if (jsonObject == null) {
jsonObject = new JSONObject();
}
jsonObject.put("beforeJar", runFile.getName());
// 如果升级的版本号一致
if (StrUtil.equals(version, JpomManifest.getInstance().getVersion())) {
version = StrUtil.format("{}_{}", version, System.currentTimeMillis());
}
String newFile;
File to;
while (true) {
newFile = JpomApplication.getAppType().name() + "-" + version + FileUtil.JAR_FILE_EXT;
to = FileUtil.file(runPath, newFile);
if (FileUtil.equals(to, runFile)) {
version = StrUtil.format("{}_{}", version, RandomUtil.randomInt(1, 100));
continue;
}
break;
}
//
FileUtil.move(new File(path), to, true);
jsonObject.put("newJar", newFile);
jsonObject.put("updateTime", new DateTime().toString());
// 更新管理命令
List<String> newData = new LinkedList<>();
//
String typeName = JpomApplication.getAppType().name().toLowerCase();
final String[] oldName = new String[] { typeName + ".log" };
final boolean[] logBack = { true };
File scriptFile = getScriptFile();
Charset charset = ExtConfigBean.getInstance().getConsoleLogCharset();
String finalNewFile = newFile;
FileUtil.readLines(scriptFile, charset, (LineHandler) line -> {
if (!line.startsWith(String.valueOf(StrUtil.C_TAB)) && !line.startsWith(String.valueOf(StrUtil.C_SPACE))) {
if (StrUtil.containsAny(line, "RUNJAR=")) {
if ("sh".equals(CommandUtil.SUFFIX)) {
newData.add(StrUtil.format("RUNJAR=\"{}\"", finalNewFile));
} else if ("bat".equals(CommandUtil.SUFFIX)) {
newData.add(StrUtil.format("set RUNJAR={}", finalNewFile));
} else {
newData.add(line);
}
} else if (SystemUtil.getOsInfo().isWindows()) {
if (StrUtil.containsAny(line, "set LogName=")) {
oldName[0] = CharSequenceUtil.splitToArray(line, "=")[0];
newData.add(StrUtil.format("set LogName={}_{}.log", typeName, System.currentTimeMillis()));
} else if (StrUtil.containsAny(line, "set LogBack=")) {
logBack[0] = Convert.toBool(CharSequenceUtil.splitToArray(line, "=")[1], true);
newData.add(line);
} else {
newData.add(line);
}
} else {
newData.add(line);
}
} else {
newData.add(line);
}
});
// 新增升级次数 @author jzy 2021-08-04
jsonObject.put("upgradeCount", jsonObject.getIntValue("upgradeCount"));
jsonObject.put("oldLogName", oldName[0]);
jsonObject.put("logBack", logBack[0]);
//
JsonFileUtil.saveJson(upgrade, jsonObject);
FileUtil.writeLines(newData, scriptFile, charset);
}
use of io.jpom.system.JpomRuntimeException in project Jpom by dromara.
the class TomcatManageService method tomcatCmd.
/**
* 访问tomcat Url
*
* @param tomcatInfoModel tomcat信息
* @param cmd 命令
* @return 访问结果
*/
private String tomcatCmd(TomcatInfoModel tomcatInfoModel, String cmd) {
String url = String.format("http://127.0.0.1:%d/jpomAgent/%s", tomcatInfoModel.getPort(), cmd);
HttpRequest httpRequest = new HttpRequest(url);
// 设置超时时间为3秒
httpRequest.setConnectionTimeout(3000);
String body = "";
try {
HttpResponse httpResponse = httpRequest.execute();
if (httpResponse.isOk()) {
body = httpResponse.body();
}
if (httpResponse.getStatus() == HttpStatus.HTTP_NOT_FOUND) {
// 没有插件
tomcatInfoModel.initTomcat();
throw new JpomRuntimeException("tomcat 未初始化,已经重新初始化请稍后再试");
}
} catch (JpomRuntimeException jpom) {
throw jpom;
} catch (Exception ignored) {
}
return body;
}
use of io.jpom.system.JpomRuntimeException in project Jpom by dromara.
the class BaseDbCommonService method update.
/**
* 修改数据
*
* @param entity 要修改的数据
* @param where 条件
* @return 影响行数
*/
public int update(Entity entity, Entity where) {
if (!DbConfig.getInstance().isInit()) {
// ignore
log.error("The database is not initialized, this execution will be ignored:{},{}", this.tClass, this.getClass());
return 0;
}
Db db = Db.use();
db.setWrapper((Character) null);
if (where.isEmpty()) {
throw new JpomRuntimeException("没有更新条件");
}
entity.setTableName(tableName);
where.setTableName(tableName);
try {
return db.update(entity, where);
} catch (Exception e) {
throw warpException(e);
}
}
use of io.jpom.system.JpomRuntimeException in project Jpom by dromara.
the class BaseDbCommonService method del.
/**
* 根据条件删除
*
* @param where 条件
* @return 影响行数
*/
public int del(Entity where) {
if (!DbConfig.getInstance().isInit()) {
// ignore
log.error("The database is not initialized, this execution will be ignored:{},{}", this.tClass, this.getClass());
return 0;
}
where.setTableName(tableName);
if (where.isEmpty()) {
throw new JpomRuntimeException("没有删除条件");
}
Db db = Db.use();
db.setWrapper((Character) null);
try {
return db.del(where);
} catch (Exception e) {
throw warpException(e);
}
}
Aggregations