Skip to content

Commit 3c17fc6

Browse files
committed
Bug fixing for pipeline run. Looks already ok :-)
1 parent 70ca7eb commit 3c17fc6

File tree

5 files changed

+113
-67
lines changed

5 files changed

+113
-67
lines changed

frontend/client/views/overview/index.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export default {
6969
.get('/api/v1/pipelines/start/' + pipelineid)
7070
.then(response => {
7171
if (response.data) {
72-
this.$router.push({path: '/pipelines/detail', query: { pipelineid: pipelineid, runid: response.data.id }})
72+
this.$router.push({path: '/pipelines/detail', query: { pipelineid: pipelineid, runid: response.data.id }})
7373
}
7474
})
7575
.catch(error => {

frontend/client/views/pipelines/detail.vue

+89-61
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,41 @@ export default {
1919
2020
data () {
2121
return {
22-
pipelineView: null
22+
pipelineView: null,
23+
nodes: null,
24+
edges: null,
25+
lastRedraw: false,
26+
pipelineViewOptions: {
27+
physics: { stabilization: true },
28+
layout: {
29+
hierarchical: {
30+
enabled: true,
31+
levelSeparation: 200,
32+
direction: 'LR',
33+
sortMethod: 'directed'
34+
}
35+
},
36+
nodes: {
37+
borderWidth: 4,
38+
size: 40,
39+
color: {
40+
border: '#222222'
41+
},
42+
font: { color: '#eeeeee' }
43+
},
44+
edges: {
45+
smooth: {
46+
type: 'cubicBezier',
47+
forceDirection: 'vertical',
48+
roundness: 0.4
49+
},
50+
color: {
51+
color: 'whitesmoke',
52+
highlight: '#4da2fc'
53+
},
54+
arrows: {to: true}
55+
}
56+
}
2357
}
2458
},
2559
@@ -43,26 +77,37 @@ export default {
4377
// runID is optional
4478
var runID = this.$route.query.runid
4579
46-
// Get all information from this specific pipeline
47-
var pipeline = null
48-
this.$http
49-
.get('/api/v1/pipelines/detail/' + pipelineID)
50-
.then(response => {
51-
this.pipeline = response.data
52-
})
53-
5480
// If runid was set, look up this run
55-
var pipelineRun = null
5681
if (runID) {
57-
this.$http
58-
.get('/api/v1/pipelines/detail/' + pipelineID + '/' + runID)
59-
.then(response => {
60-
this.pipelineRun = response.data
82+
// Run ID specified. Do concurrent request
83+
this.$http.all([this.getPipeline(pipelineID), this.getPipelineRun(pipelineID, runID)])
84+
.then(this.$http.spread(function (pipeline, pipelineRun) {
85+
// We only redraw the pipeline if pipeline is running
86+
if (pipelineRun.data.status !== 'running' && !this.lastRedraw) {
87+
this.drawPipelineDetail(pipeline.data, pipelineRun.data)
88+
this.lastRedraw = true
89+
} else if (pipelineRun.data.status === 'running') {
90+
this.lastRedraw = false
91+
this.drawPipelineDetail(pipeline.data, pipelineRun.data)
92+
}
93+
}.bind(this)))
94+
} else {
95+
this.getPipeline(pipelineID)
96+
.then((response) => {
97+
if (!this.lastRedraw) {
98+
this.drawPipelineDetail(response.data, null)
99+
this.lastRedraw = true
100+
}
61101
})
62102
}
103+
},
104+
105+
getPipeline (pipelineID) {
106+
return this.$http.get('/api/v1/pipelines/detail/' + pipelineID, { showProgressBar: false })
107+
},
63108
64-
// Draw pipeline view
65-
this.drawPipelineDetail(pipeline, pipelineRun)
109+
getPipelineRun (pipelineID, runID) {
110+
return this.$http.get('/api/v1/pipelines/detail/' + pipelineID + '/' + runID, { showProgressBar: false })
66111
},
67112
68113
drawPipelineDetail (pipeline, pipelineRun) {
@@ -73,23 +118,25 @@ export default {
73118
} else {
74119
jobs = pipeline.jobs
75120
}
76-
77-
// prepare data object for vis
78-
var data = {
79-
nodes: [],
80-
edges: []
81-
}
121+
console.log(pipeline)
122+
console.log(pipelineRun)
123+
console.log(jobs)
124+
// Initiate data structure
125+
var nodesArray = []
126+
var edgesArray = []
82127
83128
// Iterate all jobs of the pipeline
84129
for (let i = 0, l = jobs.length; i < l; i++) {
85130
// Choose the image for this node
86131
var nodeImage = require('assets/questionmark.png')
87132
if (jobs[i].status) {
88133
switch (jobs[i].status) {
89-
case 'success':
134+
case 'success':
90135
nodeImage = require('assets/success.png')
136+
break
91137
case 'failed':
92-
nodeImage = require('assets/failed.png')
138+
nodeImage = require('assets/fail.png')
139+
break
93140
}
94141
}
95142
@@ -102,7 +149,7 @@ export default {
102149
}
103150
104151
// Add node to nodes list
105-
data.nodes.push(node)
152+
nodesArray.push(node)
106153
107154
// Iterate all jobs again to find the next highest job priority
108155
var highestPrio = null
@@ -123,53 +170,34 @@ export default {
123170
}
124171
125172
// add edge to edges list
126-
data.edges.push(edge)
173+
edgesArray.push(edge)
127174
}
128175
}
129176
}
130177
}
131178
132-
// Define vis options
133-
var options = {
134-
physics: { stabilization: true },
135-
layout: {
136-
hierarchical: {
137-
enabled: true,
138-
levelSeparation: 200,
139-
direction: 'LR',
140-
sortMethod: 'directed'
141-
}
142-
},
143-
nodes: {
144-
borderWidth: 4,
145-
size: 40,
146-
color: {
147-
border: '#222222'
148-
},
149-
font: { color: '#eeeeee' }
150-
},
151-
edges: {
152-
smooth: {
153-
type: 'cubicBezier',
154-
forceDirection: 'vertical',
155-
roundness: 0.4
156-
},
157-
color: {
158-
color: 'whitesmoke',
159-
highlight: '#4da2fc'
160-
},
161-
arrows: {to: true}
162-
}
163-
}
164-
165179
// If pipelineView already exist, just update it
166180
if (this.pipelineView) {
167181
// Redraw
168-
this.pipelineView.Redraw()
182+
this.nodes.clear()
183+
this.edges.clear()
184+
this.nodes.add(nodesArray)
185+
this.edges.add(edgesArray)
186+
this.pipelineView.stabilize()
169187
} else {
188+
// translate to vis data structure
189+
this.nodes = new Vis.DataSet(nodesArray)
190+
this.edges = new Vis.DataSet(edgesArray)
191+
192+
// prepare data object for vis
193+
var data = {
194+
nodes: this.nodes,
195+
edges: this.edges
196+
}
197+
170198
// Find container
171199
var container = document.getElementById('pipeline-detail')
172-
this.pipelineView = new Vis.Network(container, data, options)
200+
this.pipelineView = new Vis.Network(container, data, this.pipelineViewOptions)
173201
}
174202
}
175203
}

gaia.go

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ const (
4747

4848
// JobFailed status
4949
JobFailed JobStatus = "failed"
50+
51+
// JobRunning status
52+
JobRunning JobStatus = "running"
5053
)
5154

5255
// User is the user object

handlers/handler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ func InitHandlers(i *iris.Application, store *store.Store, scheduler *scheduler.
4949
i.Post(p+"pipelines/name", PipelineNameAvailable)
5050
i.Get(p+"pipelines", PipelineGetAll)
5151
i.Get(p+"pipelines/detail/{id:string}", PipelineGet)
52+
i.Get(p+"pipelines/detail/{pipelineid:string}/{runid:string}", PipelineRunGet)
5253
i.Get(p+"pipelines/start/{id:string}", PipelineStart)
53-
i.Get(p+"pipelines/run/{pipelineid:string}/{runid:string}", PipelineRunGet)
5454

5555
return nil
5656
}

scheduler/scheduler.go

+19-4
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,20 @@ func (s *Scheduler) SchedulePipeline(p *gaia.Pipeline) (*gaia.PipelineRun, error
155155
// increment by one
156156
highestID++
157157

158+
// Get jobs
159+
jobs, err := s.getPipelineJobs(p)
160+
if err != nil {
161+
gaia.Cfg.Logger.Error("cannot get pipeline jobs during schedule", "error", err.Error(), "pipeline", p)
162+
return nil, err
163+
}
164+
158165
// Create new not scheduled pipeline run
159166
run := gaia.PipelineRun{
160167
UniqueID: uuid.Must(uuid.NewV4()).String(),
161168
ID: highestID,
162169
PipelineID: p.ID,
163170
ScheduleDate: time.Now(),
171+
Jobs: jobs,
164172
Status: gaia.RunNotScheduled,
165173
}
166174

@@ -170,8 +178,7 @@ func (s *Scheduler) SchedulePipeline(p *gaia.Pipeline) (*gaia.PipelineRun, error
170178

171179
// executePipeline executes the given pipeline and updates it status periodically.
172180
func (s *Scheduler) executePipeline(p *gaia.Pipeline, r *gaia.PipelineRun) {
173-
// Set pessimistic values
174-
r.Status = gaia.RunFailed
181+
// Set start time
175182
r.RunDate = time.Now()
176183

177184
// Get all jobs
@@ -181,6 +188,7 @@ func (s *Scheduler) executePipeline(p *gaia.Pipeline, r *gaia.PipelineRun) {
181188
gaia.Cfg.Logger.Error("cannot get pipeline jobs before execution", "error", err.Error())
182189

183190
// Update store
191+
r.Status = gaia.RunFailed
184192
s.storeService.PipelinePutRun(r)
185193
return
186194
}
@@ -210,13 +218,14 @@ func executeJob(job *gaia.Job, p *gaia.Pipeline, wg *sync.WaitGroup, triggerSave
210218
return
211219
}
212220

213-
// Lets be pessimistic
214-
job.Status = gaia.JobFailed
221+
// Set Job to running
222+
job.Status = gaia.JobRunning
215223

216224
// Create the start command for the pipeline
217225
c := createPipelineCmd(p)
218226
if c == nil {
219227
gaia.Cfg.Logger.Debug("cannot execute pipeline job", "error", errCreateCMDForPipeline.Error(), "job", job)
228+
job.Status = gaia.JobFailed
220229
return
221230
}
222231

@@ -226,6 +235,7 @@ func executeJob(job *gaia.Job, p *gaia.Pipeline, wg *sync.WaitGroup, triggerSave
226235
// Connect to plugin(pipeline)
227236
if err := pC.Connect(); err != nil {
228237
gaia.Cfg.Logger.Debug("cannot connect to pipeline", "error", err.Error(), "pipeline", p)
238+
job.Status = gaia.JobFailed
229239
return
230240
}
231241
defer pC.Close()
@@ -234,6 +244,7 @@ func executeJob(job *gaia.Job, p *gaia.Pipeline, wg *sync.WaitGroup, triggerSave
234244
if err := pC.Execute(job); err != nil {
235245
// TODO: Show it to user
236246
gaia.Cfg.Logger.Debug("error during job execution", "error", err.Error(), "job", job)
247+
job.Status = gaia.JobFailed
237248
}
238249

239250
// If we are here, the job execution was ok
@@ -287,6 +298,8 @@ func (s *Scheduler) scheduleJobsByPriority(r *gaia.PipelineRun, p *gaia.Pipeline
287298
for _, job := range r.Jobs {
288299
switch job.Status {
289300
case gaia.JobFailed:
301+
r.Status = gaia.RunFailed
302+
s.storeService.PipelinePutRun(r)
290303
return
291304
case gaia.JobWaitingExec:
292305
notExecJob = true
@@ -295,6 +308,8 @@ func (s *Scheduler) scheduleJobsByPriority(r *gaia.PipelineRun, p *gaia.Pipeline
295308

296309
// All jobs have been executed
297310
if !notExecJob {
311+
r.Status = gaia.RunSuccess
312+
s.storeService.PipelinePutRun(r)
298313
return
299314
}
300315

0 commit comments

Comments
 (0)