use of com.orion.ops.entity.domain.ApplicationVcsDO in project orion-ops by lijiahangmax.
the class ApplicationVcsServiceImpl method getAppVcsDetail.
@Override
public ApplicationVcsVO getAppVcsDetail(Long id) {
ApplicationVcsDO vcs = applicationVcsDAO.selectById(id);
Valid.notNull(vcs, MessageConst.UNKNOWN_DATA);
return Converts.to(vcs, ApplicationVcsVO.class);
}
use of com.orion.ops.entity.domain.ApplicationVcsDO in project orion-ops by lijiahangmax.
the class ApplicationVcsServiceImpl method openEventGit.
@Override
public Gits openEventGit(Long id) {
// 查询数据
ApplicationVcsDO vcs = applicationVcsDAO.selectById(id);
Valid.notNull(vcs, MessageConst.UNKNOWN_DATA);
Valid.isTrue(VcsStatus.OK.getStatus().equals(vcs.getVcsStatus()), MessageConst.VCS_UNINITIALIZED);
// 获取仓库位置
File vcsPath = new File(Utils.getVcsEventDir(id));
if (!vcsPath.isDirectory()) {
// 修改状态为未初始化
ApplicationVcsDO entity = new ApplicationVcsDO();
entity.setId(id);
entity.setVcsStatus(VcsStatus.UNINITIALIZED.getStatus());
applicationVcsDAO.updateById(entity);
throw Exceptions.argument(MessageConst.VCS_PATH_ABSENT, Exceptions.runtime(vcsPath.getAbsolutePath()));
}
// 打开git
try {
Gits gits = Gits.of(vcsPath);
String[] pair = this.getVcsUsernamePassword(vcs);
String username = pair[0];
String password = pair[1];
if (username != null) {
gits.auth(username, password);
}
return gits;
} catch (Exception e) {
throw Exceptions.runtime(MessageConst.VCS_UNABLE_CONNECT, e);
}
}
use of com.orion.ops.entity.domain.ApplicationVcsDO in project orion-ops by lijiahangmax.
the class ApplicationVcsServiceImpl method cleanBuildVcs.
@Override
public void cleanBuildVcs(Long id) {
// 查询数据
ApplicationVcsDO vcs = applicationVcsDAO.selectById(id);
Valid.notNull(vcs, MessageConst.UNKNOWN_DATA);
// 设置日志参数
EventParamsHolder.addParam(EventKeys.ID, id);
EventParamsHolder.addParam(EventKeys.NAME, vcs.getVcsName());
File rootPath = new File(Files1.getPath(SystemEnvAttr.VCS_PATH.getValue(), id + Const.EMPTY));
if (!Files1.isDirectory(rootPath)) {
return;
}
// 查询文件夹
File[] files = rootPath.listFiles(e -> !e.getName().equals(Const.EVENT) && e.isDirectory() && Strings.isInteger(e.getName()));
if (Arrays1.isEmpty(files)) {
return;
}
// 保留两个版本 防止清空正在进行中的构建任务
int length = files.length;
if (length <= 2) {
return;
}
Arrays.sort(files, Comparator.comparing(s -> Integer.parseInt(s.getName())));
for (int i = 0; i < length - 2; i++) {
Files1.delete(files[i]);
}
}
use of com.orion.ops.entity.domain.ApplicationVcsDO in project orion-ops by lijiahangmax.
the class ApplicationVcsServiceImpl method addAppVcs.
@Override
public Long addAppVcs(ApplicationVcsRequest request) {
// 检查名称是否存在
this.checkNamePresent(null, request.getName());
// 插入
ApplicationVcsDO insert = new ApplicationVcsDO();
insert.setVcsName(request.getName());
insert.setVcsDescription(request.getDescription());
insert.setVcsType(VcsType.GIT.getType());
insert.setVscUrl(request.getUrl());
insert.setVscUsername(request.getUsername());
insert.setVcsAuthType(request.getAuthType());
insert.setVcsTokenType(request.getTokenType());
// 加密密码
String password = request.getPassword();
if (!Strings.isBlank(password)) {
password = ValueMix.encrypt(password);
insert.setVcsPassword(password);
}
// 加密token
String token = request.getPrivateToken();
if (!Strings.isBlank(token)) {
token = ValueMix.encrypt(token);
insert.setVcsPrivateToken(token);
}
insert.setVcsStatus(VcsStatus.UNINITIALIZED.getStatus());
applicationVcsDAO.insert(insert);
// 设置日志参数
EventParamsHolder.addParams(insert);
return insert.getId();
}
use of com.orion.ops.entity.domain.ApplicationVcsDO in project orion-ops by lijiahangmax.
the class ApplicationVcsServiceImpl method deleteAppVcs.
@Override
public Integer deleteAppVcs(Long id) {
ApplicationVcsDO beforeVcs = applicationVcsDAO.selectById(id);
Valid.notNull(beforeVcs, MessageConst.UNKNOWN_DATA);
// 清空app引用
applicationInfoDAO.cleanVcsCount(id);
// 删除
int effect = applicationVcsDAO.deleteById(id);
// 设置日志参数
EventParamsHolder.addParam(EventKeys.ID, id);
EventParamsHolder.addParam(EventKeys.NAME, beforeVcs.getVcsName());
return effect;
}
Aggregations