Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 日志下载接口报错 #5757 #5759

Merged
merged 2 commits into from
Dec 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("\${devopsGateway.api:#{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("$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