forked from apache/solr
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SOLR-16825: Generate v2 API SolrRequest bindings (apache#1793)
Prior to this commit, SolrJ had no real coverage of v2 APIs beyond the generic V2Request class. This commit introduces the first request- specific v2 SolrRequest implementations to SolrJ. Rather than duplicating details about the API here in SolrJ so that both the server-side API definition and the client objects need maintained by hand, this commit generates the v2 SolrRequest classes from the OpenAPI specification (which in turn is generated from the server-side API definition). This ensures that there's only one "source of truth" that needs maintained for each API. To achieve this, this commit introduces a new gradle module, 'api', to hold interfaces (representing Solr's APIs) and POJOs (representing the API's inputs and outputs). This module is all that is needed to generate Solr's OpenAPI spec, and for SolrJ in turn to generate SolrRequest implementations from that spec. This commit restricts v2 SolrRequest generation to a few example APIs to prove the approach. Additional APIs will be added in subsequent commits. --------- Co-authored-by: Houston Putman <[email protected]>
- Loading branch information
1 parent
9b1aba2
commit 326753c
Showing
106 changed files
with
1,032 additions
and
336 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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,61 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
plugins { | ||
id 'io.swagger.core.v3.swagger-gradle-plugin' version '2.2.2' | ||
} | ||
|
||
apply plugin: 'java-library' | ||
|
||
description = 'API - Interfaces and classes used to represent Solrs APIs' | ||
|
||
ext { | ||
openApiSpecDir = "${buildDir}/generated/openapi" | ||
openApiSpecFile = "${project.openApiSpecDir}/openapi.json" | ||
} | ||
|
||
configurations { | ||
openapiSpec { | ||
canBeConsumed = true | ||
canBeResolved = false | ||
} | ||
} | ||
|
||
resolve { | ||
classpath = sourceSets.main.runtimeClasspath | ||
outputDir = file(project.openApiSpecDir) | ||
prettyPrint = true | ||
} | ||
|
||
dependencies { | ||
runtimeOnly 'org.slf4j:slf4j-api' | ||
|
||
implementation 'jakarta.ws.rs:jakarta.ws.rs-api' | ||
implementation 'com.fasterxml.jackson.core:jackson-annotations' | ||
api 'io.swagger.core.v3:swagger-annotations' | ||
implementation 'org.semver4j:semver4j' | ||
|
||
testImplementation project(':solr:test-framework') | ||
testImplementation project(':solr:api') | ||
testImplementation 'org.apache.lucene:lucene-test-framework' | ||
} | ||
|
||
artifacts { | ||
openapiSpec resolve.outputDir, { | ||
builtBy resolve | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
solr/api/src/java/org/apache/solr/client/api/endpoint/AddReplicaPropertyApi.java
This file contains 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,60 @@ | ||
/* | ||
* 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 static org.apache.solr.client.api.util.Constants.BINARY_CONTENT_TYPE_V2; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.parameters.RequestBody; | ||
import javax.ws.rs.PUT; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import org.apache.solr.client.api.model.AddReplicaPropertyRequestBody; | ||
import org.apache.solr.client.api.model.SolrJerseyResponse; | ||
|
||
@Path("/collections/{collName}/shards/{shardName}/replicas/{replicaName}/properties/{propName}") | ||
public interface AddReplicaPropertyApi { | ||
|
||
@PUT | ||
@Produces({"application/json", "application/xml", BINARY_CONTENT_TYPE_V2}) | ||
@Operation( | ||
summary = "Adds a property to the specified replica", | ||
tags = {"replicas"}) | ||
public SolrJerseyResponse addReplicaProperty( | ||
@Parameter( | ||
description = "The name of the collection the replica belongs to.", | ||
required = true) | ||
@PathParam("collName") | ||
String collName, | ||
@Parameter(description = "The name of the shard the replica belongs to.", required = true) | ||
@PathParam("shardName") | ||
String shardName, | ||
@Parameter(description = "The replica, e.g., `core_node1`.", required = true) | ||
@PathParam("replicaName") | ||
String replicaName, | ||
@Parameter(description = "The name of the property to add.", required = true) | ||
@PathParam("propName") | ||
String propertyName, | ||
@RequestBody( | ||
description = "The value of the replica property to create or update", | ||
required = true) | ||
AddReplicaPropertyRequestBody requestBody) | ||
throws Exception; | ||
} |
45 changes: 45 additions & 0 deletions
45
solr/api/src/java/org/apache/solr/client/api/endpoint/DeleteAliasApi.java
This file contains 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,45 @@ | ||
/* | ||
* 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 static org.apache.solr.client.api.util.Constants.BINARY_CONTENT_TYPE_V2; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import javax.ws.rs.DELETE; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.QueryParam; | ||
import org.apache.solr.client.api.model.SolrJerseyResponse; | ||
|
||
@Path("/aliases/{aliasName}") | ||
public interface DeleteAliasApi { | ||
|
||
@DELETE | ||
@Produces({"application/json", "application/xml", BINARY_CONTENT_TYPE_V2}) | ||
@Operation( | ||
summary = "Deletes an alias by its name", | ||
tags = {"aliases"}) | ||
SolrJerseyResponse deleteAlias( | ||
@Parameter(description = "The name of the alias to delete", required = true) | ||
@PathParam("aliasName") | ||
String aliasName, | ||
@QueryParam("async") String asyncId) | ||
throws Exception; | ||
} |
47 changes: 47 additions & 0 deletions
47
solr/api/src/java/org/apache/solr/client/api/endpoint/DeleteCollectionApi.java
This file contains 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,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.client.api.endpoint; | ||
|
||
import static org.apache.solr.client.api.util.Constants.BINARY_CONTENT_TYPE_V2; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import javax.ws.rs.DELETE; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.QueryParam; | ||
import org.apache.solr.client.api.model.SubResponseAccumulatingJerseyResponse; | ||
|
||
@Path("/collections/{collectionName}") | ||
public interface DeleteCollectionApi { | ||
|
||
@DELETE | ||
@Produces({"application/json", "application/xml", BINARY_CONTENT_TYPE_V2}) | ||
@Operation( | ||
summary = "Deletes a collection from SolrCloud", | ||
tags = {"collections"}) | ||
SubResponseAccumulatingJerseyResponse deleteCollection( | ||
@Parameter(description = "The name of the collection to be deleted.", required = true) | ||
@PathParam("collectionName") | ||
String collectionName, | ||
@QueryParam("followAliases") Boolean followAliases, | ||
@Parameter(description = "An ID to track the request asynchronously") @QueryParam("async") | ||
String asyncId) | ||
throws Exception; | ||
} |
19 changes: 19 additions & 0 deletions
19
solr/api/src/java/org/apache/solr/client/api/endpoint/package-info.java
This file contains 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,19 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** Interfaces representing individual Solr v2 APIs. */ | ||
package org.apache.solr.client.api.endpoint; |
41 changes: 41 additions & 0 deletions
41
solr/api/src/java/org/apache/solr/client/api/model/AddReplicaPropertyRequestBody.java
This file contains 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,41 @@ | ||
/* | ||
* 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 org.apache.solr.client.api.util.ReflectWritable; | ||
|
||
public class AddReplicaPropertyRequestBody implements ReflectWritable { | ||
public AddReplicaPropertyRequestBody() {} | ||
|
||
public AddReplicaPropertyRequestBody(String value) { | ||
this.value = value; | ||
} | ||
|
||
@Schema(description = "The value to assign to the property.", required = true) | ||
@JsonProperty("value") | ||
public String value; | ||
|
||
@Schema( | ||
description = | ||
"If `true`, then setting this property in one replica will remove the property from all other replicas in that shard. The default is `false`.\\nThere is one pre-defined property `preferredLeader` for which `shardUnique` is forced to `true` and an error returned if `shardUnique` is explicitly set to `false`.", | ||
defaultValue = "false") | ||
@JsonProperty("shardUnique") | ||
public Boolean shardUnique; | ||
} |
This file contains 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.