-
Notifications
You must be signed in to change notification settings - Fork 857
SOLR-16458: Migrate node properties API to JAX-RS #4775
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
iprithv
wants to merge
2
commits into
apache:main
Choose a base branch
from
iprithv:node-properties-jaxrs
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.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
8 changes: 8 additions & 0 deletions
8
changelog/unreleased/SOLR-16458-migrate-node-properties-api.yml
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 @@ | ||
| title: "v2 GET /api/node/properties is now a JAX-RS API; a single property is fetched at /api/node/properties/{propertyName} (SolrJ: NodeApi.GetNodeProperties / GetNodeProperty)" | ||
| type: added | ||
| authors: | ||
| - name: Prithvi S | ||
| nick: iprithv | ||
| links: | ||
| - name: SOLR-16458 | ||
| url: https://issues.apache.org/jira/browse/SOLR-16458 |
44 changes: 44 additions & 0 deletions
44
solr/api/src/java/org/apache/solr/client/api/endpoint/NodePropertiesApi.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,44 @@ | ||
| /* | ||
| * 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.client.api.endpoint; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.Parameter; | ||
| import jakarta.ws.rs.GET; | ||
| import jakarta.ws.rs.Path; | ||
| import jakarta.ws.rs.PathParam; | ||
| import org.apache.solr.client.api.model.NodePropertiesResponse; | ||
|
|
||
| /** V2 API definition for listing JRE system properties on a Solr node. */ | ||
| @Path("/node/properties") | ||
| public interface NodePropertiesApi { | ||
|
|
||
| @GET | ||
| @Operation( | ||
| summary = "List system properties for the target Solr node.", | ||
| tags = {"node"}) | ||
| NodePropertiesResponse getNodeProperties(); | ||
|
|
||
| @GET | ||
| @Path("/{propertyName}") | ||
| @Operation( | ||
| summary = "Get a single system property for the target Solr node.", | ||
| tags = {"node"}) | ||
| NodePropertiesResponse getNodeProperty( | ||
| @Parameter(description = "Name of the system property to return.") @PathParam("propertyName") | ||
| String propertyName); | ||
| } |
34 changes: 34 additions & 0 deletions
34
solr/api/src/java/org/apache/solr/client/api/model/NodePropertiesResponse.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,34 @@ | ||
| /* | ||
| * 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.client.api.model; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Response body for {@code GET /api/node/properties} and {@code GET | ||
| * /api/node/properties/{propertyName}}. | ||
| */ | ||
| public class NodePropertiesResponse extends SolrJerseyResponse { | ||
|
|
||
| public static final String SYSTEM_PROPERTIES = "system.properties"; | ||
|
|
||
| @Schema(description = "JRE system properties for the Solr node. Secret values are redacted.") | ||
| @JsonProperty(SYSTEM_PROPERTIES) | ||
| public Map<String, String> systemProperties; | ||
| } | ||
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 |
|---|---|---|
|
|
@@ -16,24 +16,27 @@ | |
| */ | ||
| package org.apache.solr.handler.admin; | ||
|
|
||
| import static org.apache.solr.client.api.model.NodePropertiesResponse.SYSTEM_PROPERTIES; | ||
| import static org.apache.solr.common.params.CommonParams.NAME; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Collection; | ||
| import java.util.Enumeration; | ||
| import org.apache.solr.api.AnnotatedApi; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import org.apache.solr.api.Api; | ||
| import org.apache.solr.api.JerseyResource; | ||
| import org.apache.solr.common.util.NamedList; | ||
| import org.apache.solr.common.util.SimpleOrderedMap; | ||
| import org.apache.solr.core.CoreContainer; | ||
| import org.apache.solr.core.NodeConfig; | ||
| import org.apache.solr.handler.RequestHandlerBase; | ||
| import org.apache.solr.handler.admin.api.NodePropertiesAPI; | ||
| import org.apache.solr.handler.admin.api.GetNodeProperties; | ||
| import org.apache.solr.request.SolrQueryRequest; | ||
| import org.apache.solr.response.SolrQueryResponse; | ||
| import org.apache.solr.security.AuthorizationContext; | ||
|
|
||
| /** | ||
| * v1 implementation of {@code GET /admin/info/properties}. Business logic lives in {@link | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great! |
||
| * GetNodeProperties}. | ||
| * | ||
| * @since solr 1.2 | ||
| */ | ||
| public class PropertiesRequestHandler extends RequestHandlerBase { | ||
|
|
@@ -50,22 +53,14 @@ public PropertiesRequestHandler(CoreContainer cc) { | |
| } | ||
|
|
||
| @Override | ||
| public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException { | ||
| NamedList<String> props = new SimpleOrderedMap<>(); | ||
| String name = req.getParams().get(NAME); | ||
| NodeConfig nodeConfig = getCoreContainer(req).getNodeConfig(); | ||
| if (name != null) { | ||
| String property = nodeConfig.getRedactedSysPropValue(name); | ||
| props.add(name, property); | ||
| } else { | ||
| Enumeration<?> enumeration = System.getProperties().propertyNames(); | ||
| while (enumeration.hasMoreElements()) { | ||
| name = (String) enumeration.nextElement(); | ||
| props.add(name, nodeConfig.getRedactedSysPropValue(name)); | ||
| } | ||
| } | ||
| rsp.add("system.properties", props); | ||
| public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { | ||
| rsp.setHttpCaching(false); | ||
| String name = req.getParams().get(NAME); | ||
| Map<String, String> props = | ||
| new GetNodeProperties(getCoreContainer(req)).collectProperties(name); | ||
| NamedList<String> values = new SimpleOrderedMap<>(); | ||
| props.forEach(values::add); | ||
| rsp.add(SYSTEM_PROPERTIES, values); | ||
| } | ||
|
|
||
| //////////////////////// SolrInfoMBeans methods ////////////////////// | ||
|
|
@@ -82,7 +77,12 @@ public Category getCategory() { | |
|
|
||
| @Override | ||
| public Collection<Api> getApis() { | ||
| return AnnotatedApi.getApis(new NodePropertiesAPI(this)); | ||
| return List.of(); | ||
| } | ||
|
|
||
| @Override | ||
| public Collection<Class<? extends JerseyResource>> getJerseyResources() { | ||
| return List.of(GetNodeProperties.class); | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
82 changes: 82 additions & 0 deletions
82
solr/core/src/java/org/apache/solr/handler/admin/api/GetNodeProperties.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,82 @@ | ||
| /* | ||
| * 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.api; | ||
|
|
||
| import jakarta.inject.Inject; | ||
| import java.util.Enumeration; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.Map; | ||
| import org.apache.solr.api.JerseyResource; | ||
| import org.apache.solr.client.api.endpoint.NodePropertiesApi; | ||
| import org.apache.solr.client.api.model.NodePropertiesResponse; | ||
| import org.apache.solr.core.CoreContainer; | ||
| import org.apache.solr.core.NodeConfig; | ||
| import org.apache.solr.jersey.PermissionName; | ||
| import org.apache.solr.security.PermissionNameProvider; | ||
|
|
||
| /** | ||
| * V2 API for listing system properties on the receiving node. | ||
| * | ||
| * <p>GET /api/node/properties lists all properties. GET /api/node/properties/{propertyName} returns | ||
| * a single property. Both are analogous to v1 /admin/info/properties, which still uses a {@code | ||
| * name} query parameter for the single-property form. | ||
| * | ||
| * <p>The v1 {@link org.apache.solr.handler.admin.PropertiesRequestHandler} delegates to this class. | ||
| */ | ||
| public class GetNodeProperties extends JerseyResource implements NodePropertiesApi { | ||
|
|
||
| private final CoreContainer coreContainer; | ||
|
|
||
| @Inject | ||
| public GetNodeProperties(CoreContainer coreContainer) { | ||
| this.coreContainer = coreContainer; | ||
| } | ||
|
|
||
| @Override | ||
| @PermissionName(PermissionNameProvider.Name.CONFIG_READ_PERM) | ||
| public NodePropertiesResponse getNodeProperties() { | ||
| return buildResponse(null); | ||
| } | ||
|
|
||
| @Override | ||
| @PermissionName(PermissionNameProvider.Name.CONFIG_READ_PERM) | ||
| public NodePropertiesResponse getNodeProperty(String propertyName) { | ||
| return buildResponse(propertyName); | ||
| } | ||
|
|
||
| private NodePropertiesResponse buildResponse(String name) { | ||
| final NodePropertiesResponse response = instantiateJerseyResponse(NodePropertiesResponse.class); | ||
| response.systemProperties = collectProperties(name); | ||
| return response; | ||
| } | ||
|
|
||
| /** Collect redacted system properties, optionally limited to a single named property. */ | ||
| public Map<String, String> collectProperties(String name) { | ||
| final NodeConfig nodeConfig = coreContainer.getNodeConfig(); | ||
| final Map<String, String> props = new LinkedHashMap<>(); | ||
| if (name != null) { | ||
| props.put(name, nodeConfig.getRedactedSysPropValue(name)); | ||
| } else { | ||
| Enumeration<?> enumeration = System.getProperties().propertyNames(); | ||
| while (enumeration.hasMoreElements()) { | ||
| String propertyName = (String) enumeration.nextElement(); | ||
| props.put(propertyName, nodeConfig.getRedactedSysPropValue(propertyName)); | ||
| } | ||
| } | ||
| return props; | ||
| } | ||
| } |
47 changes: 0 additions & 47 deletions
47
solr/core/src/java/org/apache/solr/handler/admin/api/NodePropertiesAPI.java
This file was deleted.
Oops, something went wrong.
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
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.
is it really as simple as a string/string? Great.