robocanic commented on code in PR #1340:
URL: https://github.com/apache/dubbo-admin/pull/1340#discussion_r2446461225


##########
pkg/core/engine/subscriber/runtime_instance.go:
##########
@@ -0,0 +1,185 @@
+/*
+ * 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 subscriber
+
+import (
+       "errors"
+       "reflect"
+
+       "github.com/duke-git/lancet/v2/strutil"
+       "k8s.io/client-go/tools/cache"
+
+       "github.com/apache/dubbo-admin/pkg/common/bizerror"
+       "github.com/apache/dubbo-admin/pkg/core/events"
+       "github.com/apache/dubbo-admin/pkg/core/logger"
+       meshresource 
"github.com/apache/dubbo-admin/pkg/core/resource/apis/mesh/v1alpha1"
+       coremodel "github.com/apache/dubbo-admin/pkg/core/resource/model"
+       "github.com/apache/dubbo-admin/pkg/core/store"
+       "github.com/apache/dubbo-admin/pkg/core/store/index"
+)
+
+type RuntimeInstanceEventSubscriber struct {
+       instanceResourceStore store.ResourceStore
+       eventEmitter          events.Emitter
+}
+
+func (s *RuntimeInstanceEventSubscriber) ResourceKind() coremodel.ResourceKind 
{
+       return meshresource.RuntimeInstanceKind
+}
+
+func (s *RuntimeInstanceEventSubscriber) Name() string {
+       return "Engine-" + s.ResourceKind().ToString()
+}
+
+func (s *RuntimeInstanceEventSubscriber) ProcessEvent(event events.Event) 
error {
+       newObj, ok := event.NewObj().(*meshresource.RuntimeInstanceResource)
+       if !ok && newObj != nil {
+               return 
bizerror.NewAssertionError(meshresource.RuntimeInstanceKind, 
reflect.TypeOf(event.NewObj()).Name())
+       }
+       oldObj, ok := event.OldObj().(*meshresource.RuntimeInstanceResource)
+       if !ok && oldObj != nil {
+               return 
bizerror.NewAssertionError(meshresource.RuntimeInstanceKind, 
reflect.TypeOf(event.OldObj()).Name())
+       }
+       var processErr error
+       switch event.Type() {
+       case cache.Added, cache.Updated, cache.Replaced, cache.Sync:
+               if newObj == nil {
+                       errStr := "process runtime instance upsert event, but 
new obj is nil, skipped processing"
+                       logger.Error(errStr)
+                       return errors.New(errStr)
+               }
+               processErr = s.processUpsert(newObj)
+       case cache.Deleted:
+               if oldObj == nil {
+                       errStr := "process runtime instance delete event, but 
old obj is nil, skipped processing"
+                       logger.Error(errStr)
+                       return errors.New(errStr)
+               }
+               processErr = s.processDelete(oldObj)
+       }
+       eventStr := event.String()
+       if processErr != nil {

Review Comment:
   fixed



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to