From d79b19aeda8b7d69ebc6e3e4a99e1a8b1aea1f5d Mon Sep 17 00:00:00 2001 From: Andrzej Bialecki Date: Mon, 26 Apr 2021 17:50:03 +0200 Subject: [PATCH] SOLR-15019: Remove support for (unsecure) env variables until it's needed. --- .../cluster/placement/AttributeFetcher.java | 6 ------ .../solr/cluster/placement/AttributeValues.java | 5 ----- .../placement/impl/AttributeFetcherImpl.java | 10 ---------- .../placement/impl/AttributeValuesImpl.java | 9 --------- .../placement/AttributeFetcherForTest.java | 5 ----- .../impl/PlacementPluginIntegrationTest.java | 17 ----------------- .../solrj/impl/SolrClientNodeStateProvider.java | 3 --- .../solr/common/cloud/rule/ImplicitSnitch.java | 1 - 8 files changed, 56 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/cluster/placement/AttributeFetcher.java b/solr/core/src/java/org/apache/solr/cluster/placement/AttributeFetcher.java index ae2afc7b8140..2d9e581b058e 100644 --- a/solr/core/src/java/org/apache/solr/cluster/placement/AttributeFetcher.java +++ b/solr/core/src/java/org/apache/solr/cluster/placement/AttributeFetcher.java @@ -32,12 +32,6 @@ public interface AttributeFetcher { */ AttributeFetcher requestNodeSystemProperty(String name); - /** - * Request an environment variable on each node. To get the value use {@link AttributeValues#getEnvironmentVariable(Node, String)} - * @param name environment property name - */ - AttributeFetcher requestNodeEnvironmentVariable(String name); - /** * Request a node metric from each node. To get the value use {@link AttributeValues#getNodeMetric(Node, NodeMetric)} * @param metric metric to retrieve (see {@link NodeMetric}) diff --git a/solr/core/src/java/org/apache/solr/cluster/placement/AttributeValues.java b/solr/core/src/java/org/apache/solr/cluster/placement/AttributeValues.java index b0e7e45c56e1..a3666cc55cd6 100644 --- a/solr/core/src/java/org/apache/solr/cluster/placement/AttributeValues.java +++ b/solr/core/src/java/org/apache/solr/cluster/placement/AttributeValues.java @@ -27,11 +27,6 @@ public interface AttributeValues { */ Optional getSystemProperty(Node node, String name); - /** - * For the given node: environment variable value - */ - Optional getEnvironmentVariable(Node node, String name); - /** * For the given node: metric identified by an instance of {@link NodeMetric} */ diff --git a/solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeFetcherImpl.java b/solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeFetcherImpl.java index af8e72e461c0..0dcac3b38a9c 100644 --- a/solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeFetcherImpl.java +++ b/solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeFetcherImpl.java @@ -64,12 +64,6 @@ public AttributeFetcher requestNodeSystemProperty(String name) { return this; } - @Override - public AttributeFetcher requestNodeEnvironmentVariable(String name) { - requestedNodeSystemSnitchTags.add(getSystemEnvSnitchTag(name)); - return this; - } - @Override public AttributeFetcher requestNodeMetric(NodeMetric metric) { requestedNodeMetricSnitchTags.add(metric); @@ -214,8 +208,4 @@ public static String getMetricSnitchTag(NodeMetric metric) { public static String getSystemPropertySnitchTag(String name) { return ImplicitSnitch.SYSPROP + name; } - - public static String getSystemEnvSnitchTag(String name) { - return ImplicitSnitch.SYSENV + name; - } } diff --git a/solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeValuesImpl.java b/solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeValuesImpl.java index 873bd3d867c2..5861b87fdac7 100644 --- a/solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeValuesImpl.java +++ b/solr/core/src/java/org/apache/solr/cluster/placement/impl/AttributeValuesImpl.java @@ -53,15 +53,6 @@ public Optional getSystemProperty(Node node, String name) { return Optional.ofNullable(nodeToValue.get(node)); } - @Override - public Optional getEnvironmentVariable(Node node, String name) { - Map nodeToValue = systemSnitchToNodeToValue.get(AttributeFetcherImpl.getSystemEnvSnitchTag(name)); - if (nodeToValue == null) { - return Optional.empty(); - } - return Optional.ofNullable(nodeToValue.get(node)); - } - @Override @SuppressWarnings("unchecked") public Optional getNodeMetric(Node node, NodeMetric metric) { diff --git a/solr/core/src/test/org/apache/solr/cluster/placement/AttributeFetcherForTest.java b/solr/core/src/test/org/apache/solr/cluster/placement/AttributeFetcherForTest.java index bcc300ba1086..8553ee0c967c 100644 --- a/solr/core/src/test/org/apache/solr/cluster/placement/AttributeFetcherForTest.java +++ b/solr/core/src/test/org/apache/solr/cluster/placement/AttributeFetcherForTest.java @@ -35,11 +35,6 @@ public AttributeFetcher requestNodeSystemProperty(String name) { return this; } - @Override - public AttributeFetcher requestNodeEnvironmentVariable(String name) { - throw new UnsupportedOperationException("Not yet implemented..."); - } - @Override public AttributeFetcher requestNodeMetric(NodeMetric metric) { return this; diff --git a/solr/core/src/test/org/apache/solr/cluster/placement/impl/PlacementPluginIntegrationTest.java b/solr/core/src/test/org/apache/solr/cluster/placement/impl/PlacementPluginIntegrationTest.java index f2140e74a207..93003a1316d7 100644 --- a/solr/core/src/test/org/apache/solr/cluster/placement/impl/PlacementPluginIntegrationTest.java +++ b/solr/core/src/test/org/apache/solr/cluster/placement/impl/PlacementPluginIntegrationTest.java @@ -360,18 +360,6 @@ public void testAttributeFetcherImpl() throws Exception { AttributeFetcher attributeFetcher = new AttributeFetcherImpl(cloudManager); NodeMetric someMetricKey = new NodeMetricImpl<>("solr.jvm:system.properties:user.name"); String sysprop = "user.name"; - Set potentialEnvVars = Set.of("PWD", "TMPDIR", "TMP", "TEMP", "USER", "USERNAME", "HOME"); - - String envVar = null; - for (String env : potentialEnvVars) { - if (System.getenv(env) != null) { - envVar = env; - break; - } - } - if (envVar == null) { - fail("None of the potential env vars exist? " + potentialEnvVars); - } attributeFetcher .fetchFrom(cluster.getLiveNodes()) .requestNodeMetric(NodeMetricImpl.HEAP_USAGE) @@ -382,11 +370,9 @@ public void testAttributeFetcherImpl() throws Exception { .requestNodeMetric(NodeMetricImpl.AVAILABLE_PROCESSORS) .requestNodeMetric(someMetricKey) .requestNodeSystemProperty(sysprop) - .requestNodeEnvironmentVariable(envVar) .requestCollectionMetrics(collection, Set.of(ReplicaMetricImpl.INDEX_SIZE_GB, ReplicaMetricImpl.QUERY_RATE_1MIN, ReplicaMetricImpl.UPDATE_RATE_1MIN)); AttributeValues attributeValues = attributeFetcher.fetchAttributes(); String userName = System.getProperty("user.name"); - String envVarValue = System.getenv(envVar); // node metrics for (Node node : cluster.getLiveNodes()) { Optional doubleOpt = attributeValues.getNodeMetric(node, NodeMetricImpl.HEAP_USAGE); @@ -409,9 +395,6 @@ public void testAttributeFetcherImpl() throws Exception { Optional syspropOpt = attributeValues.getSystemProperty(node, sysprop); assertTrue("sysprop", syspropOpt.isPresent()); assertEquals("user.name sysprop", userName, syspropOpt.get()); - Optional envVarOpt = attributeValues.getEnvironmentVariable(node, envVar); - assertTrue("envVar", envVarOpt.isPresent()); - assertEquals("envVar " + envVar, envVarValue, envVarOpt.get()); } assertTrue(attributeValues.getCollectionMetrics(COLLECTION).isPresent()); CollectionMetrics collectionMetrics = attributeValues.getCollectionMetrics(COLLECTION).get(); 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.java index ccc6583d28d6..a6ae53e117c4 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 @@ -209,9 +209,6 @@ protected void getRemoteInfo(String solrNode, Set requestedTags, SnitchC if (tag.startsWith(SYSPROP)) { metricsKeyVsTag.computeIfAbsent("solr.jvm:system.properties:" + tag.substring(SYSPROP.length()), k -> new HashSet<>()) .add(tag); - } else if (tag.startsWith(SYSENV)) { - metricsKeyVsTag.computeIfAbsent("solr.jvm:system.env:" + tag.substring(SYSENV.length()), k -> new HashSet<>()) - .add(tag); } else if (tag.startsWith(METRICS_PREFIX)) { metricsKeyVsTag.computeIfAbsent(tag.substring(METRICS_PREFIX.length()), k -> new HashSet<>()) .add(tag); diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/rule/ImplicitSnitch.java b/solr/solrj/src/java/org/apache/solr/common/cloud/rule/ImplicitSnitch.java index acc412f22bd6..afada51c6d65 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/rule/ImplicitSnitch.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/rule/ImplicitSnitch.java @@ -49,7 +49,6 @@ public class ImplicitSnitch extends Snitch { public static final String ROLE = "role"; public static final String NODEROLE = "nodeRole"; public static final String SYSPROP = "sysprop."; - public static final String SYSENV = "sysenv."; public static final String SYSLOADAVG = "sysLoadAvg"; public static final String HEAPUSAGE = "heapUsage"; public static final List IP_SNITCHES = Collections.unmodifiableList(Arrays.asList("ip_1", "ip_2", "ip_3", "ip_4"));