Search in sources :

Example 1 with Strings

use of com.orion.utils.Strings in project orion-ops by lijiahangmax.

the class TerminalSessionManager method getOnlineTerminal.

/**
 * session 列表
 *
 * @param request request
 * @return dataGrid
 */
public DataGrid<MachineTerminalManagerVO> getOnlineTerminal(MachineTerminalManagerRequest request) {
    List<MachineTerminalManagerVO> sessionList = sessionHolder.values().stream().filter(s -> Optional.ofNullable(request.getToken()).filter(Strings::isNotBlank).map(t -> s.getToken().contains(t)).orElse(true)).filter(s -> Optional.ofNullable(request.getMachineName()).filter(Strings::isNotBlank).map(t -> s.getHint().getMachineName().toLowerCase().contains(t.toLowerCase())).orElse(true)).filter(s -> Optional.ofNullable(request.getMachineTag()).filter(Strings::isNotBlank).map(t -> s.getHint().getMachineTag().contains(t)).orElse(true)).filter(s -> Optional.ofNullable(request.getMachineHost()).filter(Strings::isNotBlank).map(t -> s.getHint().getMachineHost().contains(t)).orElse(true)).filter(s -> Optional.ofNullable(request.getUserId()).map(t -> s.getHint().getUserId().equals(t)).orElse(true)).filter(s -> Optional.ofNullable(request.getUsername()).map(t -> s.getHint().getUsername().toLowerCase().contains(t.toLowerCase())).orElse(true)).filter(s -> Optional.ofNullable(request.getMachineId()).map(t -> s.getHint().getMachineId().equals(t)).orElse(true)).filter(s -> {
        if (request.getConnectedTimeStart() == null || request.getConnectedTimeEnd() == null) {
            return true;
        }
        return DateRanges.inRange(request.getConnectedTimeStart(), request.getConnectedTimeEnd(), s.getHint().getConnectedTime());
    }).map(s -> {
        MachineTerminalManagerVO vo = Converts.to(s.getHint(), MachineTerminalManagerVO.class);
        vo.setToken(s.getToken());
        return vo;
    }).sorted(Comparator.comparing(MachineTerminalManagerVO::getConnectedTime).reversed()).collect(Collectors.toList());
    List<MachineTerminalManagerVO> page = Lists.newLimitList(sessionList).limit(request.getLimit()).page(request.getPage());
    return DataGrid.of(page, sessionList.size());
}
Also used : EventKeys(com.orion.ops.consts.event.EventKeys) MachineTerminalManagerVO(com.orion.ops.entity.vo.MachineTerminalManagerVO) HttpWrapper(com.orion.lang.wrapper.HttpWrapper) EventParamsHolder(com.orion.ops.consts.event.EventParamsHolder) Collectors(java.util.stream.Collectors) Converts(com.orion.utils.convert.Converts) Component(org.springframework.stereotype.Component) List(java.util.List) MachineTerminalManagerRequest(com.orion.ops.entity.request.MachineTerminalManagerRequest) Map(java.util.Map) Lists(com.orion.utils.collect.Lists) Optional(java.util.Optional) IOperateHandler(com.orion.ops.handler.terminal.IOperateHandler) Maps(com.orion.utils.collect.Maps) DateRanges(com.orion.utils.time.DateRanges) Comparator(java.util.Comparator) TerminalConnectHint(com.orion.ops.handler.terminal.TerminalConnectHint) DataGrid(com.orion.lang.wrapper.DataGrid) Strings(com.orion.utils.Strings) Strings(com.orion.utils.Strings) MachineTerminalManagerVO(com.orion.ops.entity.vo.MachineTerminalManagerVO)

Example 2 with Strings

use of com.orion.utils.Strings 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

DataGrid (com.orion.lang.wrapper.DataGrid)2 EventKeys (com.orion.ops.consts.event.EventKeys)2 EventParamsHolder (com.orion.ops.consts.event.EventParamsHolder)2 Strings (com.orion.utils.Strings)2 Maps (com.orion.utils.collect.Maps)2 Converts (com.orion.utils.convert.Converts)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)1 MutableLinkedHashMap (com.orion.lang.collect.MutableLinkedHashMap)1 HttpWrapper (com.orion.lang.wrapper.HttpWrapper)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 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