summaryrefslogtreecommitdiffstats
path: root/msb2pilot/src
diff options
context:
space:
mode:
authorLvbo163 <lv.bo163@zte.com.cn>2018-08-06 16:14:05 +0800
committerLvbo163 <lv.bo163@zte.com.cn>2018-08-06 16:14:05 +0800
commitf003bbb0f7609d793ea08781cefb49adce1b3ed1 (patch)
tree8ce20b5891603c161400404d9e93ac9ae29adf23 /msb2pilot/src
parent4933a469c8c76b0b2c5e03ddaedefbc1bd40122d (diff)
udpate pilot by consul data
Issue-ID: MSB-262 Change-Id: Ife9e7ab2f4678286684d4c6552870c98b0ac40c5 Signed-off-by: Lvbo163 <lv.bo163@zte.com.cn>
Diffstat (limited to 'msb2pilot/src')
-rw-r--r--msb2pilot/src/msb2pilot/pilot/msb.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/msb2pilot/src/msb2pilot/pilot/msb.go b/msb2pilot/src/msb2pilot/pilot/msb.go
index 9b6a977..a1b5b5f 100644
--- a/msb2pilot/src/msb2pilot/pilot/msb.go
+++ b/msb2pilot/src/msb2pilot/pilot/msb.go
@@ -35,11 +35,26 @@ func SyncMsbData(newServices []*models.MsbService) {
log.Log.Debug("sync msb rewrite rule to pilot")
createServices, updateServices, deleteServices := compareServices(cachedServices, newServices)
- log.Log.Debug("SyncMsbData: ", len(createServices), len(updateServices), len(deleteServices))
+ saveService(OperationCreate, createServices)
+ saveService(OperationUpdate, updateServices)
+ saveService(OperationDelete, deleteServices)
cachedServices = newServices
}
+func saveService(operation Operation, services []*models.MsbService) {
+ if len(services) == 0 {
+ return
+ }
+ configs, err := parseServiceToConfig(services)
+ if err != nil {
+ log.Log.Error("param parse error", err)
+ return
+ }
+ fails := Save(operation, configs)
+ log.Log.Debug("%d services need to %s, %d fails. \n", len(services), operation, len(fails))
+}
+
func compareServices(oldServices, newServices []*models.MsbService) (createServices, updateServices, deleteServices []*models.MsbService) {
oldServiceMap := toServiceMap(oldServices)
newServiceMap := toServiceMap(newServices)