Search in sources :

Example 1 with ApplicationBuildRequest

use of com.orion.ops.entity.request.ApplicationBuildRequest in project orion-ops by lijiahangmax.

the class ApplicationBuildServiceImpl method rebuild.

@Override
public Long rebuild(Long id) {
    // 查询构建
    ApplicationBuildDO build = applicationBuildDAO.selectById(id);
    Valid.notNull(build, MessageConst.UNKNOWN_DATA);
    // 重新提交
    ApplicationBuildRequest request = new ApplicationBuildRequest();
    request.setAppId(build.getAppId());
    request.setProfileId(build.getProfileId());
    request.setBranchName(build.getBranchName());
    request.setCommitId(build.getCommitId());
    request.setDescription(build.getDescription());
    return this.submitBuildTask(request);
}
Also used : ApplicationBuildRequest(com.orion.ops.entity.request.ApplicationBuildRequest)

Example 2 with ApplicationBuildRequest

use of com.orion.ops.entity.request.ApplicationBuildRequest in project orion-ops by lijiahangmax.

the class ApplicationBuildServiceImpl method submitBuildTask.

@Override
public Long submitBuildTask(ApplicationBuildRequest request) {
    Long appId = request.getAppId();
    Long profileId = request.getProfileId();
    // 查询应用
    ApplicationInfoDO app = applicationInfoDAO.selectById(appId);
    Valid.notNull(app, MessageConst.APP_ABSENT);
    // 查询环境
    ApplicationProfileDO profile = applicationProfileDAO.selectById(profileId);
    Valid.notNull(profile, MessageConst.PROFILE_ABSENT);
    // 查询应用执行块
    List<ApplicationActionDO> actions = applicationActionService.getAppProfileActions(appId, profileId, StageType.BUILD.getType());
    Valid.notEmpty(actions, MessageConst.APP_PROFILE_NOT_CONFIGURED);
    UserDTO user = Currents.getUser();
    // 获取构建序列
    Integer buildSeq = applicationEnvService.getBuildSeqAndIncrement(appId, profileId);
    // 设置构建参数
    ApplicationBuildDO buildTask = new ApplicationBuildDO();
    buildTask.setAppId(appId);
    buildTask.setAppName(app.getAppName());
    buildTask.setAppTag(app.getAppTag());
    buildTask.setProfileId(profileId);
    buildTask.setProfileName(profile.getProfileName());
    buildTask.setProfileTag(profile.getProfileTag());
    buildTask.setBuildSeq(buildSeq);
    buildTask.setBranchName(request.getBranchName());
    buildTask.setCommitId(request.getCommitId());
    buildTask.setVcsId(app.getVcsId());
    buildTask.setBuildStatus(BuildStatus.WAIT.getStatus());
    buildTask.setDescription(request.getDescription());
    buildTask.setCreateUserId(user.getId());
    buildTask.setCreateUserName(user.getUsername());
    applicationBuildDAO.insert(buildTask);
    Long buildId = buildTask.getId();
    // 设置目录信息
    buildTask.setLogPath(PathBuilders.getBuildLogPath(buildId));
    String bundlePath = applicationEnvService.getAppEnvValue(appId, profileId, ApplicationEnvAttr.BUNDLE_PATH.getKey());
    buildTask.setBundlePath(PathBuilders.getBuildBundlePath(buildId) + "/" + Files1.getFileName(bundlePath));
    // 更新构建信息
    applicationBuildDAO.updateById(buildTask);
    // 检查是否包含环境变量命令
    final boolean hasEnvCommand = actions.stream().filter(s -> ActionType.BUILD_COMMAND.getType().equals(s.getActionType())).map(ApplicationActionDO::getActionCommand).filter(Strings::isNotBlank).anyMatch(s -> s.contains(EnvConst.SYMBOL));
    Map<String, String> env = Maps.newMap();
    if (hasEnvCommand) {
        // 查询应用环境变量
        env.putAll(applicationEnvService.getAppProfileFullEnv(appId, profileId));
        // 查询机器环境变量
        env.putAll(machineEnvService.getFullMachineEnv(Const.HOST_MACHINE_ID));
        // 查询系统环境变量
        env.putAll(systemEnvService.getFullSystemEnv());
        // 添加构建环境变量
        env.putAll(this.getBuildEnv(buildId, buildSeq, app.getVcsId(), request));
    }
    // 设置action
    for (ApplicationActionDO action : actions) {
        ApplicationActionLogDO actionLog = new ApplicationActionLogDO();
        actionLog.setRelId(buildId);
        actionLog.setStageType(StageType.BUILD.getType());
        actionLog.setMachineId(Const.HOST_MACHINE_ID);
        actionLog.setActionId(action.getAppId());
        actionLog.setActionName(action.getActionName());
        actionLog.setActionType(action.getActionType());
        if (ActionType.BUILD_COMMAND.equals(ActionType.of(action.getActionType()))) {
            actionLog.setActionCommand(Strings.format(action.getActionCommand(), EnvConst.SYMBOL, env));
        }
        actionLog.setRunStatus(ActionStatus.WAIT.getStatus());
        applicationActionLogDAO.insert(actionLog);
        // 设置日志路径
        actionLog.setLogPath(PathBuilders.getBuildActionLogPath(buildId, actionLog.getId()));
        // 更新
        applicationActionLogDAO.updateById(actionLog);
    }
    // 提交构建任务
    log.info("提交应用构建任务 buildId: {}", buildId);
    BuildMachineProcessor buildProcessor = new BuildMachineProcessor(buildId);
    Threads.start(buildProcessor, SchedulerPools.APP_BUILD_SCHEDULER);
    // 设置日志参数
    EventParamsHolder.addParams(buildTask);
    return buildId;
}
Also used : EventKeys(com.orion.ops.consts.event.EventKeys) com.orion.ops.dao(com.orion.ops.dao) com.orion.ops.entity.vo(com.orion.ops.entity.vo) MessageConst(com.orion.ops.consts.MessageConst) EnvConst(com.orion.ops.consts.env.EnvConst) EventParamsHolder(com.orion.ops.consts.event.EventParamsHolder) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) BuildMachineProcessor(com.orion.ops.handler.app.machine.BuildMachineProcessor) ApplicationBuildRequest(com.orion.ops.entity.request.ApplicationBuildRequest) PathBuilders(com.orion.ops.utils.PathBuilders) Service(org.springframework.stereotype.Service) Map(java.util.Map) MutableLinkedHashMap(com.orion.lang.collect.MutableLinkedHashMap) Maps(com.orion.utils.collect.Maps) Const(com.orion.ops.consts.Const) com.orion.ops.consts.app(com.orion.ops.consts.app) DataGrid(com.orion.lang.wrapper.DataGrid) com.orion.ops.entity.domain(com.orion.ops.entity.domain) com.orion.ops.service.api(com.orion.ops.service.api) Resource(javax.annotation.Resource) Threads(com.orion.utils.Threads) IMachineProcessor(com.orion.ops.handler.app.machine.IMachineProcessor) Valid(com.orion.ops.utils.Valid) UserDTO(com.orion.ops.entity.dto.UserDTO) Files1(com.orion.utils.io.Files1) Objects(java.util.Objects) DataQuery(com.orion.ops.utils.DataQuery) Converts(com.orion.utils.convert.Converts) BuildSessionHolder(com.orion.ops.handler.app.build.BuildSessionHolder) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) SystemEnvAttr(com.orion.ops.consts.system.SystemEnvAttr) SchedulerPools(com.orion.ops.consts.SchedulerPools) Optional(java.util.Optional) Currents(com.orion.ops.utils.Currents) Strings(com.orion.utils.Strings) Transactional(org.springframework.transaction.annotation.Transactional) BuildMachineProcessor(com.orion.ops.handler.app.machine.BuildMachineProcessor) UserDTO(com.orion.ops.entity.dto.UserDTO)

