Skip to content

Commit 2e2e24f

Browse files
committed
Implemented status text for create pipeline history view
1 parent 61f045e commit 2e2e24f

File tree

7 files changed

+129
-96
lines changed

7 files changed

+129
-96
lines changed

frontend/client/views/pipelines/create.vue

+7-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@
9696
styleClass="table table-own-bordered">
9797
<template slot="table-row" slot-scope="props">
9898
<td>{{ props.row.pipeline.name }}</td>
99-
<td class="progress-bar-height"><div class="progress-bar-middle" v-bind:class="{ blink: props.row.status < 100 }"><progress-bar :type="'info'" :size="'small'" :value="props.row.status" :max="100" :show-label="false"></progress-bar></div></td>
99+
<td class="progress-bar-height">
100+
<div class="progress-bar-middle" v-bind:class="{ blink: props.row.status < 100 }" v-if="props.row.statustype === 'running'">
101+
<progress-bar :type="'info'" :size="'small'" :value="props.row.status" :max="100" :show-label="false"></progress-bar>
102+
</div>
103+
<div v-else-if="props.row.statustype === 'success'" style="color: green;">{{ props.row.statustype }}</div>
104+
<div v-else style="color: red;">{{ props.row.statustype }}</div>
105+
</td>
100106
<td>{{ props.row.pipeline.type }}</td>
101107
<td :title="props.row.created" v-tippy="{ arrow : true, animation : 'shift-away'}">{{ convertTime(props.row.created) }}</td>
102108
</template>

gaia.go

