summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLvbo163 <lv.bo163@zte.com.cn>2018-08-07 15:12:22 +0800
committerLvbo163 <lv.bo163@zte.com.cn>2018-08-07 15:12:22 +0800
commite782c794c9fe6441120b8d0d239414f9a3421288 (patch)
tree5069f759ac8027ab831f168b5416917761821957
parent38447771f156197521f34f2c89f6b4fb4c42b28c (diff)
add a test rest api
Issue-ID: MSB-271 Change-Id: Ic3476a98d66ad285f400e7bbdc6e8021be50e980 Signed-off-by: Lvbo163 <lv.bo163@zte.com.cn>
-rw-r--r--msb2pilot/src/msb2pilot/controllers/routerule.go52
-rw-r--r--msb2pilot/src/msb2pilot/main.go6
-rw-r--r--msb2pilot/src/msb2pilot/pilot/controller.go1
-rw-r--r--msb2pilot/src/msb2pilot/pilot/msb.go10
-rw-r--r--msb2pilot/src/msb2pilot/routers/router.go1
5 files changed, 64 insertions, 6 deletions
diff --git a/msb2pilot/src/msb2pilot/controllers/routerule.go b/msb2pilot/src/msb2pilot/controllers/routerule.go
new file mode 100644
index 0000000..f32708e
--- /dev/null
+++ b/msb2pilot/src/msb2pilot/controllers/routerule.go
@@ -0,0 +1,52 @@
+/**
+ * Copyright (c) 2018 ZTE Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and the Apache License 2.0 which both accompany this distribution,
+ * and are available at http://www.eclipse.org/legal/epl-v10.html
+ * and http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Contributors:
+ * ZTE - initial Project
+ */
+package controllers
+
+import (
+ "encoding/json"
+ "msb2pilot/log"
+ "msb2pilot/pilot"
+
+ "github.com/astaxie/beego"
+)
+
+type RouteRuleController struct {
+ beego.Controller
+}
+
+func (this *RouteRuleController) Get() {
+ log.Log.Debug("routerule controller get method called")
+
+ name := this.GetString("name")
+ namespace := this.GetString("namespace")
+ log.Log.Debug("name is : " + name)
+ log.Log.Debug("namespace is: " + namespace)
+ if name != "" { // get routerule detail
+ data, _ := pilot.Get("routerules", namespace, name)
+ b, _ := json.Marshal(data)
+ log.Log.Debug(string(b))
+
+ this.Data["json"] = pilot.ConvertConfig(*data)
+
+ } else { // get routerule name list
+ data, _ := pilot.List("routerules", "")
+ b, _ := json.Marshal(data)
+ log.Log.Debug(string(b))
+ rules := make([]interface{}, 0, len(data))
+ for _, config := range data {
+ rules = append(rules, pilot.ConvertConfig(config))
+ }
+
+ this.Data["json"] = rules
+ }
+ this.ServeJSON()
+}
diff --git a/msb2pilot/src/msb2pilot/main.go b/msb2pilot/src/msb2pilot/main.go
index 7ed762c..708e88c 100644
--- a/msb2pilot/src/msb2pilot/main.go
+++ b/msb2pilot/src/msb2pilot/main.go
@@ -12,10 +12,10 @@
package main
import (
- "fmt"
"msb2pilot/consul"
"msb2pilot/log"
"msb2pilot/models"
+ "msb2pilot/pilot"
_ "msb2pilot/routers"
"time"
@@ -37,5 +37,7 @@ func syncConsulData() {
}
func syncMsbData(newServices []*models.MsbService) {
- fmt.Println(len(newServices), "services updated", time.Now())
+ stop := make(chan struct{})
+ monitor := consul.NewConsulMonitor(nil, 20*time.Second, pilot.SyncMsbData)
+ monitor.Start(stop)
}
diff --git a/msb2pilot/src/msb2pilot/pilot/controller.go b/msb2pilot/src/msb2pilot/pilot/controller.go
index ddb59ec..f0cf87d 100644
--- a/msb2pilot/src/msb2pilot/pilot/controller.go
+++ b/msb2pilot/src/msb2pilot/pilot/controller.go
@@ -161,6 +161,7 @@ func Update(config *model.Config) (string, error) {
}
func operate(operation Operation, config *model.Config) (string, error) {
+ log.Log.Informational("%s %s %s %s", operation, config.Type, config.Name, config.Namespace)
switch operation {
case OperationCreate:
return client.Create(*config)
diff --git a/msb2pilot/src/msb2pilot/pilot/msb.go b/msb2pilot/src/msb2pilot/pilot/msb.go
index d81b2f1..fb87d08 100644
--- a/msb2pilot/src/msb2pilot/pilot/msb.go
+++ b/msb2pilot/src/msb2pilot/pilot/msb.go
@@ -47,6 +47,7 @@ func SyncMsbData(newServices []*models.MsbService) {
func saveService(operation Operation, services []*models.MsbService) {
if len(services) == 0 {
+ log.Log.Debug("0 services need to %s. \n", operation)
return
}
configs, err := parseServiceToConfig(services)
@@ -55,20 +56,21 @@ func saveService(operation Operation, services []*models.MsbService) {
return
}
fails := Save(operation, configs)
- log.Log.Debug("%d services need to %s, %d fails. \n", len(services), operation, len(fails))
+ log.Log.Debug("%d services %d rules need to %s, %d fails. \n", len(services), len(configs), operation, len(fails))
}
func deleteAllMsbRules() {
log.Log.Informational("delete all msb rules")
- configs, err := List("route-rule", "")
+ configs, err := List("routerules", "")
if err != nil {
+ log.Log.Error("fail to load rule list", err)
return
}
deleteList := msbRuleFilter(configs)
-
- Save(OperationDelete, deleteList)
+ failed := Save(OperationDelete, deleteList)
+ log.Log.Debug("deleteAllMsbRules total %d rules, fail %d", len(configs), len(failed))
}
func msbRuleFilter(configs []istioModel.Config) []istioModel.Config {
diff --git a/msb2pilot/src/msb2pilot/routers/router.go b/msb2pilot/src/msb2pilot/routers/router.go
index 1a8d1e5..8768359 100644
--- a/msb2pilot/src/msb2pilot/routers/router.go
+++ b/msb2pilot/src/msb2pilot/routers/router.go
@@ -18,5 +18,6 @@ import (
)
func init() {
+ beego.Router("/routerule", &controllers.RouteRuleController{})
beego.Router("/", &controllers.MainController{})
}