-
Notifications
You must be signed in to change notification settings - Fork 810
SOLR-18091: Separate out core specific info into CoreInfoHandler #4084
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
epugh
wants to merge
14
commits into
apache:main
Choose a base branch
from
epugh:SOLR-18091
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+453
−98
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
926bdb1
Seperate out into two end points
epugh e662b0d
use better path name
epugh a0345d7
remove commented code
epugh 25419e4
add some docs
epugh 7d82015
finally chase out remnants
epugh 9576ad4
Merge remote-tracking branch 'upstream/main' into SOLR-18091
epugh 587f980
Introduce a test to support new handler
epugh 96b553b
lint
epugh 0d4064f
lint
epugh a02dcdf
More robust test to pass precheck
epugh 01ce123
Use the new endpoints for a core.
epugh ea51ef6
Now supporting the host name
epugh c96a8e3
rework the docs to reflect the new handler.
epugh 84c94b0
pass forbiddenapi check
epugh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc | ||
| title: Seperate the node/container level info from the core level info for the admin end points. | ||
| type: other # added, changed, fixed, deprecated, removed, dependency_update, security, other | ||
| authors: | ||
| - name: Eric Pugh | ||
| links: | ||
| - name: SOLR-18091 | ||
| url: https://issues.apache.org/jira/browse/SOLR-18091 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
solr/core/src/java/org/apache/solr/handler/admin/CoreInfoHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| * 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.handler.admin; | ||
|
|
||
| import java.io.IOException; | ||
| import java.lang.invoke.MethodHandles; | ||
| import java.nio.file.Path; | ||
| import java.util.Date; | ||
| import org.apache.solr.common.util.SimpleOrderedMap; | ||
| import org.apache.solr.core.SolrCore; | ||
| import org.apache.solr.handler.RequestHandlerBase; | ||
| import org.apache.solr.request.SolrQueryRequest; | ||
| import org.apache.solr.response.SolrQueryResponse; | ||
| import org.apache.solr.schema.IndexSchema; | ||
| import org.apache.solr.security.AuthorizationContext; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * This handler returns core level info. See {@link org.apache.solr.handler.admin.SystemInfoHandler} | ||
| */ | ||
| public class CoreInfoHandler extends RequestHandlerBase { | ||
| private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); | ||
|
|
||
| @Override | ||
| public String getDescription() { | ||
| return "Get Core Info"; | ||
| } | ||
|
|
||
| @Override | ||
| public Category getCategory() { | ||
| return Category.ADMIN; | ||
| } | ||
|
|
||
| @Override | ||
| public Name getPermissionName(AuthorizationContext request) { | ||
| return Name.CONFIG_READ_PERM; | ||
| } | ||
|
|
||
| @Override | ||
| public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { | ||
| rsp.setHttpCaching(false); | ||
| SolrCore core = req.getCore(); | ||
|
|
||
| rsp.add("core", getCoreInfo(core, req.getSchema())); | ||
| } | ||
|
|
||
| private SimpleOrderedMap<Object> getCoreInfo(SolrCore core, IndexSchema schema) { | ||
| SimpleOrderedMap<Object> info = new SimpleOrderedMap<>(); | ||
|
|
||
| info.add("schema", schema != null ? schema.getSchemaName() : "no schema!"); | ||
|
|
||
| // Now | ||
| info.add("now", new Date()); | ||
|
|
||
| // Start Time | ||
| info.add("start", core.getStartTimeStamp()); | ||
|
|
||
| // Solr Home | ||
| SimpleOrderedMap<Object> dirs = new SimpleOrderedMap<>(); | ||
| dirs.add("cwd", Path.of(System.getProperty("user.dir")).toAbsolutePath().toString()); | ||
| dirs.add("instance", core.getInstancePath().toString()); | ||
| try { | ||
| dirs.add("data", core.getDirectoryFactory().normalize(core.getDataDir())); | ||
| } catch (IOException e) { | ||
| log.warn("Problem getting the normalized data directory path", e); | ||
| dirs.add("data", "N/A"); | ||
| } | ||
| dirs.add("dirimpl", core.getDirectoryFactory().getClass().getName()); | ||
| try { | ||
| dirs.add("index", core.getDirectoryFactory().normalize(core.getIndexDir())); | ||
| } catch (IOException e) { | ||
| log.warn("Problem getting the normalized index directory path", e); | ||
| dirs.add("index", "N/A"); | ||
| } | ||
| info.add("directory", dirs); | ||
| return info; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
solr/core/src/test/org/apache/solr/handler/admin/CoreInfoHandlerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /* | ||
| * 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.handler.admin; | ||
|
|
||
| import java.util.Date; | ||
| import org.apache.solr.SolrTestCaseJ4; | ||
| import org.apache.solr.common.util.NamedList; | ||
| import org.apache.solr.common.util.SimpleOrderedMap; | ||
| import org.apache.solr.core.SolrCore; | ||
| import org.apache.solr.request.SolrQueryRequest; | ||
| import org.apache.solr.response.SolrQueryResponse; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.Test; | ||
|
|
||
| /** Test for {@link CoreInfoHandler} */ | ||
| public class CoreInfoHandlerTest extends SolrTestCaseJ4 { | ||
|
|
||
| @BeforeClass | ||
| public static void beforeClass() throws Exception { | ||
| initCore("solrconfig.xml", "schema.xml"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCoreInfoHandlerResponse() throws Exception { | ||
| CoreInfoHandler handler = new CoreInfoHandler(); | ||
| SolrQueryRequest req = req(); | ||
| SolrQueryResponse rsp = new SolrQueryResponse(); | ||
|
|
||
| handler.handleRequestBody(req, rsp); | ||
|
|
||
| NamedList<Object> values = rsp.getValues(); | ||
| assertNotNull("Response should not be null", values); | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| SimpleOrderedMap<Object> core = (SimpleOrderedMap<Object>) values.get("core"); | ||
| assertNotNull("Core info should not be null", core); | ||
|
|
||
| // Verify schema name is present | ||
| String schema = (String) core.get("schema"); | ||
| assertNotNull("Schema should not be null", schema); | ||
| assertEquals("test", schema); | ||
|
|
||
| // Verify 'now' date is present and reasonable | ||
| Date now = (Date) core.get("now"); | ||
| assertNotNull("Now date should not be null", now); | ||
| Date currentTime = new Date(); | ||
| long responseTime = now.getTime(); | ||
| assertTrue( | ||
| "Response time should be close to current time", | ||
| Math.abs(currentTime.getTime() - responseTime) < 5000); // within 5 seconds | ||
|
|
||
| // Verify start time is present | ||
| Date start = (Date) core.get("start"); | ||
| assertNotNull("Start time should not be null", start); | ||
| assertTrue("Start time should be before or equal to now", start.getTime() <= now.getTime()); | ||
|
|
||
| // Verify directory info | ||
| @SuppressWarnings("unchecked") | ||
| SimpleOrderedMap<Object> directory = (SimpleOrderedMap<Object>) core.get("directory"); | ||
| assertNotNull("Directory info should not be null", directory); | ||
|
|
||
| // Check all expected directory fields are present | ||
| assertNotNull("cwd should not be null", directory.get("cwd")); | ||
| assertNotNull("instance should not be null", directory.get("instance")); | ||
| assertNotNull("data should not be null", directory.get("data")); | ||
| assertNotNull("dirimpl should not be null", directory.get("dirimpl")); | ||
| assertNotNull("index should not be null", directory.get("index")); | ||
|
|
||
| assertFalse("HTTP caching should be disabled", rsp.isHttpCaching()); | ||
|
|
||
| req.close(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCoreInfoMatchesActualCore() throws Exception { | ||
| CoreInfoHandler handler = new CoreInfoHandler(); | ||
|
|
||
| try (SolrQueryRequest req = req()) { | ||
| SolrCore core = req.getCore(); | ||
| assertNotNull("Core should not be null", core); | ||
|
|
||
| SolrQueryResponse rsp = new SolrQueryResponse(); | ||
| handler.handleRequestBody(req, rsp); | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| SimpleOrderedMap<Object> coreInfo = (SimpleOrderedMap<Object>) rsp.getValues().get("core"); | ||
|
|
||
| // Verify the schema name matches what we expect | ||
| String schemaName = (String) coreInfo.get("schema"); | ||
| assertEquals("Schema name should match", core.getLatestSchema().getSchemaName(), schemaName); | ||
|
|
||
| // Verify start time matches core's start time | ||
| Date startTime = (Date) coreInfo.get("start"); | ||
| assertEquals( | ||
| "Start time should match core start time", | ||
| core.getStartTimeStamp().getTime(), | ||
| startTime.getTime()); | ||
|
|
||
| // Verify instance path is correctly reported | ||
| @SuppressWarnings("unchecked") | ||
| SimpleOrderedMap<Object> directory = (SimpleOrderedMap<Object>) coreInfo.get("directory"); | ||
| String instancePath = (String) directory.get("instance"); | ||
| assertEquals("Instance path should match", core.getInstancePath().toString(), instancePath); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this request handler need
if (AdminHandlersProxy.maybeProxyToNodes(req, rsp, getCoreContainer(req))) {likeSystemInfoHandlerhas? Is that soemthing every class needs?