Search in sources :

Example 1 with OutGivingNodeProject

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

the class OutGivingRun method startRun.

/**
 * 开始异步执行分发任务
 *
 * @param id        分发id
 * @param file      文件
 * @param userModel 操作的用户
 * @param unzip     解压
 */
public static void startRun(String id, File file, UserModel userModel, boolean unzip) {
    OutGivingServer outGivingServer = SpringUtil.getBean(OutGivingServer.class);
    OutGivingModel item = outGivingServer.getByKey(id);
    Objects.requireNonNull(item, "不存在分发");
    AfterOpt afterOpt = ObjectUtil.defaultIfNull(EnumUtil.likeValueOf(AfterOpt.class, item.getAfterOpt()), AfterOpt.No);
    // 
    List<OutGivingNodeProject> outGivingNodeProjects = item.outGivingNodeProjectList();
    // 开启线程
    if (afterOpt == AfterOpt.Order_Restart || afterOpt == AfterOpt.Order_Must_Restart) {
        ThreadUtil.execute(() -> {
            // 截取睡眠时间
            int sleepTime = ObjectUtil.defaultIfNull(item.getIntervalTime(), 10);
            // 
            boolean cancel = false;
            for (OutGivingNodeProject outGivingNodeProject : outGivingNodeProjects) {
                if (cancel) {
                    String userId = userModel == null ? JpomApplication.SYSTEM_ID : userModel.getId();
                    OutGivingItemRun.updateStatus(null, id, outGivingNodeProject, OutGivingNodeProject.Status.Cancel, "前一个节点分发失败,取消分发", userId);
                } else {
                    OutGivingItemRun outGivingRun = new OutGivingItemRun(item, outGivingNodeProject, file, userModel, unzip);
                    OutGivingNodeProject.Status status = outGivingRun.call();
                    if (status != OutGivingNodeProject.Status.Ok) {
                        if (afterOpt == AfterOpt.Order_Must_Restart) {
                            // 完整重启,不再继续剩余的节点项目
                            cancel = true;
                        }
                    }
                    // 休眠x秒 等待之前项目正常启动
                    ThreadUtil.sleep(sleepTime, TimeUnit.SECONDS);
                }
            }
        });
    } else if (afterOpt == AfterOpt.Restart || afterOpt == AfterOpt.No) {
        outGivingNodeProjects.forEach(outGivingNodeProject -> ThreadUtil.execAsync(new OutGivingItemRun(item, outGivingNodeProject, file, userModel, unzip)));
    } else {
        // 
        throw new IllegalArgumentException("Not implemented " + afterOpt.getDesc());
    }
}
Also used : NodeForward(io.jpom.common.forward.NodeForward) ObjectUtil(cn.hutool.core.util.ObjectUtil) EnumUtil(cn.hutool.core.util.EnumUtil) NodeModel(io.jpom.model.data.NodeModel) SpringUtil(cn.jiangzeyin.common.spring.SpringUtil) AfterOpt(io.jpom.model.AfterOpt) File(java.io.File) OutGivingModel(io.jpom.model.data.OutGivingModel) NodeUrl(io.jpom.common.forward.NodeUrl) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) JsonMessage(cn.jiangzeyin.common.JsonMessage) OutGivingNodeProject(io.jpom.model.data.OutGivingNodeProject) StrUtil(cn.hutool.core.util.StrUtil) List(java.util.List) JpomApplication(io.jpom.JpomApplication) JSONObject(com.alibaba.fastjson.JSONObject) OutGivingServer(io.jpom.service.node.OutGivingServer) ThreadUtil(cn.hutool.core.thread.ThreadUtil) UserModel(io.jpom.model.data.UserModel) OutGivingServer(io.jpom.service.node.OutGivingServer) OutGivingNodeProject(io.jpom.model.data.OutGivingNodeProject) AfterOpt(io.jpom.model.AfterOpt) OutGivingModel(io.jpom.model.data.OutGivingModel)

Example 2 with OutGivingNodeProject

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

the class OutGivingProjectController method getItemData.

