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());
}
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;
}
Aggregations