lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject [27/50] lucene-solr:jira/solr-11458-2: SOLR-11291: Factor out abstract metrics/SolrCore[Container]Reporter classes. (Omar Abdelnabi, Christine Poerschke)
Date Mon, 04 Dec 2017 17:49:11 GMT
SOLR-11291: Factor out abstract metrics/SolrCore[Container]Reporter classes. (Omar Abdelnabi,
Christine Poerschke)


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/812db14f
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/812db14f
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/812db14f

Branch: refs/heads/jira/solr-11458-2
Commit: 812db14f278ce8fe03de94d18e0c662d104f62e3
Parents: 64b3a5b
Author: Christine Poerschke <cpoerschke@apache.org>
Authored: Tue Nov 28 15:39:55 2017 +0000
Committer: Christine Poerschke <cpoerschke@apache.org>
Committed: Tue Nov 28 15:39:55 2017 +0000

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  3 ++
 .../solr/metrics/SolrCoreContainerReporter.java | 47 ++++++++++++++++++++
 .../apache/solr/metrics/SolrCoreReporter.java   | 47 ++++++++++++++++++++
 .../apache/solr/metrics/SolrMetricManager.java  | 10 ++---
 .../reporters/solr/SolrClusterReporter.java     | 12 ++---
 .../reporters/solr/SolrShardReporter.java       | 12 ++---
 .../reporters/solr/SolrCloudReportersTest.java  |  8 ++++
 7 files changed, 117 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/812db14f/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index ac5b605..1358212 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -211,6 +211,9 @@ Other Changes
 * SOLR-11507: SOLR-11638: Randomize SolrTestCaseJ4.CloudSolrClientBuilder more, and simplify
it.
   (Jason Gerlowski, David Smiley)
 
+* SOLR-11291: Factor out abstract metrics/SolrCore[Container]Reporter classes.
+  (Omar Abdelnabi, Christine Poerschke)
+
 ==================  7.1.0 ==================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/812db14f/solr/core/src/java/org/apache/solr/metrics/SolrCoreContainerReporter.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/metrics/SolrCoreContainerReporter.java b/solr/core/src/java/org/apache/solr/metrics/SolrCoreContainerReporter.java