@RequestMapping(value = "getItemData.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String getItemData(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "id error") String id) {
    HttpServletRequest request = getRequest();
    String workspaceId = outGivingServer.getCheckUserWorkspace(request);
    OutGivingModel outGivingServerItem = outGivingServer.getByKey(id, request);
    Objects.requireNonNull(outGivingServerItem, "没有数据");
    List<OutGivingNodeProject> outGivingNodeProjectList = outGivingServerItem.outGivingNodeProjectList();
    List<JSONObject> collect = outGivingNodeProjectList.stream().map(outGivingNodeProject -> {
        NodeModel nodeModel = nodeService.getByKey(outGivingNodeProject.getNodeId());
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("nodeId", outGivingNodeProject.getNodeId());
        jsonObject.put("projectId", outGivingNodeProject.getProjectId());
        jsonObject.put("nodeName", nodeModel.getName());
        jsonObject.put("id", BaseNodeModel.fullId(workspaceId, outGivingNodeProject.getNodeId(), outGivingNodeProject.getProjectId()));
        // set projectStatus property
        // NodeModel node = nodeService.getItem(outGivingNodeProject.getNodeId());
        // Project Status: data.pid > 0 means running
        JSONObject projectStatus = JsonMessage.toJson(200, "success");
        if (nodeModel.isOpenStatus()) {
            JSONObject projectInfo = null;
            try {
                projectInfo = projectInfoCacheService.getItem(nodeModel, outGivingNodeProject.getProjectId());
                projectStatus = NodeForward.requestBySys(nodeModel, NodeUrl.Manage_GetProjectStatus, "id", outGivingNodeProject.getProjectId()).toJson();
            } catch (Exception e) {
                jsonObject.put("errorMsg", "error " + e.getMessage());
            }
            if (projectInfo != null) {
                jsonObject.put("projectName", projectInfo.getString("name"));
            }
        } else {
            jsonObject.put("errorMsg", "节点未启用");
        }
        JSONObject data = projectStatus.getJSONObject("data");
        if (data != null && data.getInteger("pId") != null) {
            jsonObject.put("projectStatus", data.getIntValue("pId") > 0);
        } else {
            jsonObject.put("projectStatus", false);
        }
        jsonObject.put("outGivingStatus", outGivingNodeProject.getStatusMsg());
        jsonObject.put("outGivingResult", outGivingNodeProject.getResult());
        jsonObject.put("lastTime", outGivingNodeProject.getLastOutGivingTime());
        return jsonObject;
    }).collect(Collectors.toList());
    return JsonMessage.getString(200, "", collect);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MultipartFileBuilder(cn.jiangzeyin.controller.multipart.MultipartFileBuilder) DefaultSystemLog(cn.jiangzeyin.common.DefaultSystemLog) ServerWhitelist(io.jpom.model.data.ServerWhitelist) ServerConfigBean(io.jpom.system.ServerConfigBean) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Feature(io.jpom.permission.Feature) ProjectInfoCacheService(io.jpom.service.node.ProjectInfoCacheService) JsonMessage(cn.jiangzeyin.common.JsonMessage) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpUtil(cn.hutool.http.HttpUtil) BaseEnum(io.jpom.model.BaseEnum) OutGivingRun(io.jpom.outgiving.OutGivingRun) BaseNodeModel(io.jpom.model.BaseNodeModel) OutGivingServer(io.jpom.service.node.OutGivingServer) MethodFeature(io.jpom.permission.MethodFeature) NodeForward(io.jpom.common.forward.NodeForward) ClassFeature(io.jpom.permission.ClassFeature) MediaType(org.springframework.http.MediaType) NodeModel(io.jpom.model.data.NodeModel) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Set(java.util.Set) IOException(java.io.IOException) AfterOpt(io.jpom.model.AfterOpt) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) File(java.io.File) BooleanUtil(cn.hutool.core.util.BooleanUtil) OutGivingModel(io.jpom.model.data.OutGivingModel) NodeUrl(io.jpom.common.forward.NodeUrl) Objects(java.util.Objects) OutGivingNodeProject(io.jpom.model.data.OutGivingNodeProject) CollUtil(cn.hutool.core.collection.CollUtil) StrUtil(cn.hutool.core.util.StrUtil) ValidatorRule(cn.jiangzeyin.common.validator.ValidatorRule) List(java.util.List) ValidatorItem(cn.jiangzeyin.common.validator.ValidatorItem) StringUtil(io.jpom.util.StringUtil) Convert(cn.hutool.core.convert.Convert) ConfigBean(io.jpom.system.ConfigBean) FileUtil(cn.hutool.core.io.FileUtil) JSONObject(com.alibaba.fastjson.JSONObject) BaseServerController(io.jpom.common.BaseServerController) Assert(org.springframework.util.Assert) BaseNodeModel(io.jpom.model.BaseNodeModel) NodeModel(io.jpom.model.data.NodeModel) JSONObject(com.alibaba.fastjson.JSONObject) OutGivingNodeProject(io.jpom.model.data.OutGivingNodeProject) OutGivingModel(io.jpom.model.data.OutGivingModel) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with OutGivingNodeProject

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

