Skip to content

Commit

Permalink
add header info in api run-log (#1004)
Browse files Browse the repository at this point in the history
  • Loading branch information
yudong2015 authored Oct 11, 2023
1 parent 182ea83 commit 6834bd0
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 18 deletions.
4 changes: 2 additions & 2 deletions pkg/client/devops/fake/fakedevops.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ func (d *Devops) DownloadArtifact(projectName, pipelineName, runId, filename str
return nil, nil
}

func (d *Devops) GetRunLog(projectName, pipelineName, runId string, httpParameters *devops.HttpParameters) ([]byte, error) {
return nil, nil
func (d *Devops) GetRunLog(projectName, pipelineName, runId string, httpParameters *devops.HttpParameters) ([]byte, http.Header, error) {
return nil, nil, nil
}
func (d *Devops) GetStepLog(projectName, pipelineName, runId, nodeId, stepId string, httpParameters *devops.HttpParameters) ([]byte, http.Header, error) {
return nil, nil, nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/devops/fake/fakedevops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ func TestNotImplement(t *testing.T) {
assertNils(t, o1, o2)
o1, o2 = client.DownloadArtifact("", "", "", "", false, "")
assertNils(t, o1, o2)
o1, o2 = client.GetRunLog("", "", "", nil)
assertNils(t, o1, o2)
o1, o2, o3 = client.GetRunLog("", "", "", nil)
assertNils(t, o1, o2, o3)
o1, o2, o3 = client.GetStepLog("", "", "", "", "", nil)
assertNils(t, o1, o2, o3)
o1, o2 = client.RunPipeline("", "", nil)
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/devops/jclient/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (j *JenkinsClient) DownloadArtifact(projectName, pipelineName, runID, filen
}

// GetRunLog returns the log output of a pipeline run
func (j *JenkinsClient) GetRunLog(projectName, pipelineName, runID string, httpParameters *devops.HttpParameters) ([]byte, error) {
func (j *JenkinsClient) GetRunLog(projectName, pipelineName, runID string, httpParameters *devops.HttpParameters) ([]byte, http.Header, error) {
return j.jenkins.GetRunLog(projectName, pipelineName, runID, httpParameters)
}

Expand Down
5 changes: 2 additions & 3 deletions pkg/client/devops/jenkins/jenkins.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,13 @@ func (j *Jenkins) GetArtifacts(projectName, pipelineName, runId string, httpPara
return res, err
}

func (j *Jenkins) GetRunLog(projectName, pipelineName, runId string, httpParameters *devops.HttpParameters) ([]byte, error) {
func (j *Jenkins) GetRunLog(projectName, pipelineName, runId string, httpParameters *devops.HttpParameters) ([]byte, http.Header, error) {
PipelineOjb := &Pipeline{
HttpParameters: httpParameters,
Jenkins: j,
Path: fmt.Sprintf(GetRunLogUrl+httpParameters.Url.RawQuery, projectName, pipelineName, runId),
}
res, err := PipelineOjb.GetRunLog()
return res, err
return PipelineOjb.GetRunLog()
}

func (j *Jenkins) GetStepLog(projectName, pipelineName, runId, nodeId, stepId string, httpParameters *devops.HttpParameters) ([]byte, http.Header, error) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/client/devops/jenkins/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,13 @@ func (p *Pipeline) GetArtifacts() ([]devops.Artifacts, error) {
return artifacts, err
}

func (p *Pipeline) GetRunLog() ([]byte, error) {
res, err := p.Jenkins.SendPureRequest(p.Path, p.HttpParameters)
func (p *Pipeline) GetRunLog() ([]byte, http.Header, error) {
res, header, err := p.Jenkins.SendPureRequestWithHeaderResp(p.Path, p.HttpParameters)
if err != nil {
klog.Error(err)
}

return res, err
return res, header, err
}

func (p *Pipeline) GetStepLog() ([]byte, http.Header, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/devops/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ type PipelineOperator interface {
RunPipeline(projectName, pipelineName string, httpParameters *HttpParameters) (*RunPipeline, error)
GetArtifacts(projectName, pipelineName, runId string, httpParameters *HttpParameters) ([]Artifacts, error)
DownloadArtifact(projectName, pipelineName, runId, filename string, isMultiBranch bool, branchName string) (io.ReadCloser, error)
GetRunLog(projectName, pipelineName, runId string, httpParameters *HttpParameters) ([]byte, error)
GetRunLog(projectName, pipelineName, runId string, httpParameters *HttpParameters) ([]byte, http.Header, error)
GetStepLog(projectName, pipelineName, runId, nodeId, stepId string, httpParameters *HttpParameters) ([]byte, http.Header, error)
GetNodeSteps(projectName, pipelineName, runId, nodeId string, httpParameters *HttpParameters) ([]NodeSteps, error)
GetPipelineRunNodes(projectName, pipelineName, runId string, httpParameters *HttpParameters) ([]PipelineRunNodes, error)
Expand Down
8 changes: 7 additions & 1 deletion pkg/kapis/devops/v1alpha2/devops.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,18 @@ func (h *ProjectPipelineHandler) GetRunLog(req *restful.Request, resp *restful.R
pipelineName := req.PathParameter("pipeline")
runId := req.PathParameter("run")

res, err := h.devopsOperator.GetRunLog(projectName, pipelineName, runId, req.Request)
res, header, err := h.devopsOperator.GetRunLog(projectName, pipelineName, runId, req.Request)
if err != nil {
parseErr(err, resp)
return
}

for k, v := range header {
if strings.HasPrefix(k, jenkinsHeaderPre) {
resp.AddHeader(k, v[0])
}
}

resp.Write(res)
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/models/devops/devops.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ type DevopsOperator interface {
ReplayPipeline(projectName, pipelineName, runId string, req *http.Request) (*devops.ReplayPipeline, error)
RunPipeline(projectName, pipelineName string, req *http.Request) (*devops.RunPipeline, error)
GetArtifacts(projectName, pipelineName, runId string, req *http.Request) ([]devops.Artifacts, error)
GetRunLog(projectName, pipelineName, runId string, req *http.Request) ([]byte, error)
GetRunLog(projectName, pipelineName, runId string, req *http.Request) ([]byte, http.Header, error)
GetStepLog(projectName, pipelineName, runId, nodeId, stepId string, req *http.Request) ([]byte, http.Header, error)
GetNodeSteps(projectName, pipelineName, runId, nodeId string, req *http.Request) ([]devops.NodeSteps, error)
GetPipelineRunNodes(projectName, pipelineName, runId string, req *http.Request) ([]devops.PipelineRunNodes, error)
Expand Down Expand Up @@ -550,15 +550,15 @@ func (d devopsOperator) GetArtifacts(projectName, pipelineName, runId string, re
return res, err
}

func (d devopsOperator) GetRunLog(projectName, pipelineName, runId string, req *http.Request) ([]byte, error) {
func (d devopsOperator) GetRunLog(projectName, pipelineName, runId string, req *http.Request) ([]byte, http.Header, error) {

res, err := d.devopsClient.GetRunLog(projectName, pipelineName, runId, convertToHttpParameters(req))
res, header, err := d.devopsClient.GetRunLog(projectName, pipelineName, runId, convertToHttpParameters(req))
if err != nil {
klog.Error(err)
return nil, err
return nil, nil, err
}

return res, err
return res, header, err
}

func (d devopsOperator) GetStepLog(projectName, pipelineName, runId, nodeId, stepId string, req *http.Request) ([]byte, http.Header, error) {
Expand Down

0 comments on commit 6834bd0

Please sign in to comment.