Skip to content

Commit 703718f

Browse files
committed
WIP job log view
1 parent a6daf05 commit 703718f

File tree

5 files changed

+60
-12
lines changed

5 files changed

+60
-12
lines changed

frontend/client/router/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default new Router({
2020
component: lazyLoading('pipelines/detail')
2121
},
2222
{
23-
name: 'Job Log',
23+
name: 'Logs',
2424
path: '/jobs/log',
2525
component: lazyLoading('jobs/log')
2626
}

frontend/client/views/jobs/log.vue

+30-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div class="job-log-view">
3-
<message :direction="'down'" :message="'This is a cool test and test and test and test and test and test'" :duration="0"></message>
3+
<message :direction="'down'" :message="logText" :duration="0"></message>
44
<div class="job-loading" v-if="jobRunning"></div>
55
</div>
66
</template>
@@ -11,14 +11,19 @@ import Message from 'vue-bulma-message'
1111
export default {
1212
data () {
1313
return {
14-
job: null,
14+
logText: '',
1515
jobRunning: true,
1616
runID: null,
17-
pipelineID: null
17+
pipelineID: null,
18+
jobID: null,
19+
startPos: 0
1820
}
1921
},
2022
2123
mounted () {
24+
// Reset log text
25+
this.logText = ''
26+
2227
// Fetch data from backend
2328
this.fetchData()
2429
@@ -38,18 +43,37 @@ export default {
3843
3944
methods: {
4045
fetchData () {
41-
// look up url parameters
46+
// look up required url parameters
4247
this.pipelineID = this.$route.query.pipelineid
4348
this.runID = this.$route.query.runid
4449
if (!this.runID || !this.pipelineID) {
4550
return
4651
}
4752
53+
// job id is optional. If ommitted, all logs from all jobs
54+
// are displayed.
55+
this.jobID = this.$route.query.jobID
56+
57+
// Maximum received bytes
58+
const bufferSize = 1024
4859
this.$http
49-
.get('/api/v1/pipelines', { showProgressBar: false })
60+
.get('/api/v1/jobs/log', {
61+
showProgressBar: false,
62+
params: {
63+
pipelineid: this.pipelineid,
64+
runid: this.runID,
65+
jobid: this.jobid,
66+
start: this.startPos,
67+
maxbufferlen: bufferSize
68+
}
69+
})
5070
.then(response => {
5171
if (response.data) {
52-
this.pipelines = response.data
72+
// We add the received log
73+
this.logText += response.data.log
74+
75+
// Set the new start position defined by return value
76+
this.startPos = response.data.start
5377
}
5478
})
5579
.catch((error) => {

frontend/client/views/pipelines/detail.vue

+11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
<div class="tile">
55
<div class="tile is-vertical is-parent is-12">
66
<article class="tile is-child notification content-article">
7+
<div v-if="job">
8+
<p>
9+
Job: {{ job }}
10+
</p>
11+
</div>
712
<div id="pipeline-detail"></div>
813
</article>
914
</div>
@@ -74,6 +79,7 @@ export default {
7479
}
7580
],
7681
runsRows: [],
82+
job: null,
7783
pipelineViewOptions: {
7884
physics: { stabilization: true },
7985
layout: {
@@ -305,6 +311,11 @@ export default {
305311
// Create vis network
306312
// We have to move out the instance out of vue because of https://github.com/almende/vis/issues/2567
307313
window.pipelineView = new Vis.Network(container, data, this.pipelineViewOptions)
314+
315+
// Create an selectNode event
316+
window.pipelineView.on('selectNode', function (params) {
317+
this.job = this.nodes.get(params.nodes[0])
318+
}.bind(this))
308319
}
309320
},
310321

handlers/handler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func InitHandlers(i *iris.Application, store *store.Store, scheduler *scheduler.
7979
i.Get(p+"pipelines/runs/{pipelineid:string}", PipelineGetAllRuns)
8080

8181
// Jobs
82-
i.Get(p+"jobs/log{pipelineid:int}{pipelinerunid:int}{jobid:int}{start:int}{maxbufferlen:int}", GetJobLogs)
82+
i.Get(p+"jobs/log{pipelineid}{pipelinerunid}{jobid}{start:int}{maxbufferlen:int}", GetJobLogs)
8383

8484
// Authentication Barrier
8585
i.UseGlobal(authBarrier)

handlers/job.go

+17-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@ const (
1313
maxMaxBufferLen = 1024
1414
)
1515

16-
// GetJobLogs returns logs for the given job with paging option.
16+
// jobLogs represents the json format which is returned
17+
// by GetJobLogs.
18+
type jobLogs struct {
19+
Log string `json:"log"`
20+
StartPos int `json:"start"`
21+
}
22+
23+
// GetJobLogs returns logs and new start position for the given job.
1724
//
1825
// Required parameters:
1926
// pipelineid - Related pipeline id
@@ -26,7 +33,7 @@ func GetJobLogs(ctx iris.Context) {
2633
pipelineID := ctx.Params().Get("pipelineid")
2734
pipelineRunID := ctx.Params().Get("pipelinerunid")
2835
jobID := ctx.Params().Get("jobid")
29-
startPos, err := ctx.Params().GetInt64("start")
36+
startPos, err := ctx.Params().GetInt("start")
3037
if err != nil {
3138
ctx.StatusCode(iris.StatusBadRequest)
3239
ctx.WriteString("invalid start position given")
@@ -58,13 +65,19 @@ func GetJobLogs(ctx iris.Context) {
5865

5966
// Read file
6067
buf := make([]byte, maxBufferLen)
61-
_, err = file.ReadAt(buf, startPos)
68+
bytesRead, err := file.ReadAt(buf, int64(startPos))
6269
if err != io.EOF && err != nil {
6370
ctx.StatusCode(iris.StatusInternalServerError)
6471
ctx.WriteString(err.Error())
6572
return
6673
}
6774

75+
// Create return struct
76+
j := jobLogs{
77+
Log: string(buf[:]),
78+
StartPos: startPos + bytesRead,
79+
}
80+
6881
// Return logs
69-
ctx.WriteString(string(buf[:]))
82+
ctx.JSON(j)
7083
}

0 commit comments

Comments
 (0)