You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2020/11/25 03:38:10 UTC

[GitHub] [servicecomb-service-center] little-cui commented on a change in pull request #755: Incremental synchronization of sc: sync between sc and syncer

little-cui commented on a change in pull request #755:
URL: https://github.com/apache/servicecomb-service-center/pull/755#discussion_r530085383



##########
File path: server/rest/syncer/service.go
##########
@@ -0,0 +1,71 @@
+/*
+ * 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 syncer
+
+import (
+	"context"
+	"github.com/apache/servicecomb-service-center/pkg/log"
+	"github.com/apache/servicecomb-service-center/server/syncernotify"
+	"github.com/astaxie/beego"
+	"github.com/gorilla/websocket"
+	"net/http"
+	"os"
+	"strings"
+)
+
+var (
+	ServiceAPI   = &Service{}
+	configs      map[string]string
+	environments = make(map[string]string)
+)
+
+func init() {
+	// cache envs
+	for _, kv := range os.Environ() {
+		arr := strings.Split(kv, "=")
+		environments[arr[0]] = arr[1]
+	}
+
+	// cache configs
+	configs, _ = beego.AppConfig.GetSection("default")
+	if section, err := beego.AppConfig.GetSection(beego.BConfig.RunMode); err == nil {

Review comment:
       应使用server/config包的机制加载配置

##########
File path: server/server.go
##########
@@ -173,6 +176,9 @@ func (s *ServiceCenterServer) startServices() {
 	// notifications
 	s.notifyService.Start()
 
+	// notify syncer
+	s.syncerNotifyService.Start()

Review comment:
       应改成可插拔的,因为并不是所有场景都有syncer

##########
File path: datasource/etcd/event/instance_event_handler.go
##########
@@ -83,17 +85,22 @@ func (h *InstanceEventHandler) OnEvent(evt sd.KvEvent) {
 		}
 	}
 
+	// 查询服务版本信息
+	ctx := context.WithValue(context.WithValue(context.Background(),
+		util.CtxCacheOnly, "1"),
+		util.CtxGlobal, "1")
+	ms, err := serviceUtil.GetService(ctx, domainProject, providerID)

Review comment:
       这里异常没有处理,会有nil panic

##########
File path: server/syncernotify/websocket.go
##########
@@ -0,0 +1,245 @@
+/*
+ * 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 syncernotify
+
+import (
+	"context"
+	"encoding/json"
+	"fmt"
+	pb "github.com/apache/servicecomb-service-center/pkg/dump"
+	"github.com/apache/servicecomb-service-center/pkg/log"
+	"github.com/apache/servicecomb-service-center/pkg/util"
+	"github.com/gorilla/websocket"
+	"time"
+)
+
+type WebSocket struct {

Review comment:
       感觉又copy了一份代码,是否能抽象出扩展部分,做可插拔的




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org