Aggregations

ApplicationBuildRequest (com.orion.ops.entity.request.ApplicationBuildRequest)2 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)1 MutableLinkedHashMap (com.orion.lang.collect.MutableLinkedHashMap)1 DataGrid (com.orion.lang.wrapper.DataGrid)1 Const (com.orion.ops.consts.Const)1 MessageConst (com.orion.ops.consts.MessageConst)1 SchedulerPools (com.orion.ops.consts.SchedulerPools)1 com.orion.ops.consts.app (com.orion.ops.consts.app)1 EnvConst (com.orion.ops.consts.env.EnvConst)1 EventKeys (com.orion.ops.consts.event.EventKeys)1 EventParamsHolder (com.orion.ops.consts.event.EventParamsHolder)1 SystemEnvAttr (com.orion.ops.consts.system.SystemEnvAttr)1 com.orion.ops.dao (com.orion.ops.dao)1 com.orion.ops.entity.domain (com.orion.ops.entity.domain)1 UserDTO (com.orion.ops.entity.dto.UserDTO)1 com.orion.ops.entity.vo (com.orion.ops.entity.vo)1 BuildSessionHolder (com.orion.ops.handler.app.build.BuildSessionHolder)1 BuildMachineProcessor (com.orion.ops.handler.app.machine.BuildMachineProcessor)1 IMachineProcessor (com.orion.ops.handler.app.machine.IMachineProcessor)1 com.orion.ops.service.api (com.orion.ops.service.api)1