Skip to content

Commit

Permalink
feat: 日志下载接口报错 TencentBlueKing#5757
Browse files Browse the repository at this point in the history
  • Loading branch information
yongyiduan committed Dec 10, 2021
1 parent feadcd4 commit 57c474a
Showing 1 changed file with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@

package com.tencent.devops.openapi.resources.apigw.v3

import com.tencent.devops.common.api.auth.AUTH_HEADER_USER_ID
import com.tencent.devops.common.api.pojo.Result
import com.tencent.devops.common.api.util.OkhttpUtils
import com.tencent.devops.common.client.Client
import com.tencent.devops.common.log.pojo.QueryLogStatus
import com.tencent.devops.common.web.RestResource
Expand All @@ -36,12 +38,18 @@ import com.tencent.devops.common.log.pojo.QueryLogs
import com.tencent.devops.openapi.api.apigw.v3.ApigwLogResourceV3
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.Response

@RestResource
class ApigwLogResourceV3Impl @Autowired constructor(
private val client: Client
) : ApigwLogResourceV3 {

@Value("\${gateway.url:#{null}}")
private val gatewayUrl: String? = ""

override fun getInitLogs(
appCode: String?,
apigwType: String?,
Expand Down Expand Up @@ -152,15 +160,20 @@ class ApigwLogResourceV3Impl @Autowired constructor(
"downloadLogs project[$projectId] pipelineId[$pipelineId] buildId[$buildId]" +
"jobId[$jobId] executeCount[$executeCount] tag[$tag] jobId[$jobId]"
)
return client.get(ServiceLogResource::class).downloadLogs(
userId = userId,
projectId = projectId,
pipelineId = pipelineId,
buildId = buildId,
tag = tag,
jobId = jobId,
executeCount = executeCount
)
val path = StringBuilder("http://$gatewayUrl/log/api/service/logs/")
path.append(projectId)
path.append("/$pipelineId/$buildId/download?executeCount=${executeCount ?: 1}")

if (!tag.isNullOrBlank()) path.append("&tag=$tag")
if (!jobId.isNullOrBlank()) path.append("&jobId=$jobId")

val response = OkhttpUtils.doLongGet(path.toString(), mapOf(AUTH_HEADER_USER_ID to userId))
return Response
.ok(response.body()!!.byteStream(), MediaType.APPLICATION_OCTET_STREAM_TYPE)
.header("content-disposition", "attachment; filename = $pipelineId-$buildId-log.txt")
.header("Cache-Control", "no-cache")
.header("X-DEVOPS-PROJECT-ID", "gitciproject")
.build()
}

override fun getLogMode(
Expand Down

0 comments on commit 57c474a

Please sign in to comment.