Feature: add syncer config framework (#1197)

* Feature: add syncer config framework

* Feature: add syncer resource
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 @@
 
 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/syncer/bootstrap/bootstrap.go b/syncer/bootstrap/bootstrap.go
new file mode 100644
index 0000000..fc6c6e6
--- /dev/null
+++ b/syncer/bootstrap/bootstrap.go
@@ -0,0 +1,25 @@
+/*
+ * 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 bootstrap
+
+import (
+	_ "github.com/apache/servicecomb-service-center/syncer/resource"
+)
+
+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/syncer/config/config_test.go b/syncer/config/config_test.go
new file mode 100644
index 0000000..f494184
--- /dev/null
+++ b/syncer/config/config_test.go
@@ -0,0 +1,30 @@
+/*
+ * 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_test
+
+import (
+	"testing"
+
+	"github.com/apache/servicecomb-service-center/syncer/config"
+	"github.com/stretchr/testify/assert"
+)
+
+func TestGetConfig(t *testing.T) {
+	assert.NoError(t, config.Init())
+	assert.NotNil(t, config.GetConfig().Sync)
+}
diff --git a/syncer/init/init.go b/syncer/init/init.go
new file mode 100644
index 0000000..162bbe7
--- /dev/null
+++ b/syncer/init/init.go
@@ -0,0 +1,29 @@
+/*
+ * 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 init
+
+import (
+	"github.com/apache/servicecomb-service-center/pkg/log"
+	"github.com/apache/servicecomb-service-center/syncer/config"
+)
+
+func init() {
+	if err := config.Init(); err != nil {
+		log.Error("syncer config init failed", err)
+	}
+}
diff --git a/syncer/resource/admin/admin.go b/syncer/resource/admin/admin.go
new file mode 100644
index 0000000..8c971cc
--- /dev/null
+++ b/syncer/resource/admin/admin.go
@@ -0,0 +1,39 @@
+/*
+ * 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 admin
+
+import (
+	"net/http"
+
+	"github.com/apache/servicecomb-service-center/pkg/rest"
+)
+
+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/syncer/resource/register.go b/syncer/resource/register.go
new file mode 100644
index 0000000..3e7877e
--- /dev/null
+++ b/syncer/resource/register.go
@@ -0,0 +1,31 @@
+/*
+ * 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 resource
+
+import (
+	"github.com/apache/servicecomb-service-center/pkg/rest"
+	"github.com/apache/servicecomb-service-center/syncer/resource/admin"
+)
+
+func init() {
+	initRouter()
+}
+
+func initRouter() {
+	rest.RegisterServant(&admin.Resource{})
+}
diff --git a/syncer/server/server.go b/syncer/server/server.go
new file mode 100644
index 0000000..ed83ad8
--- /dev/null
+++ b/syncer/server/server.go
@@ -0,0 +1,23 @@
+/*
+ * 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 server
+
+func Start() error {
+	// TODO
+	return nil
+}