use of com.orion.ops.entity.domain.ApplicationVcsDO in project orion-ops by lijiahangmax.
the class CleanVcsStatusRunner method cleanInitializing.
/**
* 清空初始化中的数据
*/
private void cleanInitializing() {
LambdaQueryWrapper<ApplicationVcsDO> wrapper = new LambdaQueryWrapper<ApplicationVcsDO>().eq(ApplicationVcsDO::getVcsStatus, VcsStatus.INITIALIZING.getStatus());
List<ApplicationVcsDO> vcsList = applicationVcsDAO.selectList(wrapper);
for (ApplicationVcsDO vcs : vcsList) {
Long id = vcs.getId();
// 更新状态
ApplicationVcsDO update = new ApplicationVcsDO();
update.setId(id);
update.setVcsStatus(VcsStatus.UNINITIALIZED.getStatus());
applicationVcsDAO.updateById(update);
// 删除文件夹
File clonePath = new File(Utils.getVcsEventDir(id));
Files1.delete(clonePath);
log.info("重置版本仓库状态-重置 id: {}, clonePath: {}", id, clonePath);
}
}
use of com.orion.ops.entity.domain.ApplicationVcsDO in project orion-ops by lijiahangmax.
the class ApplicationVcsServiceImpl method initEventVcs.
@Override
public void initEventVcs(Long id, boolean isReInit) {
// 查询数据
ApplicationVcsDO vcs = applicationVcsDAO.selectById(id);
Valid.notNull(vcs, MessageConst.UNKNOWN_DATA);
// 判断状态
if (VcsStatus.INITIALIZING.getStatus().equals(vcs.getVcsStatus())) {
throw Exceptions.runtime(MessageConst.VCS_INITIALIZING);
} else if (VcsStatus.OK.getStatus().equals(vcs.getVcsStatus()) && !isReInit) {
throw Exceptions.runtime(MessageConst.VCS_INITIALIZED);
} else if (!VcsStatus.OK.getStatus().equals(vcs.getVcsStatus()) && isReInit) {
throw Exceptions.runtime(MessageConst.VCS_UNINITIALIZED);
}
// 修改状态
ApplicationVcsDO update = new ApplicationVcsDO();
update.setId(id);
update.setVcsStatus(VcsStatus.INITIALIZING.getStatus());
applicationVcsDAO.updateById(update);
// 删除
File clonePath = new File(Utils.getVcsEventDir(id));
Files1.delete(clonePath);
// 初始化
Exception ex = null;
Gits gits = null;
try {
// clone
String[] pair = this.getVcsUsernamePassword(vcs);
String username = pair[0];
String password = pair[1];
if (username == null) {
gits = Gits.clone(vcs.getVscUrl(), clonePath);
} else {
gits = Gits.clone(vcs.getVscUrl(), clonePath, username, password);
}
} catch (Exception e) {
ex = e;
} finally {
Streams.close(gits);
}
// 修改状态
if (ex == null) {
update.setVcsStatus(VcsStatus.OK.getStatus());
} else {
Files1.delete(clonePath);
update.setVcsStatus(VcsStatus.ERROR.getStatus());
}
applicationVcsDAO.updateById(update);
// 设置日志参数
EventParamsHolder.addParam(EventKeys.ID, id);
EventParamsHolder.addParam(EventKeys.NAME, vcs.getVcsName());
if (ex != null) {
throw Exceptions.argument(MessageConst.VCS_INIT_ERROR, ex);
}
}
use of com.orion.ops.entity.domain.ApplicationVcsDO in project orion-ops by lijiahangmax.
the class ApplicationVcsServiceImpl method updateAppVcs.
@Override
public Integer updateAppVcs(ApplicationVcsRequest request) {
Long id = request.getId();
// 检查名称是否存在
this.checkNamePresent(id, request.getName());
// 查询修改前的数据
ApplicationVcsDO beforeVcs = applicationVcsDAO.selectById(id);
Valid.notNull(beforeVcs, MessageConst.UNKNOWN_DATA);
// 更新
ApplicationVcsDO update = new ApplicationVcsDO();
update.setId(id);
update.setVcsName(request.getName());
update.setVcsDescription(request.getDescription());
update.setVscUrl(request.getUrl());
update.setVscUsername(request.getUsername());
update.setVcsAuthType(request.getAuthType());
update.setVcsTokenType(request.getTokenType());
// 加密密码
String password = request.getPassword();
if (!Strings.isBlank(password)) {
password = ValueMix.encrypt(password);
update.setVcsPassword(password);
}
// 加密token
String token = request.getPrivateToken();
if (!Strings.isBlank(token)) {
token = ValueMix.encrypt(token);
update.setVcsPrivateToken(token);
}
if (!beforeVcs.getVscUrl().equals(update.getVscUrl())) {
// 如果修改了url则状态改为未初始化
update.setVcsStatus(VcsStatus.UNINITIALIZED.getStatus());
// 删除目录
File clonePath = new File(Utils.getVcsEventDir(id));
Files1.delete(clonePath);
}
int effect = applicationVcsDAO.updateById(update);
// 设置日志参数
EventParamsHolder.addParams(update);
EventParamsHolder.addParam(EventKeys.NAME, beforeVcs.getVcsName());
return effect;
}
use of com.orion.ops.entity.domain.ApplicationVcsDO in project orion-ops by lijiahangmax.
the class CheckoutActionHandler method handler.
@Override
protected void handler() {
ApplicationVcsDO vcs = applicationVcsService.selectById(store.getVcsId());
// 查询分支
String fullBranchName = store.getBranchName();
String remote = fullBranchName.substring(0, fullBranchName.indexOf("/"));
String branchName = fullBranchName.substring(fullBranchName.indexOf("/") + 1);
String commitId = store.getCommitId();
// 拼接日志
String log = "*** 检出url: " + vcs.getVscUrl() + "\n" + "*** 分支: " + fullBranchName + "\n" + "*** commit: " + commitId + "\n" + "*** 检出目录: " + store.getVcsClonePath() + "\n" + "*** 检出中...\n";
this.appendLog(log);
// clone
try {
CloneCommand clone = Git.cloneRepository().setURI(vcs.getVscUrl()).setDirectory(new File(store.getVcsClonePath())).setRemote(remote).setBranch(branchName);
// 设置密码
String[] pair = applicationVcsService.getVcsUsernamePassword(vcs);
String username = pair[0];
String password = pair[1];
if (username != null) {
clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password));
}
this.git = clone.call();
this.appendLog("*** 检出完成\n");
} catch (Exception e) {
throw Exceptions.vcs(MessageConst.CHECKOUT_ERROR, e);
}
// 已停止则关闭
if (terminated) {
return;
}
// reset
try {
git.reset().setMode(ResetCommand.ResetType.HARD).setRef(commitId).call();
} catch (Exception e) {
throw Exceptions.vcs(MessageConst.RESET_ERROR, e);
}
}
use of com.orion.ops.entity.domain.ApplicationVcsDO in project orion-ops by lijiahangmax.
the class ApplicationVcsServiceImpl method syncVcsStatus.
@Override
@Transactional(rollbackFor = Exception.class)
public void syncVcsStatus() {
List<ApplicationVcsDO> vcsList = applicationVcsDAO.selectList(new LambdaQueryWrapper<>());
for (ApplicationVcsDO vcs : vcsList) {
Long id = vcs.getId();
File vcsPath = new File(Utils.getVcsEventDir(id));
boolean isDir = Files1.isDirectory(vcsPath);
// 更新状态
ApplicationVcsDO update = new ApplicationVcsDO();
update.setId(id);
update.setVcsStatus(isDir ? VcsStatus.OK.getStatus() : VcsStatus.UNINITIALIZED.getStatus());
update.setUpdateTime(new Date());
applicationVcsDAO.updateById(update);
}
}
Aggregations