Skip to content

Commit

Permalink
Implemented getjobs and added it to ticker. Some more small stuff on ui
Browse files Browse the repository at this point in the history
  • Loading branch information
michelvocks committed Mar 6, 2018
1 parent b0c0634 commit d566d6d
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 19 deletions.
34 changes: 30 additions & 4 deletions frontend/client/views/overview/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
<div class="tile notification content-article">
<div class="status-display-success"></div>
<div class="outer-box">
<div class="outer-box-icon">
<i class="fa fa-2x fa-battery-full"></i>
<div class="outer-box-icon-image">
<img src="~assets/golang.png" class="outer-box-image">
</div>
<div>
<div class="name-link">
<a href="/" class="subtitle">Testpipeline</a>
</div>
<div style="padding-top: 10px;">
<div>
<hr style="color: lightgrey;">
this is some text ...
</div>
</div>
Expand Down Expand Up @@ -138,4 +139,29 @@ export default {
float: left;
}
.outer-box-icon-image {
float: left;
width: 40px;
height: 40px;
overflow: hidden;
border-radius: 50%;
position: relative;
border-color: whitesmoke;
border-style: solid;
margin-right: 10px;
}
.outer-box-image {
position: absolute;
width: 50px;
height: 50px;
top: 70%;
left: 50%;
transform: translate(-50%, -50%);
}
.name-link {
margin-top: 5px;
}
</style>
18 changes: 14 additions & 4 deletions gaia.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ type User struct {

// Pipeline represents a single pipeline
type Pipeline struct {
Name string `json:"name"`
Repo GitRepo `json:"repo"`
Type PipelineType `json:"type"`
Created time.Time `json:"created"`
Name string `json:"name"`
Repo GitRepo `json:"repo"`
Type PipelineType `json:"type"`
ExecPath string `json:"execpath"`
Jobs []Job `json:"jobs"`
Created time.Time `json:"created"`
}

// GitRepo represents a single git repository
Expand All @@ -46,6 +48,14 @@ type GitRepo struct {
LocalDest string
}

// Job represents a single job of a pipeline
type Job struct {
UniqueID string `json:"id"`
Title string `json:"title"`
Description string `json:"desc"`
Priority int32 `json:"priority"`
}

// CreatePipeline represents a pipeline which is not yet
// compiled.
type CreatePipeline struct {
Expand Down
22 changes: 22 additions & 0 deletions pipeline/pipeline.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package pipeline

import (
"errors"
"fmt"
"os/exec"
"sync"

"github.com/gaia-pipeline/gaia"
Expand Down Expand Up @@ -47,6 +49,10 @@ const (
var (
// GlobalActivePipelines holds globally all current active pipleines.
GlobalActivePipelines *ActivePipelines

// errMissingType is the error thrown when a pipeline is missing the type
// in the file name.
errMissingType = errors.New("couldnt find pipeline type definition")
)

// NewBuildPipeline creates a new build pipeline for the given
Expand All @@ -65,6 +71,22 @@ func NewBuildPipeline(t gaia.PipelineType) BuildPipeline {
return bP
}

// createPipelineCmd creates the execute command for the plugin system
// dependent on the plugin type.
func createPipelineCmd(p *gaia.Pipeline) *exec.Cmd {
c := &exec.Cmd{}

// Dependent on the pipeline type
switch p.Type {
case gaia.GOLANG:
c.Path = p.ExecPath
default:
c = nil
}

return c
}

// NewActivePipelines creates a new instance of ActivePipelines
func NewActivePipelines() *ActivePipelines {
ap := &ActivePipelines{
Expand Down
36 changes: 36 additions & 0 deletions pipeline/scheduler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package pipeline

import (
"github.com/gaia-pipeline/gaia"
"github.com/gaia-pipeline/gaia/plugin"
)

// setPipelineJobs uses the plugin system to get all
// jobs from the given pipeline.
// This function is blocking and might take some time.
func setPipelineJobs(p *gaia.Pipeline) {
// Create the start command for the pipeline
c := createPipelineCmd(p)
if c == nil {
gaia.Cfg.Logger.Debug("cannot set pipeline jobs", "error", errMissingType.Error(), "pipeline", p)
return
}

// Create new plugin instance
pC := plugin.NewPlugin(c)

// Connect to plugin(pipeline)
if err := pC.Connect(); err != nil {
gaia.Cfg.Logger.Debug("cannot connect to pipeline", "error", err.Error(), "pipeline", p)
return
}
defer pC.Close()

// Get jobs
jobs, err := pC.GetJobs()
if err != nil {
gaia.Cfg.Logger.Debug("cannot get jobs from pipeline", "error", err.Error(), "pipeline", p)
return
}
p.Jobs = jobs
}
18 changes: 8 additions & 10 deletions pipeline/ticker.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package pipeline

import (
"errors"
"io/ioutil"
"os"
"strings"
"time"

Expand All @@ -15,12 +15,6 @@ const (
tickerIntervalSeconds = 5
)

var (
// errMissingType is the error thrown when a pipeline is missing the type
// in the file name.
errMissingType = errors.New("couldnt find pipeline type definition")
)

// InitTicker inititates the pipeline ticker.
// This periodic job will check for new pipelines.
func InitTicker() {
Expand Down Expand Up @@ -72,11 +66,15 @@ func checkActivePipelines() {

// Create pipeline object and fill it with information
p := gaia.Pipeline{
Name: pName,
Type: pType,
Created: time.Now(),
Name: pName,
Type: pType,
ExecPath: gaia.Cfg.PipelinePath + string(os.PathSeparator) + file.Name(),
Created: time.Now(),
}

// Let us try to start the plugin and receive all implemented jobs
setPipelineJobs(&p)

// Append new pipeline
GlobalActivePipelines.Append(p)
}
Expand Down
42 changes: 41 additions & 1 deletion plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package plugin

import (
"errors"
"io"
"os/exec"

"github.com/gaia-pipeline/gaia"
"github.com/gaia-pipeline/gaia/proto"
plugin "github.com/hashicorp/go-plugin"
)
Expand Down Expand Up @@ -82,12 +84,50 @@ func (p *Plugin) Execute(j *proto.Job) error {
return err
}

// GetJobs receives all implemented jobs from the given plugin.
func (p *Plugin) GetJobs() ([]gaia.Job, error) {
l := []gaia.Job{}

// Get the stream
stream, err := p.pluginConn.GetJobs()
if err != nil {
return nil, err
}

// receive all jobs
for {
job, err := (*stream).Recv()

// Got all jobs
if err == io.EOF {
break
}

// Error during stream
if err != nil {
return nil, err
}

// Convert proto object to gaia.Job struct
j := gaia.Job{
UniqueID: job.UniqueId,
Title: job.Title,
Description: job.Description,
Priority: job.Priority,
}
l = append(l, j)
}

// return list
return l, nil
}

// Close shutdown the plugin and kills the gRPC connection.
// Remember to call this when you call plugin.Connect.
func (p *Plugin) Close() {
// We start the kill command in a goroutine because kill
// is blocking until the subprocess successfully exits.
// The user should not notice the stopping process.
// The user should not wait for this.
go func() {
p.client.Kill()
}()
Expand Down

0 comments on commit d566d6d

Please sign in to comment.