the class OutGivingController method doData.

private void doData(OutGivingModel outGivingModel) {
    outGivingModel.setName(getParameter("name"));
    Assert.hasText(outGivingModel.getName(), "分发名称不能为空");
    HttpServletRequest request = getRequest();
    List<OutGivingModel> outGivingModels = outGivingServer.list();
    // 
    Map<String, String> paramMap = ServletUtil.getParamMap(request);
    List<OutGivingNodeProject> outGivingNodeProjects = paramMap.entrySet().stream().filter(stringStringEntry -> StrUtil.startWith(stringStringEntry.getKey(), "node_")).map(stringStringEntry -> {
        int lastIndexOf = StrUtil.lastIndexOfIgnoreCase(stringStringEntry.getKey(), StrUtil.UNDERLINE);
        int indexOf = StrUtil.indexOfIgnoreCase(stringStringEntry.getKey(), StrUtil.UNDERLINE) + 1;
        String nodeId = StrUtil.sub(stringStringEntry.getKey(), indexOf, lastIndexOf);
        // 
        String nodeIdProject = stringStringEntry.getValue();
        NodeModel nodeModel = nodeService.getByKey(nodeId);
        Assert.notNull(nodeModel, "不存在对应的节点");
        // 
        boolean exists = projectInfoCacheService.exists(nodeModel.getWorkspaceId(), nodeModel.getId(), nodeIdProject);
        Assert.state(exists, "没有找到对应的项目id:" + nodeIdProject);
        // 
        OutGivingNodeProject outGivingNodeProject = outGivingModel.getNodeProject(nodeModel.getId(), nodeIdProject);
        if (outGivingNodeProject == null) {
            outGivingNodeProject = new OutGivingNodeProject();
        }
        outGivingNodeProject.setNodeId(nodeModel.getId());
        outGivingNodeProject.setProjectId(nodeIdProject);
        return outGivingNodeProject;
    }).peek(outGivingNodeProject -> {
        // 判断项目是否已经被使用过啦
        if (outGivingModels != null) {
            for (OutGivingModel outGivingModel1 : outGivingModels) {
                if (outGivingModel1.getId().equalsIgnoreCase(outGivingModel.getId())) {
                    continue;
                }
                boolean checkContains = outGivingModel1.checkContains(outGivingNodeProject.getNodeId(), outGivingNodeProject.getProjectId());
                Assert.state(!checkContains, "已经存在相同的分发项目:" + outGivingNodeProject.getProjectId());
            }
        }
    }).collect(Collectors.toList());
    Assert.state(CollUtil.size(outGivingNodeProjects) >= 2, "至少选择2个节点项目");
    outGivingModel.outGivingNodeProjectList(outGivingNodeProjects);
    // 
    String afterOpt = getParameter("afterOpt");
    AfterOpt afterOpt1 = BaseEnum.getEnum(AfterOpt.class, Convert.toInt(afterOpt, 0));
    Assert.notNull(afterOpt1, "请选择分发后的操作");
    outGivingModel.setAfterOpt(afterOpt1.getCode());
    // 
    int intervalTime = getParameterInt("intervalTime", 10);
    outGivingModel.setIntervalTime(intervalTime);
    // 
    outGivingModel.setClearOld(Convert.toBool(getParameter("clearOld"), false));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PageResultDto(io.jpom.model.PageResultDto) DbOutGivingLogService(io.jpom.service.dblog.DbOutGivingLogService) BuildReleaseMethod(io.jpom.model.enums.BuildReleaseMethod) Feature(io.jpom.permission.Feature) ServletUtil(cn.hutool.extra.servlet.ServletUtil) ProjectInfoCacheService(io.jpom.service.node.ProjectInfoCacheService) JsonMessage(cn.jiangzeyin.common.JsonMessage) HttpServletRequest(javax.servlet.http.HttpServletRequest) BaseEnum(io.jpom.model.BaseEnum) Map(java.util.Map) OutGivingServer(io.jpom.service.node.OutGivingServer) MethodFeature(io.jpom.permission.MethodFeature) NodeForward(io.jpom.common.forward.NodeForward) ClassFeature(io.jpom.permission.ClassFeature) MediaType(org.springframework.http.MediaType) NodeModel(io.jpom.model.data.NodeModel) IOException(java.io.IOException) AfterOpt(io.jpom.model.AfterOpt) Collectors(java.util.stream.Collectors) OutGivingModel(io.jpom.model.data.OutGivingModel) NodeUrl(io.jpom.common.forward.NodeUrl) OutGivingNodeProject(io.jpom.model.data.OutGivingNodeProject) CollUtil(cn.hutool.core.collection.CollUtil) StrUtil(cn.hutool.core.util.StrUtil) List(java.util.List) ValidatorItem(cn.jiangzeyin.common.validator.ValidatorItem) Const(io.jpom.common.Const) BuildInfoService(io.jpom.service.dblog.BuildInfoService) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) Convert(cn.hutool.core.convert.Convert) JSONObject(com.alibaba.fastjson.JSONObject) Entity(cn.hutool.db.Entity) UserModel(io.jpom.model.data.UserModel) BaseServerController(io.jpom.common.BaseServerController) Validator(cn.hutool.core.lang.Validator) Assert(org.springframework.util.Assert) NodeModel(io.jpom.model.data.NodeModel) OutGivingNodeProject(io.jpom.model.data.OutGivingNodeProject) AfterOpt(io.jpom.model.AfterOpt) OutGivingModel(io.jpom.model.data.OutGivingModel)

