diff --git a/scripts/deploy-codecc/bk-codecc-install.sh b/scripts/deploy-codecc/bk-codecc-install.sh index 703fe10a39d..4f1d04cc159 100755 --- a/scripts/deploy-codecc/bk-codecc-install.sh +++ b/scripts/deploy-codecc/bk-codecc-install.sh @@ -104,6 +104,10 @@ install_codecc__ms_common (){ done # 保持微服务部分子目录的强一致性. rsync -ra --delete "$BK_CODECC_SRC_DIR/$MS_NAME/lib" "$BK_CODECC_SRC_DIR/$MS_NAME/com" "$BK_CODECC_HOME/$MS_NAME" + # CodeCC启动jar包依赖顺序特殊调整 + mkdir -p $BK_CODECC_HOME/$MS_NAME/priority + ls -al $BK_CODECC_HOME/$MS_NAME/lib/|grep codecc-common 2>/dev/null && mv $BK_CODECC_HOME/$MS_NAME/lib/codecc-common-*.jar $BK_CODECC_HOME/$MS_NAME/priority/ + sed -i -e '/CLASSPATH/s/.*/CLASSPATH=\".:priority\/*:lib\/*\"/' $BK_CODECC_HOME/$MS_NAME/service.env } # 仅需复制frontend目录. @@ -178,4 +182,3 @@ else echo "INFO: using default installer for codecc micro-service." install_codecc__ms_common "$MS_NAME" "$@" fi - diff --git a/scripts/deploy-codecc/bkce-set-env03-codecc.sh b/scripts/deploy-codecc/bkce-set-env03-codecc.sh index 508f194fac5..290839c5f2c 100755 --- a/scripts/deploy-codecc/bkce-set-env03-codecc.sh +++ b/scripts/deploy-codecc/bkce-set-env03-codecc.sh @@ -18,6 +18,7 @@ codecc_env_03="./bin/03-userdef/codecc.env" set_env03 (){ for kv in "$@"; do + grep -qxF "$kv" "$codecc_env_default" 2>/dev/null || echo "$kv" >> "$codecc_env_default" if ! grep -q "^${kv%%=*}=[^ ]" "$codecc_env_03" 2>/dev/null; then # 非空则不覆盖. echo "SET_ENV03: $codecc_env_03 中未曾赋值,新增 $kv" [[ "$kv" =~ ^[A-Z0-9_]+=$ ]] && echo -e "\033[31;1m注意:\033[m$kv 赋值为空,请检查蓝鲸是否安装正确 @@ -86,4 +87,3 @@ fi echo "合并env." ./bin/merge_env.sh codecc &>/dev/null || true - diff --git a/src/backend/codecc/core/common/common-client/common-client-consul/src/main/kotlin/com/tencent/devops/common/client/ConsulClientAutoConfiguration.kt b/src/backend/codecc/core/common/common-client/common-client-consul/src/main/kotlin/com/tencent/devops/common/client/ConsulClientAutoConfiguration.kt index 5382b91248f..6968ee8e403 100644 --- a/src/backend/codecc/core/common/common-client/common-client-consul/src/main/kotlin/com/tencent/devops/common/client/ConsulClientAutoConfiguration.kt +++ b/src/backend/codecc/core/common/common-client/common-client-consul/src/main/kotlin/com/tencent/devops/common/client/ConsulClientAutoConfiguration.kt @@ -30,6 +30,8 @@ package com.tencent.devops.common.client import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_BK_TICKET import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_PROJECT_ID import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_USER_ID +import com.tencent.devops.common.client.discovery.ConsulDiscoveryUtils +import com.tencent.devops.common.client.discovery.DiscoveryUtils import com.tencent.devops.common.client.ms.ConsulServiceClient import com.tencent.devops.common.client.pojo.AllProperties import com.tencent.devops.common.client.proxy.DevopsProxy @@ -42,6 +44,7 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter import org.springframework.boot.autoconfigure.AutoConfigureOrder import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration +import org.springframework.cloud.client.serviceregistry.Registration import org.springframework.cloud.consul.discovery.ConsulDiscoveryClient import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration @@ -117,5 +120,9 @@ class ConsulClientAutoConfiguration { } } + @Bean + @ConditionalOnMissingBean(DiscoveryUtils::class) + fun discoveryUtils(@Autowired registration: Registration) = ConsulDiscoveryUtils(registration) + } diff --git a/src/backend/codecc/core/common/common-client/common-client-k8s/src/main/kotlin/com/tencent/devops/common/client/KubernetesClientAutoConfiguration.kt b/src/backend/codecc/core/common/common-client/common-client-k8s/src/main/kotlin/com/tencent/devops/common/client/KubernetesClientAutoConfiguration.kt index c0c362b637f..28b5d52a540 100644 --- a/src/backend/codecc/core/common/common-client/common-client-k8s/src/main/kotlin/com/tencent/devops/common/client/KubernetesClientAutoConfiguration.kt +++ b/src/backend/codecc/core/common/common-client/common-client-k8s/src/main/kotlin/com/tencent/devops/common/client/KubernetesClientAutoConfiguration.kt @@ -30,6 +30,8 @@ package com.tencent.devops.common.client import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_BK_TICKET import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_PROJECT_ID import com.tencent.devops.common.api.auth.AUTH_HEADER_DEVOPS_USER_ID +import com.tencent.devops.common.client.discovery.DiscoveryUtils +import com.tencent.devops.common.client.discovery.KubernetesDiscoveryUtils import com.tencent.devops.common.client.ms.KubernetesClient import com.tencent.devops.common.client.pojo.AllProperties import com.tencent.devops.common.client.proxy.DevopsProxy @@ -41,10 +43,13 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.autoconfigure.AutoConfigureAfter import org.springframework.boot.autoconfigure.AutoConfigureOrder import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean +import org.springframework.cloud.client.discovery.DiscoveryClient import org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration import org.springframework.cloud.kubernetes.client.discovery.KubernetesInformerDiscoveryClient import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration + +import com.tencent.devops.common.service.Profile import org.springframework.context.annotation.PropertySource import org.springframework.core.Ordered import org.springframework.web.context.request.RequestContextHolder @@ -118,4 +123,10 @@ class KubernetesClientAutoConfiguration { } } + @Bean + @ConditionalOnMissingBean(DiscoveryUtils::class) + fun discoveryUtils(@Autowired discoveryClient: DiscoveryClient, + @Autowired profile: Profile + ) = KubernetesDiscoveryUtils(discoveryClient,profile) + } diff --git a/src/backend/codecc/core/defect/biz-defect/src/main/java/com/tencent/bk/codecc/defect/service/AbstractQueryWarningBizService.java b/src/backend/codecc/core/defect/biz-defect/src/main/java/com/tencent/bk/codecc/defect/service/AbstractQueryWarningBizService.java index 629cd242ba2..81446c7ac1f 100644 --- a/src/backend/codecc/core/defect/biz-defect/src/main/java/com/tencent/bk/codecc/defect/service/AbstractQueryWarningBizService.java +++ b/src/backend/codecc/core/defect/biz-defect/src/main/java/com/tencent/bk/codecc/defect/service/AbstractQueryWarningBizService.java @@ -720,7 +720,7 @@ protected String getFileContent(long taskId, String projectId, String userId, St content = pipelineScmService.getFileContentOauth(oauthUserId, GitUtil.INSTANCE.getProjectName(url), relPath, (revision != null ? revision : branch)); - } else if(projectId.startsWith("git_") || projectId.startsWith("github_")){ + } else if (projectId != null && (projectId.startsWith("git_") || projectId.startsWith("github_"))) { content = pipelineScmService.getStreamFileContent(projectId, userId, url, relPath, revision, branch); }else { content = pipelineScmService.getFileContent(taskId, repoId, relPath, revision, branch, subModule, createFrom); diff --git a/src/backend/codecc/core/defect/biz-defect/src/main/java/com/tencent/bk/codecc/defect/service/impl/CCNQueryWarningBizServiceImpl.java b/src/backend/codecc/core/defect/biz-defect/src/main/java/com/tencent/bk/codecc/defect/service/impl/CCNQueryWarningBizServiceImpl.java index 97b49c9cf1b..08330624141 100644 --- a/src/backend/codecc/core/defect/biz-defect/src/main/java/com/tencent/bk/codecc/defect/service/impl/CCNQueryWarningBizServiceImpl.java +++ b/src/backend/codecc/core/defect/biz-defect/src/main/java/com/tencent/bk/codecc/defect/service/impl/CCNQueryWarningBizServiceImpl.java @@ -185,9 +185,15 @@ public CommonDefectDetailQueryRspVO processQueryWarningDetailRequest(long taskId // 校验传入的路径是否合法(路径是否是告警对应的文件) verifyFilePathIsValid(queryWarningDetailReq.getFilePath(), ccnDefectEntity.getFilePath()); + //获取任务信息 + Result taskInfoResult = client.get(ServiceTaskRestResource.class).getTaskInfoById(taskId); + TaskDetailVO taskDetailVO = taskInfoResult.getData(); + //根据文件路径从分析集群获取文件内容 - String content = getFileContent(taskId, null, userId, ccnDefectEntity.getUrl(), ccnDefectEntity.getRepoId(), - ccnDefectEntity.getRelPath(), ccnDefectEntity.getRevision(), ccnDefectEntity.getBranch(), ccnDefectEntity.getSubModule()); + String content = getFileContent(taskId, taskDetailVO == null ? null : taskDetailVO.getProjectId(), userId, + ccnDefectEntity.getUrl(), ccnDefectEntity.getRepoId(), + ccnDefectEntity.getRelPath(), ccnDefectEntity.getRevision(), ccnDefectEntity.getBranch(), + ccnDefectEntity.getSubModule()); content = trimCodeSegment(content, ccnDefectEntity.getStartLines(), ccnDefectEntity.getEndLines(), ccnDefectQueryRspVO); //设置代码评论 diff --git a/src/backend/codecc/core/defect/biz-defect/src/main/java/com/tencent/bk/codecc/defect/service/impl/DUPCQueryWarningBizServiceImpl.java b/src/backend/codecc/core/defect/biz-defect/src/main/java/com/tencent/bk/codecc/defect/service/impl/DUPCQueryWarningBizServiceImpl.java index 7cbde1eaac6..6606b4b5940 100644 --- a/src/backend/codecc/core/defect/biz-defect/src/main/java/com/tencent/bk/codecc/defect/service/impl/DUPCQueryWarningBizServiceImpl.java +++ b/src/backend/codecc/core/defect/biz-defect/src/main/java/com/tencent/bk/codecc/defect/service/impl/DUPCQueryWarningBizServiceImpl.java @@ -53,6 +53,7 @@ import com.tencent.bk.codecc.task.api.ServiceTaskRestResource; import com.tencent.bk.codecc.task.vo.TaskDetailVO; import com.tencent.devops.common.api.exception.CodeCCException; +import com.tencent.devops.common.api.pojo.Result; import com.tencent.devops.common.constant.ComConstants; import com.tencent.devops.common.constant.CommonMessageCode; import com.tencent.devops.common.service.BizServiceFactory; @@ -206,9 +207,14 @@ public CommonDefectDetailQueryRspVO processGetFileContentSegmentRequest(long tas throw new CodeCCException(CommonMessageCode.RECORD_NOT_EXITS, new String[]{"重复率的缺陷实体"}, null); } + //获取任务信息 + Result taskInfoResult = client.get(ServiceTaskRestResource.class).getTaskInfoById(taskId); + TaskDetailVO taskDetailVO = taskInfoResult.getData(); + // 1. 根据文件路径从分析集群获取文件内容 - String content = getFileContent(taskId, null, userId, dupcDefectEntity.getUrl(), dupcDefectEntity.getRepoId(), dupcDefectEntity.getRelPath(), - dupcDefectEntity.getRevision(), dupcDefectEntity.getBranch(), dupcDefectEntity.getSubModule()); + String content = getFileContent(taskId, taskDetailVO == null ? null : taskDetailVO.getProjectId(), userId, + dupcDefectEntity.getUrl(), dupcDefectEntity.getRepoId(), dupcDefectEntity.getRelPath(), + dupcDefectEntity.getRevision(), dupcDefectEntity.getBranch(), dupcDefectEntity.getSubModule()); // 2. 根据告警的开始行和结束行截取文件片段 CommonDefectDetailQueryRspVO dupcDefectQueryRspVO = new CommonDefectDetailQueryRspVO(); @@ -286,13 +292,16 @@ private CommonDefectDetailQueryRspVO getSourceCodeBlockDetail(long taskId, Strin // 校验传入的路径是否合法(路径是否是告警对应的文件) verifyFilePathIsValid(defectQueryReqVO.getFilePath(), dupcDefectEntity.getFilePath()); - + //获取任务信息 + Result taskInfoResult = client.get(ServiceTaskRestResource.class).getTaskInfoById(taskId); + TaskDetailVO taskDetailVO = taskInfoResult.getData(); //根据文件路径从分析集群获取文件内容 String content = ""; if (StringUtils.isNotBlank(dupcDefectEntity.getRelPath())) { - content = getFileContent(taskId, null, userId, dupcDefectEntity.getUrl(), dupcDefectEntity.getRepoId(), dupcDefectEntity.getRelPath(), - dupcDefectEntity.getRevision(), dupcDefectEntity.getBranch(), dupcDefectEntity.getSubModule()); + content = getFileContent(taskId, taskDetailVO == null ? null : taskDetailVO.getProjectId(), userId, + dupcDefectEntity.getUrl(), dupcDefectEntity.getRepoId(), dupcDefectEntity.getRelPath(), + dupcDefectEntity.getRevision(), dupcDefectEntity.getBranch(), dupcDefectEntity.getSubModule()); } List blockEntityList = dupcDefectEntity.getBlockList();