Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
722ab39
Add kubernetes a bussiness.go file to check bussiness result
zenlint Apr 20, 2016
09c5db3
Update for merge2.0, using details in kubernetes, can buidable version.
zenlint Apr 20, 2016
2a57a54
test
zenlint Apr 22, 2016
5d6c1ed
test1
zenlint Apr 22, 2016
0917b33
test2
zenlint Apr 22, 2016
a0c8512
testi3
zenlint Apr 22, 2016
b426468
test4
zenlint Apr 22, 2016
8a86842
test4
zenlint Apr 22, 2016
2375e36
test5o
zenlint Apr 22, 2016
f901af4
testa
zenlint Apr 22, 2016
d93dfc3
testao
zenlint Apr 22, 2016
48140f2
testy
zenlint Apr 22, 2016
b6becd2
testwatchpodsbs
zenlint Apr 22, 2016
8a7728d
update
zenlint Apr 22, 2016
b890abe
update
zenlint Apr 22, 2016
0e3c5dc
run with no bug
zenlint Apr 22, 2016
852760d
add delete
zenlint Apr 22, 2016
47530d4
Fix delete handler bug
zenlint Apr 22, 2016
9545503
update
zenlint Apr 23, 2016
662b6e1
udpate
zenlint Apr 23, 2016
f815334
update
zenlint Apr 23, 2016
58ef585
Fix bugs
zenlint Apr 23, 2016
749ee3c
Split to stage
zenlint Apr 23, 2016
4891216
update for stage
zenlint Apr 23, 2016
c2df2e1
update
zenlint Apr 23, 2016
3726c37
add env
zenlint Apr 23, 2016
88fbb2e
fix bug in watch
zenlint Apr 23, 2016
456a24f
fix bug in watch
zenlint Apr 23, 2016
7e7b7ac
OK
zenlint Apr 23, 2016
c4c88b2
move k8s host and port to yaml conifg
winebag Apr 27, 2016
34f9c2c
add runtime.yaml
winebag Apr 27, 2016
6115997
Merge pull request #2 from winebag/develop
zenlint May 4, 2016
b605576
etcd persiste
winebag May 12, 2016
4634804
Merge remote-tracking branch 'upstream/develop' into etcdtest
May 12, 2016
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
5 changes: 5 additions & 0 deletions cmd/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ func runWeb(c *cli.Context) {
fmt.Println(err)
return
}

if err := models.InitEtcd(); err != nil {
fmt.Println(err)
return
}
if err := models.InitK8s(); err != nil {
fmt.Println(err)
return
}
models.SyncDatabase()

m := macaron.New()
Expand Down
32 changes: 32 additions & 0 deletions conf/runtime.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
run:
runMode: dev
logPath: log/vessel
http:
listenMode: http
httpsCertFile: cert/containerops/containerops.crt
httpsKeyFile: cert/containerops/containerops.key
host: 0.0.0.0
port: 4488
database:
username: root
password: dolo0425
protocol: tcp
host: 10.67.147.80
port: 3306
schema: vesseldb
param:
charset: utf8
parseTime: True
loc: Local
etcd:
endpoints:
- host: 127.0.0.1
port: 4001
- host: localhost
port: 4001
username: etcd
password: etcd
k8s:
host: 127.0.0.1
port: 8080
17 changes: 10 additions & 7 deletions handler/pipeline.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package handler

