Search in sources :

Example 1 with ApplicationVcsDO

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);
    }
}
Also used : ApplicationVcsDO(com.orion.ops.entity.domain.ApplicationVcsDO) File(java.io.File)

Example 2 with ApplicationVcsDO

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);
    }
}
Also used : Gits(com.orion.vcs.git.Gits) ApplicationVcsDO(com.orion.ops.entity.domain.ApplicationVcsDO) File(java.io.File)

Example 3 with ApplicationVcsDO

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;
}
Also used : ApplicationVcsDO(com.orion.ops.entity.domain.ApplicationVcsDO) File(java.io.File)

Example 4 with ApplicationVcsDO

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);
    }
}
Also used : CloneCommand(org.eclipse.jgit.api.CloneCommand) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) ApplicationVcsDO(com.orion.ops.entity.domain.ApplicationVcsDO) File(java.io.File)

Example 5 with ApplicationVcsDO

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);
    }
}
Also used : ApplicationVcsDO(com.orion.ops.entity.domain.ApplicationVcsDO) File(java.io.File) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ApplicationVcsDO (com.orion.ops.entity.domain.ApplicationVcsDO)11 File (java.io.File)8 Gits (com.orion.vcs.git.Gits)3 Transactional (org.springframework.transaction.annotation.Transactional)2 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)1 DataGrid (com.orion.lang.wrapper.DataGrid)1 Const (com.orion.ops.consts.Const)1 MessageConst (com.orion.ops.consts.MessageConst)1 VcsAuthType (com.orion.ops.consts.app.VcsAuthType)1 VcsStatus (com.orion.ops.consts.app.VcsStatus)1 VcsTokenType (com.orion.ops.consts.app.VcsTokenType)1 VcsType (com.orion.ops.consts.app.VcsType)1 EventKeys (com.orion.ops.consts.event.EventKeys)1 EventParamsHolder (com.orion.ops.consts.event.EventParamsHolder)1 SystemEnvAttr (com.orion.ops.consts.system.SystemEnvAttr)1 ApplicationBuildDAO (com.orion.ops.dao.ApplicationBuildDAO)1 ApplicationInfoDAO (com.orion.ops.dao.ApplicationInfoDAO)1 ApplicationVcsDAO (com.orion.ops.dao.ApplicationVcsDAO)1 ApplicationVcsRequest (com.orion.ops.entity.request.ApplicationVcsRequest)1 ApplicationVcsBranchVO (com.orion.ops.entity.vo.ApplicationVcsBranchVO)1