Example 4 with OutGivingNodeProject

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

the class OutGivingController method releaseDel.

/**
 * 删除分发信息
 *
 * @param id 分发id
 * @return json
 */
@RequestMapping(value = "release_del.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DEL)
public String releaseDel(String id) {
    HttpServletRequest request = getRequest();
    // 判断构建
    boolean releaseMethod = buildService.checkReleaseMethod(id, request, BuildReleaseMethod.Outgiving);
    Assert.state(!releaseMethod, "当前分发存在构建项,不能删除");
    OutGivingModel outGivingServerItem = outGivingServer.getByKey(id, request);
    UserModel userModel = getUser();
    // 解除项目分发独立分发属性
    List<OutGivingNodeProject> outGivingNodeProjectList = outGivingServerItem.outGivingNodeProjectList();
    if (outGivingNodeProjectList != null) {
        outGivingNodeProjectList.forEach(outGivingNodeProject -> {
            NodeModel item = nodeService.getByKey(outGivingNodeProject.getNodeId());
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("id", outGivingNodeProject.getProjectId());
            NodeForward.request(item, NodeUrl.Manage_ReleaseOutGiving, userModel, jsonObject);
        });
    }
    int byKey = outGivingServer.delByKey(id, request);
    if (byKey > 0) {
        // 删除日志
        Entity where = new Entity();
        where.set("outGivingId", id);
        dbOutGivingLogService.del(where);
    }
    return JsonMessage.getString(200, "操作成功");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) UserModel(io.jpom.model.data.UserModel) Entity(cn.hutool.db.Entity) NodeModel(io.jpom.model.data.NodeModel) JSONObject(com.alibaba.fastjson.JSONObject) OutGivingNodeProject(io.jpom.model.data.OutGivingNodeProject) OutGivingModel(io.jpom.model.data.OutGivingModel) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Example 5 with OutGivingNodeProject

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

the class OutGivingItemRun method updateStatus.

/**
 * 更新状态
 *
 * @param logId                    日志ID
 * @param outGivingId              分发id
 * @param outGivingNodeProjectItem 分发项
 * @param status                   状态
 * @param msg                      消息描述
 */
public static void updateStatus(String logId, String outGivingId, OutGivingNodeProject outGivingNodeProjectItem, OutGivingNodeProject.Status status, String msg, String userId) {
    synchronized (outGivingId.intern()) {
        OutGivingServer outGivingServer = SpringUtil.getBean(OutGivingServer.class);
        OutGivingModel outGivingModel = outGivingServer.getByKey(outGivingId);
        List<OutGivingNodeProject> outGivingNodeProjects = outGivingModel.outGivingNodeProjectList();
        Assert.notEmpty(outGivingNodeProjects, "没有分发项目");
        OutGivingNodeProject finOutGivingNodeProject = null;
        // 
        for (OutGivingNodeProject outGivingNodeProject : outGivingNodeProjects) {
            if (!outGivingNodeProject.getProjectId().equalsIgnoreCase(outGivingNodeProjectItem.getProjectId()) || !outGivingNodeProject.getNodeId().equalsIgnoreCase(outGivingNodeProjectItem.getNodeId())) {
                continue;
            }
            outGivingNodeProject.setStatus(status.getCode());
            outGivingNodeProject.setResult(msg);
            outGivingNodeProject.setLastOutGivingTime(DateUtil.now());
            // 
            finOutGivingNodeProject = outGivingNodeProject;
        }
        {
            List<OutGivingNodeProject.Status> collect = outGivingNodeProjects.stream().map(outGivingNodeProject -> EnumUtil.likeValueOf(OutGivingNodeProject.Status.class, outGivingNodeProject.getStatus())).collect(Collectors.toList());
            OutGivingModel.Status outGivingStatus = CollUtil.contains(collect, OutGivingNodeProject.Status.Ing) ? OutGivingModel.Status.ING : OutGivingModel.Status.DONE;
            // 更新分发数据
            OutGivingModel outGivingModel1 = new OutGivingModel();
            outGivingModel1.setId(outGivingId);
            outGivingModel1.setStatus(outGivingStatus.getCode());
            outGivingModel1.outGivingNodeProjectList(outGivingNodeProjects);
            outGivingServer.update(outGivingModel1);
        }
        // 更新日志数据
        OutGivingLog outGivingLog = new OutGivingLog();
        outGivingLog.setId(StrUtil.emptyToDefault(logId, IdUtil.fastSimpleUUID()));
        if (finOutGivingNodeProject != null) {
            outGivingLog.setNodeId(finOutGivingNodeProject.getNodeId());
            outGivingLog.setProjectId(finOutGivingNodeProject.getProjectId());
        }
        outGivingLog.setModifyUser(userId);
        outGivingLog.setOutGivingId(outGivingId);
        outGivingLog.setResult(msg);
        outGivingLog.setStatus(status.getCode());
        DbOutGivingLogService dbOutGivingLogService = SpringUtil.getBean(DbOutGivingLogService.class);
        if (status == OutGivingNodeProject.Status.Ing || status == OutGivingNodeProject.Status.Cancel) {
            // 开始或者 取消都还没有记录
            dbOutGivingLogService.insert(outGivingLog);
        } else {
            outGivingLog.setEndTime(SystemClock.now());
            dbOutGivingLogService.update(outGivingLog);
        }
    }
}
Also used : HttpStatus(cn.hutool.http.HttpStatus) OutGivingServer(io.jpom.service.node.OutGivingServer) OutGivingNodeProject(io.jpom.model.data.OutGivingNodeProject) OutGivingLog(io.jpom.model.log.OutGivingLog) OutGivingModel(io.jpom.model.data.OutGivingModel) List(java.util.List) DbOutGivingLogService(io.jpom.service.dblog.DbOutGivingLogService)

Aggregations

OutGivingModel (io.jpom.model.data.OutGivingModel)5 OutGivingNodeProject (io.jpom.model.data.OutGivingNodeProject)5 JSONObject (com.alibaba.fastjson.JSONObject)4 NodeModel (io.jpom.model.data.NodeModel)4 OutGivingServer (io.jpom.service.node.OutGivingServer)4 List (java.util.List)4 StrUtil (cn.hutool.core.util.StrUtil)3 JsonMessage (cn.jiangzeyin.common.JsonMessage)3 NodeForward (io.jpom.common.forward.NodeForward)3 NodeUrl (io.jpom.common.forward.NodeUrl)3 AfterOpt (io.jpom.model.AfterOpt)3 UserModel (io.jpom.model.data.UserModel)3 ClassFeature (io.jpom.permission.ClassFeature)3 Feature (io.jpom.permission.Feature)3 MethodFeature (io.jpom.permission.MethodFeature)3 CollUtil (cn.hutool.core.collection.CollUtil)2 Convert (cn.hutool.core.convert.Convert)2 Entity (cn.hutool.db.Entity)2 ValidatorItem (cn.jiangzeyin.common.validator.ValidatorItem)2 BaseServerController (io.jpom.common.BaseServerController)2