little-cui commented on a change in pull request #1211:
URL:
https://github.com/apache/servicecomb-service-center/pull/1211#discussion_r780869072
##########
File path: datasource/etcd/ms.go
##########
@@ -599,12 +602,35 @@ func (ds *MetadataManager) registerInstance(ctx
context.Context, request *pb.Reg
instanceFlag, instanceID, remoteIP), nil)
return "", pb.NewError(pb.ErrServiceNotExists, "Service does
not exist.")
}
-
+ sendEvent(sync.CreateAction, datasource.ResourceInstance, request)
log.Info(fmt.Sprintf("register instance %s, instanceID %s, operator %s",
instanceFlag, instanceID, remoteIP))
return instanceID, nil
}
+func sendEvent(action string, resourceType string, resource interface{}) {
+ if datasource.EnableSync {
+ eventID, err := guuid.NewV4()
+ if err != nil {
+ log.Error("fail to create eventID", err)
+ return
+ }
+ resourceValue, err := json.Marshal(resource)
+ if err != nil {
+ log.Error("fail to marshal the resource", err)
+ return
+ }
+ event := v1.Event{
+ Id: eventID.String(),
+ Action: action,
+ Subject: resourceType,
+ Value: resourceValue,
+ }
+ log.Info(fmt.Sprintf("success to send event %s", event.Subject))
+ // to send event
Review comment:
加TODO
##########
File path: datasource/etcd/ms.go
##########
@@ -599,12 +602,35 @@ func (ds *MetadataManager) registerInstance(ctx
context.Context, request *pb.Reg
instanceFlag, instanceID, remoteIP), nil)
return "", pb.NewError(pb.ErrServiceNotExists, "Service does
not exist.")
}
-
+ sendEvent(sync.CreateAction, datasource.ResourceInstance, request)
log.Info(fmt.Sprintf("register instance %s, instanceID %s, operator %s",
instanceFlag, instanceID, remoteIP))
return instanceID, nil
}
+func sendEvent(action string, resourceType string, resource interface{}) {
Review comment:
应该放到sync包的service下
##########
File path: datasource/etcd/ms.go
##########
@@ -599,12 +602,35 @@ func (ds *MetadataManager) registerInstance(ctx
context.Context, request *pb.Reg
instanceFlag, instanceID, remoteIP), nil)
return "", pb.NewError(pb.ErrServiceNotExists, "Service does
not exist.")
}
-
+ sendEvent(sync.CreateAction, datasource.ResourceInstance, request)
log.Info(fmt.Sprintf("register instance %s, instanceID %s, operator %s",
instanceFlag, instanceID, remoteIP))
return instanceID, nil
}
+func sendEvent(action string, resourceType string, resource interface{}) {
+ if datasource.EnableSync {
Review comment:
改成卫语句,提前返回
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]