Skip to content

Comments

SOLR-18056: Added method to get url scheme based on cluster type#4162

Open
VishnuPriyaChandraSekar wants to merge 2 commits intoapache:mainfrom
VishnuPriyaChandraSekar:SOLR-18056-urlScheme-csp
Open

SOLR-18056: Added method to get url scheme based on cluster type#4162
VishnuPriyaChandraSekar wants to merge 2 commits intoapache:mainfrom
VishnuPriyaChandraSekar:SOLR-18056-urlScheme-csp

Conversation

@VishnuPriyaChandraSekar
Copy link

@VishnuPriyaChandraSekar VishnuPriyaChandraSekar commented Feb 23, 2026

https://issues.apache.org/jira/browse/SOLR-18056

Description

Currently, CloudSolrClient depends on the cluster property to determine the url scheme for Zookeeper and Http based cluster. This approach is rigid and non-user friendly. For example: url scheme can be determined using solr URLs for Http based cluster but currently the user has to unnecessarily has to provide the 'URL_SCHEME' in the cluster properties.

Solution

Added getUrlScheme method in ClusterStateProvider abstract class so the url scheme can be determined based on cluster type.

  • HttpClusterStateProvider will determine the scheme from solr Urls
  • ZkClientClusterStateProvider will determine the scheme with the help of cluster property if available otherwise it depends on system property solr.ssl.enabled (Similar to the solution recommended in SOLR-18055

Tests

  • Added an integration test ClusterStateProviderUrlSchemeTest.java to verify the correctness of getUrlScheme in HttpClusterStateProvider and ZkClientClusterStateProvider

Checklist

Please review the following and check all that apply:

  • I have reviewed the guidelines for How to Contribute and my code conforms to the standards described there to the best of my ability.
  • I have created a Jira issue and added the issue ID to my pull request title.
  • I have given Solr maintainers access to contribute to my PR branch. (optional but recommended, not available for branches on forks living under an organisation)
  • I have developed this patch against the main branch.
  • I have run ./gradlew check.
  • I have added tests for my changes.
  • I have added documentation for the Reference Guide
  • I have added a changelog entry for my change

Copy link
Contributor

@dsmiley dsmiley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this :-)

@@ -0,0 +1,8 @@
# See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc
title: Added method to get url scheme based on cluster type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
title: Added method to get url scheme based on cluster type
title: Improved CloudSolrClient's urlScheme detection by using the scheme of provided Solr URLs, or looking at "solr.ssl.enabled".

if (urlSchemeClusterProperty != null) {
return urlSchemeClusterProperty.toString();
}
return Boolean.parseBoolean(System.getProperty(SOLR_SSL_ENABLED, "false")) ? "https" : "http";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should come first -- thus if set, we ignore the cluster properties

solrUrls.stream()
.map(BaseHttpClusterStateProvider::stringToUrl)
.collect(Collectors.toList());
if (this.configuredNodes.stream().map(URL::getProtocol).collect(Collectors.toSet()).size()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (this.configuredNodes.stream().map(URL::getProtocol).collect(Collectors.toSet()).size()
if (this.configuredNodes.stream().map(URL::getProtocol).distinct().count()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also consider simply not checking/enforcing this, and not even storing a field. Grabbing the first in getScheme is fine.


String getQuorumHosts();

/** Get url scheme. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** Get url scheme. */
/** Get URL scheme -- http or https. Never null. */

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you not want to put these tests into ClusterStateProviderTest ?

assertEquals("https", clusterStateProvider.getUrlScheme());
} finally {
System.clearProperty(SOLR_SSL_ENABLED);
assertNull(System.getProperty(SOLR_SSL_ENABLED));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jeesh; do we not trust Java?

if (urlSchemeClusterProperty != null) {
return urlSchemeClusterProperty.toString();
}
return Boolean.parseBoolean(System.getProperty(SOLR_SSL_ENABLED, "false")) ? "https" : "http";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solr, even SolrJ, uses EnvUtils to read system properties. It's important here since this way we allow an env var approach SOLR_SSL_ENABLED

@dsmiley dsmiley changed the title [SOLR-18056] Added method to get url scheme based on cluster type SOLR-18056: Added method to get url scheme based on cluster type Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants