Search in sources :

Example 21 with Tuple

use of cn.hutool.core.lang.Tuple in project Jpom by dromara.

the class NodeUpdateController method downloadRemote.

/**
 * 远程下载
 *
 * @return json
 * @see RemoteVersion
 */
@GetMapping(value = "download_remote.json", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.REMOTE_DOWNLOAD)
public String downloadRemote() throws IOException {
    String saveDir = ServerConfigBean.getInstance().getAgentPath().getAbsolutePath();
    Tuple download = RemoteVersion.download(saveDir, Type.Agent, false);
    // 保存文件
    this.saveAgentFile(download);
    return JsonMessage.getString(200, "下载成功");
}
Also used : Tuple(cn.hutool.core.lang.Tuple) GetMapping(org.springframework.web.bind.annotation.GetMapping) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Example 22 with Tuple

use of cn.hutool.core.lang.Tuple in project Jpom by dromara.

the class NodeUpdateHandler method updateNode.

/**
 * 更新节点
 *
 * @param model 参数
 */
private void updateNode(WebSocketMessageModel model, WebSocketSession session) {
    JSONObject params = (JSONObject) model.getParams();
    JSONArray ids = params.getJSONArray("ids");
    if (CollUtil.isEmpty(ids)) {
        return;
    }
    String protocol = params.getString("protocol");
    boolean http = StrUtil.equalsIgnoreCase(protocol, "http");
    try {
        AgentFileModel agentFileModel = systemParametersServer.getConfig(AgentFileModel.ID, AgentFileModel.class);
        // 
        if (agentFileModel == null || !FileUtil.exist(agentFileModel.getSavePath())) {
            this.onError(session, "Agent JAR包不存在");
            return;
        }
        JsonMessage<Tuple> error = JpomManifest.checkJpomJar(agentFileModel.getSavePath(), Type.Agent, false);
        if (error.getCode() != HttpStatus.HTTP_OK) {
            this.onError(session, "Agent JAR 损坏请重新上传," + error.getMsg());
            return;
        }
        for (int i = 0; i < ids.size(); i++) {
            int finalI = i;
            ThreadUtil.execute(() -> this.updateNodeItem(ids.getString(finalI), session, agentFileModel, http));
        }
    } catch (Exception e) {
        DefaultSystemLog.getLog().error("升级失败", e);
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) Tuple(cn.hutool.core.lang.Tuple) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) AgentFileModel(io.jpom.model.AgentFileModel)

Aggregations

Tuple (cn.hutool.core.lang.Tuple)22 File (java.io.File)8 JSONObject (com.alibaba.fastjson.JSONObject)6 ClassFeature (io.jpom.permission.ClassFeature)6 Feature (io.jpom.permission.Feature)6 MethodFeature (io.jpom.permission.MethodFeature)6 ZipFile (java.util.zip.ZipFile)4 MultipartFileBuilder (cn.jiangzeyin.controller.multipart.MultipartFileBuilder)3 RepositoryModel (io.jpom.model.data.RepositoryModel)2 SystemPermission (io.jpom.permission.SystemPermission)2 JpomRuntimeException (io.jpom.system.JpomRuntimeException)2 ServerConfigBean (io.jpom.system.ServerConfigBean)2 IOException (java.io.IOException)2 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 JarFile (java.util.jar.JarFile)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 JarClassLoader (cn.hutool.core.lang.JarClassLoader)1