Apache Lucene open-source search software
SOLR-14412 zkRun+https (#1437)
Mike Drob58f9c79c6d2b
diff --git a/solr/core/src/java/org/apache/solr/core/ZkContainer.java b/solr/core/src/java/org/apache/solr/core/ZkContainer.javaindex 5a50fd70c75..fcb2e881624 100644--- a/solr/core/src/java/org/apache/solr/core/ZkContainer.java+++ b/solr/core/src/java/org/apache/solr/core/ZkContainer.java@@ -30,12 +30,15 @@ import java.util.concurrent.TimeoutException;import java.util.function.Predicate;import java.util.function.Supplier;+import org.apache.commons.lang3.StringUtils;import org.apache.solr.cloud.SolrZkServer;import org.apache.solr.cloud.ZkController;import org.apache.solr.common.AlreadyClosedException;import org.apache.solr.common.SolrException;+import org.apache.solr.common.cloud.ClusterProperties;import org.apache.solr.common.cloud.Replica;import org.apache.solr.common.cloud.ZkConfigManager;+import org.apache.solr.common.cloud.ZkStateReader;import org.apache.solr.common.cloud.ZooKeeperException;import org.apache.solr.common.util.ExecutorUtil;import org.apache.solr.logging.MDCLoggingContext;@@ -124,12 +127,18 @@ public class ZkContainer {ZkController zkController = new ZkController(cc, zookeeperHost, zkClientConnectTimeout, config, descriptorsSupplier);- if (zkRun != null && zkServer.getServers().size() > 1 && confDir == null && boostrapConf == false) {- // we are part of an ensemble and we are not uploading the config - pause to give the config time- // to get up- Thread.sleep(10000);+ if (zkRun != null) {+ if (StringUtils.isNotEmpty(System.getProperty("solr.jetty.https.port"))) {+ // Embedded ZK and probably running with SSL+ new ClusterProperties(zkController.getZkClient()).setClusterProperty(ZkStateReader.URL_SCHEME, "https");+ }+ if (zkServer.getServers().size() > 1 && confDir == null && boostrapConf == false) {+ // we are part of an ensemble and we are not uploading the config - pause to give the config time+ // to get up+ Thread.sleep(10000);+ }}-+if(confDir != null) {Path configPath = Paths.get(confDir);if (!Files.isDirectory(configPath))diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientNodeStateProvider.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientNodeStateProvider.javaindex a2a699ee29c..554de2d515a 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientNodeStateProvider.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/SolrClientNodeStateProvider.java@@ -193,37 +193,9 @@ public class SolrClientNodeStateProvider implements NodeStateProvider, MapWriterModifiableSolrParams params = new ModifiableSolrParams();params.add("key", metricsKeyVsTag.keySet().toArray(new String[0]));try {-- SimpleSolrResponse rsp = null;- int cnt = 0;- while (cnt++ < 3) {- try {- rsp = ctx.invoke(solrNode, CommonParams.METRICS_PATH, params);- break;- } catch (SolrException | SolrServerException | IOException e) {- boolean hasCauseIOException = false;- Throwable cause = e;- while (cause != null) {- if (cause instanceof IOException) {- hasCauseIOException = true;- break;- }- cause = cause.getCause();- }- if (hasCauseIOException || e instanceof IOException) {- log.info("Error on getting remote info, trying again: " + e.getMessage());- Thread.sleep(500);- continue;- } else {- throw e;- }- }- }--- SimpleSolrResponse frsp = rsp;+ SimpleSolrResponse rsp = ctx.invokeWithRetry(solrNode, CommonParams.METRICS_PATH, params);metricsKeyVsTag.forEach((key, tag) -> {- Object v = Utils.getObjectByPath(frsp.nl, true, Arrays.asList("metrics", key));+ Object v = Utils.getObjectByPath(rsp.nl, true, Arrays.asList("metrics", key));if (tag instanceof Function) {Pair<String, Object> p = (Pair<String, Object>) ((Function) tag).apply(v);ctx.getTags().put(p.first(), p.second());@@ -300,41 +272,8 @@ public class SolrClientNodeStateProvider implements NodeStateProvider, MapWriterparams.add("prefix", StrUtils.join(prefixes, ','));try {- SimpleSolrResponse rsp = null;- int retries = 5;- int cnt = 0;- while (cnt++ < retries) {- try {- rsp = snitchContext.invoke(solrNode, CommonParams.METRICS_PATH, params);- break;- } catch (SolrException | SolrServerException | IOException e) {- if (e instanceof SolrServerException) {-- }-- boolean hasCauseIOException = false;- Throwable cause = e;- while (cause != null) {- if (cause instanceof IOException) {- hasCauseIOException = true;- break;- }- cause = cause.getCause();- }- if (hasCauseIOException || e instanceof IOException) {- log.info("Error on getting remote info, trying again: " + e.getMessage());- Thread.sleep(500);- continue;- } else {- throw e;- }- }- }-- if (cnt == retries || rsp == null) {- throw new SolrException(ErrorCode.SERVER_ERROR, "Could not get remote info after many retries on NoHttpResponseException");- }-+ SimpleSolrResponse rsp = snitchContext.invokeWithRetry(solrNode, CommonParams.METRICS_PATH, params);+Map m = rsp.nl.asMap(4);if (requestedTags.contains(FREEDISK.tagName)) {Object n = Utils.getObjectByPath(m, true, "metrics/solr.node/CONTAINER.fs.usableSpace");@@ -398,6 +337,39 @@ public class SolrClientNodeStateProvider implements NodeStateProvider, MapWriterreturn Utils.getJson(zkClientClusterStateProvider.getZkStateReader().getZkClient(), path, true);}+ /**+ * Will attempt to call {@link #invoke(String, String, SolrParams)} up to five times, retrying on any IO Exceptions+ */+ public SimpleSolrResponse invokeWithRetry(String solrNode, String path, SolrParams params) throws InterruptedException, IOException, SolrServerException {+ int retries = 5;+ int cnt = 0;++ while (cnt++ < retries) {+ try {+ return invoke(solrNode, path, params);+ } catch (SolrException | SolrServerException | IOException e) {+ boolean hasIOExceptionCause = false;++ Throwable t = e;+ while (t != null) {+ if (t instanceof IOException) {+ hasIOExceptionCause = true;+ break;+ }+ t = t.getCause();+ }++ if (hasIOExceptionCause) {+ log.info("Error on getting remote info, trying again: " + e.getMessage());+ Thread.sleep(500);+ } else {+ throw e;+ }+ }+ }++ throw new SolrException(ErrorCode.SERVER_ERROR, "Could not get remote info after many retries on NoHttpResponseException");+ }public SimpleSolrResponse invoke(String solrNode, String path, SolrParams params)throws IOException, SolrServerException {