use of com.orion.ops.service.api.ApplicationEnvService in project orion-ops by lijiahangmax.
the class ApplicationEnvServiceImpl method configAppEnv.
@Override
@Transactional(rollbackFor = Exception.class)
public void configAppEnv(ApplicationConfigRequest request) {
ApplicationEnvService self = SpringHolder.getBean(ApplicationEnvService.class);
StageType stageType = StageType.of(request.getStageType());
List<ApplicationEnvRequest> list = Lists.newList();
Long appId = request.getAppId();
Long profileId = request.getProfileId();
ApplicationConfigEnvRequest requestEnv = request.getEnv();
// 构建产物目录
String bundlePath = requestEnv.getBundlePath();
if (!Strings.isBlank(bundlePath)) {
ApplicationEnvRequest bundlePathEnv = new ApplicationEnvRequest();
bundlePathEnv.setKey(ApplicationEnvAttr.BUNDLE_PATH.getKey());
bundlePathEnv.setValue(bundlePath);
bundlePathEnv.setDescription(ApplicationEnvAttr.BUNDLE_PATH.getDescription());
list.add(bundlePathEnv);
}
// 产物传输目录
String transferPath = requestEnv.getTransferPath();
if (!Strings.isBlank(transferPath)) {
ApplicationEnvRequest transferPathEnv = new ApplicationEnvRequest();
transferPathEnv.setKey(ApplicationEnvAttr.TRANSFER_PATH.getKey());
transferPathEnv.setValue(transferPath);
transferPathEnv.setDescription(ApplicationEnvAttr.TRANSFER_PATH.getDescription());
list.add(transferPathEnv);
}
// 产物传输类型
String transferDirType = requestEnv.getTransferDirType();
if (!Strings.isBlank(transferDirType)) {
ApplicationEnvRequest transferDirTypeEnv = new ApplicationEnvRequest();
transferDirTypeEnv.setKey(ApplicationEnvAttr.TRANSFER_DIR_TYPE.getKey());
transferDirTypeEnv.setValue(TransferDirType.of(transferDirType).getValue());
transferDirTypeEnv.setDescription(ApplicationEnvAttr.TRANSFER_DIR_TYPE.getDescription());
list.add(transferDirTypeEnv);
}
// 发布序列
Integer releaseSerial = requestEnv.getReleaseSerial();
if (releaseSerial != null) {
ApplicationEnvRequest releaseSerialEnv = new ApplicationEnvRequest();
releaseSerialEnv.setKey(ApplicationEnvAttr.RELEASE_SERIAL.getKey());
releaseSerialEnv.setValue(SerialType.of(releaseSerial).getValue());
releaseSerialEnv.setDescription(ApplicationEnvAttr.RELEASE_SERIAL.getDescription());
list.add(releaseSerialEnv);
}
// 异常处理
Integer exceptionHandler = requestEnv.getExceptionHandler();
if (exceptionHandler != null) {
ApplicationEnvRequest exceptionHandlerEnv = new ApplicationEnvRequest();
exceptionHandlerEnv.setKey(ApplicationEnvAttr.EXCEPTION_HANDLER.getKey());
exceptionHandlerEnv.setValue(ExceptionHandlerType.of(exceptionHandler).getValue());
exceptionHandlerEnv.setDescription(ApplicationEnvAttr.EXCEPTION_HANDLER.getDescription());
list.add(exceptionHandlerEnv);
}
// 构建检查是否有构建序列
if (StageType.BUILD.equals(stageType)) {
self.checkInitSystemEnv(appId, profileId);
}
// 添加环境变量
for (ApplicationEnvRequest env : list) {
env.setAppId(appId);
env.setProfileId(profileId);
self.addAppEnv(env);
}
}
use of com.orion.ops.service.api.ApplicationEnvService in project orion-ops by lijiahangmax.
the class ApplicationEnvServiceImpl method syncAppEnv.
@Override
@Transactional(rollbackFor = Exception.class)
public void syncAppEnv(Long id, Long appId, Long profileId, List<Long> targetProfileIdList) {
ApplicationEnvService self = SpringHolder.getBean(ApplicationEnvService.class);
List<ApplicationEnvDO> envList;
// 查询数据
if (Const.N_N_L_1.equals(id)) {
// 全量同步
LambdaQueryWrapper<ApplicationEnvDO> wrapper = new LambdaQueryWrapper<ApplicationEnvDO>().eq(ApplicationEnvDO::getAppId, appId).eq(ApplicationEnvDO::getProfileId, profileId).eq(ApplicationEnvDO::getSystemEnv, Const.NOT_SYSTEM).orderByAsc(ApplicationEnvDO::getUpdateTime);
envList = applicationEnvDAO.selectList(wrapper);
} else {
// 查询数据
ApplicationEnvDO env = applicationEnvDAO.selectById(id);
Valid.notNull(env, MessageConst.UNKNOWN_DATA);
envList = Lists.singleton(env);
}
// 同步数据
for (Long targetProfileId : targetProfileIdList) {
// 同步环境变量
for (ApplicationEnvDO syncEnv : envList) {
ApplicationEnvRequest request = new ApplicationEnvRequest();
request.setAppId(syncEnv.getAppId());
request.setProfileId(targetProfileId);
request.setKey(syncEnv.getAttrKey());
request.setValue(syncEnv.getAttrValue());
request.setDescription(syncEnv.getDescription());
self.addAppEnv(request);
}
// 初始化系统变量
self.checkInitSystemEnv(appId, targetProfileId);
}
// 设置日志参数
EventParamsHolder.addParam(EventKeys.ID, id);
EventParamsHolder.addParam(EventKeys.APP_ID, appId);
EventParamsHolder.addParam(EventKeys.PROFILE_ID, profileId);
EventParamsHolder.addParam(EventKeys.ID_LIST, targetProfileIdList);
EventParamsHolder.addParam(EventKeys.ENV_COUNT, envList.size());
EventParamsHolder.addParam(EventKeys.PROFILE_COUNT, targetProfileIdList.size());
}
use of com.orion.ops.service.api.ApplicationEnvService in project orion-ops by lijiahangmax.
the class ApplicationEnvServiceImpl method saveEnv.
@Override
@Transactional(rollbackFor = Exception.class)
public void saveEnv(Long appId, Long profileId, Map<String, String> env) {
ApplicationEnvService self = SpringHolder.getBean(ApplicationEnvService.class);
// 倒排
List<Map.Entry<String, String>> entries = Lists.newList(env.entrySet());
for (int i = entries.size() - 1; i >= 0; i--) {
// 更新
Map.Entry<String, String> entry = entries.get(i);
ApplicationEnvRequest request = new ApplicationEnvRequest();
request.setAppId(appId);
request.setProfileId(profileId);
request.setKey(entry.getKey());
request.setValue(entry.getValue());
self.addAppEnv(request);
}
}
use of com.orion.ops.service.api.ApplicationEnvService in project orion-ops by lijiahangmax.
the class ApplicationEnvServiceImpl method copyAppEnv.
@Override
@Transactional(rollbackFor = Exception.class)
public void copyAppEnv(Long appId, Long targetAppId) {
ApplicationEnvService self = SpringHolder.getBean(ApplicationEnvService.class);
// 查询
LambdaQueryWrapper<ApplicationEnvDO> wrapper = new LambdaQueryWrapper<ApplicationEnvDO>().eq(ApplicationEnvDO::getAppId, appId).eq(ApplicationEnvDO::getSystemEnv, Const.NOT_SYSTEM).orderByAsc(ApplicationEnvDO::getUpdateTime);
List<ApplicationEnvDO> envList = applicationEnvDAO.selectList(wrapper);
// 插入
for (ApplicationEnvDO env : envList) {
env.setId(null);
env.setAppId(targetAppId);
env.setCreateTime(null);
env.setUpdateTime(null);
applicationEnvDAO.insert(env);
// 插入历史值
historyValueService.addHistory(env.getId(), HistoryValueType.APP_ENV, HistoryOperator.ADD, null, env.getAttrValue());
}
// 初始化系统变量
envList.stream().map(ApplicationEnvDO::getProfileId).distinct().forEach(profileId -> self.checkInitSystemEnv(targetAppId, profileId));
}
Aggregations