From dev-return-62067-archive-asf-public=cust-asf.ponee.io@storm.apache.org Wed Jul 15 16:13:21 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 1109B1804BB for ; Wed, 15 Jul 2020 18:13:20 +0200 (CEST) Received: (qmail 16949 invoked by uid 500); 15 Jul 2020 16:13:20 -0000 Mailing-List: contact dev-help@storm.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@storm.apache.org Delivered-To: mailing list dev@storm.apache.org Received: (qmail 16932 invoked by uid 99); 15 Jul 2020 16:13:20 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Jul 2020 16:13:20 +0000 From: =?utf-8?q?GitBox?= To: dev@storm.apache.org Subject: =?utf-8?q?=5BGitHub=5D_=5Bstorm=5D_Ethanlm_commented_on_a_change_in_pull_req?= =?utf-8?q?uest_=233306=3A_STORM-3671=3A_Add_TopologySummary_methods_to_Nimb?= =?utf-8?q?us?= Message-ID: <159482960000.29655.11508995371321544955.asfpy@gitbox.apache.org> Date: Wed, 15 Jul 2020 16:13:20 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit In-Reply-To: References: 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 c */ ClusterSummary getClusterInfo() throws TException; + java.util.List 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 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 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 c */ ClusterSummary getClusterInfo() throws TException; + java.util.List 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 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 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 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 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 orig, Map deser) public static TopologyInfo getTopologyInfo(String name, String asUser, Map 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 c */ ClusterSummary getClusterInfo() throws TException; + java.util.List 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 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 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 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 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 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 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 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: users@infra.apache.org