ability to persist agent data

This commit is contained in:
Brad Rydzewski 2015-04-29 15:26:22 -07:00
parent 4071ea73a0
commit ca931cd9eb
5 changed files with 51 additions and 2 deletions

9
common/agent.go Normal file
View file

@ -0,0 +1,9 @@
package common
// Agent represents a worker that has connected
// to the system in order to perform work
type Agent struct {
Name string
Addr string
IsHealthy bool
}

1
datastore/bolt/agent.go Normal file
View file

@ -0,0 +1 @@
package bolt

View file

@ -23,6 +23,7 @@ var (
bucketRepoParams = []byte("repo_params") bucketRepoParams = []byte("repo_params")
bucketRepoUsers = []byte("repo_users") bucketRepoUsers = []byte("repo_users")
bucketBuild = []byte("build") bucketBuild = []byte("build")
bucketBuildAgent = []byte("build_agent")
bucketBuildStatus = []byte("build_status") bucketBuildStatus = []byte("build_status")
bucketBuildLogs = []byte("build_logs") bucketBuildLogs = []byte("build_logs")
bucketBuildSeq = []byte("build_seq") bucketBuildSeq = []byte("build_seq")
@ -49,6 +50,7 @@ func New(path string) (*DB, error) {
tx.CreateBucketIfNotExists(bucketRepoParams) tx.CreateBucketIfNotExists(bucketRepoParams)
tx.CreateBucketIfNotExists(bucketRepoUsers) tx.CreateBucketIfNotExists(bucketRepoUsers)
tx.CreateBucketIfNotExists(bucketBuild) tx.CreateBucketIfNotExists(bucketBuild)
tx.CreateBucketIfNotExists(bucketBuildAgent)
tx.CreateBucketIfNotExists(bucketBuildStatus) tx.CreateBucketIfNotExists(bucketBuildStatus)
tx.CreateBucketIfNotExists(bucketBuildLogs) tx.CreateBucketIfNotExists(bucketBuildLogs)
tx.CreateBucketIfNotExists(bucketBuildSeq) tx.CreateBucketIfNotExists(bucketBuildSeq)

View file

@ -3,10 +3,11 @@ package bolt
import ( import (
//"bytes" //"bytes"
"encoding/binary" "encoding/binary"
"github.com/boltdb/bolt"
"github.com/drone/drone/common"
"strconv" "strconv"
"time" "time"
"github.com/boltdb/bolt"
"github.com/drone/drone/common"
) )
// Build gets the specified build number for the // Build gets the specified build number for the
@ -213,3 +214,27 @@ func (db *DB) SetBuildTask(repo string, build int, task *common.Task) error {
}) })
} }
// SetBuildAgent insert or updates the agent that is
// running a build.
func (db *DB) SetBuildAgent(repo string, build int, agent *common.Agent) error {
key := []byte(repo + "/" + strconv.Itoa(build))
return db.Update(func(t *bolt.Tx) error {
return update(t, bucketBuildAgent, key, agent)
})
}
func (db *DB) DelBuildAgent(repo string, build int, agent *common.Agent) error {
key := []byte(repo + "/" + strconv.Itoa(build))
return db.Update(func(t *bolt.Tx) error {
return delete(t, bucketBuildAgent, key)
})
}
func (db *DB) BuildAgent(repo string, build int) (*common.Agent, error) {
key := []byte(repo + "/" + strconv.Itoa(build))
agent := &common.Agent{}
err := db.View(func(t *bolt.Tx) error {
return get(t, bucketBuildAgent, key, agent)
})
return agent, err
}

View file

@ -101,6 +101,10 @@ type Datastore interface {
// named repository. // named repository.
BuildLast(string) (*common.Build, error) BuildLast(string) (*common.Build, error)
// BuildAgent returns the agent that is being
// used to execute the build.
// BuildAgent(string, int) (*common.Agent, error)
// SetBuild inserts or updates a build for the named // SetBuild inserts or updates a build for the named
// repository. The build number is incremented and // repository. The build number is incremented and
// assigned to the provided build. // assigned to the provided build.
@ -120,6 +124,14 @@ type Datastore interface {
// an error is returned. // an error is returned.
SetBuildTask(string, int, *common.Task) error SetBuildTask(string, int, *common.Task) error
// SetBuildAgent insert or updates the agent that is
// running a build.
// SetBuildAgent(string, int, *common.Agent) error
// DelBuildAgent purges the referce to the agent
// that ran a build.
// DelBuildAgent(string, int, *common.Agent) error
// LogReader gets the task logs at index N for // LogReader gets the task logs at index N for
// the named repository and build number. // the named repository and build number.
LogReader(string, int, int) (io.Reader, error) LogReader(string, int, int) (io.Reader, error)