+20-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import (
1010
// PipelineType represents supported plugin types
1111
type PipelineType string
1212

13+
// CreatePipelineType represents the different status types
14+
// a create pipeline can have.
15+
type CreatePipelineType string
16+
1317
// PipelineRunStatus represents the different status a run
1418
// can have.
1519
type PipelineRunStatus string
@@ -24,6 +28,15 @@ const (
2428
// PTypeGolang golang plugin type
2529
PTypeGolang PipelineType = "golang"
2630

31+
// CreatePipelineFailed status
32+
CreatePipelineFailed CreatePipelineType = "failed"
33+
34+
// CreatePipelineRunning status
35+
CreatePipelineRunning CreatePipelineType = "running"
36+
37+
// CreatePipelineSuccess status
38+
CreatePipelineSuccess CreatePipelineType = "success"
39+
2740
// RunNotScheduled status
2841
RunNotScheduled PipelineRunStatus = "not scheduled"
2942

@@ -51,7 +64,7 @@ const (
5164
// JobRunning status
5265
JobRunning JobStatus = "running"
5366

54-
// Name of the logs folder in pipeline run folder
67+
// LogsFolderName represents the Name of the logs folder in pipeline run folder
5568
LogsFolderName = "logs"
5669
)
5770

@@ -99,11 +112,12 @@ type Job struct {
99112
// CreatePipeline represents a pipeline which is not yet
100113
// compiled.
101114
type CreatePipeline struct {
102-
ID string `json:"id,omitempty"`
103-
Pipeline Pipeline `json:"pipeline,omitempty"`
104-
Status int `json:"status,omitempty"`
105-
Output string `json:"errmsg,omitempty"`
106-
Created time.Time `json:"created,omitempty"`
115+
ID string `json:"id,omitempty"`
116+
Pipeline Pipeline `json:"pipeline,omitempty"`
117+
Status int `json:"status,omitempty"`
118+
StatusType CreatePipelineType `json:"statustype,omitempty"`
119+
Output string `json:"errmsg,omitempty"`
120+
Created time.Time `json:"created,omitempty"`
107121
}
108122

109123
// PrivateKey represents a pem encoded private key

handlers/pipeline.go

+1-84
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,6 @@ var (
3232
const (
3333
// Split char to separate path from pipeline and name
3434
pipelinePathSplitChar = "/"
35-
36-
// Percent of pipeline creation progress after git clone
37-
pipelineCloneStatus = 25
38-
39-
// Percent of pipeline creation progress after compile process done
40-
pipelineCompileStatus = 75
41-
42-
// Completed percent progress
43-
pipelineCompleteStatus = 100
4435
)
4536

4637
// PipelineGitLSRemote checks for available git remote branches.
@@ -89,81 +80,7 @@ func CreatePipeline(ctx iris.Context) {
8980
}
9081

9182
// Cloning the repo and compiling the pipeline will be done async
92-
go createPipelineExecute(p)
93-
}
94-
95-
// createPipelineExecute clones the given git repo and compiles
96-
// the pipeline. After every step, the status will be stored.
97-
// This method is designed to be called async.
98-
func createPipelineExecute(p *gaia.CreatePipeline) {
99-
// Define build process for the given type
100-
bP := pipeline.NewBuildPipeline(p.Pipeline.Type)
101-
if bP == nil {
102-
// Pipeline type is not supported
103-
gaia.Cfg.Logger.Debug("create pipeline failed. Pipeline type is not supported", "type", p.Pipeline.Type)
104-
return
105-
}
106-
107-
// Setup environment before cloning repo and command
108-
err := bP.PrepareEnvironment(p)
109-
if err != nil {
110-
gaia.Cfg.Logger.Error("cannot prepare build", "error", err.Error())
111-
return
112-
}
113-
114-
// Clone git repo
115-
err = pipeline.GitCloneRepo(&p.Pipeline.Repo)
116-
if err != nil {
117-
// Add error message and store
118-
p.Output = err.Error()
119-
storeService.CreatePipelinePut(p)
120-
gaia.Cfg.Logger.Debug("cannot clone repo", "error", err.Error())
121-
return
122-
}
123-
124-
// Update status of our pipeline build
125-
p.Status = pipelineCloneStatus
126-
err = storeService.CreatePipelinePut(p)
127-
if err != nil {
128-
gaia.Cfg.Logger.Error("cannot put create pipeline into store", "error", err.Error())
129-
return
130-
}
131-
132-
// Run compile process
133-
err = bP.ExecuteBuild(p)
134-
if err != nil {
135-
// Add error message and store
136-
p.Output = err.Error()
137-
storeService.CreatePipelinePut(p)
138-
gaia.Cfg.Logger.Debug("cannot compile pipeline", "error", err.Error())
139-
return
140-
}
141-
142-
// Update status of our pipeline build
143-
p.Status = pipelineCompileStatus
144-
err = storeService.CreatePipelinePut(p)
145-
if err != nil {
146-
gaia.Cfg.Logger.Error("cannot put create pipeline into store", "error", err.Error())
147-
return
148-
}
149-
150-
// Copy compiled binary to plugins folder
151-
err = bP.CopyBinary(p)
152-
if err != nil {
153-
// Add error message and store
154-
p.Output = err.Error()
155-
storeService.CreatePipelinePut(p)
156-
gaia.Cfg.Logger.Debug("cannot copy compiled binary", "error", err.Error())
157-
return
158-
}
159-
160-
// Set create pipeline status to complete
161-
p.Status = pipelineCompleteStatus
162-
err = storeService.CreatePipelinePut(p)
163-
if err != nil {
164-
gaia.Cfg.Logger.Error("cannot put create pipeline into store", "error", err.Error())
165-
return
166-
}
83+
go pipeline.CreatePipeline(p)
16784
}
16885

16986
// CreatePipelineGetAll returns a json array of

pipeline/create_pipeline.go

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package pipeline
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/gaia-pipeline/gaia"
7+
)
8+
9+
const (
10+
// Percent of pipeline creation progress after git clone
11+
pipelineCloneStatus = 25
12+
13+
// Percent of pipeline creation progress after compile process done
14+
pipelineCompileStatus = 75
15+
16+
// Completed percent progress
17+
pipelineCompleteStatus = 100
18+
)
19+
20+
// CreatePipeline is the main function which executes step by step the creation
21+
// of a plugin.
22+
// After each step, the status is written to store and can be retrieved via API.
23+
func CreatePipeline(p *gaia.CreatePipeline) {
24+
// Set running status
25+
p.StatusType = gaia.CreatePipelineSuccess
26+
27+
// Define build process for the given type
28+
bP := newBuildPipeline(p.Pipeline.Type)
29+
if bP == nil {
30+
// Pipeline type is not supported
31+
p.StatusType = gaia.CreatePipelineFailed
32+
p.Output = fmt.Sprintf("create pipeline failed. Pipeline type is not supported %s is not supported", p.Pipeline.Type)
33+
storeService.CreatePipelinePut(p)
34+
return
35+
}
36+
37+
// Setup environment before cloning repo and command
38+
err := bP.PrepareEnvironment(p)
39+
if err != nil {
40+
p.StatusType = gaia.CreatePipelineFailed
41+
p.Output = fmt.Sprintf("cannot prepare build: %s", err.Error())
42+
storeService.CreatePipelinePut(p)
43+
return
44+
}
45+
46+
// Clone git repo
47+
err = gitCloneRepo(&p.Pipeline.Repo)
48+
if err != nil {
49+
p.StatusType = gaia.CreatePipelineFailed
50+
p.Output = fmt.Sprintf("cannot prepare build: %s", err.Error())
51+
storeService.CreatePipelinePut(p)
52+
return
53+
}
54+
55+
// Update status of our pipeline build
56+
p.Status = pipelineCloneStatus
57+
err = storeService.CreatePipelinePut(p)
58+
if err != nil {
59+
gaia.Cfg.Logger.Error("cannot put create pipeline into store", "error", err.Error())
60+
return
61+
}
62+
63+
// Run compile process
64+
err = bP.ExecuteBuild(p)
65+
if err != nil {
66+
p.StatusType = gaia.CreatePipelineFailed
67+
p.Output = fmt.Sprintf("cannot compile pipeline: %s", err.Error())
68+
storeService.CreatePipelinePut(p)
69+
return
70+
}
71+
72+
// Update status of our pipeline build
73+
p.Status = pipelineCompileStatus
74+
err = storeService.CreatePipelinePut(p)
75+
if err != nil {
76+
gaia.Cfg.Logger.Error("cannot put create pipeline into store", "error", err.Error())
77+
return
78+
}
79+
80+
// Copy compiled binary to plugins folder
81+
err = bP.CopyBinary(p)
82+
if err != nil {
83+
p.StatusType = gaia.CreatePipelineFailed
84+
p.Output = fmt.Sprintf("cannot copy compiled binary: %s", err.Error())
85+
storeService.CreatePipelinePut(p)
86+
return
87+
}
88+
89+
// Set create pipeline status to complete
90+
p.Status = pipelineCompleteStatus
91+
err = storeService.CreatePipelinePut(p)
92+
if err != nil {
93+
gaia.Cfg.Logger.Error("cannot put create pipeline into store", "error", err.Error())
94+
return
95+
}
96+
}

pipeline/git.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ func GitLSRemote(repo *gaia.GitRepo) error {
7373
return nil
7474
}
7575

76-
// GitCloneRepo clones the given repo to a local folder.
76+
// gitCloneRepo clones the given repo to a local folder.
7777
// The destination will be attached to the given repo obj.
78-
func GitCloneRepo(repo *gaia.GitRepo) error {
78+
func gitCloneRepo(repo *gaia.GitRepo) error {
7979
// Check if credentials were provided
8080
var auth transport.AuthMethod
8181
if repo.Username != "" && repo.Password != "" {

pipeline/git_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func TestGitCloneRepo(t *testing.T) {
1111
repo := &gaia.GitRepo{
1212
URL: "https://github.com/gaia-pipeline/gaia",
1313
}
14-
err := GitCloneRepo(repo)
14+
err := gitCloneRepo(repo)
1515
if err != nil {
1616
t.Fatal(err)
1717
}

pipeline/pipeline.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ var (
5454
errMissingType = errors.New("couldnt find pipeline type definition")
5555
)
5656

57-
// NewBuildPipeline creates a new build pipeline for the given
57+
// newBuildPipeline creates a new build pipeline for the given
5858
// pipeline type.
59-
func NewBuildPipeline(t gaia.PipelineType) BuildPipeline {
59+
func newBuildPipeline(t gaia.PipelineType) BuildPipeline {
6060
var bP BuildPipeline
6161

6262
// Create build pipeline for given pipeline type

0 commit comments

Comments
 (0)