Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipeline parameters #71

Merged
merged 2 commits into from
Aug 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions cmd/gaia/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ func main() {
os.Exit(1)
}

// Initiating Vault
// Check Vault path
if gaia.Cfg.VaultPath == "" {
// Set default to data folder
gaia.Cfg.VaultPath = gaia.Cfg.DataPath
}
_, err = services.VaultService(nil)
if err != nil {
gaia.Cfg.Logger.Error("error initiating vault")
os.Exit(1)
}

// Initialize scheduler
_, err = services.SchedulerService()
if err != nil {
Expand All @@ -159,18 +171,6 @@ func main() {
os.Exit(1)
}

// Initiating Vault
// Check Vault path
if gaia.Cfg.VaultPath == "" {
// Set default to data folder
gaia.Cfg.VaultPath = gaia.Cfg.DataPath
}
_, err = services.VaultService(nil)
if err != nil {
gaia.Cfg.Logger.Error("error initiating vault")
os.Exit(1)
}

// Start ticker. Periodic job to check for new plugins.
pipeline.InitTicker()

Expand Down
5 changes: 5 additions & 0 deletions frontend/client/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export default new Router({
name: 'Pipeline Logs',
path: '/pipeline/log',
component: lazyLoading('pipeline/log')
},
{
name: 'Pipeline Parameters',
path: '/pipeline/params',
component: lazyLoading('pipeline/params')
}
]
})
Expand Down
29 changes: 23 additions & 6 deletions frontend/client/views/overview/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
unknown
</span><br />
<div class="pipelinegrid-footer">
<a class="button is-primary" @click="startPipeline(pipeline.p.id)" style="width: 250px;">
<a class="button is-primary" @click="checkPipelineArgs(pipeline.p)" style="width: 250px;">
<span class="icon">
<i class="fa fa-play-circle"></i>
</span>
Expand All @@ -52,7 +52,7 @@
</template>
<div v-if="pipelines.length == 0" class="no-pipelines-div">
<span class="no-pipelines-text">No pipelines are available. Please create a pipeline first.</span>
</div>
</div>
</div>
</template>

Expand All @@ -62,7 +62,8 @@ import moment from 'moment'
export default {
data () {
return {
pipelines: []
pipelines: [],
pipeline: null
}
},

Expand Down Expand Up @@ -102,13 +103,29 @@ export default {
})
},

startPipeline (pipelineid) {
checkPipelineArgs (pipeline) {
this.pipeline = pipeline

// check if this pipeline has args
for (let x = 0, y = pipeline.jobs.length; x < y; x++) {
if (pipeline.jobs[x].args && pipeline.jobs[x].args.type !== 'vault') {
// we found args. Redirect user to params view.
this.$router.push({path: '/pipeline/params', query: { pipelineid: pipeline.id }})
return
}
}

// No args. Just start pipeline.
this.startPipeline()
},

startPipeline () {
// Send start request
this.$http
.post('/api/v1/pipeline/' + pipelineid + '/start')
.post('/api/v1/pipeline/' + this.pipeline.id + '/start')
.then(response => {
if (response.data) {
this.$router.push({path: '/pipeline/detail', query: { pipelineid: pipelineid, runid: response.data.id }})
this.$router.push({path: '/pipeline/detail', query: { pipelineid: this.pipeline.id, runid: response.data.id }})
}
})
.catch((error) => {
Expand Down
28 changes: 22 additions & 6 deletions frontend/client/views/pipeline/detail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="tile is-ancestor">
<div class="tile is-vertical">
<div class="tile is-parent">
<a class="button is-primary" @click="startPipeline(pipelineID)" style="margin-right: 10px;">
<a class="button is-primary" @click="checkPipelineArgs" style="margin-right: 10px;">
<span class="icon">
<i class="fa fa-play-circle"></i>
</span>
Expand Down Expand Up @@ -120,7 +120,8 @@ export default {
},
arrows: {to: true}
}
}
},
pipeline: null
}
},

