You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2022/01/12 07:29:08 UTC

[servicecomb-service-center] branch grpc created (now a406ecf)

This is an automated email from the ASF dual-hosted git repository.

littlecui pushed a change to branch grpc
in repository https://gitbox.apache.org/repos/asf/servicecomb-service-center.git.


      at a406ecf  Refactor: add syncer server

This branch includes the following new commits:

     new a406ecf  Refactor: add syncer server

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[servicecomb-service-center] 01/01: Refactor: add syncer server

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

littlecui pushed a commit to branch grpc
in repository https://gitbox.apache.org/repos/asf/servicecomb-service-center.git

commit a406ecfe5205ff76edb6279ea592c169b5be45e7
Author: little-cui <su...@qq.com>
AuthorDate: Wed Jan 12 15:19:22 2022 +0800

    Refactor: add syncer server
---
 cmd/scserver/main.go                      | 13 +++++++++++--
 etc/conf/chassis.yaml                     |  2 +-
 etc/conf/lager.yaml                       |  8 ++++++++
 etc/conf/microservice.yaml                |  4 ++--
 etc/conf/syncer.yaml                      | 10 ++--------
 server/core/core.go                       |  8 --------
 server/server.go                          | 13 -------------
 syncer/config/config.go                   |  8 +-------
 syncer/init/init.go                       | 16 ++++++++++++++++
 {server/rpc/sync => syncer/rpc}/server.go | 19 ++++++++++++++++++-
 syncer/server/server.go                   | 18 +++++++++++++++---
 syncer/service/admin/health.go            |  6 +++---
 12 files changed, 77 insertions(+), 48 deletions(-)

diff --git a/cmd/scserver/main.go b/cmd/scserver/main.go
index d599ffb..7b33135 100644
--- a/cmd/scserver/main.go
+++ b/cmd/scserver/main.go
@@ -18,15 +18,24 @@
 package main
 
 import (
-	_ "github.com/apache/servicecomb-service-center/server/init"
+	"context"
+
 	_ "github.com/apache/servicecomb-service-center/syncer/init"
 
-	_ "github.com/apache/servicecomb-service-center/server/bootstrap"
 	_ "github.com/apache/servicecomb-service-center/syncer/bootstrap"
 
+	_ "github.com/apache/servicecomb-service-center/server/init"
+
+	_ "github.com/apache/servicecomb-service-center/server/bootstrap"
+
 	"github.com/apache/servicecomb-service-center/server"
+	syncsvr "github.com/apache/servicecomb-service-center/syncer/server"
+	"github.com/go-chassis/foundation/gopool"
 )
 
 func main() {
+	gopool.Go(func(_ context.Context) {
+		syncsvr.Run()
+	})
 	server.Run()
 }
diff --git a/etc/conf/chassis.yaml b/etc/conf/chassis.yaml
index 13b325c..6751911 100755
--- a/etc/conf/chassis.yaml
+++ b/etc/conf/chassis.yaml
@@ -8,7 +8,7 @@ servicecomb:
   handler:
     chain:
       Provider:
-        default: access-log,ratelimiter-provider,monitoring
+        default: ratelimiter-provider,monitoring
 # ssl:
 #   Provider.cipherPlugin: default
 #   Provider.verifyPeer: false
diff --git a/etc/conf/lager.yaml b/etc/conf/lager.yaml
new file mode 100644
index 0000000..9e71e08
--- /dev/null
+++ b/etc/conf/lager.yaml
@@ -0,0 +1,8 @@
+#logWriters: file
+logLevel: DEBUG
+#logFile: ./syncer.log
+logFormatText: true
+logRotateCompress: true
+logRotateSize: 20
+logBackupCount: 100
+#accessLogFile: ./access.log
\ No newline at end of file
diff --git a/etc/conf/microservice.yaml b/etc/conf/microservice.yaml
index 224fde3..59b1ab4 100755
--- a/etc/conf/microservice.yaml
+++ b/etc/conf/microservice.yaml
@@ -1,4 +1,4 @@
 servicecomb:
   service:
