use of cn.hutool.core.lang.Tuple in project Jpom by dromara.
the class JpomManifest method init.
private static void init() {
if (JPOM_MANIFEST == null) {
synchronized (JpomManifest.class) {
if (JPOM_MANIFEST == null) {
JPOM_MANIFEST = new JpomManifest();
File jarFile = getRunPath();
Tuple jarVersion = getJarVersion(jarFile);
if (jarVersion != null) {
JPOM_MANIFEST.setVersion(jarVersion.get(0));
JPOM_MANIFEST.setTimeStamp(jarVersion.get(1));
}
JPOM_MANIFEST.setJarFile(FileUtil.getAbsolutePath(jarFile));
//
JPOM_MANIFEST.randomId = IdUtil.fastSimpleUUID();
}
String jpomTag = StrUtil.format("Jpom {}/{}", JPOM_MANIFEST.getType(), JPOM_MANIFEST.getVersion());
GlobalHeaders.INSTANCE.header(Header.USER_AGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36 " + jpomTag, true);
}
}
}
use of cn.hutool.core.lang.Tuple in project Jpom by dromara.
the class RemoteVersion method upgrade.
/**
* 升级
*
* @param savePath 下载文件保存路径
* @param consumer 执行申请前回调
* @throws IOException 异常
*/
public static void upgrade(String savePath, Consumer<Tuple> consumer) throws IOException {
Type type = JpomManifest.getInstance().getType();
// 下载
Tuple data = download(savePath, type);
File file = data.get(3);
// 基础检查
String path = FileUtil.getAbsolutePath(file);
String version = data.get(0);
JpomManifest.releaseJar(path, version);
//
if (consumer != null) {
consumer.accept(data);
}
JpomApplication.restart();
}
use of cn.hutool.core.lang.Tuple in project Jpom by dromara.
the class AbstractProjectCommander method runDsl.
private String runDsl(NodeProjectInfoModel nodeProjectInfoModel, String opt, Function<DslYmlDto.BaseProcess, String> function) {
Tuple dslProcess = nodeProjectInfoModel.getDslProcess(opt);
String errorMsg = dslProcess.get(0);
if (errorMsg != null) {
return errorMsg;
}
DslYmlDto.BaseProcess process = dslProcess.get(1);
if (process == null) {
return "yml 未配置 运行管理 " + opt;
}
return function.apply(process);
// String log = nodeProjectInfoModel.getAbsoluteLog(null);
// return DslScriptBuilder.run(process, log);
}
use of cn.hutool.core.lang.Tuple in project Jpom by dromara.
the class SshInstallAgentController method getAgentFile.
private JSONObject getAgentFile() throws IOException {
ServerConfigBean instance = ServerConfigBean.getInstance();
File agentZipPath = instance.getAgentZipPath();
Assert.state(FileUtil.exist(agentZipPath), "插件包文件不存在,需要重新上传");
String tempFilePath = instance.getUserTempPath().getAbsolutePath();
//
File tempAgent = FileUtil.file(tempFilePath, "temp_agent");
FileUtil.del(tempAgent);
try {
// 解析压缩包
File jarFile = JpomManifest.zipFileFind(FileUtil.getAbsolutePath(agentZipPath), Type.Agent, FileUtil.getAbsolutePath(tempAgent));
// 获取包内容
JsonMessage<Tuple> tupleJsonMessage = JpomManifest.checkJpomJar(FileUtil.getAbsolutePath(jarFile), Type.Agent, false);
Assert.state(tupleJsonMessage.getCode() == 200, tupleJsonMessage::getMsg);
Tuple data = tupleJsonMessage.getData();
JSONObject jsonObject = new JSONObject();
jsonObject.put("version", data.get(0));
jsonObject.put("timeStamp", data.get(1));
jsonObject.put("path", FileUtil.getAbsolutePath(agentZipPath));
return jsonObject;
} finally {
FileUtil.del(tempAgent);
}
}
use of cn.hutool.core.lang.Tuple in project Jpom by dromara.
the class OutGivingProjectEditController method saveNodeData.
/**
* 保存节点项目数据
*
* @param outGivingModel 节点分发项目
* @param edit 是否为编辑模式
* @return 错误信息
*/
private String saveNodeData(OutGivingModel outGivingModel, List<Tuple> tuples, boolean edit) {
// if () {
// if (!edit) {
// outGivingServer.delByKey(outGivingModel.getId());
// }
// return JsonMessage.getString(405, "数据异常,请重新操作");
// }
UserModel userModel = getUser();
List<Tuple> success = new ArrayList<>();
boolean fail = false;
try {
for (Tuple tuple : tuples) {
NodeModel nodeModel = tuple.get(0);
JSONObject data = tuple.get(1);
//
JsonMessage<String> jsonMessage = this.sendData(nodeModel, userModel, data, true);
if (jsonMessage.getCode() != HttpStatus.HTTP_OK) {
if (!edit) {
fail = true;
outGivingServer.delByKey(outGivingModel.getId());
}
return JsonMessage.getString(406, nodeModel.getName() + "节点失败:" + jsonMessage.getMsg());
}
success.add(tuple);
// 同步项目信息
projectInfoCacheService.syncNode(nodeModel, outGivingModel.getId());
}
} catch (Exception e) {
DefaultSystemLog.getLog().error("保存分发项目失败", e);
if (!edit) {
fail = true;
outGivingServer.delByKey(outGivingModel.getId());
}
return JsonMessage.getString(500, "保存节点数据失败:" + e.getMessage());
} finally {
if (fail) {
try {
for (Tuple entry : success) {
deleteNodeProject(entry.get(0), userModel, outGivingModel.getId());
}
} catch (Exception e) {
DefaultSystemLog.getLog().error("还原项目失败", e);
}
}
}
return null;
}
Aggregations