You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2023/02/06 09:44:44 UTC

[skywalking] branch master updated: Fix Scope.Finder.valueOf method bug. (#10351)

This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git


The following commit(s) were added to refs/heads/master by this push:
     new 60b061f5f9 Fix Scope.Finder.valueOf method bug. (#10351)
60b061f5f9 is described below

commit 60b061f5f9f48a7dd0aa238f9218503c74882ad0
Author: 吴晟 Wu Sheng <wu...@foxmail.com>
AuthorDate: Mon Feb 6 17:44:26 2023 +0800

    Fix Scope.Finder.valueOf method bug. (#10351)
    
    The previous implementation could only support scopes being catalogs.
---
 .../oap/server/core/query/enumeration/Scope.java   | 51 ++++++++++++++++++----
 1 file changed, 42 insertions(+), 9 deletions(-)

diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/enumeration/Scope.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/enumeration/Scope.java
index 1c16e01d38..e05b60c1f1 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/enumeration/Scope.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/enumeration/Scope.java
@@ -18,11 +18,23 @@
 
 package org.apache.skywalking.oap.server.core.query.enumeration;
 
-import java.util.HashMap;
 import lombok.Getter;
-import org.apache.skywalking.oap.server.core.UnexpectedException;
 import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine;
 
+import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.inEndpointCatalog;
+import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.inEndpointRelationCatalog;
+import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.inProcessCatalog;
+import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.inProcessRelationCatalog;
+import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.inServiceCatalog;
+import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.inServiceInstanceCatalog;
+import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.inServiceInstanceRelationCatalog;
+import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.inServiceRelationCatalog;
+
+/**
+ * Scope n query stage represents the scope catalog. All scopes with their catalogs are defined in {@link DefaultScopeDefine}.
+ * Scope IDs could be various due to different OAL/MAL input.
+ * Scope catalog provides high dimension classification for all scopes as a hierarchy structure.
+ */
 public enum Scope {
     /**
      * @since Deprecated from 9.0.0
@@ -35,25 +47,46 @@ public enum Scope {
     ServiceRelation(DefaultScopeDefine.SERVICE_RELATION),
     ServiceInstanceRelation(DefaultScopeDefine.SERVICE_INSTANCE_RELATION),
     EndpointRelation(DefaultScopeDefine.ENDPOINT_RELATION),
+    Process(DefaultScopeDefine.PROCESS),
     ProcessRelation(DefaultScopeDefine.PROCESS_RELATION);
 
+    /**
+     * Scope ID is defined in {@link DefaultScopeDefine}.
+     */
     @Getter
     private int scopeId;
 
     Scope(int scopeId) {
         this.scopeId = scopeId;
-        Finder.ALL_QUERY_SCOPES.put(scopeId, this);
     }
 
     public static class Finder {
-        private static HashMap<Integer, Scope> ALL_QUERY_SCOPES = new HashMap<>();
-
         public static Scope valueOf(int scopeId) {
-            Scope scope = ALL_QUERY_SCOPES.get(scopeId);
-            if (scope == null) {
-                throw new UnexpectedException("Can't find scope id =" + scopeId);
+            if (inServiceCatalog(scopeId)) {
+                return Service;
+            }
+            if (inServiceInstanceCatalog(scopeId)) {
+                return ServiceInstance;
+            }
+            if (inEndpointCatalog(scopeId)) {
+                return Endpoint;
+            }
+            if (inServiceRelationCatalog(scopeId)) {
+                return ServiceRelation;
+            }
+            if (inServiceInstanceRelationCatalog(scopeId)) {
+                return ServiceInstanceRelation;
+            }
+            if (inEndpointRelationCatalog(scopeId)) {
+                return EndpointRelation;
+            }
+            if (inProcessCatalog(scopeId)) {
+                return Process;
+            }
+            if (inProcessRelationCatalog(scopeId)) {
+                return ProcessRelation;
             }
-            return scope;
+            return All;
         }
     }