Skip to content
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

SOLR-17562: Unify JAX-RS "raw response" endpoints #3032

Merged
merged 8 commits into from
Jan 19, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Switch ZK-Read and Replication to StreamingOutput
This also switches the endpoint-definitions to be codegen compatible
using the new "rawOutput" property.
gerlowskija committed Jan 14, 2025
commit 61180850476298fa39847ec7aeab399b043d7e24
2 changes: 2 additions & 0 deletions solr/api/build.gradle
Original file line number Diff line number Diff line change
@@ -55,6 +55,8 @@ resolve {
outputDir = file(project.openApiSpecDir)
outputFileName = "solr-openapi-${version}"
prettyPrint = true
// Ignore resources not annotated with 'Operation', useful for omitting endpoints from OAS
readAllResources = false
}

dependencies {
Original file line number Diff line number Diff line change
@@ -89,6 +89,7 @@ SolrJerseyResponse uploadConfigSet(

@PUT
@Path("{filePath:.+}")
@Operation(summary = "Create a new configset.", tags = "configsets")
SolrJerseyResponse uploadConfigSetFile(
@PathParam("configSetName") String configSetName,
@PathParam("filePath") String filePath,
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
*/
package org.apache.solr.client.api.endpoint;

import static org.apache.solr.client.api.util.Constants.OMIT_FROM_CODEGEN_PROPERTY;
import static org.apache.solr.client.api.util.Constants.RAW_OUTPUT_PROPERTY;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
@@ -59,10 +59,9 @@ FileListResponse fetchFileList(
@CoreApiParameters
@Operation(
summary = "Get a stream of a specific file path of a core",
tags = {"core-replication"},
extensions = { // TODO Remove as a part of SOLR-17562
@Extension(
properties = {@ExtensionProperty(name = OMIT_FROM_CODEGEN_PROPERTY, value = "true")})
tags = {"replication"},
extensions = {
@Extension(properties = {@ExtensionProperty(name = RAW_OUTPUT_PROPERTY, value = "true")})
})
@Path("/files/{filePath}")
StreamingOutput fetchFile(
Original file line number Diff line number Diff line change
@@ -16,15 +16,19 @@
*/
package org.apache.solr.client.api.endpoint;

import static org.apache.solr.client.api.util.Constants.RAW_OUTPUT_PROPERTY;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.extensions.Extension;
import io.swagger.v3.oas.annotations.extensions.ExtensionProperty;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;
import org.apache.solr.client.api.model.ZooKeeperFileResponse;
import jakarta.ws.rs.core.StreamingOutput;
import org.apache.solr.client.api.model.ZooKeeperListChildrenResponse;

/** V2 API definitions for Solr's ZooKeeper ready-proxy endpoint */
@@ -35,9 +39,12 @@ public interface ZooKeeperReadApis {
@Path("/data{zkPath:.+}")
@Operation(
summary = "Return the data stored in a specified ZooKeeper node",
tags = {"zookeeper-read"})
tags = {"zookeeper-read"},
extensions = {
@Extension(properties = {@ExtensionProperty(name = RAW_OUTPUT_PROPERTY, value = "true")})
})
@Produces({"application/vnd.apache.solr.raw", MediaType.APPLICATION_JSON})
ZooKeeperFileResponse readNode(
StreamingOutput readNode(
@Parameter(description = "The path of the node to read from ZooKeeper") @PathParam("zkPath")
String zkPath);

@@ -48,7 +55,7 @@ ZooKeeperFileResponse readNode(
@GET
@Path("/data/security.json")
@Produces({"application/vnd.apache.solr.raw", MediaType.APPLICATION_JSON})
ZooKeeperFileResponse readSecurityJsonNode();
StreamingOutput readSecurityJsonNode();

@GET
@Path("/children{zkPath:.*}")

This file was deleted.

27 changes: 15 additions & 12 deletions solr/core/src/java/org/apache/solr/handler/admin/ZookeeperRead.java
Original file line number Diff line number Diff line change
@@ -21,19 +21,21 @@
import static org.apache.solr.security.PermissionNameProvider.Name.ZK_READ_PERM;

import jakarta.inject.Inject;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.StreamingOutput;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.solr.client.api.endpoint.ZooKeeperReadApis;
import org.apache.solr.client.api.model.ZooKeeperFileResponse;
import org.apache.solr.client.api.model.ZooKeeperListChildrenResponse;
import org.apache.solr.client.api.model.ZooKeeperStat;
import org.apache.solr.client.solrj.impl.BinaryResponseParser;
import org.apache.solr.client.solrj.impl.XMLResponseParser;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.util.ContentStreamBase;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.handler.admin.api.AdminAPIBase;
import org.apache.solr.jersey.PermissionName;
@@ -64,15 +66,15 @@ public ZookeeperRead(CoreContainer coreContainer, SolrQueryRequest req, SolrQuer
/** Request contents of a znode, except security.json */
@Override
@PermissionName(ZK_READ_PERM)
public ZooKeeperFileResponse readNode(String zkPath) {
public StreamingOutput readNode(String zkPath) {
zkPath = sanitizeZkPath(zkPath);
return readNodeAndAddToResponse(zkPath);
}

/** Request contents of the security.json node */
@Override
@PermissionName(SECURITY_READ_PERM)
public ZooKeeperFileResponse readSecurityJsonNode() {
public StreamingOutput readSecurityJsonNode() {
return readNodeAndAddToResponse("/security.json");
}

@@ -141,18 +143,19 @@ private String guessMime(byte firstByte) {
}

/** Reads content of a znode */
private ZooKeeperFileResponse readNodeAndAddToResponse(String zkPath) {
final ZooKeeperFileResponse zkFileResponse =
instantiateJerseyResponse(ZooKeeperFileResponse.class);

private StreamingOutput readNodeAndAddToResponse(String zkPath) {
byte[] d = readPathFromZookeeper(zkPath);
if (d == null || d.length == 0) {
zkFileResponse.zkData = EMPTY;
return zkFileResponse;
d = new byte[0];
}

zkFileResponse.output = new ContentStreamBase.ByteArrayStream(d, null, guessMime(d[0]));
return zkFileResponse;
final var bytesToWrite = d;
return new StreamingOutput() {
@Override
public void write(OutputStream output) throws IOException, WebApplicationException {
output.write(bytesToWrite);
}
};
}

/** Reads a single node from zookeeper and return as byte array */