[ 
https://issues.apache.org/jira/browse/SCB-977?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16673359#comment-16673359
 ] 

ASF GitHub Bot commented on SCB-977:
------------------------------------

asifdxtreme closed pull request #478: SCB-977 Dependencies will not be updated 
in 5min when re-create provider service
URL: https://github.com/apache/incubator-servicecomb-service-center/pull/478
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 00000000..3befe092
--- /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 00000000..9a4ec3b5
--- /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 3b5d2a8b..ca09aa90 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 0d7c363e..afedf689 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 53b09a72..57eeb8a6 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 ce6e08c8..8daf89c5 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 ad42578a..e915db7e 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))


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Dependencies will not be updated in 5min when micro service is changed
> ----------------------------------------------------------------------
>
>                 Key: SCB-977
>                 URL: https://issues.apache.org/jira/browse/SCB-977
>             Project: Apache ServiceComb
>          Issue Type: Bug
>          Components: Service-Center
>            Reporter: little-cui
>            Assignee: little-cui
>            Priority: Major
>             Fix For: service-center-1.1.0
>
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to