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

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


The following commit(s) were added to refs/heads/master by this push:
     new 2e7ea92  Feature: add syncer config framework (#1197)
2e7ea92 is described below

commit 2e7ea92ed49d4b2194e9c114e9428026a26311c8
Author: little-cui <[email protected]>
AuthorDate: Fri Dec 31 16:24:58 2021 +0800

    Feature: add syncer config framework (#1197)
    
    * Feature: add syncer config framework
    
    * Feature: add syncer resource
---
 cmd/scserver/main.go                               |  2 +
 etc/conf/app.yaml                                  | 16 -----
 etc/conf/syncer.yaml                               | 73 +++++-----------------
 .../main.go => syncer/bootstrap/bootstrap.go       | 11 +---
 syncer/config/config.go                            | 73 ++++++++++++++++++++++
 .../main.go => syncer/config/config_test.go        | 14 ++---
 cmd/scserver/main.go => syncer/init/init.go        | 15 +++--
 .../main.go => syncer/resource/admin/admin.go      | 23 ++++---
 .../main.go => syncer/resource/register.go         | 17 ++---
 cmd/scserver/main.go => syncer/server/server.go    | 15 ++---
 10 files changed, 138 insertions(+), 121 deletions(-)

diff --git a/cmd/scserver/main.go b/cmd/scserver/main.go
index 4e91806..d599ffb 100644
--- a/cmd/scserver/main.go
+++ b/cmd/scserver/main.go
@@ -19,8 +19,10 @@ package main
 
 import (
        _ "github.com/apache/servicecomb-service-center/server/init"
+       _ "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"
 )
diff --git a/etc/conf/app.yaml b/etc/conf/app.yaml
index 2848946..91618d3 100644
--- a/etc/conf/app.yaml
+++ b/etc/conf/app.yaml
@@ -16,22 +16,6 @@
 # environment can specify the sc running env, like dev or prod
 environment: dev
 
-sync:
-  datacenter:
-    name: dc1
-  peers:
-    - name: dc2
-      kind: servicecomb
-      endpoints: ["https://127.0.0.1:30100";]
-      # only allow mode implemented in incremental approach like push, 
watch(such as pub/sub, long polling)
-      mode: [push]
-      caFile: certs/ca.crt
-      revision: 100
-    - name: dc3
-      kind: consul
-      # since consul will not push data to servcecomb, if we need set push and 
watch mode to achieve two direction sync
-      mode: [push, watch]
-      revison: 200
 server:
   host: 127.0.0.1
   port: 30100
diff --git a/etc/conf/syncer.yaml b/etc/conf/syncer.yaml
index 45b36c1..fa20b18 100644
--- a/etc/conf/syncer.yaml
+++ b/etc/conf/syncer.yaml
@@ -1,56 +1,17 @@
-# run mode, supports (single, cluster)
-mode: signle
-# node name, must be unique on the network
-node: syncer-node
-# Cluster name, clustering by this name
-cluster: syncer-cluster
-dataDir: ./syncer-data/
-listener:
-  # Address used to network with other Syncers in LAN
-  bindAddr: 0.0.0.0:30190
-  # Address used to network with other Syncers in WAN
-  advertiseAddr: ""
-  # Address used to synchronize data with other Syncers
-  rpcAddr: 0.0.0.0:30191
-  # Address used to communicate with other cluster peers
-  peerAddr: 127.0.0.1:30192
-  tlsMount:
-    enabled: false
-    name: syncer
-join:
-  enabled: false
-  # Address to join the network by specifying at least one existing member
-  address: 127.0.0.1:30190
-  # Limit the maximum of RetryJoin, default is 0, means no limit
-  retryMax: 3
-  retryInterval: 30s
-task:
-  kind: ticker
-  params:
-    # Time interval between timing tasks, default is 30s
-    - key: interval
-      value: 30s
-registry:
-  plugin: servicecenter
-  address: http://127.0.0.1:30100
-  tlsMount:
-    enabled: false
-    name: servicecenter
-tlsConfigs:
-  - name: syncer
-    verifyPeer: true
-    minVersion: TLSv1.2
-    caFile: ./certs/trust.cer
-    certFile: ./certs/server.cer
-    keyFile: ./certs/server_key.pem
-    passphrase: ""
-    ciphers:
-      - TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
-      - TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
-      - TLS_RSA_WITH_AES_256_GCM_SHA384
-      - TLS_RSA_WITH_AES_128_GCM_SHA256
-  - name: servicecenter
-    verifyPeer: false
-    caFile: ./certs/trust.cer
-    certFile: ./certs/server.cer
-    keyFile: ./certs/server_key.pem
\ No newline at end of file
+sync:
+  enableOnStart: false
+  datacenter:
+    name: dc1
+  peers:
+    - name: dc2
+      kind: servicecomb
+      endpoints: ["https://127.0.0.1:30100";]
+      # only allow mode implemented in incremental approach like push, 
watch(such as pub/sub, long polling)
+      mode: [push]
+      caFile: certs/ca.crt
+      revision: 100
+    - name: dc3
+      kind: consul
+      # since consul will not push data to servcecomb, if we need set push and 
watch mode to achieve two direction sync
+      mode: [push,watch]
+      revison: 200
diff --git a/cmd/scserver/main.go b/syncer/bootstrap/bootstrap.go
similarity index 78%
copy from cmd/scserver/main.go
copy to syncer/bootstrap/bootstrap.go
index 4e91806..fc6c6e6 100644
--- a/cmd/scserver/main.go
+++ b/syncer/bootstrap/bootstrap.go
@@ -15,16 +15,11 @@
  * limitations under the License.
  */
 
-package main
+package bootstrap
 
 import (
-       _ "github.com/apache/servicecomb-service-center/server/init"
-
-       _ "github.com/apache/servicecomb-service-center/server/bootstrap"
-
-       "github.com/apache/servicecomb-service-center/server"
+       _ "github.com/apache/servicecomb-service-center/syncer/resource"
 )
 
-func main() {
-       server.Run()
+func init() {
 }
diff --git a/syncer/config/config.go b/syncer/config/config.go
new file mode 100644
index 0000000..174fc7e
--- /dev/null
+++ b/syncer/config/config.go
@@ -0,0 +1,73 @@
+/*
+ * 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 config
+
+import (
+       "fmt"
+       "path/filepath"
+
+       "github.com/apache/servicecomb-service-center/pkg/log"
+       "github.com/apache/servicecomb-service-center/pkg/util"
+       "github.com/go-chassis/go-archaius"
+)
+
+var config Config
+
+type Config struct {
+       Sync *Sync `yaml:"sync"`
+}
+
+type Sync struct {
+       Peers []*Peer `yaml:"peers"`
+}
+
+type Peer struct {
+       // TODO
+}
+
+func Init() error {
+       err := archaius.Init(archaius.WithMemorySource(), 
archaius.WithENVSource())
+       if err != nil {
+               log.Fatal("can not init archaius", err)
+       }
+
+       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))
+       }
+
+       err = Reload()
+       if err != nil {
+               log.Fatal("reload syncer configs failed", err)
+       }
+       return nil
+}
+
+//Reload reload the all configurations
+func Reload() error {
+       err := archaius.UnmarshalConfig(&config)
+       if err != nil {
+               return err
+       }
+       return nil
+}
+
+// GetConfig return the syncer full configurations
+func GetConfig() Config {
+       return config
+}
diff --git a/cmd/scserver/main.go b/syncer/config/config_test.go
similarity index 77%
copy from cmd/scserver/main.go
copy to syncer/config/config_test.go
index 4e91806..f494184 100644
--- a/cmd/scserver/main.go
+++ b/syncer/config/config_test.go
@@ -15,16 +15,16 @@
  * limitations under the License.
  */
 
-package main
+package config_test
 
 import (
-       _ "github.com/apache/servicecomb-service-center/server/init"
+       "testing"
 
-       _ "github.com/apache/servicecomb-service-center/server/bootstrap"
-
-       "github.com/apache/servicecomb-service-center/server"
+       "github.com/apache/servicecomb-service-center/syncer/config"
+       "github.com/stretchr/testify/assert"
 )
 
-func main() {
-       server.Run()
+func TestGetConfig(t *testing.T) {
+       assert.NoError(t, config.Init())
+       assert.NotNil(t, config.GetConfig().Sync)
 }
diff --git a/cmd/scserver/main.go b/syncer/init/init.go
similarity index 77%
copy from cmd/scserver/main.go
copy to syncer/init/init.go
index 4e91806..162bbe7 100644
--- a/cmd/scserver/main.go
+++ b/syncer/init/init.go
@@ -15,16 +15,15 @@
  * limitations under the License.
  */
 
-package main
+package init
 
 import (
-       _ "github.com/apache/servicecomb-service-center/server/init"
-
-       _ "github.com/apache/servicecomb-service-center/server/bootstrap"
-
-       "github.com/apache/servicecomb-service-center/server"
+       "github.com/apache/servicecomb-service-center/pkg/log"
+       "github.com/apache/servicecomb-service-center/syncer/config"
 )
 
-func main() {
-       server.Run()
+func init() {
+       if err := config.Init(); err != nil {
+               log.Error("syncer config init failed", err)
+       }
 }
diff --git a/cmd/scserver/main.go b/syncer/resource/admin/admin.go
similarity index 65%
copy from cmd/scserver/main.go
copy to syncer/resource/admin/admin.go
index 4e91806..8c971cc 100644
--- a/cmd/scserver/main.go
+++ b/syncer/resource/admin/admin.go
@@ -15,16 +15,25 @@
  * limitations under the License.
  */
 
-package main
+package admin
 
 import (
-       _ "github.com/apache/servicecomb-service-center/server/init"
+       "net/http"
 
-       _ "github.com/apache/servicecomb-service-center/server/bootstrap"
-
-       "github.com/apache/servicecomb-service-center/server"
+       "github.com/apache/servicecomb-service-center/pkg/rest"
 )
 
-func main() {
-       server.Run()
+type Resource struct {
+}
+
+// URLPatterns 路由
+func (res *Resource) URLPatterns() []rest.Route {
+       return []rest.Route{
+               {Method: http.MethodGet, Path: "/v1/syncer/health", Func: 
res.HealthCheck},
+       }
+}
+
+func (res *Resource) HealthCheck(w http.ResponseWriter, r *http.Request) {
+       // TODO call health service
+       rest.WriteResponse(w, r, nil, nil)
 }
diff --git a/cmd/scserver/main.go b/syncer/resource/register.go
similarity index 77%
copy from cmd/scserver/main.go
copy to syncer/resource/register.go
index 4e91806..3e7877e 100644
--- a/cmd/scserver/main.go
+++ b/syncer/resource/register.go
@@ -15,16 +15,17 @@
  * limitations under the License.
  */
 
-package main
+package resource
 
 import (
-       _ "github.com/apache/servicecomb-service-center/server/init"
-
-       _ "github.com/apache/servicecomb-service-center/server/bootstrap"
-
-       "github.com/apache/servicecomb-service-center/server"
+       "github.com/apache/servicecomb-service-center/pkg/rest"
+       "github.com/apache/servicecomb-service-center/syncer/resource/admin"
 )
 
-func main() {
-       server.Run()
+func init() {
+       initRouter()
+}
+
+func initRouter() {
+       rest.RegisterServant(&admin.Resource{})
 }
diff --git a/cmd/scserver/main.go b/syncer/server/server.go
similarity index 77%
copy from cmd/scserver/main.go
copy to syncer/server/server.go
index 4e91806..ed83ad8 100644
--- a/cmd/scserver/main.go
+++ b/syncer/server/server.go
@@ -15,16 +15,9 @@
  * limitations under the License.
  */
 
-package main
+package server
 
-import (
-       _ "github.com/apache/servicecomb-service-center/server/init"
-
-       _ "github.com/apache/servicecomb-service-center/server/bootstrap"
-
-       "github.com/apache/servicecomb-service-center/server"
-)
-
-func main() {
-       server.Run()
+func Start() error {
+       // TODO
+       return nil
 }

Reply via email to