Skip to content

Commit

Permalink
Implemented status text for create pipeline history view
Browse files Browse the repository at this point in the history
  • Loading branch information
michelvocks committed Mar 12, 2018
1 parent 61f045e commit 2e2e24f
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 96 deletions.
8 changes: 7 additions & 1 deletion frontend/client/views/pipelines/create.vue
Expand Up @@ -96,7 +96,13 @@
styleClass="table table-own-bordered">
<template slot="table-row" slot-scope="props">
<td>{{ props.row.pipeline.name }}</td>
<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>
<td class="progress-bar-height">
<div class="progress-bar-middle" v-bind:class="{ blink: props.row.status < 100 }" v-if="props.row.statustype === 'running'">
<progress-bar :type="'info'" :size="'small'" :value="props.row.status" :max="100" :show-label="false"></progress-bar>
</div>
<div v-else-if="props.row.statustype === 'success'" style="color: green;">{{ props.row.statustype }}</div>
<div v-else style="color: red;">{{ props.row.statustype }}</div>
</td>
<td>{{ props.row.pipeline.type }}</td>
<td :title="props.row.created" v-tippy="{ arrow : true, animation : 'shift-away'}">{{ convertTime(props.row.created) }}</td>
</template>
Expand Down
26 changes: 20 additions & 6 deletions gaia.go
Expand Up @@ -10,6 +10,10 @@ import (
// PipelineType represents supported plugin types
type PipelineType string

// CreatePipelineType represents the different status types
// a create pipeline can have.
type CreatePipelineType string

// PipelineRunStatus represents the different status a run
// can have.
type PipelineRunStatus string
Expand All @@ -24,6 +28,15 @@ const (
// PTypeGolang golang plugin type
PTypeGolang PipelineType = "golang"

// CreatePipelineFailed status
CreatePipelineFailed CreatePipelineType = "failed"

// CreatePipelineRunning status
CreatePipelineRunning CreatePipelineType = "running"

// CreatePipelineSuccess status
CreatePipelineSuccess CreatePipelineType = "success"

// RunNotScheduled status
RunNotScheduled PipelineRunStatus = "not scheduled"

Expand Down Expand Up @@ -51,7 +64,7 @@ const (
// JobRunning status
JobRunning JobStatus = "running"

// Name of the logs folder in pipeline run folder
// LogsFolderName represents the Name of the logs folder in pipeline run folder
LogsFolderName = "logs"
)

Expand Down Expand Up @@ -99,11 +112,12 @@ type Job struct {
// CreatePipeline represents a pipeline which is not yet
// compiled.
type CreatePipeline struct {
ID string `json:"id,omitempty"`
Pipeline Pipeline `json:"pipeline,omitempty"`
Status int `json:"status,omitempty"`
Output string `json:"errmsg,omitempty"`
Created time.Time `json:"created,omitempty"`
ID string `json:"id,omitempty"`
Pipeline Pipeline `json:"pipeline,omitempty"`
Status int `json:"status,omitempty"`
StatusType CreatePipelineType `json:"statustype,omitempty"`
Output string `json:"errmsg,omitempty"`
Created time.Time `json:"created,omitempty"`
}

// PrivateKey represents a pem encoded private key
Expand Down
85 changes: 1 addition & 84 deletions handlers/pipeline.go
Expand Up @@ -32,15 +32,6 @@ var (
const (
// Split char to separate path from pipeline and name
pipelinePathSplitChar = "/"

// Percent of pipeline creation progress after git clone
pipelineCloneStatus = 25

// Percent of pipeline creation progress after compile process done
pipelineCompileStatus = 75

// Completed percent progress
pipelineCompleteStatus = 100
)

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

// Cloning the repo and compiling the pipeline will be done async
go createPipelineExecute(p)
}

// createPipelineExecute clones the given git repo and compiles
// the pipeline. After every step, the status will be stored.
// This method is designed to be called async.
func createPipelineExecute(p *gaia.CreatePipeline) {
// Define build process for the given type
bP := pipeline.NewBuildPipeline(p.Pipeline.Type)
if bP == nil {
// Pipeline type is not supported
gaia.Cfg.Logger.Debug("create pipeline failed. Pipeline type is not supported", "type", p.Pipeline.Type)
return
}

// Setup environment before cloning repo and command
err := bP.PrepareEnvironment(p)
if err != nil {
gaia.Cfg.Logger.Error("cannot prepare build", "error", err.Error())
return
}

// Clone git repo
err = pipeline.GitCloneRepo(&p.Pipeline.Repo)
if err != nil {
// Add error message and store
p.Output = err.Error()
storeService.CreatePipelinePut(p)
gaia.Cfg.Logger.Debug("cannot clone repo", "error", err.Error())
return
}

// Update status of our pipeline build
p.Status = pipelineCloneStatus
err = storeService.CreatePipelinePut(p)
if err != nil {
gaia.Cfg.Logger.Error("cannot put create pipeline into store", "error", err.Error())
return
}

// Run compile process
err = bP.ExecuteBuild(p)
if err != nil {
// Add error message and store
p.Output = err.Error()
storeService.CreatePipelinePut(p)
gaia.Cfg.Logger.Debug("cannot compile pipeline", "error", err.Error())
return
}

// Update status of our pipeline build
p.Status = pipelineCompileStatus
err = storeService.CreatePipelinePut(p)
if err != nil {
gaia.Cfg.Logger.Error("cannot put create pipeline into store", "error", err.Error())
return
}

// Copy compiled binary to plugins folder
err = bP.CopyBinary(p)
if err != nil {
// Add error message and store
p.Output = err.Error()
storeService.CreatePipelinePut(p)
gaia.Cfg.Logger.Debug("cannot copy compiled binary", "error", err.Error())
return
}

// Set create pipeline status to complete
p.Status = pipelineCompleteStatus
err = storeService.CreatePipelinePut(p)
if err != nil {
gaia.Cfg.Logger.Error("cannot put create pipeline into store", "error", err.Error())
return
}
go pipeline.CreatePipeline(p)
}

// CreatePipelineGetAll returns a json array of
Expand Down
96 changes: 96 additions & 0 deletions pipeline/create_pipeline.go
@@ -0,0 +1,96 @@
package pipeline

import (
"fmt"

"github.com/gaia-pipeline/gaia"
)

const (
// Percent of pipeline creation progress after git clone
pipelineCloneStatus = 25

// Percent of pipeline creation progress after compile process done
pipelineCompileStatus = 75

// Completed percent progress
pipelineCompleteStatus = 100
)

// CreatePipeline is the main function which executes step by step the creation
// of a plugin.
// After each step, the status is written to store and can be retrieved via API.
func CreatePipeline(p *gaia.CreatePipeline) {
// Set running status
p.StatusType = gaia.CreatePipelineSuccess

// Define build process for the given type
bP := newBuildPipeline(p.Pipeline.Type)
if bP == nil {
// Pipeline type is not supported
p.StatusType = gaia.CreatePipelineFailed
p.Output = fmt.Sprintf("create pipeline failed. Pipeline type is not supported %s is not supported", p.Pipeline.Type)
storeService.CreatePipelinePut(p)
return
}

// Setup environment before cloning repo and command
err := bP.PrepareEnvironment(p)
if err != nil {
p.StatusType = gaia.CreatePipelineFailed
p.Output = fmt.Sprintf("cannot prepare build: %s", err.Error())
storeService.CreatePipelinePut(p)
return
}

// Clone git repo
err = gitCloneRepo(&p.Pipeline.Repo)
if err != nil {
p.StatusType = gaia.CreatePipelineFailed
p.Output = fmt.Sprintf("cannot prepare build: %s", err.Error())
storeService.CreatePipelinePut(p)
return
}

// Update status of our pipeline build
p.Status = pipelineCloneStatus
err = storeService.CreatePipelinePut(p)
if err != nil {
gaia.Cfg.Logger.Error("cannot put create pipeline into store", "error", err.Error())
return
}

// Run compile process
err = bP.ExecuteBuild(p)
if err != nil {
p.StatusType = gaia.CreatePipelineFailed
p.Output = fmt.Sprintf("cannot compile pipeline: %s", err.Error())
storeService.CreatePipelinePut(p)
return
}

// Update status of our pipeline build
p.Status = pipelineCompileStatus
err = storeService.CreatePipelinePut(p)
if err != nil {
gaia.Cfg.Logger.Error("cannot put create pipeline into store", "error", err.Error())
return
}

// Copy compiled binary to plugins folder
err = bP.CopyBinary(p)
if err != nil {
p.StatusType = gaia.CreatePipelineFailed
p.Output = fmt.Sprintf("cannot copy compiled binary: %s", err.Error())
storeService.CreatePipelinePut(p)
return
}

// Set create pipeline status to complete
p.Status = pipelineCompleteStatus
err = storeService.CreatePipelinePut(p)
if err != nil {
gaia.Cfg.Logger.Error("cannot put create pipeline into store", "error", err.Error())
return
}
}
4 changes: 2 additions & 2 deletions pipeline/git.go
Expand Up @@ -73,9 +73,9 @@ func GitLSRemote(repo *gaia.GitRepo) error {
return nil
}

// GitCloneRepo clones the given repo to a local folder.
// gitCloneRepo clones the given repo to a local folder.
// The destination will be attached to the given repo obj.
func GitCloneRepo(repo *gaia.GitRepo) error {
func gitCloneRepo(repo *gaia.GitRepo) error {
// Check if credentials were provided
var auth transport.AuthMethod
if repo.Username != "" && repo.Password != "" {
Expand Down
2 changes: 1 addition & 1 deletion pipeline/git_test.go
Expand Up @@ -11,7 +11,7 @@ func TestGitCloneRepo(t *testing.T) {
repo := &gaia.GitRepo{
URL: "https://github.com/gaia-pipeline/gaia",
}
err := GitCloneRepo(repo)
err := gitCloneRepo(repo)
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions pipeline/pipeline.go
Expand Up @@ -54,9 +54,9 @@ var (
errMissingType = errors.New("couldnt find pipeline type definition")
)

// NewBuildPipeline creates a new build pipeline for the given
// newBuildPipeline creates a new build pipeline for the given
// pipeline type.
func NewBuildPipeline(t gaia.PipelineType) BuildPipeline {
func newBuildPipeline(t gaia.PipelineType) BuildPipeline {
var bP BuildPipeline

// Create build pipeline for given pipeline type
Expand Down

0 comments on commit 2e2e24f

Please sign in to comment.