mirror of
https://gitee.com/dromara/Jpom.git
synced 2024-12-02 20:08:40 +08:00
安装....
This commit is contained in:
parent
ebc5f261e3
commit
35231fa028
@ -2,6 +2,7 @@ package cn.jiangzeyin.controller;
|
||||
|
||||
import cn.jiangzeyin.common.interceptor.LoginInterceptor;
|
||||
import cn.jiangzeyin.controller.base.AbstractBaseControl;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
|
||||
/**
|
||||
* @author jiangzeyin
|
||||
@ -16,4 +17,8 @@ public abstract class BaseController extends AbstractBaseControl {
|
||||
userName = getSessionAttribute(LoginInterceptor.SESSION_NAME);
|
||||
userPwd = getSessionAttribute(LoginInterceptor.SESSION_PWD);
|
||||
}
|
||||
|
||||
public static String getUserName() {
|
||||
return (String) getRequestAttributes().getAttribute(LoginInterceptor.SESSION_NAME, RequestAttributes.SCOPE_SESSION);
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,23 @@
|
||||
package cn.jiangzeyin.controller.manage;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.ZipUtil;
|
||||
import cn.jiangzeyin.common.JsonMessage;
|
||||
import cn.jiangzeyin.controller.BaseController;
|
||||
import cn.jiangzeyin.model.ProjectInfoModel;
|
||||
import cn.jiangzeyin.oss.OssManagerService;
|
||||
import cn.jiangzeyin.service.manage.CommandService;
|
||||
import cn.jiangzeyin.service.manage.ManageService;
|
||||
import cn.jiangzeyin.service.oss.OssManagerService;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
@ -22,17 +29,46 @@ public class BuildController extends BaseController {
|
||||
|
||||
@Resource
|
||||
private OssManagerService ossManagerService;
|
||||
|
||||
@Resource
|
||||
private ManageService manageService;
|
||||
@Resource
|
||||
private CommandService commandService;
|
||||
|
||||
@RequestMapping(value = "build", method = RequestMethod.GET)
|
||||
public String console(String id) throws IOException {
|
||||
public String build(String id) throws IOException {
|
||||
ProjectInfoModel projectInfoModel = manageService.getProjectInfo(id);
|
||||
if (projectInfoModel != null && StrUtil.isNotEmpty(projectInfoModel.getBuildTag())) {
|
||||
JSONArray jsonArray = ossManagerService.list(projectInfoModel.getBuildTag());
|
||||
setAttribute("array", jsonArray);
|
||||
setAttribute("id", id);
|
||||
}
|
||||
return "manage/build";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "build_install", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
||||
@ResponseBody
|
||||
public String buildInstall(String id, String key) throws IOException {
|
||||
ProjectInfoModel projectInfoModel = manageService.getProjectInfo(id);
|
||||
if (projectInfoModel == null) {
|
||||
return JsonMessage.getString(400, "没有对应项目");
|
||||
}
|
||||
if (StrUtil.isEmpty(projectInfoModel.getBuildTag())) {
|
||||
return JsonMessage.getString(400, "项目还不支持构建");
|
||||
}
|
||||
File file = ossManagerService.download(key);
|
||||
if (!file.exists()) {
|
||||
return JsonMessage.getString(500, "下载远程文件失败");
|
||||
}
|
||||
File lib = new File(projectInfoModel.getLib());
|
||||
FileUtil.mkdir(lib);
|
||||
if (!FileUtil.clean(lib)) {
|
||||
return JsonMessage.getString(500, "清楚旧lib失败");
|
||||
}
|
||||
ZipUtil.unzip(file, lib);
|
||||
String result = commandService.execCommand(CommandService.CommandOp.restart, projectInfoModel, null);
|
||||
if (result.contains(CommandService.RUNING_TAG)) {
|
||||
return JsonMessage.getString(200, "ok");
|
||||
}
|
||||
return JsonMessage.getString(505, "安装失败:" + result);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
package cn.jiangzeyin.service;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.jiangzeyin.common.spring.SpringUtil;
|
||||
import cn.jiangzeyin.controller.BaseController;
|
||||
import cn.jiangzeyin.util.JsonUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
@ -27,6 +30,17 @@ public class BaseService {
|
||||
return file;
|
||||
}
|
||||
|
||||
protected File getTempPath() throws IOException {
|
||||
File file = getDataPath();
|
||||
String userName = BaseController.getUserName();
|
||||
if (StrUtil.isEmpty(userName)) {
|
||||
throw new RuntimeException("没有登录");
|
||||
}
|
||||
file = new File(file.getPath() + "/temp/", userName);
|
||||
FileUtil.mkdir(file);
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据文件的路径,如果文件不存在,则创建一个
|
||||
*
|
||||
|
@ -59,7 +59,6 @@ public class CommandService {
|
||||
if (commandOp == CommandOp.showlog) {
|
||||
return result;
|
||||
}
|
||||
InputStream is;
|
||||
CommandService commandService = SpringUtil.getBean(CommandService.class);
|
||||
String commandPath = commandService.getCommandPath();
|
||||
|
||||
@ -72,6 +71,7 @@ public class CommandService {
|
||||
String jvm = projectInfoModel.getJvm();
|
||||
String args = projectInfoModel.getArgs();
|
||||
try {
|
||||
InputStream is;
|
||||
// 执行命令
|
||||
String command = String.format("%s %s %s %s %s %s %s [%s][%s]", commandPath, commandOp.toString(), tag, mainClass, lib, log, token, jvm, args);
|
||||
DefaultSystemLog.LOG().info(command);
|
||||
|
@ -1,19 +1,23 @@
|
||||
package cn.jiangzeyin.oss;
|
||||
package cn.jiangzeyin.service.oss;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.jiangzeyin.common.spring.SpringUtil;
|
||||
import cn.jiangzeyin.service.BaseService;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyun.oss.OSSClient;
|
||||
import com.aliyun.oss.model.GetObjectRequest;
|
||||
import com.aliyun.oss.model.ListObjectsRequest;
|
||||
import com.aliyun.oss.model.OSSObjectSummary;
|
||||
import com.aliyun.oss.model.ObjectListing;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -22,7 +26,18 @@ import java.util.List;
|
||||
* Created by jiangzeyin on 2018/9/28.
|
||||
*/
|
||||
@Service
|
||||
public class OssManagerService {
|
||||
public class OssManagerService extends BaseService {
|
||||
|
||||
public File download(String key) throws IOException {
|
||||
File file = getTempPath();
|
||||
file = new File(file, key);
|
||||
OSSClient ossClient = getOSSClient();
|
||||
// 下载OSS文件到本地文件。如果指定的本地文件存在会覆盖,不存在则新建。
|
||||
ossClient.getObject(new GetObjectRequest(getBucketName(), key), file);
|
||||
// 关闭OSSClient。
|
||||
ossClient.shutdown();
|
||||
return file;
|
||||
}
|
||||
|
||||
public JSONArray list(String name) {
|
||||
OSSClient ossClient;
|
@ -29,7 +29,9 @@
|
||||
<td>$item.time</td>
|
||||
<td>$item.size</td>
|
||||
<td>
|
||||
<button class="layui-btn layui-btn-normal layui-btn-sm">安装</button>
|
||||
<button name="install" data-name="$item.shortKey" data-key="$item.key" data-id="$id"
|
||||
class="layui-btn layui-btn-normal layui-btn-sm">安装
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
#end
|
||||
@ -40,9 +42,43 @@
|
||||
<script type="text/javascript">
|
||||
layui.use(['layer', 'element', 'table', 'form'], function () {
|
||||
var $ = layui.$;
|
||||
var table = layui.table;
|
||||
var form = layui.form;
|
||||
var layer = layui.layer;
|
||||
|
||||
$("button[name='install']").click(function () {
|
||||
var that = $(this);
|
||||
var name = that.attr("data-name");
|
||||
layer.confirm('您确定要安装【' + name + '】?', {
|
||||
btn: ['确定', '不确定'] //按钮
|
||||
}, function (index) {
|
||||
layer.close(index);
|
||||
index = layer.load(1, {
|
||||
shade: [0.5, '#fff'] //0.1透明度的白色背景
|
||||
});
|
||||
var key = that.attr("data-key");
|
||||
var id = that.attr("data-id");
|
||||
$.ajax({
|
||||
url: './build_install',
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: {id: id, key: key},
|
||||
success: function (data) {
|
||||
layer.msg(data.msg);
|
||||
if (200 == data.code) {
|
||||
|
||||
}
|
||||
},
|
||||
error: function (err) {
|
||||
layer.msg('安装失败');
|
||||
},
|
||||
complete: function () {
|
||||
layer.close(index);
|
||||
}
|
||||
});
|
||||
}, function () {
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</html>
|
@ -110,7 +110,6 @@
|
||||
|
||||
// 提交项目表单
|
||||
form.on('submit(submitProject)', function (data) {
|
||||
console.log(data.field)
|
||||
$.ajax({
|
||||
url: data.form.action,
|
||||
type: 'POST',
|
||||
|
@ -173,7 +173,6 @@
|
||||
} else if ('file' === event) {
|
||||
fileManage(data);
|
||||
} else if ('build' === event) {
|
||||
console.log(data)
|
||||
layer.open({
|
||||
type: 2,
|
||||
title: '自动构建',
|
||||
|
Loading…
Reference in New Issue
Block a user