Search in sources :

Example 21 with NodeModel

use of io.jpom.model.data.NodeModel in project Jpom by dromara.

the class NodeEditController method nodeStatus.

@RequestMapping(value = "node_status", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.LIST)
public String nodeStatus() {
    long timeMillis = System.currentTimeMillis();
    NodeModel node = getNode();
    JSONObject jsonObject = NodeForward.requestData(node, NodeUrl.Status, getRequest(), JSONObject.class);
    Assert.notNull(jsonObject, "获取信息失败");
    JSONArray jsonArray = new JSONArray();
    jsonObject.put("timeOut", System.currentTimeMillis() - timeMillis);
    jsonObject.put("nodeId", node.getId());
    jsonArray.add(jsonObject);
    return JsonMessage.getString(200, "", jsonArray);
}
Also used : NodeModel(io.jpom.model.data.NodeModel) JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Example 22 with NodeModel

use of io.jpom.model.data.NodeModel in project Jpom by dromara.

the class SystemUpdateController method checkVersion.

/**
 * 检查是否存在新版本
 *
 * @return json
 * @see RemoteVersion
 */
@PostMapping(value = "check_version.json", produces = MediaType.APPLICATION_JSON_VALUE)
public String checkVersion() {
    NodeModel nodeModel = tryGetNode();
    if (nodeModel != null) {
        return NodeForward.request(getNode(), getRequest(), NodeUrl.CHECK_VERSION).toString();
    }
    RemoteVersion remoteVersion = RemoteVersion.loadRemoteInfo();
    return JsonMessage.getString(200, "", remoteVersion);
}
Also used : NodeModel(io.jpom.model.data.NodeModel) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 23 with NodeModel

use of io.jpom.model.data.NodeModel in project Jpom by dromara.

the class SystemUpdateController method uploadJar.

@PostMapping(value = "uploadJar.json", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EXECUTE)
public String uploadJar() throws IOException {
    NodeModel nodeModel = tryGetNode();
    if (nodeModel != null) {
        return NodeForward.requestMultipart(getNode(), getMultiRequest(), NodeUrl.SystemUploadJar).toString();
    }
    // 
    Objects.requireNonNull(JpomManifest.getScriptFile());
    MultipartFileBuilder multipartFileBuilder = createMultipart();
    String absolutePath = ServerConfigBean.getInstance().getUserTempPath().getAbsolutePath();
    multipartFileBuilder.setFileExt("jar", "zip").addFieldName("file").setUseOriginalFilename(true).setSavePath(absolutePath);
    String path = multipartFileBuilder.save();
    // 解析压缩包
    File file = JpomManifest.zipFileFind(path, Type.Server, absolutePath);
    path = FileUtil.getAbsolutePath(file);
    // 基础检查
    JsonMessage<Tuple> error = JpomManifest.checkJpomJar(path, Type.Server);
    if (error.getCode() != HttpStatus.HTTP_OK) {
        return error.toString();
    }
    Tuple data = error.getData();
    String version = data.get(0);
    JpomManifest.releaseJar(path, version);
    // 
    backupInfoService.autoBackup();
    // 
    JpomApplication.restart();
    return JsonMessage.getString(200, Const.UPGRADE_MSG);
}
Also used : NodeModel(io.jpom.model.data.NodeModel) MultipartFileBuilder(cn.jiangzeyin.controller.multipart.MultipartFileBuilder) File(java.io.File) Tuple(cn.hutool.core.lang.Tuple) PostMapping(org.springframework.web.bind.annotation.PostMapping) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Example 24 with NodeModel

use of io.jpom.model.data.NodeModel in project Jpom by dromara.

the class SystemUpdateController method upgrade.

/**
 * 远程下载升级
 *
 * @return json
 * @see RemoteVersion
 */
@GetMapping(value = "remote_upgrade.json", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DOWNLOAD)
public String upgrade() throws IOException {
    NodeModel nodeModel = tryGetNode();
    if (nodeModel != null) {
        return NodeForward.request(getNode(), getRequest(), NodeUrl.REMOTE_UPGRADE).toString();
    }
    RemoteVersion.upgrade(ConfigBean.getInstance().getTempPath().getAbsolutePath(), objects -> backupInfoService.autoBackup());
    return JsonMessage.getString(200, Const.UPGRADE_MSG);
}
Also used : NodeModel(io.jpom.model.data.NodeModel) GetMapping(org.springframework.web.bind.annotation.GetMapping) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Example 25 with NodeModel

use of io.jpom.model.data.NodeModel in project Jpom by dromara.

the class SystemUpdateController method info.

@PostMapping(value = "info", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.LIST)
public String info() {
    NodeModel nodeModel = tryGetNode();
    if (nodeModel != null) {
        return NodeForward.request(getNode(), getRequest(), NodeUrl.Info).toString();
    }
    JpomManifest instance = JpomManifest.getInstance();
    RemoteVersion remoteVersion = RemoteVersion.cacheInfo();
    // 
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("manifest", instance);
    jsonObject.put("remoteVersion", remoteVersion);
    return JsonMessage.getString(200, "", jsonObject);
}
Also used : NodeModel(io.jpom.model.data.NodeModel) JSONObject(com.alibaba.fastjson.JSONObject) PostMapping(org.springframework.web.bind.annotation.PostMapping) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Aggregations

NodeModel (io.jpom.model.data.NodeModel)64 JSONObject (com.alibaba.fastjson.JSONObject)27 Feature (io.jpom.permission.Feature)23 MethodFeature (io.jpom.permission.MethodFeature)23 ClassFeature (io.jpom.permission.ClassFeature)22 UserModel (io.jpom.model.data.UserModel)17 StrUtil (cn.hutool.core.util.StrUtil)12 NodeService (io.jpom.service.node.NodeService)12 Collectors (java.util.stream.Collectors)12 JsonMessage (cn.jiangzeyin.common.JsonMessage)11 List (java.util.List)11 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 CollUtil (cn.hutool.core.collection.CollUtil)9 DefaultSystemLog (cn.jiangzeyin.common.DefaultSystemLog)9 NodeForward (io.jpom.common.forward.NodeForward)8 NodeUrl (io.jpom.common.forward.NodeUrl)8 Assert (org.springframework.util.Assert)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 JSONArray (com.alibaba.fastjson.JSONArray)7 BaseServerController (io.jpom.common.BaseServerController)7