-    name: servicecomb-service-center
-    version: 2.0.0
\ No newline at end of file
+    name: SERVICECENTER
+    version: 2.1.0
\ No newline at end of file
diff --git a/etc/conf/syncer.yaml b/etc/conf/syncer.yaml
index 30802d5..d4fa7c1 100644
--- a/etc/conf/syncer.yaml
+++ b/etc/conf/syncer.yaml
@@ -1,14 +1,8 @@
 sync:
-  enableOnStart: true
+  enableOnStart: false
   peers:
-    - name: dc2
+    - name: dc
       kind: servicecomb
       endpoints: ["127.0.0.1:30105"]
       # only allow mode implemented in incremental approach like push, watch(such as pub/sub, long polling)
       mode: [push]
-      revision: 100
-    - name: dc3
-      kind: consul
-      endpoints: []
-      # since consul will not push data to servcecomb, if we need set push and watch mode to achieve two direction sync
-      mode: [push,watch]
diff --git a/server/core/core.go b/server/core/core.go
index 42e6c04..d3f006d 100644
--- a/server/core/core.go
+++ b/server/core/core.go
@@ -20,11 +20,6 @@ package core
 import (
 	"os"
 
-	"github.com/go-chassis/go-chassis/v2"
-
-	//grpc plugin
-	_ "github.com/go-chassis/go-chassis-extension/protocol/grpc/server"
-
 	// import the grace package and parse grace cmd line
 	_ "github.com/apache/servicecomb-service-center/pkg/grace"
 
@@ -34,9 +29,6 @@ import (
 )
 
 func Initialize() {
-	if err := chassis.Init(); err != nil {
-		log.Warn(err.Error())
-	}
 	// initialize configuration
 	config.Init()
 	// Logging
diff --git a/server/server.go b/server/server.go
index 51530b3..df1bb64 100644
--- a/server/server.go
+++ b/server/server.go
@@ -26,7 +26,6 @@ import (
 	"strings"
 	"time"
 
-	syncv1 "github.com/apache/servicecomb-service-center/api/sync/v1"
 	"github.com/apache/servicecomb-service-center/datasource"
 	nf "github.com/apache/servicecomb-service-center/pkg/event"
 	"github.com/apache/servicecomb-service-center/pkg/log"
@@ -38,13 +37,10 @@ import (
 	"github.com/apache/servicecomb-service-center/server/event"
 	"github.com/apache/servicecomb-service-center/server/metrics"
 	"github.com/apache/servicecomb-service-center/server/plugin/security/tlsconf"
-	"github.com/apache/servicecomb-service-center/server/rpc/sync"
 	"github.com/apache/servicecomb-service-center/server/service/gov"
 	"github.com/apache/servicecomb-service-center/server/service/rbac"
 	snf "github.com/apache/servicecomb-service-center/server/syncernotify"
 	"github.com/go-chassis/foundation/gopool"
-	"github.com/go-chassis/go-chassis/v2"
-	chassisServer "github.com/go-chassis/go-chassis/v2/core/server"
 	"github.com/little-cui/etcdadpt"
 )
 
@@ -78,15 +74,6 @@ func (s *ServiceCenterServer) Run() {
 
 	s.startServices()
 
-	chassis.RegisterSchema("grpc", &sync.Server{},
-		chassisServer.WithRPCServiceDesc(&syncv1.EventService_ServiceDesc))
-
-	go func() {
-		if err := chassis.Run(); err != nil {
-			log.Warn(err.Error())
-		}
-	}()
-
 	signal.RegisterListener()
 
 	s.waitForQuit()
diff --git a/syncer/config/config.go b/syncer/config/config.go
index adccf33..149933d 100644
--- a/syncer/config/config.go
+++ b/syncer/config/config.go
@@ -45,13 +45,7 @@ type Peer struct {
 }
 
 func Init() error {
-	err := archaius.Init(archaius.WithMemorySource(), archaius.WithENVSource())
-	if err != nil {
-		log.Fatal("can not init archaius", err)
-		return err
-	}
-
-	err = archaius.AddFile(filepath.Join(util.GetAppRoot(), "conf", "syncer.yaml"))
+	err := archaius.AddFile(filepath.Join(util.GetAppRoot(), "conf", "syncer.yaml"))
 	if err != nil {
 		log.Warn(fmt.Sprintf("can not add syncer config file source, error: %s", err))
 		return err
diff --git a/syncer/init/init.go b/syncer/init/init.go
index 162bbe7..d97fb13 100644
--- a/syncer/init/init.go
+++ b/syncer/init/init.go
@@ -18,11 +18,27 @@
 package init
 
 import (
+	_ "github.com/go-chassis/go-chassis/v2/middleware/monitoring"
+	_ "github.com/go-chassis/go-chassis/v2/middleware/ratelimiter"
+
+	//grpc plugin
+	_ "github.com/go-chassis/go-chassis-extension/protocol/grpc/server"
+
+	syncv1 "github.com/apache/servicecomb-service-center/api/sync/v1"
 	"github.com/apache/servicecomb-service-center/pkg/log"
 	"github.com/apache/servicecomb-service-center/syncer/config"
+	"github.com/apache/servicecomb-service-center/syncer/rpc"
+	"github.com/go-chassis/go-chassis/v2"
+	chassisServer "github.com/go-chassis/go-chassis/v2/core/server"
 )
 
 func init() {
+	chassis.RegisterSchema("grpc", &rpc.Server{},
+		chassisServer.WithRPCServiceDesc(&syncv1.EventService_ServiceDesc))
+
+	if err := chassis.Init(); err != nil {
+		log.Warn(err.Error())
+	}
 	if err := config.Init(); err != nil {
 		log.Error("syncer config init failed", err)
 	}
diff --git a/server/rpc/sync/server.go b/syncer/rpc/server.go
similarity index 52%
rename from server/rpc/sync/server.go
rename to syncer/rpc/server.go
index a564c45..d212d76 100644
--- a/server/rpc/sync/server.go
+++ b/syncer/rpc/server.go
@@ -1,4 +1,21 @@
-package sync
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package rpc
 
 import (
 	"context"
diff --git a/syncer/server/server.go b/syncer/server/server.go
index ed83ad8..4324d5e 100644
--- a/syncer/server/server.go
+++ b/syncer/server/server.go
@@ -17,7 +17,19 @@
 
 package server
 
-func Start() error {
-	// TODO
-	return nil
+import (
+	"github.com/apache/servicecomb-service-center/pkg/log"
+	"github.com/apache/servicecomb-service-center/syncer/config"
+	"github.com/go-chassis/go-chassis/v2"
+)
+
+func Run() {
+	if !config.GetConfig().Sync.EnableOnStart {
+		log.Warn("syncer is disabled")
+		return
+	}
+
+	if err := chassis.Run(); err != nil {
+		log.Warn(err.Error())
+	}
 }
diff --git a/syncer/service/admin/health.go b/syncer/service/admin/health.go
index b7c136e..865be9f 100644
--- a/syncer/service/admin/health.go
+++ b/syncer/service/admin/health.go
@@ -24,8 +24,8 @@ import (
 	v1sync "github.com/apache/servicecomb-service-center/api/sync/v1"
 	"github.com/apache/servicecomb-service-center/client"
 	"github.com/apache/servicecomb-service-center/pkg/rpc"
-	"github.com/apache/servicecomb-service-center/server/rpc/sync"
 	"github.com/apache/servicecomb-service-center/syncer/config"
+	rpc2 "github.com/apache/servicecomb-service-center/syncer/rpc"
 )
 
 const (
@@ -82,14 +82,14 @@ func Health() (*Resp, error) {
 func getPeerStatus(endpoints []string) string {
 	conn, err := rpc.GetRoundRobinLbConn(&rpc.Config{Addrs: endpoints, Scheme: scheme, ServiceName: serviceName})
 	if err != nil || conn == nil {
-		return sync.HealthStatusAbnormal
+		return rpc2.HealthStatusAbnormal
 	}
 	defer conn.Close()
 
 	set := client.NewSet(conn)
 	reply, err := set.EventServiceClient.Health(context.Background(), &v1sync.HealthRequest{})
 	if err != nil || reply == nil {
-		return sync.HealthStatusAbnormal
+		return rpc2.HealthStatusAbnormal
 	}
 	return reply.Status
 }