Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb8a6922

Browse files
committed
Implemented output of all logs in the backend
1 parentff4c926 commitb8a6922

File tree

2 files changed

+83
-21
lines changed

2 files changed

+83
-21
lines changed

‎frontend/client/views/pipeline/detail.vue‎

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
<divclass="tile is-ancestor">
33
<divclass="tile is-vertical">
44
<divclass="tile is-parent">
5-
<aclass="button is-primary"@click="jobLog"style="margin-right:10px;">
5+
<aclass="button is-primary"@click="startPipeline(pipelineID)"style="margin-right:10px;">
66
<spanclass="icon">
77
<iclass="fa fa-play-circle"></i>
88
</span>
99
<span>Start Pipeline</span>
1010
</a>
11-
<aclass="button is-green-button"@click="jobLog">
11+
<aclass="button is-green-button"@click="jobLog"v-if="runID">
1212
<spanclass="icon">
1313
<iclass="fa fa-terminal"></i>
1414
</span>
@@ -19,17 +19,6 @@
1919
<divclass="tile">
2020
<divclass="tile is-vertical is-parent is-12">
2121
<articleclass="tile is-child notification content-article">
22-
<divv-if="job">
23-
<aclass="button is-primary"@click="jobLog">
24-
<spanclass="icon">
25-
<iclass="fa fa-terminal"></i>
26-
</span>
27-
<span>Show Job log</span>
28-
</a>
29-
<p>
30-
Job: {{ job }}
31-
</p>
32-
</div>
3322
<divid="pipeline-detail"></div>
3423
</article>
3524
</div>
@@ -362,6 +351,21 @@ export default {
362351
363352
jobLog () {
364353
this.$router.push({path:'/pipeline/log', query: { pipelineid:this.pipelineID, runid:this.runID, jobid:this.job.internalID }})
354+
},
355+
356+
startPipeline (pipelineid) {
357+
// Send start request
358+
this.$http
359+
.post('/api/v1/pipeline/'+ pipelineid+'/start')
360+
.then(response=> {
361+
if (response.data) {
362+
this.$router.push({path:'/pipeline/detail', query: { pipelineid: pipelineid, runid:response.data.id }})
363+
}
364+
})
365+
.catch((error)=> {
366+
this.$store.commit('clearIntervals')
367+
this.$onError(error)
368+
})
365369
}
366370
}
367371

‎handlers/pipeline_run.go‎

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/http"
77
"os"
88
"path/filepath"
9+
"sort"
910
"strconv"
1011

1112
"github.com/gaia-pipeline/gaia"
@@ -21,6 +22,7 @@ const (
2122
typejobLogsstruct {
2223
Logstring`json:"log"`
2324
StartPosint`json:"start"`
25+
Finishedbool`json:"finished"`
2426
}
2527

2628
// PipelineRunGet returns details about a specific pipeline run.
@@ -68,6 +70,7 @@ func PipelineGetAllRuns(c echo.Context) error {
6870
}
6971

7072
// GetJobLogs returns logs and new start position for the given job.
73+
// If no jobID is given, a collection of all jobs logs will be returned.
7174
//
7275
// Required parameters:
7376
// pipelineid - Related pipeline id
@@ -95,32 +98,87 @@ func GetJobLogs(c echo.Context) error {
9598
returnc.String(http.StatusBadRequest,fmt.Sprintf("invalid maxbufferlen provided. Max number is %d",maxMaxBufferLen))
9699
}
97100

101+
// Transform pipelineid to int
102+
p,err:=strconv.Atoi(pipelineID)
103+
iferr!=nil {
104+
returnc.String(http.StatusBadRequest,"invalid pipeline id given")
105+
}
106+
107+
// Transform pipelinerunid to int
108+
r,err:=strconv.Atoi(pipelineRunID)
109+
iferr!=nil {
110+
returnc.String(http.StatusBadRequest,"invalid pipeline run id given")
111+
}
112+
113+
// Get pipeline run from store
114+
run,err:=storeService.PipelineGetRunByPipelineIDAndID(p,r)
115+
iferr!=nil {
116+
returnc.String(http.StatusBadRequest,"cannot find pipeline run with given pipeline id and pipeline run id")
117+
}
118+
119+
// jobID is not empty, just return the logs from this job
120+
ifjobID!="" {
121+
for_,job:=rangerun.Jobs {
122+
ifstrconv.FormatUint(uint64(job.ID),10)==jobID {
123+
// Get logs
124+
jL,err:=getLogs(pipelineID,pipelineRunID,jobID,startPos,maxBufferLen)
125+
iferr!=nil {
126+
returnc.String(http.StatusBadRequest,err.Error())
127+
}
128+
129+
returnc.JSON(http.StatusOK,*jL)
130+
}
131+
}
132+
133+
// Logs for given job id not found
134+
returnc.String(http.StatusBadRequest,"cannot find job with given job id")
135+
}
136+
137+
// Sort the slice. This is important for the order of the returned logs.
138+
sort.Slice(run.Jobs,func(i,jint)bool {
139+
returnrun.Jobs[i].Priority<run.Jobs[j].Priority
140+
})
141+
142+
// Return a collection of all logs
143+
jobs:= []jobLogs{}
144+
for_,job:=rangerun.Jobs {
145+
// Get logs
146+
jL,err:=getLogs(pipelineID,pipelineRunID,strconv.FormatUint(uint64(job.ID),10),startPos,maxBufferLen)
147+
iferr!=nil {
148+
returnc.String(http.StatusBadRequest,err.Error())
149+
}
150+
151+
jobs=append(jobs,*jL)
152+
}
153+
154+
// Return logs
155+
returnc.JSON(http.StatusOK,jobs)
156+
}
157+
158+
funcgetLogs(pipelineID,pipelineRunID,jobIDstring,startPos,maxBufferLenint) (*jobLogs,error) {
98159
// Lookup log file
99160
logFilePath:=filepath.Join(gaia.Cfg.WorkspacePath,pipelineID,pipelineRunID,gaia.LogsFolderName,jobID)
100161
if_,err:=os.Stat(logFilePath);os.IsNotExist(err) {
101-
returnc.String(http.StatusNotFound,errLogNotFound.Error())
162+
returnnil,err
102163
}
103164

104165
// Open file
105166
file,err:=os.Open(logFilePath)
106167
iferr!=nil {
107-
returnc.String(http.StatusInternalServerError,err.Error())
168+
returnnil,err
108169
}
109170
deferfile.Close()
110171

111172
// Read file
112173
buf:=make([]byte,maxBufferLen)
113174
bytesRead,err:=file.ReadAt(buf,int64(startPos))
114175
iferr!=io.EOF&&err!=nil {
115-
returnc.String(http.StatusInternalServerError,err.Error())
176+
returnnil,err
116177
}
117178

118179
// Create return struct
119-
j:=jobLogs{
180+
return&jobLogs{
120181
Log:string(buf[:]),
121182
StartPos:startPos+bytesRead,
122-
}
123-
124-
// Return logs
125-
returnc.JSON(http.StatusOK,j)
183+
},nil
126184
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp