merrimanr commented on a change in pull request #1367: METRON-2022: Metron rest 
creates large number of connections to ZK which causes subsequent connection to 
zk fail
URL: https://github.com/apache/metron/pull/1367#discussion_r270564845
 
 

 ##########
 File path: 
metron-platform/metron-solr/src/main/java/org/apache/metron/solr/dao/SolrDao.java
 ##########
 @@ -168,18 +168,21 @@ public Document 
removeCommentFromAlert(CommentAddRemoveRequest request, Document
   }
 
   /**
-   * Builds a Solr client using the ZK hosts from the global config.
+   * Returns the SolrClient.
    * @return SolrClient
    */
   public SolrClient getSolrClient() {
-    return new CloudSolrClient.Builder().withZkHost(getZkHosts()).build();
+    if (this.client == null) {
+      throw new IllegalStateException("The SolrDao must be initialized first");
+    }
+    return this.client;
   }
 
   /**
    * Builds a Solr client using the ZK hosts specified.
    * @return SolrClient
    */
-  public SolrClient getSolrClient(List<String> zkHosts) {
+  protected SolrClient getSolrClient(List<String> zkHosts) {
     return new CloudSolrClient.Builder().withZkHost(zkHosts).build();
 
 Review comment:
   I moved the SolrClient creation to a factory.  This should closely match the 
way we do it for the `ElasticsearchDao` classes.  The `SolrDao` and 
`SolrMetaAlertDao` are created separately in `IndexConfig` so I had to keep the 
`SolrDao.getSolrClient` method.  Now it only returns the current client and 
throws an exception if `SolrDao` hasn't been initialized.  

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to