diff --git a/src/backend/analyst/api-analyst/src/main/kotlin/com/tencent/bkrepo/analyst/message/ScannerMessageCode.kt b/src/backend/analyst/api-analyst/src/main/kotlin/com/tencent/bkrepo/analyst/message/ScannerMessageCode.kt index d9c2233c04..8366c568ce 100644 --- a/src/backend/analyst/api-analyst/src/main/kotlin/com/tencent/bkrepo/analyst/message/ScannerMessageCode.kt +++ b/src/backend/analyst/api-analyst/src/main/kotlin/com/tencent/bkrepo/analyst/message/ScannerMessageCode.kt @@ -58,7 +58,8 @@ enum class ScannerMessageCode( EXPORT_REPORT_STATUS_UN_QUALITY("export.report.status.un.quality", 26), EXPORT_REPORT_STATUS_QUALITY_PASS("export.report.status.quality.pass", 27), EXPORT_REPORT_STATUS_QUALITY_UN_PASS("export.report.status.quality.un.pass", 28), - EXPORT_REPORT_STATUS_FAILED("export.report.status.failed", 29); + EXPORT_REPORT_STATUS_FAILED("export.report.status.failed", 29), + ANALYST_ARTIFACT_DELETED("analyst.artifact.deleted", 30); override fun getBusinessCode() = businessCode override fun getKey() = key diff --git a/src/backend/analyst/biz-analyst/src/main/kotlin/com/tencent/bkrepo/analyst/exception/ArtifactDeletedException.kt b/src/backend/analyst/biz-analyst/src/main/kotlin/com/tencent/bkrepo/analyst/exception/ArtifactDeletedException.kt new file mode 100644 index 0000000000..e934185fab --- /dev/null +++ b/src/backend/analyst/biz-analyst/src/main/kotlin/com/tencent/bkrepo/analyst/exception/ArtifactDeletedException.kt @@ -0,0 +1,34 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.tencent.bkrepo.analyst.exception + +import com.tencent.bkrepo.analyst.message.ScannerMessageCode +import com.tencent.bkrepo.common.api.exception.ErrorCodeException + +class ArtifactDeletedException(val sha256: String) : + ErrorCodeException(ScannerMessageCode.ANALYST_ARTIFACT_DELETED, sha256) diff --git a/src/backend/analyst/biz-analyst/src/main/kotlin/com/tencent/bkrepo/analyst/service/impl/TemporaryScanTokenServiceImpl.kt b/src/backend/analyst/biz-analyst/src/main/kotlin/com/tencent/bkrepo/analyst/service/impl/TemporaryScanTokenServiceImpl.kt index 3755f4a926..63a66516f8 100644 --- a/src/backend/analyst/biz-analyst/src/main/kotlin/com/tencent/bkrepo/analyst/service/impl/TemporaryScanTokenServiceImpl.kt +++ b/src/backend/analyst/biz-analyst/src/main/kotlin/com/tencent/bkrepo/analyst/service/impl/TemporaryScanTokenServiceImpl.kt @@ -29,12 +29,15 @@ package com.tencent.bkrepo.analyst.service.impl import com.tencent.bkrepo.analyst.configuration.ScannerProperties import com.tencent.bkrepo.analyst.configuration.ScannerProperties.Companion.EXPIRED_SECONDS +import com.tencent.bkrepo.analyst.exception.ArtifactDeletedException import com.tencent.bkrepo.analyst.pojo.SubScanTask +import com.tencent.bkrepo.analyst.pojo.request.ReportResultRequest import com.tencent.bkrepo.analyst.service.ScanService import com.tencent.bkrepo.analyst.service.TemporaryScanTokenService import com.tencent.bkrepo.auth.api.ServiceTemporaryTokenClient import com.tencent.bkrepo.auth.pojo.token.TemporaryTokenCreateRequest import com.tencent.bkrepo.auth.pojo.token.TokenType +import com.tencent.bkrepo.common.analysis.pojo.scanner.SubScanTaskStatus import com.tencent.bkrepo.common.analysis.pojo.scanner.standard.FileUrl import com.tencent.bkrepo.common.analysis.pojo.scanner.standard.StandardScanner import com.tencent.bkrepo.common.analysis.pojo.scanner.standard.ToolInput @@ -125,7 +128,13 @@ class TemporaryScanTokenServiceImpl( } override fun getToolInput(subtaskId: String, token: String): ToolInput { - return getToolInput(scanService.get(subtaskId).apply { this.token = token }) + try { + return getToolInput(scanService.get(subtaskId).apply { this.token = token }) + } catch (e: ArtifactDeletedException) { + logger.warn("artifact [${e.sha256}] was deleted, set subtask[$subtaskId] to failed") + scanService.reportResult(ReportResultRequest(subtaskId, SubScanTaskStatus.FAILED.name)) + throw e + } } override fun pullToolInput(executionCluster: String, token: String): ToolInput? { @@ -133,7 +142,13 @@ class TemporaryScanTokenServiceImpl( return subtask?.let { logger.info("executionCluster[$executionCluster] pull subtask[${it.taskId}]") subtask.token = token - getToolInput(it) + try { + getToolInput(it) + } catch (e: ArtifactDeletedException) { + logger.warn("artifact [${e.sha256}] was deleted, set subtask[${it.taskId}] to failed") + scanService.reportResult(ReportResultRequest(it.taskId, SubScanTaskStatus.FAILED.name)) + null + } } } @@ -221,11 +236,15 @@ class TemporaryScanTokenServiceImpl( .build() ) - if (res.isNotOk() || res.data!!.records.isEmpty()) { + if (res.isNotOk()) { logger.error("get node of layer[$it] failed, msg[${res.message}]") throw SystemErrorException() } + if (res.data!!.records.isEmpty()) { + throw ArtifactDeletedException(it) + } + res.data!!.records.first() } } diff --git a/src/backend/analyst/biz-analyst/src/main/kotlin/com/tencent/bkrepo/analyst/statemachine/subtask/action/FinishSubtaskAction.kt b/src/backend/analyst/biz-analyst/src/main/kotlin/com/tencent/bkrepo/analyst/statemachine/subtask/action/FinishSubtaskAction.kt index 6916a27162..54b03b0d22 100644 --- a/src/backend/analyst/biz-analyst/src/main/kotlin/com/tencent/bkrepo/analyst/statemachine/subtask/action/FinishSubtaskAction.kt +++ b/src/backend/analyst/biz-analyst/src/main/kotlin/com/tencent/bkrepo/analyst/statemachine/subtask/action/FinishSubtaskAction.kt @@ -104,7 +104,7 @@ class FinishSubtaskAction( require(context is FinishSubtaskContext) with(context) { if (targetState != SubScanTaskStatus.SUCCESS.name) { - logger.error( + logger.warn( "task[${subtask.parentScanTaskId}], subtask[${subtask.id}], " + "scan failed: $scanExecutorResult" ) diff --git a/src/backend/analyst/biz-analyst/src/main/resources/i18n/messages_en.properties b/src/backend/analyst/biz-analyst/src/main/resources/i18n/messages_en.properties index 998713b72c..5849d09068 100644 --- a/src/backend/analyst/biz-analyst/src/main/resources/i18n/messages_en.properties +++ b/src/backend/analyst/biz-analyst/src/main/resources/i18n/messages_en.properties @@ -52,3 +52,4 @@ export.report.status.un.quality=no quality rules set export.report.status.quality.pass=quality rules passed export.report.status.quality.un.pass=quality rule failed export.report.status.failed=scan anomalies +analyst.artifact.deleted=Artifact [{0}] was deleted diff --git a/src/backend/analyst/biz-analyst/src/main/resources/i18n/messages_zh_CN.properties b/src/backend/analyst/biz-analyst/src/main/resources/i18n/messages_zh_CN.properties index 595acab509..fb922c710f 100644 --- a/src/backend/analyst/biz-analyst/src/main/resources/i18n/messages_zh_CN.properties +++ b/src/backend/analyst/biz-analyst/src/main/resources/i18n/messages_zh_CN.properties @@ -52,3 +52,4 @@ export.report.status.un.quality=未设置质量规则 export.report.status.quality.pass=质量规则通过 export.report.status.quality.un.pass=质量规则未通过 export.report.status.failed=扫描异常 +analyst.artifact.deleted=制品 [{0}] 已被删除 diff --git a/src/backend/analyst/biz-analyst/src/main/resources/i18n/messages_zh_TW.properties b/src/backend/analyst/biz-analyst/src/main/resources/i18n/messages_zh_TW.properties index 2589e354f3..10cec731a8 100644 --- a/src/backend/analyst/biz-analyst/src/main/resources/i18n/messages_zh_TW.properties +++ b/src/backend/analyst/biz-analyst/src/main/resources/i18n/messages_zh_TW.properties @@ -52,4 +52,4 @@ export.report.status.un.quality=未設置質量規則 export.report.status.quality.pass=質量規則通過 export.report.status.quality.un.pass=質量規則未通過 export.report.status.failed=掃描異常 - +analyst.artifact.deleted=製品 [{0}] 已刪除