laminelam commented on code in PR #2417:
URL: https://github.com/apache/solr/pull/2417#discussion_r1585444338


##########
solr/core/src/java/org/apache/solr/cli/SolrCLI.java:
##########
@@ -607,6 +611,46 @@ public static String getZkHost(CommandLine cli) throws 
Exception {
     return zkHost;
   }
 
+  public static SolrZkClient getSolrZkClient(CommandLine cli) throws Exception 
{
+    return getSolrZkClient(cli, getZkHost(cli));
+  }
+
+  public static SolrZkClient getSolrZkClient(CommandLine cli, String zkHost) 
throws Exception {
+    if (zkHost == null) {
+      throw new IllegalStateException(
+          "Solr at "
+              + cli.getOptionValue("solrUrl")
+              + " is running in standalone server mode, this command can only 
be used when running in SolrCloud mode.\n");
+    }
+    return new SolrZkClient.Builder()
+        .withUrl(zkHost)
+        .withTimeout(SolrZkClientTimeout.DEFAULT_ZK_CLIENT_TIMEOUT, 
TimeUnit.MILLISECONDS)
+        .withSolrClassLoader(getSolrResourceLoader())
+        .build();
+  }
+
+  public static CloudHttp2SolrClient getCloudHttp2SolrClient(String zkHost) {
+    return getCloudHttp2SolrClient(zkHost, null);
+  }
+
+  public static CloudHttp2SolrClient getCloudHttp2SolrClient(
+      String zkHost, Http2SolrClient.Builder builder) {
+    return new CloudHttp2SolrClient.Builder(Collections.singletonList(zkHost), 
Optional.empty())
+        .withSolrClassLoader(getSolrResourceLoader())
+        .withInternalClientBuilder(builder)
+        .build();
+  }
+
+  private static SolrResourceLoader getSolrResourceLoader() {
+    String dir = System.getProperty("solr.solr.home");
+    if (StrUtils.isNullOrEmpty(dir)) {
+      dir = System.getProperty("solr.install.dir");
+    }
+    final SolrResourceLoader loader = new SolrResourceLoader(Paths.get(dir));
+    NodeConfig.initModules(loader, null);

Review Comment:
   [@dsmiley](https://github.com/dsmiley)
Firstable, I really appreciate the 
time you're spending on this, and your inputs are very valuable.
   
   I thought of adding a custom loader for CLI code but didn't want to 
duplicate the existing code. Actually I already did it 
[here](https://github.com/apache/solr/pull/826/commits/b3f4f830986042e8f194fa84088752f93b3abba8#diff-27c02533050bbfcb97de03a7d7e33588bb547f7b46f7e86e09c36175a5ef85c5)
 but end up abandoning it. The only way I found to load a SRL, without code 
duplication, is the one based on the NodeConfig logic.
   
   Will get rid of SRL as far as this PR is concerned (for the CLI part).
   Still, I don't see how we can access modules classes from solrj without 
passing a SRL?
   
   SolrCLI is just a client, it doesn’t have access to CoreContainer which runs 
on the server. It
   Can't get a SRL from Thread.currentThread().getContextClassLoader() neither, 
for the same reason. All it does is create a CloudHttp2SolrClient to connect to 
the cluster.
   
   When building a CloudHttp2SolrClient, the chain of calls is:
   
   CloudHttp2SolrClient  —> ZkClientClusterStateProvider —> ZkStateReader —> 
SolrZkClient
   
   If SolrZkClient needs a class part of _modules_, we need a way to pass 
though a SRL.
   
   Anyway, I am going remove SRL code here and let's continue this discussion 
on the [other 
thread](https://github.com/apache/solr/pull/1994#discussion_r1534863816). 
   Thank you again, David, and Eric,  for all the inputs.



-- 
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: issues-unsubscr...@solr.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to