Ethanlm commented on a change in pull request #3306:
URL: https://github.com/apache/storm/pull/3306#discussion_r452949990



##########
File path: storm-client/src/jvm/org/apache/storm/ILocalCluster.java
##########
@@ -135,6 +137,12 @@ ILocalTopology submitTopologyWithOpts(String topologyName, 
Map<String, Object> c
      */
     ClusterSummary getClusterInfo() throws TException;
 
+    java.util.List<TopologySummary> getTopologySummaryInfo() throws 
AuthorizationException, TException;

Review comment:
       suggest to import `java.util.List` and then use List directly
   suggest to change to `getTopologySummaries`
   can delete `AuthorizationException`
   

##########
File path: storm-core/src/jvm/org/apache/storm/command/GetErrors.java
##########
@@ -42,15 +42,10 @@ public static void main(String[] args) throws Exception {
             public void run(Nimbus.Iface client) throws Exception {
                 GetInfoOptions opts = new GetInfoOptions();
                 opts.set_num_err_choice(NumErrorsChoice.ONE);
-                String topologyId = Utils.getTopologyId(name, client);
-
-                TopologyInfo topologyInfo = null;
-                if (topologyId != null) {
-                    topologyInfo = client.getTopologyInfoWithOpts(topologyId, 
opts);
-                }
+                TopologyInfo topologyInfo = 
client.getTopologyInfoByNameWithOpts(name, opts);
 
                 Map<String, Object> outputMap = new HashMap<>();
-                if (topologyId == null || topologyInfo == null) {
+                if (topologyInfo == null) {

Review comment:
       Will topologyInfo ever be `null`?

##########
File path: storm-server/src/main/java/org/apache/storm/LocalCluster.java
##########
@@ -572,11 +573,43 @@ public ClusterSummary getClusterInfo() throws TException {
         return getNimbus().getClusterInfo();
     }
 
+    @Override
+    public List<TopologySummary> getTopologySummaries() throws 
AuthorizationException, TException {

Review comment:
       AuthorizationException can be removed

##########
File path: storm-client/src/jvm/org/apache/storm/ILocalCluster.java
##########
@@ -135,6 +137,12 @@ ILocalTopology submitTopologyWithOpts(String topologyName, 
Map<String, Object> c
      */
     ClusterSummary getClusterInfo() throws TException;
 
+    java.util.List<TopologySummary> getTopologySummaryInfo() throws 
AuthorizationException, TException;
+
+    TopologySummary getTopologySummaryByName(java.lang.String name) throws 
AuthorizationException, TException;
+
+    TopologySummary getTopologySummaryById(java.lang.String id) throws 
AuthorizationException, TException;

Review comment:
       `String` should be good enough.
   can delete `AuthorizationException` , since it extends `TException`
   
   

##########
File path: storm-server/src/main/java/org/apache/storm/LocalCluster.java
##########
@@ -572,11 +573,43 @@ public ClusterSummary getClusterInfo() throws TException {
         return getNimbus().getClusterInfo();
     }
 
+    @Override
+    public List<TopologySummary> getTopologySummaries() throws 
AuthorizationException, TException {
+        return getNimbus().getTopologySummaries();
+    }
+
+    @Override
+    public TopologySummary getTopologySummaryByName(String name) throws 
AuthorizationException, TException {
+        return getNimbus().getTopologySummaryByName(name);
+    }
+
+    @Override
+    public TopologySummary getTopologySummaryById(String id) throws 
AuthorizationException, TException {
+        return getNimbus().getTopologySummaryById(id);
+    }
+
     @Override
     public TopologyInfo getTopologyInfo(String id) throws TException {
         return getNimbus().getTopologyInfo(id);
     }
 
+    @Override
+    public TopologyInfo getTopologyInfoByName(String name) throws TException {
+        return getNimbus().getTopologyInfoByName(name);
+    }
+
+    @Override
+    public TopologyInfo getTopologyInfoWithOpts(String id, GetInfoOptions 
options) throws NotAliveException, AuthorizationException,
+        TException {
+        return nimbus.getTopologyInfoWithOpts(id, options);
+    }
+
+    @Override
+    public TopologyInfo getTopologyInfoByNameWithOpts(String name, 
GetInfoOptions options) throws NotAliveException, AuthorizationException,

Review comment:
       NotAliveException, AuthorizationException can be removed

##########
File path: storm-server/src/main/java/org/apache/storm/daemon/nimbus/Nimbus.java
##########
@@ -2968,16 +2978,14 @@ private SupervisorSummary makeSupervisorSummary(String 
supervisorId, SupervisorI
         return ret;
     }
 
-    private ClusterSummary getClusterInfoImpl() throws Exception {
+    private ClusterSummary getClusterInfoImpl() throws Exception, 
AuthorizationException {

Review comment:
       `AuthorizationException` is not needed

##########
File path: storm-server/src/main/java/org/apache/storm/daemon/nimbus/Nimbus.java
##########
@@ -4654,6 +4714,55 @@ public ClusterSummary getClusterInfo() throws 
AuthorizationException, TException
         }
     }
 
+    @Override
+    public List<TopologySummary> getTopologySummaries() throws 
AuthorizationException, TException {
+        try {
+            getTopologySummariesCalls.mark();
+            checkAuthorization(null, null, "getTopologySummaries");
+            return getTopologySummariesImpl();
+        } catch (Exception e) {
+            LOG.warn("Get TopologySummary info exception.", e);
+            if (e instanceof TException) {
+                throw (TException) e;
+            }
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    public TopologySummary getTopologySummaryByName(String name) throws 
AuthorizationException, TException {
+        try {
+            getTopologySummaryByNameCalls.mark();
+            checkAuthorization(null, null, "getTopologySummaries");
+            IStormClusterState state = stormClusterState;
+            String topoId = state.getTopoId(name).orElseThrow(() -> new 
WrappedNotAliveException(name + " is not alive"));
+            return getTopologySummary(topoId, 
state.topologyBases().get(topoId));
+        } catch (Exception e) {
+            LOG.warn("Get TopologySummaryByName info exception.", e);
+            if (e instanceof TException) {
+                throw (TException) e;
+            }
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    public TopologySummary getTopologySummaryById(String id) throws 
AuthorizationException, TException {

Review comment:
       looks like we don't need AuthorizationException

##########
File path: storm-server/src/test/java/org/apache/storm/TestRebalance.java
##########
@@ -151,28 +151,22 @@ public void waitTopologyScheduled(String topoName, 
ILocalCluster cluster, int re
 
     public boolean checkTopologyScheduled(String topoName, ILocalCluster 
cluster) throws TException {
         if (checkTopologyUp(topoName, cluster)) {
-            ClusterSummary sum = cluster.getClusterInfo();
-            for (TopologySummary topoSum : sum.get_topologies()) {
-                if (topoSum.get_name().equals(topoName)) {
-                    String status = topoSum.get_status();
-                    String sched_status = topoSum.get_sched_status();
-                    if (status.equals("ACTIVE") && (sched_status != null && 
!sched_status.equals(""))) {
-                        return true;
-                    }
-                }
+            TopologySummary topoSum = 
cluster.getTopologySummaryByName(topoName);
+            String status = topoSum.get_status();
+            String sched_status = topoSum.get_sched_status();
+            if (status.equals("ACTIVE") && (sched_status != null && 
!sched_status.equals(""))) {
+                return true;
             }
         }
         return false;
     }
 
     public boolean checkTopologyUp(String topoName, ILocalCluster cluster) 
throws TException {
         ClusterSummary sum = cluster.getClusterInfo();
-
-        for (TopologySummary topoSum : sum.get_topologies()) {
-            if (topoSum.get_name().equals(topoName)) {
+        TopologySummary topoSum = cluster.getTopologySummaryByName(topoName);
+            if (topoSum != null) {

Review comment:
       Will it ever be `null`? Looks to me `getTopologySummaryByName` throws 
exception if it can't find the topo

##########
File path: storm-server/src/main/java/org/apache/storm/daemon/nimbus/Nimbus.java
##########
@@ -4654,6 +4714,55 @@ public ClusterSummary getClusterInfo() throws 
AuthorizationException, TException
         }
     }
 
+    @Override
+    public List<TopologySummary> getTopologySummaries() throws 
AuthorizationException, TException {
+        try {
+            getTopologySummariesCalls.mark();
+            checkAuthorization(null, null, "getTopologySummaries");
+            return getTopologySummariesImpl();
+        } catch (Exception e) {
+            LOG.warn("Get TopologySummary info exception.", e);
+            if (e instanceof TException) {
+                throw (TException) e;
+            }
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    public TopologySummary getTopologySummaryByName(String name) throws 
AuthorizationException, TException {

Review comment:
       looks like we don't need AuthorizationException

##########
File path: storm-client/src/storm.thrift
##########
@@ -777,9 +777,14 @@ service Nimbus {
   string getNimbusConf() throws (1: AuthorizationException aze);
   // stats functions
   ClusterSummary getClusterInfo() throws (1: AuthorizationException aze);
+  list<TopologySummary> getTopologySummaries() throws (1: 
AuthorizationException aze);
+  TopologySummary getTopologySummaryByName(1: string name) throws (1: 
AuthorizationException aze);
+  TopologySummary getTopologySummaryById(1: string id) throws (1: 
AuthorizationException aze);

Review comment:
       I think this is better to be `getTopologySummary` (without `ById`) since 
other functions don't have `ById` when it is getting information by id, e.g. 
`getTopologyInfo, getTopologyPageInfo, getTopologyConf, getTopology`, etc

##########
File path: 
examples/storm-starter/src/jvm/org/apache/storm/starter/InOrderDeliveryTest.java
##########
@@ -40,16 +40,11 @@
 public class InOrderDeliveryTest {
 
     public static void printMetrics(Nimbus.Iface client, String name) throws 
Exception {
-        ClusterSummary summary = client.getClusterInfo();
-        String id = null;
-        for (TopologySummary ts : summary.get_topologies()) {
-            if (name.equals(ts.get_name())) {
-                id = ts.get_id();
-            }
-        }
-        if (id == null) {
+        TopologySummary ts = client.getTopologySummaryByName(name);
+        if (ts == null) {

Review comment:
       I beliefve this is no longer needed, since if `getTopologySummaryByName` 
fails, `getTopologySummaryByName` will throw `TException` or `RuntimeException`.
   
   If this is not the case, then other places where we invoke 
`getTopologySummaryByName` should also deal with the `result=null`.

##########
File path: storm-client/src/jvm/org/apache/storm/utils/Utils.java
##########
@@ -1188,28 +1188,18 @@ static boolean isValidConf(Map<String, Object> orig, 
Map<String, Object> deser)
 
     public static TopologyInfo getTopologyInfo(String name, String asUser, 
Map<String, Object> topoConf) {
         try (NimbusClient client = 
NimbusClient.getConfiguredClientAs(topoConf, asUser)) {
-            String topologyId = getTopologyId(name, client.getClient());
-            if (null != topologyId) {
-                return client.getClient().getTopologyInfo(topologyId);
-            }
-            return null;
+            return client.getClient().getTopologyInfoByName(name);
         } catch (Exception e) {
             throw new RuntimeException(e);
         }
     }
 
     public static String getTopologyId(String name, Nimbus.Iface client) {
         try {
-            ClusterSummary summary = client.getClusterInfo();
-            for (TopologySummary s : summary.get_topologies()) {
-                if (s.get_name().equals(name)) {
-                    return s.get_id();
-                }
-            }
+            return client.getTopologySummaryByName(name).get_id();
         } catch (Exception e) {
             throw new RuntimeException(e);
         }
-        return null;

Review comment:
       I noticed that there is syntax change here. Before the change, 
`getTopologyId` returns `null` when it couldn't get the summary. But with the 
change, it will throw exceptions when there is no such topology with this 
`name`. Is there any impact here?

##########
File path: storm-client/src/jvm/org/apache/storm/ILocalCluster.java
##########
@@ -135,6 +137,12 @@ ILocalTopology submitTopologyWithOpts(String topologyName, 
Map<String, Object> c
      */
     ClusterSummary getClusterInfo() throws TException;
 
+    java.util.List<TopologySummary> getTopologySummaryInfo() throws 
AuthorizationException, TException;
+
+    TopologySummary getTopologySummaryByName(java.lang.String name) throws 
AuthorizationException, TException;

Review comment:
       `String` should be good enough.
   can delete `AuthorizationException`, since it extends `TException`

##########
File path: storm-server/src/main/java/org/apache/storm/LocalCluster.java
##########
@@ -572,11 +573,43 @@ public ClusterSummary getClusterInfo() throws TException {
         return getNimbus().getClusterInfo();
     }
 
+    @Override
+    public List<TopologySummary> getTopologySummaries() throws 
AuthorizationException, TException {
+        return getNimbus().getTopologySummaries();
+    }
+
+    @Override
+    public TopologySummary getTopologySummaryByName(String name) throws 
AuthorizationException, TException {

Review comment:
       AuthorizationException can be removed

##########
File path: 
integration-test/src/test/java/org/apache/storm/st/wrapper/StormCluster.java
##########
@@ -108,7 +108,7 @@ public TopologySummary getOneActive() throws TException {
     }
 
     public TopologyInfo getInfo(TopologySummary topologySummary) throws 
TException {
-        return client.getTopologyInfo(topologySummary.get_id());
+        return client.getTopologyInfoByName(topologySummary.get_id());

Review comment:
       This doesn't look right.

##########
File path: storm-server/src/main/java/org/apache/storm/LocalCluster.java
##########
@@ -572,11 +573,43 @@ public ClusterSummary getClusterInfo() throws TException {
         return getNimbus().getClusterInfo();
     }
 
+    @Override
+    public List<TopologySummary> getTopologySummaries() throws 
AuthorizationException, TException {
+        return getNimbus().getTopologySummaries();
+    }
+
+    @Override
+    public TopologySummary getTopologySummaryByName(String name) throws 
AuthorizationException, TException {
+        return getNimbus().getTopologySummaryByName(name);
+    }
+
+    @Override
+    public TopologySummary getTopologySummaryById(String id) throws 
AuthorizationException, TException {

Review comment:
       AuthorizationException can be removed

##########
File path: storm-server/src/main/java/org/apache/storm/LocalCluster.java
##########
@@ -572,11 +573,43 @@ public ClusterSummary getClusterInfo() throws TException {
         return getNimbus().getClusterInfo();
     }
 
+    @Override
+    public List<TopologySummary> getTopologySummaries() throws 
AuthorizationException, TException {
+        return getNimbus().getTopologySummaries();
+    }
+
+    @Override
+    public TopologySummary getTopologySummaryByName(String name) throws 
AuthorizationException, TException {
+        return getNimbus().getTopologySummaryByName(name);
+    }
+
+    @Override
+    public TopologySummary getTopologySummaryById(String id) throws 
AuthorizationException, TException {
+        return getNimbus().getTopologySummaryById(id);
+    }
+
     @Override
     public TopologyInfo getTopologyInfo(String id) throws TException {
         return getNimbus().getTopologyInfo(id);
     }
 
+    @Override
+    public TopologyInfo getTopologyInfoByName(String name) throws TException {
+        return getNimbus().getTopologyInfoByName(name);
+    }
+
+    @Override
+    public TopologyInfo getTopologyInfoWithOpts(String id, GetInfoOptions 
options) throws NotAliveException, AuthorizationException,

Review comment:
       NotAliveException, AuthorizationException can be removed

##########
File path: storm-server/src/main/java/org/apache/storm/daemon/nimbus/Nimbus.java
##########
@@ -4056,6 +4077,45 @@ public TopologyInfo getTopologyInfo(String id) throws 
NotAliveException, Authori
         }
     }
 
+    @Override
+    public TopologyInfo getTopologyInfoByName(String name) throws 
NotAliveException, AuthorizationException, TException {
+        try {
+            getTopologyInfoByNameCalls.mark();
+            GetInfoOptions options = new GetInfoOptions();
+            options.set_num_err_choice(NumErrorsChoice.ALL);
+
+            return getTopologyInfoByNameImpl(name, options);
+        } catch (Exception e) {
+            LOG.warn("get topology info exception. (topology name={})", name, 
e);
+            if (e instanceof TException) {
+                throw (TException) e;
+            }
+            throw new RuntimeException(e);
+        }
+    }
+
+    private TopologyInfo getTopologyInfoByNameImpl(String name, GetInfoOptions 
options) throws

Review comment:
       This might should be `getTopologyInfoByNameWithOptsImpl`?

##########
File path: storm-server/src/test/java/org/apache/storm/TestRebalance.java
##########
@@ -43,11 +44,10 @@
     private static final Logger LOG = 
LoggerFactory.getLogger(TestRebalance.class);
 
     public static String topoNameToId(String topoName, ILocalCluster cluster) 
throws TException {
-        for (TopologySummary topoSum : 
cluster.getClusterInfo().get_topologies()) {
+        TopologySummary topoSum = cluster.getTopologySummaryByName(topoName);
             if (topoSum.get_name().equals(topoName)) {

Review comment:
       Why will the returned topologySummary.get_name != topoName?

##########
File path: storm-server/src/main/java/org/apache/storm/daemon/nimbus/Nimbus.java
##########
@@ -502,11 +507,16 @@ public Nimbus(Map<String, Object> conf, INimbus inimbus, 
IStormClusterState stor
         this.getTopologyCalls = 
metricsRegistry.registerMeter("nimbus:num-getTopology-calls");
         this.getUserTopologyCalls = 
metricsRegistry.registerMeter("nimbus:num-getUserTopology-calls");
         this.getClusterInfoCalls = 
metricsRegistry.registerMeter("nimbus:num-getClusterInfo-calls");
+        this.getTopologySummariesCalls = 
metricsRegistry.registerMeter("nimbus:num-getTopologySummaries-calls");

Review comment:
       We need to update docs/ClusterMetrics.md too

##########
File path: storm-server/src/main/java/org/apache/storm/daemon/nimbus/Nimbus.java
##########
@@ -4056,6 +4077,45 @@ public TopologyInfo getTopologyInfo(String id) throws 
NotAliveException, Authori
         }
     }
 
+    @Override
+    public TopologyInfo getTopologyInfoByName(String name) throws 
NotAliveException, AuthorizationException, TException {
+        try {
+            getTopologyInfoByNameCalls.mark();
+            GetInfoOptions options = new GetInfoOptions();
+            options.set_num_err_choice(NumErrorsChoice.ALL);
+
+            return getTopologyInfoByNameImpl(name, options);
+        } catch (Exception e) {
+            LOG.warn("get topology info exception. (topology name={})", name, 
e);
+            if (e instanceof TException) {
+                throw (TException) e;
+            }
+            throw new RuntimeException(e);
+        }
+    }
+
+    private TopologyInfo getTopologyInfoByNameImpl(String name, GetInfoOptions 
options) throws
+        NotAliveException, AuthorizationException, TException {
+        IStormClusterState state = stormClusterState;
+        String id = state.getTopoId(name).orElseThrow(() -> new 
WrappedNotAliveException(name + " is not alive"));
+        return getTopologyInfoWithOpts(id, options);
+    }
+
+    @Override
+    public TopologyInfo getTopologyInfoByNameWithOpts(String name, 
GetInfoOptions options) throws
+        NotAliveException, AuthorizationException, TException {

Review comment:
       looks like we don't need `NotAliveException, AuthorizationException`

##########
File path: storm-server/src/main/java/org/apache/storm/daemon/nimbus/Nimbus.java
##########
@@ -4056,6 +4077,45 @@ public TopologyInfo getTopologyInfo(String id) throws 
NotAliveException, Authori
         }
     }
 
+    @Override
+    public TopologyInfo getTopologyInfoByName(String name) throws 
NotAliveException, AuthorizationException, TException {

Review comment:
       Looks like we don't need `NotAliveException, AuthorizationException`

##########
File path: storm-server/src/main/java/org/apache/storm/daemon/nimbus/Nimbus.java
##########
@@ -4654,6 +4714,55 @@ public ClusterSummary getClusterInfo() throws 
AuthorizationException, TException
         }
     }
 
+    @Override
+    public List<TopologySummary> getTopologySummaries() throws 
AuthorizationException, TException {
+        try {
+            getTopologySummariesCalls.mark();
+            checkAuthorization(null, null, "getTopologySummaries");
+            return getTopologySummariesImpl();
+        } catch (Exception e) {
+            LOG.warn("Get TopologySummary info exception.", e);
+            if (e instanceof TException) {
+                throw (TException) e;
+            }
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    public TopologySummary getTopologySummaryByName(String name) throws 
AuthorizationException, TException {
+        try {
+            getTopologySummaryByNameCalls.mark();
+            checkAuthorization(null, null, "getTopologySummaries");
+            IStormClusterState state = stormClusterState;
+            String topoId = state.getTopoId(name).orElseThrow(() -> new 
WrappedNotAliveException(name + " is not alive"));
+            return getTopologySummary(topoId, 
state.topologyBases().get(topoId));
+        } catch (Exception e) {
+            LOG.warn("Get TopologySummaryByName info exception.", e);
+            if (e instanceof TException) {
+                throw (TException) e;
+            }
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    public TopologySummary getTopologySummaryById(String id) throws 
AuthorizationException, TException {
+        try {
+            getTopologySummaryByIdCalls.mark();
+            IStormClusterState state = stormClusterState;
+            StormBase base = state.topologyBases().get(id);
+            checkAuthorization(null, null, "getTopology");

Review comment:
       Why is this `getTopology` while `getTopologySummaryByName` uses 
`getTopologySummaries` 
   
   Should we have `getTopologySummaryByName` for `getTopologySummaryByName` 
method and `getTopologySummaryById` for `getTopologySummaryById` method?

##########
File path: storm-server/src/main/java/org/apache/storm/daemon/nimbus/Nimbus.java
##########
@@ -4654,6 +4714,55 @@ public ClusterSummary getClusterInfo() throws 
AuthorizationException, TException
         }
     }
 
+    @Override
+    public List<TopologySummary> getTopologySummaries() throws 
AuthorizationException, TException {
+        try {
+            getTopologySummariesCalls.mark();
+            checkAuthorization(null, null, "getTopologySummaries");
+            return getTopologySummariesImpl();
+        } catch (Exception e) {
+            LOG.warn("Get TopologySummary info exception.", e);
+            if (e instanceof TException) {
+                throw (TException) e;
+            }
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    public TopologySummary getTopologySummaryByName(String name) throws 
AuthorizationException, TException {
+        try {
+            getTopologySummaryByNameCalls.mark();
+            checkAuthorization(null, null, "getTopologySummaries");
+            IStormClusterState state = stormClusterState;
+            String topoId = state.getTopoId(name).orElseThrow(() -> new 
WrappedNotAliveException(name + " is not alive"));
+            return getTopologySummary(topoId, 
state.topologyBases().get(topoId));
+        } catch (Exception e) {
+            LOG.warn("Get TopologySummaryByName info exception.", e);
+            if (e instanceof TException) {
+                throw (TException) e;
+            }
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    public TopologySummary getTopologySummaryById(String id) throws 
AuthorizationException, TException {
+        try {
+            getTopologySummaryByIdCalls.mark();
+            IStormClusterState state = stormClusterState;
+            StormBase base = state.topologyBases().get(id);

Review comment:
       `base` can be null if this topology doesn't exist. Then there will be 
NullPointerException in `getTopologySummary(id, base)` . Is this intended? 

##########
File path: storm-server/src/main/java/org/apache/storm/daemon/nimbus/Nimbus.java
##########
@@ -4654,6 +4714,55 @@ public ClusterSummary getClusterInfo() throws 
AuthorizationException, TException
         }
     }
 
+    @Override
+    public List<TopologySummary> getTopologySummaries() throws 
AuthorizationException, TException {

Review comment:
       looks like we don't need AuthorizationException




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to