import (
"encoding/json"
"net/http"
"strings"
"time"
"encoding/json"

log "github.com/Sirupsen/logrus"
"gopkg.in/macaron.v1"

"github.com/containerops/vessel/models"
"github.com/containerops/vessel/module/kubernetes"
"github.com/containerops/vessel/module/pipeline"
"github.com/containerops/vessel/utils"
)
Expand Down Expand Up @@ -93,8 +94,8 @@ func createPipelineAndStage(pst models.PipelineSpecTemplate) (*models.Pipeline,
plInfo.Labels = utils.TransMapToStr(pst.MetaData.Labels)
plInfo.Annotations = utils.TransMapToStr(pst.MetaData.Annotations)
//ignore plJson Detail
pstbs,err := json.Marshal(pst)
if err != nil{
pstbs, err := json.Marshal(pst)
if err != nil {
return nil, err
}
plInfo.Detail = string(pstbs)
Expand All @@ -115,8 +116,8 @@ func createPipelineAndStage(pst models.PipelineSpecTemplate) (*models.Pipeline,
//StatusCheckInterval to Detail
//StatusCheckCount to Detail

sbs,err := json.Marshal(value)
if err != nil{
sbs, err := json.Marshal(value)
if err != nil {
return nil, err
}
sInfo.Detail = string(sbs)
Expand Down Expand Up @@ -147,8 +148,10 @@ func V1GETPipelineHandler(ctx *macaron.Context) (int, []byte) {
return http.StatusOK, []byte("")
}

func V1DELETEPipelineHandler(ctx *macaron.Context) (int, []byte) {
return http.StatusOK, []byte("")
func V1DELETEPipelineHandler(ctx *macaron.Context, reqData models.PipelineSpecTemplate) (int, []byte) {
kubernetes.DeletePipeline(&reqData)
retstr := "Sent delete pipeline " + reqData.MetaData.Name + " event"
return http.StatusOK, []byte(retstr)
}

func V1RunPipelineHandler(ctx *macaron.Context) (int, []byte) {
Expand Down
33 changes: 33 additions & 0 deletions models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"fmt"
"time"

"k8s.io/kubernetes/pkg/client/restclient"
"k8s.io/kubernetes/pkg/client/unversioned"

"golang.org/x/net/context"

"github.com/containerops/vessel/setting"
Expand All @@ -15,6 +18,7 @@ import (
var (
EtcdClient client.Client
DbClient *gorm.DB
K8sClient *unversioned.Client
)

//Init Database
Expand Down Expand Up @@ -100,6 +104,20 @@ func SyncDatabase() error {
}
}

if !db.HasTable(&PipelineMetaData{}) {
err = db.CreateTable(&PipelineMetaData{}).Error
if err != nil {
return err
}
}

if !db.HasTable(&StageSpec{}) {
err = db.CreateTable(&StageSpec{}).Error
if err != nil {
return err
}
}

fmt.Println("sync DB done !")
return nil
}
Expand Down Expand Up @@ -137,6 +155,21 @@ func InitEtcd() error {

}

func InitK8s() error {
clientConfig := restclient.Config{}
host := setting.RunTime.K8s.Host + ":" + setting.RunTime.K8s.Port
fmt.Println(host)
clientConfig.Host = host
// clientConfig.Host = setting.RunTime.Database.Host
client, err := unversioned.New(&clientConfig)
if err != nil {
return err
fmt.Errorf("New unversioned client err: %v!\n", err.Error())
}
K8sClient = client
return nil
}

//
// //Sync ETCD
// func SyncETCD() error {
Expand Down
14 changes: 8 additions & 6 deletions models/pipelinetemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ type PipelineSpecTemplate struct {
Kind string `json:"kind"`
ApiVersion string `json:"apiVersion"`
MetaData PipelineMetaData `json:"metadata"`
Spec []StageSpec `json:"spec"`
Spec []StageSpec `json:"spec" sql:"-"`
}

type PipelineMetaData struct {
Expand All @@ -17,8 +17,8 @@ type PipelineMetaData struct {
CreateonTimestamp string `json:"createonTimestamp"`
DeletionTimestamp string `json:"deletionTimestamp"`
TimeoutDuration int64 `json:"timeoutDuration"`
Labels map[string]string `json:"labels"`
Annotations map[string]string `json:"annotations"`
Labels map[string]string `json:"labels" sql:"-"`
Annotations map[string]string `json:"annotations" sql:"-"`
}

/*// pipelineMetadata struct for convert from pipelineVersion.MetaData
Expand Down Expand Up @@ -53,12 +53,14 @@ type StageSpec struct {
ProjectId int64
PipelineId int64
StageId int64
Replicas int `json:"replicsa"`
Replicas int `json:"replicas"`
Dependence string `json:"dependence"`
Kind string `json:"kind"`
StatusCheckUrl string `json:"statusCheckUrl"`
StatusCheckUrl string `json:"statusCheckLink"`
StatusCheckInterval int64 `json:"statusCheckInterval"`
StatusCheckCount int64 `json:"statusCheckCount"`
StatusCheckCount int `json:"statusCheckCount"`
Image string `json:"image"`
Port int `json:"port"`
EnvName string `json:"envName"`
EnvValue string `json:"envValue"`
}
67 changes: 67 additions & 0 deletions module/etcdpersist/db/connector.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package db

import (
"database/sql"
"fmt"

"github.com/astaxie/beego/orm"
_ "github.com/go-sql-driver/mysql"
"github.com/golang/glog"
)

var (
Orm orm.Ormer
)

func init() {
orm.RegisterModel(new(Tb_etcd_backup))
}

func Syncdb(db_user, db_pass, db_host, db_port, db_name string) error {
err := Create(db_user, db_pass, db_host, db_port, db_name)
if err != nil {
return err
}
err = Connect(db_user, db_pass, db_host, db_port, db_name)
if err != nil {
return err
}
name := "default"
force := true
verbose := true
err = orm.RunSyncdb(name, force, verbose)
glog.Infoln("database init is complete.\nPlease restart the application")
return err
}

func Connect(db_user, db_pass, db_host, db_port, db_name string) error {
var dns string
orm.RegisterDriver("mysql", orm.DRMySQL)
dns = fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", db_user, db_pass, db_host, db_port, db_name)
err := orm.RegisterDataBase("default", "mysql", dns)
if err != nil {
return err
}
Orm = orm.NewOrm()
err = Orm.Using("default")
return err
}

func Create(db_user, db_pass, db_host, db_port, db_name string) error {
var dns string
var sqlstring string
dns = fmt.Sprintf("%s:%s@tcp(%s:%s)/?charset=utf8", db_user, db_pass, db_host, db_port)
sqlstring = fmt.Sprintf("CREATE DATABASE if not exists `%s` CHARSET utf8 COLLATE utf8_general_ci", db_name)
db, err := sql.Open("mysql", dns)
if err != nil {
panic(err.Error())
}
r, err := db.Exec(sqlstring)
if err != nil {
glog.Infoln(err, r)
} else {
glog.Infoln("Database ", db_name, " created")
}
defer db.Close()
return err
}
14 changes: 14 additions & 0 deletions module/etcdpersist/db/db_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package db

import (
"strings"
"testing"
)

func Test_db(t *testing.T) {
s := "/dir"
index := strings.LastIndex(s, "/")
r := []rune(s)
s = string(r[0:index])
t.Log(s == "")
}
78 changes: 78 additions & 0 deletions module/etcdpersist/db/tb_etcd_backup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package db

import (
"strings"
"time"
)

type Tb_etcd_backup struct {
Id int64
Key string `orm:"size(255)"`
Parent_key string `orm:"size(255)"`
Value string `orm:"size(255)"`
Dir bool
Ttl uint32
Modified_index uint32
Created_index uint32
}

func (this *Tb_etcd_backup) Update() (int64, error) {
return Orm.Update(this)
}

// server detection and delete expire key
func (this *Tb_etcd_backup) DeleteExpire() (bool, int64, error) {
// To be realized
return true, 0, nil
}

func (this *Tb_etcd_backup) InertOrUpdate() (bool, int64, error) {
index := strings.LastIndex(this.Key, "/")
this.Parent_key = string([]rune(this.Key)[0:index])
if this.Parent_key == "" {
this.Parent_key = "/"
}

newObj := &Tb_etcd_backup{}
newObj.Key = this.Key
newObj.Value = this.Value
newObj.Dir = this.Dir
newObj.Ttl = this.Ttl
newObj.Modified_index = this.Modified_index
newObj.Created_index = this.Created_index
newObj.Parent_key = this.Parent_key
create, id, err := Orm.ReadOrCreate(this, "Key")
if err == nil && !create {
if newObj.Modified_index > this.Modified_index {
newObj.Id = this.Id
id, err = Orm.Update(newObj)
}
}
return create, id, err
}

func (this *Tb_etcd_backup) Delete() (int64, error) {
return Orm.Delete(this)
}

func (this *Tb_etcd_backup) Read() error {
return Orm.Read(this)
}
func (this *Tb_etcd_backup) Insert() (int64, error) {
return Orm.Insert(this)
}
func (this *Tb_etcd_backup) Exist() bool {
return Orm.QueryTable("Tb_etcd_backup").Filter("Key", this.Key).Exist()
}
func (this *Tb_etcd_backup) IsDirectory() bool {
return this.Dir
}

func (this *Tb_etcd_backup) IsExpired() bool {
if this.Ttl > 0 {
if uint32(time.Now().Unix())-this.Ttl > 0 {
return true
}
}
return false
}
17 changes: 17 additions & 0 deletions module/etcdpersist/etcd-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"cluster": {
"leader": "http://192.168.40.86:4001/",
"machines": [
"http://192.168.40.86:4001/",
"http://192.168.40.86:4002/",
"http://192.168.40.86:4003/"
]
},
"config": {
"certFile": "",
"keyFile": "",
"caCertFiles": [],
"timeout":9999999999999,
"consistency": "STRONG"
}
}
Loading