Expand Down Expand Up @@ -183,6 +184,7 @@ export default {
this.drawPipelineDetail(pipeline.data, pipelineRun.data)
}
this.runsRows = pipelineRuns.data
this.pipeline = pipeline.data
}.bind(this)))
.catch((error) => {
this.$store.commit('clearIntervals')
Expand All @@ -201,6 +203,7 @@ export default {
if (pipelineRuns.data) {
this.runsRows = pipelineRuns.data
}
this.pipeline = pipeline.data
}.bind(this)))
.catch((error) => {
this.$store.commit('clearIntervals')
Expand Down Expand Up @@ -355,13 +358,27 @@ export default {
this.$router.push({path: '/pipeline/log', query: { pipelineid: this.pipelineID, runid: this.runID }})
},

startPipeline (pipelineid) {
checkPipelineArgs () {
// check if this pipeline has args
for (let x = 0, y = this.pipeline.jobs.length; x < y; x++) {
if (this.pipeline.jobs[x].args && this.pipeline.jobs[x].args.type !== 'vault') {
// we found args. Redirect user to params view.
this.$router.push({path: '/pipeline/params', query: { pipelineid: this.pipeline.id }})
return
}
}

// No args. Just start pipeline.
this.startPipeline()
},

startPipeline () {
// Send start request
this.$http
.post('/api/v1/pipeline/' + pipelineid + '/start')
.post('/api/v1/pipeline/' + this.pipeline.id + '/start')
.then(response => {
if (response.data) {
this.$router.push({path: '/pipeline/detail', query: { pipelineid: pipelineid, runid: response.data.id }})
this.$router.push({path: '/pipeline/detail', query: { pipelineid: this.pipeline.id, runid: response.data.id }})
}
})
.catch((error) => {
Expand All @@ -370,7 +387,6 @@ export default {
})
}
}

}
</script>

Expand Down
118 changes: 118 additions & 0 deletions frontend/client/views/pipeline/params.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<template>
<div>
<div class="columns is-multiline">
<template v-for="(arg, index) in args">
<div class="column is-one-third" :key="index">
<div class="content-article params-div">
<h2 v-if="arg.type !== 'boolean'">{{ arg.desc }}</h2>
<p class="control" style="padding-bottom: 5px;" v-if="arg.type === 'textfield'">
<input class="input is-medium input-bar" v-focus v-model="arg.value" :placeholder="arg.key">
</p>
<p class="control" v-else-if="arg.type === 'textarea'">
<textarea class="textarea input-bar" v-model="arg.value" :placeholder="arg.key"></textarea>
</p>
<p class="control" v-else-if="arg.type === 'boolean'">
<label class="checkbox">
<input type="checkbox">
{{ arg.desc }}
</label>
</p>
</div>
</div>
</template>
</div>
<a class="button is-primary" v-on:click="startPipeline" style="margin-top: 5px;">
<span class="icon">
<i class="fa fa-play-circle"></i>
</span>
<span>Start Pipeline</span>
</a>
</div>
</template>

<script>
export default {
data () {
return {
args: [],
pipelineID: null
}
},

mounted () {
// Fetch data from backend
this.fetchData()
},

watch: {
'$route': 'fetchData'
},

methods: {
fetchData () {
// look up url parameters
var pipelineID = this.$route.query.pipelineid
if (!pipelineID) {
return
}
this.pipelineID = pipelineID

// reset args
this.args = []

this.$http
.get('/api/v1/pipeline/' + pipelineID, { showProgressBar: false })
.then(response => {
if (response.data) {
let pipeline = response.data

// Get all arguments
for (let x = 0, y = pipeline.jobs.length; x < y; x++) {
let args = pipeline.jobs[x].args
// we skip vault cause this is automatically filled by the vault.
if (args) {
// iterate all arguments
for (let argID = 0, argTotal = args.length; argID < argTotal; argID++) {
// we skip vault arguments cause they are autofilled in the backend.
if (args[argID].type !== 'vault') {
this.args.push(args[argID])
}
}
}
}
}
})
.catch((error) => {
this.$onError(error)
})
},

startPipeline () {
// Send start request
this.$http
.post('/api/v1/pipeline/' + this.pipelineID + '/start', this.args)
.then(response => {
if (response.data) {
this.$router.push({path: '/pipeline/detail', query: { pipelineid: this.pipelineID, runid: response.data.id }})
}
})
.catch((error) => {
this.$onError(error)
})
}
}
}
</script>

<style lang="scss">

.params-div {
padding: 15px;
width: 100%;
}

.checkbox:hover {
color: #4da2fc;
}

</style>
19 changes: 14 additions & 5 deletions gaia.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,20 @@ type GitRepo struct {

// Job represents a single job of a pipeline
type Job struct {
ID uint32 `json:"id,omitempty"`
Title string `json:"title,omitempty"`
Description string `json:"desc,omitempty"`
DependsOn []*Job `json:"dependson,omitempty"`
Status JobStatus `json:"status,omitempty"`
ID uint32 `json:"id,omitempty"`
Title string `json:"title,omitempty"`
Description string `json:"desc,omitempty"`
DependsOn []*Job `json:"dependson,omitempty"`
Status JobStatus `json:"status,omitempty"`
Args []Argument `json:"args,omitempty"`
}

// Argument represents a single argument of a job
type Argument struct {
Description string `json:"desc,omitempty"`
Type string `json:"type,omitempty"`
Key string `json:"key,omitempty"`
Value string `json:"value,omitempty"`
}

// CreatePipeline represents a pipeline which is not yet
Expand Down
8 changes: 7 additions & 1 deletion handlers/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,17 @@ func PipelineDelete(c echo.Context) error {
}

// PipelineStart starts a pipeline by the given id.
// It accepts arguments for the given pipeline.
// Afterwards it returns the created/scheduled pipeline run.
func PipelineStart(c echo.Context) error {
schedulerService, _ := services.SchedulerService()
pipelineIDStr := c.Param("pipelineid")

// Look for arguments.
// We do not check for errors here cause arguments are optional.
args := []gaia.Argument{}
c.Bind(&args)

// Convert string to int because id is int
pipelineID, err := strconv.Atoi(pipelineIDStr)
if err != nil {
Expand All @@ -255,7 +261,7 @@ func PipelineStart(c echo.Context) error {
}

if foundPipeline.Name != "" {
pipelineRun, err := schedulerService.SchedulePipeline(&foundPipeline)
pipelineRun, err := schedulerService.SchedulePipeline(&foundPipeline, args)
if err != nil {
return c.String(http.StatusBadRequest, err.Error())
} else if pipelineRun != nil {
Expand Down
2 changes: 1 addition & 1 deletion handlers/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type mockScheduleService struct {
err error
}

func (ms *mockScheduleService) SchedulePipeline(p *gaia.Pipeline) (*gaia.PipelineRun, error) {
func (ms *mockScheduleService) SchedulePipeline(p *gaia.Pipeline, args []gaia.Argument) (*gaia.PipelineRun, error) {
return ms.pipelineRun, ms.err
}

Expand Down
Loading