This is an automated email from the ASF dual-hosted git repository.
asifdxtreme pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/incubator-servicecomb-service-center.git
The following commit(s) were added to refs/heads/master by this push:
new 7f9cdb7 SCB-977 Dependencies will not be updated in 5min when
re-create provider service (#478)
7f9cdb7 is described below
commit 7f9cdb72cc949a26cf1b62a1fd620e910924749f
Author: little-cui <[email protected]>
AuthorDate: Sat Nov 3 00:18:24 2018 +0800
SCB-977 Dependencies will not be updated in 5min when re-create provider
service (#478)
---
.../service/event/dependency_rule_event_handler.go | 51 +++++++++++++++++
.../event/dependency_rule_event_handler_test.go | 64 ++++++++++++++++++++++
server/service/event/event.go | 1 +
server/service/event/instance_event_handler.go | 13 +++--
server/service/event/rule_event_handler.go | 7 ++-
server/service/event/service_event_handler.go | 5 +-
server/service/event/tag_event_handler.go | 10 ++--
7 files changed, 136 insertions(+), 15 deletions(-)
diff --git a/server/service/event/dependency_rule_event_handler.go
b/server/service/event/dependency_rule_event_handler.go
new file mode 100644
index 0000000..3befe09
--- /dev/null
+++ b/server/service/event/dependency_rule_event_handler.go
@@ -0,0 +1,51 @@
+/*
+ * 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 event
+
+import (
+ "github.com/apache/incubator-servicecomb-service-center/pkg/log"
+ "github.com/apache/incubator-servicecomb-service-center/server/core"
+
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
+ pb
"github.com/apache/incubator-servicecomb-service-center/server/core/proto"
+
"github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
+
"github.com/apache/incubator-servicecomb-service-center/server/service/cache"
+)
+
+type DependencyRuleEventHandler struct {
+}
+
+func (h *DependencyRuleEventHandler) Type() discovery.Type {
+ return backend.DEPENDENCY_RULE
+}
+
+func (h *DependencyRuleEventHandler) OnEvent(evt discovery.KvEvent) {
+ action := evt.Type
+ if action != pb.EVT_UPDATE && action != pb.EVT_DELETE {
+ return
+ }
+ t, providerKey := core.GetInfoFromDependencyRuleKV(evt.KV.Key)
+ if t != core.DEPS_PROVIDER {
+ return
+ }
+ log.Debugf("caught [%s] provider rule[%s/%s/%s/%s] event",
+ action, providerKey.Environment, providerKey.AppId,
providerKey.ServiceName, providerKey.Version)
+ cache.DependencyRule.Remove(providerKey)
+}
+
+func NewDependencyRuleEventHandler() *DependencyRuleEventHandler {
+ return &DependencyRuleEventHandler{}
+}
diff --git a/server/service/event/dependency_rule_event_handler_test.go
b/server/service/event/dependency_rule_event_handler_test.go
new file mode 100644
index 0000000..9a4ec3b
--- /dev/null
+++ b/server/service/event/dependency_rule_event_handler_test.go
@@ -0,0 +1,64 @@
+/*
+ * 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 event
+
+import (
+ "github.com/apache/incubator-servicecomb-service-center/server/core"
+ pb
"github.com/apache/incubator-servicecomb-service-center/server/core/proto"
+
"github.com/apache/incubator-servicecomb-service-center/server/plugin/pkg/discovery"
+
"github.com/apache/incubator-servicecomb-service-center/server/service/cache"
+ "golang.org/x/net/context"
+ "testing"
+)
+
+func TestNewDependencyRuleEventHandler(t *testing.T) {
+ consumerId := "1"
+ provider := &pb.MicroServiceKey{Tenant: "x/y", Version: "0+"}
+ b := cache.DependencyRule.ExistVersionRule(context.Background(),
consumerId, provider)
+ if b {
+ t.Fatalf("TestNewDependencyRuleEventHandler failed")
+ }
+ h := NewDependencyRuleEventHandler()
+ h.OnEvent(discovery.KvEvent{Type: pb.EVT_CREATE})
+ b = cache.DependencyRule.ExistVersionRule(context.Background(),
consumerId, provider)
+ if !b {
+ t.Fatalf("TestNewDependencyRuleEventHandler failed")
+ }
+ h.OnEvent(discovery.KvEvent{Type: pb.EVT_INIT})
+ b = cache.DependencyRule.ExistVersionRule(context.Background(),
consumerId, provider)
+ if !b {
+ t.Fatalf("TestNewDependencyRuleEventHandler failed")
+ }
+ h.OnEvent(discovery.KvEvent{Type: pb.EVT_UPDATE, KV:
&discovery.KeyValue{
+ Key: []byte(core.GenerateProviderDependencyRuleKey("x/y",
provider))}})
+ b = cache.DependencyRule.ExistVersionRule(context.Background(),
consumerId, provider)
+ if b {
+ t.Fatalf("TestNewDependencyRuleEventHandler failed")
+ }
+ h.OnEvent(discovery.KvEvent{Type: pb.EVT_DELETE, KV:
&discovery.KeyValue{
+ Key: []byte(core.GenerateProviderDependencyRuleKey("x/y",
provider))}})
+ b = cache.DependencyRule.ExistVersionRule(context.Background(),
consumerId, provider)
+ if b {
+ t.Fatalf("TestNewDependencyRuleEventHandler failed")
+ }
+ h.OnEvent(discovery.KvEvent{Type: pb.EVT_DELETE, KV:
&discovery.KeyValue{
+ Key: []byte(core.GenerateConsumerDependencyRuleKey("x/y",
provider))}})
+ b = cache.DependencyRule.ExistVersionRule(context.Background(),
consumerId, provider)
+ if !b {
+ t.Fatalf("TestNewDependencyRuleEventHandler failed")
+ }
+}
diff --git a/server/service/event/event.go b/server/service/event/event.go
index 3b5d2a8..ca09aa9 100644
--- a/server/service/event/event.go
+++ b/server/service/event/event.go
@@ -27,4 +27,5 @@ func init() {
discovery.AddEventHandler(NewRuleEventHandler())
discovery.AddEventHandler(NewTagEventHandler())
discovery.AddEventHandler(NewDependencyEventHandler())
+ discovery.AddEventHandler(NewDependencyRuleEventHandler())
}
diff --git a/server/service/event/instance_event_handler.go
b/server/service/event/instance_event_handler.go
index 0d7c363..afedf68 100644
--- a/server/service/event/instance_event_handler.go
+++ b/server/service/event/instance_event_handler.go
@@ -60,25 +60,28 @@ func (h *InstanceEventHandler) OnEvent(evt
discovery.KvEvent) {
}
if nf.GetNotifyService().Closed() {
- log.Warnf("caught [%s] instance event %s/%s, but notify service
is closed",
+ log.Warnf("caught [%s] instance[%s/%s] event, but notify
service is closed",
action, providerId, providerInstanceId)
return
}
- log.Infof("caught [%s] instance event %s/%s", action, providerId,
providerInstanceId)
// 查询服务版本信息
ctx := util.SetContext(context.Background(), serviceUtil.CTX_CACHEONLY,
"1")
ms, err := serviceUtil.GetService(ctx, domainProject, providerId)
if ms == nil {
- log.Errorf(err, "get cached provider[%s/%s]'s file failed",
- providerId, providerInstanceId)
+ log.Errorf(err, "caught [%s] instance[%s/%s] event, get cached
provider's file failed",
+ action, providerId, providerInstanceId)
return
}
+ log.Infof("caught [%s] service[%s][%s/%s/%s/%s] instance[%s] event",
+ action, providerId, ms.Environment, ms.AppId, ms.ServiceName,
ms.Version, providerInstanceId)
+
// 查询所有consumer
consumerIds, _, err := serviceUtil.GetAllConsumerIds(ctx,
domainProject, ms)
if err != nil {
- log.Errorf(err, "get service[%s]'s consumerIds failed",
providerId)
+ log.Errorf(err, "get service[%s][%s/%s/%s/%s]'s consumerIds
failed",
+ providerId, ms.Environment, ms.AppId, ms.ServiceName,
ms.Version)
return
}
diff --git a/server/service/event/rule_event_handler.go
b/server/service/event/rule_event_handler.go
index 53b09a7..57eeb8a 100644
--- a/server/service/event/rule_event_handler.go
+++ b/server/service/event/rule_event_handler.go
@@ -67,7 +67,8 @@ func (apt *RulesChangedTask) publish(ctx context.Context,
domainProject, provide
consumerIds, err := serviceUtil.GetConsumerIds(ctx, domainProject,
provider)
if err != nil {
- log.Errorf(err, "get service[%s]'s consumerIds failed",
providerId)
+ log.Errorf(err, "get service[%s][%s/%s/%s/%s]'s consumerIds
failed",
+ providerId, provider.Environment, provider.AppId,
provider.ServiceName, provider.Version)
return err
}
providerKey := pb.MicroServiceToKey(domainProject, provider)
@@ -91,11 +92,11 @@ func (h *RuleEventHandler) OnEvent(evt discovery.KvEvent) {
providerId, ruleId, domainProject := core.GetInfoFromRuleKV(evt.KV.Key)
if nf.GetNotifyService().Closed() {
- log.Warnf("caught [%s] service rule event %s/%s, but notify
service is closed",
+ log.Warnf("caught [%s] service rule[%s/%s] event, but notify
service is closed",
action, providerId, ruleId)
return
}
- log.Infof("caught [%s] service rule event %s/%s", action, providerId,
ruleId)
+ log.Infof("caught [%s] service rule[%s/%s] event", action, providerId,
ruleId)
task.Service().Add(context.Background(),
NewRulesChangedAsyncTask(domainProject, providerId,
evt.Revision))
diff --git a/server/service/event/service_event_handler.go
b/server/service/event/service_event_handler.go
index ce6e08c..8daf89c 100644
--- a/server/service/event/service_event_handler.go
+++ b/server/service/event/service_event_handler.go
@@ -60,13 +60,12 @@ func (h *ServiceEventHandler) OnEvent(evt
discovery.KvEvent) {
return
}
- log.Infof("caught [%s] service %s/%s/%s event",
- evt.Type, ms.AppId, ms.ServiceName, ms.Version)
+ log.Infof("caught [%s] service[%s/%s/%s/%s] event",
+ evt.Type, ms.Environment, ms.AppId, ms.ServiceName, ms.Version)
// cache
providerKey := pb.MicroServiceToKey(domainProject, ms)
cache.FindInstances.Remove(providerKey)
- cache.DependencyRule.Remove(providerKey)
}
func getFramework(ms *pb.MicroService) (string, string) {
diff --git a/server/service/event/tag_event_handler.go
b/server/service/event/tag_event_handler.go
index ad42578..e915db7 100644
--- a/server/service/event/tag_event_handler.go
+++ b/server/service/event/tag_event_handler.go
@@ -71,14 +71,16 @@ func (apt *TagsChangedTask) publish(ctx context.Context,
domainProject, consumer
providerIds, err := serviceUtil.GetProviderIds(ctx, domainProject,
consumer)
if err != nil {
- log.Errorf(err, "get service[%s]'s providerIds failed",
consumerId)
+ log.Errorf(err, "get service[%s][%s/%s/%s/%s]'s providerIds
failed",
+ consumerId, consumer.Environment, consumer.AppId,
consumer.ServiceName, consumer.Version)
return err
}
for _, providerId := range providerIds {
provider, err := serviceUtil.GetService(ctx, domainProject,
providerId)
if provider == nil {
- log.Errorf(err, "get service[%s]'s provider[%s] file
failed", consumerId, providerId)
+ log.Errorf(err, "get service[%s][%s/%s/%s/%s]'s
provider[%s] file failed",
+ consumerId, consumer.Environment,
consumer.AppId, consumer.ServiceName, consumer.Version, providerId)
continue
}
@@ -104,11 +106,11 @@ func (h *TagEventHandler) OnEvent(evt discovery.KvEvent) {
consumerId, domainProject := core.GetInfoFromTagKV(evt.KV.Key)
if nf.GetNotifyService().Closed() {
- log.Warnf("caught [%s] service tags event %s/%s, but notify
service is closed",
+ log.Warnf("caught [%s] service tags[%s/%s] event, but notify
service is closed",
action, consumerId, evt.KV.Value)
return
}
- log.Infof("caught [%s] service tags event %s/%s", action, consumerId,
evt.KV.Value)
+ log.Infof("caught [%s] service tags[%s/%s] event", action, consumerId,
evt.KV.Value)
task.Service().Add(context.Background(),
NewTagsChangedAsyncTask(domainProject, consumerId,
evt.Revision))