new file mode 100644
index 0000000..b612b2e
--- /dev/null
+++ b/solr/core/src/java/org/apache/solr/metrics/SolrCoreContainerReporter.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.metrics;
+
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.core.PluginInfo;
+
+/**
+ * A {@link SolrMetricReporter} that has access to its {@link CoreContainer}.
+ */
+abstract public class SolrCoreContainerReporter extends SolrMetricReporter {
+
+  protected CoreContainer coreContainer;
+
+  protected SolrCoreContainerReporter(SolrMetricManager metricManager, String registryName)
{
+    super(metricManager, registryName);
+  }
+
+  @Override
+  final public void init(PluginInfo pluginInfo) {
+    throw new UnsupportedOperationException(getClass().getCanonicalName()+".init(PluginInfo)
is not supported, use init(PluginInfo,CoreContainer) instead.");
+  }
+
+  public void init(PluginInfo pluginInfo, CoreContainer coreContainer) {
+    super.init(pluginInfo);
+    this.coreContainer = coreContainer;
+  }
+
+  public CoreContainer getCoreContainer() {
+    return coreContainer;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/812db14f/solr/core/src/java/org/apache/solr/metrics/SolrCoreReporter.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/metrics/SolrCoreReporter.java b/solr/core/src/java/org/apache/solr/metrics/SolrCoreReporter.java
new file mode 100644
index 0000000..bd2672c
--- /dev/null
+++ b/solr/core/src/java/org/apache/solr/metrics/SolrCoreReporter.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.metrics;
+
+import org.apache.solr.core.PluginInfo;
+import org.apache.solr.core.SolrCore;
+
+/**
+ * A {@link FilteringSolrMetricReporter} that has access to its {@link SolrCore}.
+ */
+abstract public class SolrCoreReporter extends FilteringSolrMetricReporter {
+
+  protected SolrCore core;
+
+  public SolrCoreReporter(SolrMetricManager metricManager, String registryName) {
+    super(metricManager, registryName);
+  }
+
+  @Override
+  final public void init(PluginInfo pluginInfo) {
+    throw new UnsupportedOperationException(getClass().getCanonicalName()+".init(PluginInfo)
is not supported, use init(PluginInfo,SolrCore) instead.");
+  }
+
+  public void init(PluginInfo pluginInfo, SolrCore core) {
+    super.init(pluginInfo);
+    this.core = core;
+  }
+
+  public SolrCore getCore() {
+    return core;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/812db14f/solr/core/src/java/org/apache/solr/metrics/SolrMetricManager.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/metrics/SolrMetricManager.java b/solr/core/src/java/org/apache/solr/metrics/SolrMetricManager.java
index adfdda3..4223675 100644
--- a/solr/core/src/java/org/apache/solr/metrics/SolrMetricManager.java
+++ b/solr/core/src/java/org/apache/solr/metrics/SolrMetricManager.java
@@ -54,8 +54,6 @@ import org.apache.solr.core.PluginInfo;
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.core.SolrInfoBean;
 import org.apache.solr.core.SolrResourceLoader;
-import org.apache.solr.metrics.reporters.solr.SolrClusterReporter;
-import org.apache.solr.metrics.reporters.solr.SolrShardReporter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -875,10 +873,10 @@ public class SolrMetricManager {
         new Object[]{this, registry}
     );
     try {
-      if (reporter instanceof SolrShardReporter) {
-        ((SolrShardReporter)reporter).init(pluginInfo, solrCore);
-      } else if (reporter instanceof SolrClusterReporter) {
-        ((SolrClusterReporter)reporter).init(pluginInfo, coreContainer);
+      if (reporter instanceof SolrCoreReporter) {
+        ((SolrCoreReporter)reporter).init(pluginInfo, solrCore);
+      } else if (reporter instanceof SolrCoreContainerReporter) {
+        ((SolrCoreContainerReporter)reporter).init(pluginInfo, coreContainer);
       } else {
         reporter.init(pluginInfo);
       }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/812db14f/solr/core/src/java/org/apache/solr/metrics/reporters/solr/SolrClusterReporter.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/metrics/reporters/solr/SolrClusterReporter.java
b/solr/core/src/java/org/apache/solr/metrics/reporters/solr/SolrClusterReporter.java
index 35802dc..081dff0 100644
--- a/solr/core/src/java/org/apache/solr/metrics/reporters/solr/SolrClusterReporter.java
+++ b/solr/core/src/java/org/apache/solr/metrics/reporters/solr/SolrClusterReporter.java
@@ -36,8 +36,8 @@ import org.apache.solr.core.CoreContainer;
 import org.apache.solr.core.PluginInfo;
 import org.apache.solr.core.SolrInfoBean;
 import org.apache.solr.handler.admin.MetricsCollectorHandler;
+import org.apache.solr.metrics.SolrCoreContainerReporter;
 import org.apache.solr.metrics.SolrMetricManager;
-import org.apache.solr.metrics.SolrMetricReporter;
 import org.apache.zookeeper.KeeperException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -90,7 +90,7 @@ import static org.apache.solr.common.params.CommonParams.ID;
  * </pre>
  *
  */
-public class SolrClusterReporter extends SolrMetricReporter {
+public class SolrClusterReporter extends SolrCoreContainerReporter {
   private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
   public static final String CLUSTER_GROUP = SolrMetricManager.overridableRegistryName(SolrInfoBean.Group.cluster.toString());
@@ -170,11 +170,6 @@ public class SolrClusterReporter extends SolrMetricReporter {
   }
 
   @Override
-  public void init(PluginInfo pluginInfo) {
-    throw new UnsupportedOperationException(getClass().getCanonicalName()+".init(PluginInfo)
is not supported, use init(PluginInfo,CoreContainer) instead.");
-  }
-
-  @Override
   protected void doInit() {
     if (reports.isEmpty()) { // set defaults
       reports = DEFAULT_REPORTS;
@@ -193,8 +188,9 @@ public class SolrClusterReporter extends SolrMetricReporter {
     }
   }
 
+  @Override
   public void init(PluginInfo pluginInfo, CoreContainer cc) {
-    super.init(pluginInfo);
+    super.init(pluginInfo, cc);
     if (reporter != null) {
       reporter.close();;
     }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/812db14f/solr/core/src/java/org/apache/solr/metrics/reporters/solr/SolrShardReporter.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/metrics/reporters/solr/SolrShardReporter.java
b/solr/core/src/java/org/apache/solr/metrics/reporters/solr/SolrShardReporter.java
index d07609d..c477e47 100644
--- a/solr/core/src/java/org/apache/solr/metrics/reporters/solr/SolrShardReporter.java
+++ b/solr/core/src/java/org/apache/solr/metrics/reporters/solr/SolrShardReporter.java
@@ -31,7 +31,7 @@ import org.apache.solr.common.cloud.Replica;
 import org.apache.solr.core.PluginInfo;
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.handler.admin.MetricsCollectorHandler;
-import org.apache.solr.metrics.FilteringSolrMetricReporter;
+import org.apache.solr.metrics.SolrCoreReporter;
 import org.apache.solr.metrics.SolrMetricManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -59,7 +59,7 @@ import com.codahale.metrics.MetricFilter;
  *    &lt;/reporter&gt;
  * </pre>
  */
-public class SolrShardReporter extends FilteringSolrMetricReporter {
+public class SolrShardReporter extends SolrCoreReporter {
   private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
   public static final List<String> DEFAULT_FILTERS = new ArrayList(){{
@@ -92,11 +92,6 @@ public class SolrShardReporter extends FilteringSolrMetricReporter {
   }
 
   @Override
-  public void init(PluginInfo pluginInfo) {
-    throw new UnsupportedOperationException(getClass().getCanonicalName()+".init(PluginInfo)
is not supported, use init(PluginInfo,SolrCore) instead.");
-  }
-
-  @Override
   protected void doInit() {
     if (filters.isEmpty()) {
       filters = DEFAULT_FILTERS;
@@ -122,8 +117,9 @@ public class SolrShardReporter extends FilteringSolrMetricReporter {
     }
   }
 
+  @Override
   public void init(PluginInfo pluginInfo, SolrCore core) {
-    super.init(pluginInfo);
+    super.init(pluginInfo, core);
     if (reporter != null) {
       reporter.close();
     }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/812db14f/solr/core/src/test/org/apache/solr/metrics/reporters/solr/SolrCloudReportersTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/metrics/reporters/solr/SolrCloudReportersTest.java
b/solr/core/src/test/org/apache/solr/metrics/reporters/solr/SolrCloudReportersTest.java
index 6b926bf..59952c3 100644
--- a/solr/core/src/test/org/apache/solr/metrics/reporters/solr/SolrCloudReportersTest.java
+++ b/solr/core/src/test/org/apache/solr/metrics/reporters/solr/SolrCloudReportersTest.java
@@ -26,6 +26,8 @@ import org.apache.solr.cloud.SolrCloudTestCase;
 import org.apache.solr.core.CoreContainer;
 import org.apache.solr.core.SolrCore;
 import org.apache.solr.metrics.AggregateMetric;
+import org.apache.solr.metrics.SolrCoreContainerReporter;
+import org.apache.solr.metrics.SolrCoreReporter;
 import org.apache.solr.metrics.SolrMetricManager;
 import org.apache.solr.metrics.SolrMetricReporter;
 import org.apache.solr.metrics.reporters.SolrJmxReporter;
@@ -96,6 +98,9 @@ public class SolrCloudReportersTest extends SolrCloudTestCase {
       assertNotNull(reporter);
       assertTrue(reporter.toString(), reporter instanceof SolrClusterReporter);
       assertEquals(5, reporter.getPeriod());
+      assertTrue(reporter.toString(), reporter instanceof SolrCoreContainerReporter);
+      SolrCoreContainerReporter solrCoreContainerReporter = (SolrCoreContainerReporter)reporter;
+      assertNotNull(solrCoreContainerReporter.getCoreContainer());
       for (String registryName : metricManager.registryNames(".*\\.shard[0-9]\\.replica.*"))
{
         reporters = metricManager.getReporters(registryName);
         jmxReporter = 0;
@@ -114,6 +119,9 @@ public class SolrCloudReportersTest extends SolrCloudTestCase {
         assertNotNull(reporter);
         assertTrue(reporter.toString(), reporter instanceof SolrShardReporter);
         assertEquals(5, reporter.getPeriod());
+        assertTrue(reporter.toString(), reporter instanceof SolrCoreReporter);
+        SolrCoreReporter solrCoreReporter = (SolrCoreReporter)reporter;
+        assertNotNull(solrCoreReporter.getCore());
       }
       for (String registryName : metricManager.registryNames(".*\\.leader")) {
         leaderRegistries++;


Mime
View raw message