use of io.jpom.permission.Feature in project Jpom by dromara.
the class BuildInfoController method delete.
/**
* 删除构建信息
*
* @param id 构建ID
* @return json
*/
@PostMapping(value = "/build/delete", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DEL)
public String delete(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "没有数据id") String id) {
// 查询构建信息
HttpServletRequest request = getRequest();
BuildInfoModel buildInfoModel = buildInfoService.getByKey(id, request);
Objects.requireNonNull(buildInfoModel, "没有对应数据");
//
String e = buildExecuteService.checkStatus(buildInfoModel.getStatus());
Assert.isNull(e, () -> e);
// 删除构建历史
dbBuildHistoryLogService.delByWorkspace(request, entity -> entity.set("buildDataId", buildInfoModel.getId()));
// 删除构建信息文件
File file = BuildUtil.getBuildDataFile(buildInfoModel.getId());
// 快速删除
boolean fastDel = CommandUtil.systemFastDel(file);
//
Assert.state(!fastDel, "清理历史构建产物失败,已经重新尝试");
// 删除构建信息数据
buildInfoService.delByKey(buildInfoModel.getId(), request);
return JsonMessage.getString(200, "清理历史构建产物成功");
}
use of io.jpom.permission.Feature in project Jpom by dromara.
the class BuildInfoManageController method getNowLog.
/**
* 获取构建的日志
*
* @param id id
* @param buildId 构建编号
* @param line 需要获取的行号
* @return json
*/
@RequestMapping(value = "/build/manage/get-now-log", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.LIST)
public String getNowLog(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "没有数据") String id, @ValidatorItem(value = ValidatorRule.POSITIVE_INTEGER, msg = "没有buildId") int buildId, @ValidatorItem(value = ValidatorRule.POSITIVE_INTEGER, msg = "line") int line) {
BuildInfoModel item = buildInfoService.getByKey(id, getRequest());
Assert.notNull(item, "没有对应数据");
Assert.state(buildId <= item.getBuildId(), "还没有对应的构建记录");
BuildHistoryLog buildHistoryLog = new BuildHistoryLog();
buildHistoryLog.setBuildDataId(id);
buildHistoryLog.setBuildNumberId(buildId);
BuildHistoryLog queryByBean = dbBuildHistoryLogService.queryByBean(buildHistoryLog);
Assert.notNull(queryByBean, "没有对应的构建历史");
File file = BuildUtil.getLogFile(item.getId(), buildId);
Assert.state(FileUtil.isFile(file), "日志文件错误");
if (!file.exists()) {
if (buildId == item.getBuildId()) {
return JsonMessage.getString(201, "还没有日志文件");
}
return JsonMessage.getString(300, "日志文件不存在");
}
JSONObject data = FileUtils.readLogFile(file, line);
// 运行中
Integer status = queryByBean.getStatus();
data.put("run", status == BuildStatus.Ing.getCode() || status == BuildStatus.PubIng.getCode());
// 构建中
data.put("buildRun", status == BuildStatus.Ing.getCode());
return JsonMessage.getString(200, "ok", data);
}
use of io.jpom.permission.Feature in project Jpom by dromara.
the class RepositoryController method editRepository.
/**
* edit
*
* @param repositoryModelReq 仓库实体
* @return json
*/
@PostMapping(value = "/build/repository/edit")
@Feature(method = MethodFeature.EDIT)
public Object editRepository(RepositoryModel repositoryModelReq) {
this.checkInfo(repositoryModelReq);
// 检查 rsa 私钥
boolean andUpdateSshKey = this.checkAndUpdateSshKey(repositoryModelReq);
Assert.state(andUpdateSshKey, "rsa 私钥文件不存在或者有误");
if (repositoryModelReq.getRepoType() == RepositoryModel.RepoType.Git.getCode()) {
RepositoryModel repositoryModel = repositoryService.getByKey(repositoryModelReq.getId(), false);
if (repositoryModel != null) {
repositoryModelReq.setRsaPrv(StrUtil.emptyToDefault(repositoryModelReq.getRsaPrv(), repositoryModel.getRsaPrv()));
repositoryModelReq.setPassword(StrUtil.emptyToDefault(repositoryModelReq.getPassword(), repositoryModel.getPassword()));
}
// 验证 git 仓库信息
try {
IPlugin plugin = PluginFactory.getPlugin("git-clone");
Map<String, Object> map = repositoryModelReq.toMap();
Tuple branchAndTagList = (Tuple) plugin.execute("branchAndTagList", map);
// Tuple tuple = GitUtil.getBranchAndTagList(repositoryModelReq);
} catch (JpomRuntimeException jpomRuntimeException) {
throw jpomRuntimeException;
} catch (Exception e) {
DefaultSystemLog.getLog().warn("获取仓库分支失败", e);
return JsonMessage.toJson(500, "无法连接此仓库," + e.getMessage());
}
}
if (StrUtil.isEmpty(repositoryModelReq.getId())) {
// insert data
repositoryService.insert(repositoryModelReq);
} else {
// update data
// repositoryModelReq.setWorkspaceId(repositoryService.getCheckUserWorkspace(getRequest()));
repositoryService.updateById(repositoryModelReq, getRequest());
}
return JsonMessage.toJson(200, "操作成功");
}
use of io.jpom.permission.Feature in project Jpom by dromara.
the class RepositoryController method restHideField.
/**
* edit
*
* @param id 仓库信息
* @return json
*/
@PostMapping(value = "/build/repository/rest_hide_field")
@Feature(method = MethodFeature.EDIT)
public Object restHideField(@ValidatorItem String id) {
RepositoryModel repositoryModel = new RepositoryModel();
repositoryModel.setId(id);
repositoryModel.setPassword(StrUtil.EMPTY);
repositoryModel.setRsaPrv(StrUtil.EMPTY);
repositoryModel.setRsaPub(StrUtil.EMPTY);
repositoryModel.setWorkspaceId(repositoryService.getCheckUserWorkspace(getRequest()));
repositoryService.updateById(repositoryModel);
return JsonMessage.toJson(200, "操作成功");
}
use of io.jpom.permission.Feature in project Jpom by dromara.
the class DockerImagesController method pullImage.
/**
* @return json
*/
@GetMapping(value = "pull-image", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EXECUTE)
public String pullImage(@ValidatorItem String id, String repository) throws Exception {
DockerInfoModel dockerInfoModel = dockerInfoService.getByKey(id, getRequest());
IPlugin plugin = PluginFactory.getPlugin(DockerInfoService.DOCKER_PLUGIN_NAME);
Map<String, Object> parameter = dockerInfoModel.toParameter();
parameter.put("repository", repository);
//
String uuid = IdUtil.fastSimpleUUID();
File file = FileUtil.file(ServerConfigBean.getInstance().getUserTempPath(), "docker-log", uuid + ".log");
LogRecorder logRecorder = LogRecorder.builder().file(file).build();
logRecorder.info("start pull {}", repository);
Consumer<String> logConsumer = logRecorder::info;
parameter.put("logConsumer", logConsumer);
ThreadUtil.execute(() -> {
try {
plugin.execute("pullImage", parameter);
} catch (Exception e) {
logRecorder.error("拉取异常", e);
}
logRecorder.info("pull end");
});
return JsonMessage.getString(200, "开始拉取", uuid);
}
Aggregations