Search in sources :

Example 16 with BuildInfoModel

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

the class BuildExecuteService method insertLog.

/**
 * 插入记录
 */
private String insertLog(BuildExtraModule buildExtraModule, TaskData taskData) {
    BuildInfoModel buildInfoModel = taskData.buildInfoModel;
    buildExtraModule.updateValue(buildInfoModel);
    BuildHistoryLog buildHistoryLog = new BuildHistoryLog();
    // 更新其他配置字段
    // buildHistoryLog.fillLogValue(buildExtraModule);
    buildHistoryLog.setTriggerBuildType(taskData.triggerBuildType);
    // 
    buildHistoryLog.setBuildNumberId(buildInfoModel.getBuildId());
    buildHistoryLog.setBuildName(buildInfoModel.getName());
    buildHistoryLog.setBuildDataId(buildInfoModel.getId());
    buildHistoryLog.setWorkspaceId(buildInfoModel.getWorkspaceId());
    buildHistoryLog.setResultDirFile(buildInfoModel.getResultDirFile());
    buildHistoryLog.setReleaseMethod(buildExtraModule.getReleaseMethod());
    // 
    buildHistoryLog.setStatus(BuildStatus.Ing.getCode());
    buildHistoryLog.setStartTime(SystemClock.now());
    buildHistoryLog.setBuildRemark(taskData.buildRemark);
    buildHistoryLog.setExtraData(buildInfoModel.getExtraData());
    dbBuildHistoryLogService.insert(buildHistoryLog);
    // 
    buildService.updateStatus(buildHistoryLog.getBuildDataId(), BuildStatus.Ing);
    return buildHistoryLog.getId();
}
Also used : BuildHistoryLog(io.jpom.model.log.BuildHistoryLog) BuildInfoModel(io.jpom.model.data.BuildInfoModel)

Example 17 with BuildInfoModel

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

the class BuildInfoController method cleanSource.

/**
 * 清除构建信息
 *
 * @param id 构建ID
 * @return json
 */
@PostMapping(value = "/build/clean-source", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EXECUTE)
public String cleanSource(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "没有数据id") String id) {
    // 查询构建信息
    BuildInfoModel buildInfoModel = buildInfoService.getByKey(id, getRequest());
    Objects.requireNonNull(buildInfoModel, "没有对应数据");
    File source = BuildUtil.getSourceById(buildInfoModel.getId());
    // 快速删除
    boolean fastDel = CommandUtil.systemFastDel(source);
    // 
    Assert.state(!fastDel, "删除文件失败,请检查");
    return JsonMessage.getString(200, "清理成功");
}
Also used : File(java.io.File) BuildInfoModel(io.jpom.model.data.BuildInfoModel) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Example 18 with BuildInfoModel

use of io.jpom.model.data.BuildInfoModel 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, "清理历史构建产物成功");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) File(java.io.File) BuildInfoModel(io.jpom.model.data.BuildInfoModel) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Example 19 with BuildInfoModel

use of io.jpom.model.data.BuildInfoModel 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);
}
Also used : BuildHistoryLog(io.jpom.model.log.BuildHistoryLog) JSONObject(com.alibaba.fastjson.JSONObject) File(java.io.File) BuildInfoModel(io.jpom.model.data.BuildInfoModel) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 20 with BuildInfoModel

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

the class BuildTriggerApiController method trigger2.

/**
 * 构建触发器
 *
 * @param id    构建ID
 * @param token 构建的token
 * @param delay 延迟时间(单位秒)
 * @return json
 */
@RequestMapping(value = ServerOpenApi.BUILD_TRIGGER_BUILD2, produces = MediaType.APPLICATION_JSON_VALUE)
public String trigger2(@PathVariable String id, @PathVariable String token, String delay, String buildRemark) {
    BuildInfoModel item = buildInfoService.getByKey(id);
    Assert.notNull(item, "没有对应数据");
    UserModel userModel = this.getByUrlToken(token);
    // 
    Assert.notNull(userModel, "没有对应数据:-1");
    Assert.state(StrUtil.equals(token, item.getTriggerToken()), "触发token错误,或者已经失效");
    BaseServerController.resetInfo(userModel);
    JsonMessage<Integer> start = buildExecuteService.start(id, userModel, Convert.toInt(delay, 0), 1, buildRemark);
    return start.toString();
}
Also used : UserModel(io.jpom.model.data.UserModel) BuildInfoModel(io.jpom.model.data.BuildInfoModel)

Aggregations

BuildInfoModel (io.jpom.model.data.BuildInfoModel)22 ClassFeature (io.jpom.permission.ClassFeature)12 Feature (io.jpom.permission.Feature)12 MethodFeature (io.jpom.permission.MethodFeature)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 File (java.io.File)7 UserModel (io.jpom.model.data.UserModel)5 BuildHistoryLog (io.jpom.model.log.BuildHistoryLog)5 JSONObject (com.alibaba.fastjson.JSONObject)4 JsonMessage (cn.jiangzeyin.common.JsonMessage)3 BuildStatus (io.jpom.model.enums.BuildStatus)3 RepositoryModel (io.jpom.model.data.RepositoryModel)2 Convert (cn.hutool.core.convert.Convert)1 RegexPool (cn.hutool.core.lang.RegexPool)1 Validator (cn.hutool.core.lang.Validator)1 ObjectUtil (cn.hutool.core.util.ObjectUtil)1 StrUtil (cn.hutool.core.util.StrUtil)1 Entity (cn.hutool.db.Entity)1 ServletUtil (cn.hutool.extra.servlet.ServletUtil)1 DefaultSystemLog (cn.jiangzeyin.common.DefaultSystemLog)1