Search in sources :

Example 6 with ApplicationVcsDO

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

Example 7 with ApplicationVcsDO

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

Example 8 with ApplicationVcsDO

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]);
    }
}
Also used : EventKeys(com.orion.ops.consts.event.EventKeys) LogInfo(com.orion.vcs.git.info.LogInfo) Exceptions(com.orion.utils.Exceptions) java.util(java.util) ApplicationVcsCommitVO(com.orion.ops.entity.vo.ApplicationVcsCommitVO) ValueMix(com.orion.ops.utils.ValueMix) ApplicationVcsRequest(com.orion.ops.entity.request.ApplicationVcsRequest) ApplicationInfoDAO(com.orion.ops.dao.ApplicationInfoDAO) MessageConst(com.orion.ops.consts.MessageConst) ApplicationVcsBranchVO(com.orion.ops.entity.vo.ApplicationVcsBranchVO) EventParamsHolder(com.orion.ops.consts.event.EventParamsHolder) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) ApplicationVcsDAO(com.orion.ops.dao.ApplicationVcsDAO) VcsStatus(com.orion.ops.consts.app.VcsStatus) ApplicationBuildDAO(com.orion.ops.dao.ApplicationBuildDAO) ApplicationVcsInfoVO(com.orion.ops.entity.vo.ApplicationVcsInfoVO) Streams(com.orion.utils.io.Streams) Service(org.springframework.stereotype.Service) Arrays1(com.orion.utils.Arrays1) VcsAuthType(com.orion.ops.consts.app.VcsAuthType) Utils(com.orion.ops.utils.Utils) Const(com.orion.ops.consts.Const) DataGrid(com.orion.lang.wrapper.DataGrid) ApplicationVcsDO(com.orion.ops.entity.domain.ApplicationVcsDO) ApplicationVcsVO(com.orion.ops.entity.vo.ApplicationVcsVO) Resource(javax.annotation.Resource) BranchInfo(com.orion.vcs.git.info.BranchInfo) Valid(com.orion.ops.utils.Valid) File(java.io.File) Files1(com.orion.utils.io.Files1) DataQuery(com.orion.ops.utils.DataQuery) Converts(com.orion.utils.convert.Converts) Slf4j(lombok.extern.slf4j.Slf4j) VcsTokenType(com.orion.ops.consts.app.VcsTokenType) SystemEnvAttr(com.orion.ops.consts.system.SystemEnvAttr) ApplicationVcsService(com.orion.ops.service.api.ApplicationVcsService) VcsType(com.orion.ops.consts.app.VcsType) Strings(com.orion.utils.Strings) Gits(com.orion.vcs.git.Gits) Transactional(org.springframework.transaction.annotation.Transactional) ApplicationVcsDO(com.orion.ops.entity.domain.ApplicationVcsDO) File(java.io.File)

Example 9 with ApplicationVcsDO

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

Example 10 with ApplicationVcsDO

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

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