forked from apache/solr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
74 changed files
with
375 additions
and
207 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
39 changes: 39 additions & 0 deletions
39
solr/api/src/java/org/apache/solr/client/api/endpoint/UnloadCoreApi.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,39 @@ | ||
/* | ||
* 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.parameters.RequestBody; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import org.apache.solr.client.api.model.SolrJerseyResponse; | ||
import org.apache.solr.client.api.model.UnloadCoreRequestBody; | ||
|
||
/** V2 API definition for unloading a Solr core. */ | ||
@Path("/cores/{coreName}/unload") | ||
public interface UnloadCoreApi { | ||
@POST | ||
@Operation( | ||
summary = "Unloads a single core specified by name", | ||
tags = {"cores"}) | ||
SolrJerseyResponse unloadCore( | ||
@PathParam("coreName") String coreName, | ||
@RequestBody(description = "Additional properties related to the core unloading") | ||
UnloadCoreRequestBody requestBody) | ||
throws Exception; | ||
} |
40 changes: 40 additions & 0 deletions
40
solr/api/src/java/org/apache/solr/client/api/model/UnloadCoreRequestBody.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,40 @@ | ||
/* | ||
* 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; | ||
|
||
public class UnloadCoreRequestBody { | ||
@Schema(description = "If true, will remove the index when unloading the core.") | ||
@JsonProperty | ||
public Boolean deleteIndex; | ||
|
||
@Schema(description = "If true, removes the data directory and all sub-directories.") | ||
@JsonProperty | ||
public Boolean deleteDataDir; | ||
|
||
@Schema( | ||
description = | ||
"If true, removes everything related to the core, including the index directory, configuration files and other related files.") | ||
@JsonProperty | ||
public Boolean deleteInstanceDir; | ||
|
||
@Schema(description = "Request ID to track this action which will be processed asynchronously.") | ||
@JsonProperty | ||
public String async; | ||
} |
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
79 changes: 79 additions & 0 deletions
79
solr/core/src/java/org/apache/solr/handler/admin/api/UnloadCore.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,79 @@ | ||
/* | ||
* 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 static org.apache.solr.security.PermissionNameProvider.Name.CORE_EDIT_PERM; | ||
|
||
import javax.inject.Inject; | ||
import org.apache.solr.client.api.endpoint.UnloadCoreApi; | ||
import org.apache.solr.client.api.model.SolrJerseyResponse; | ||
import org.apache.solr.client.api.model.UnloadCoreRequestBody; | ||
import org.apache.solr.core.CoreContainer; | ||
import org.apache.solr.core.CoreDescriptor; | ||
import org.apache.solr.handler.admin.CoreAdminHandler; | ||
import org.apache.solr.jersey.PermissionName; | ||
import org.apache.solr.request.SolrQueryRequest; | ||
import org.apache.solr.response.SolrQueryResponse; | ||
import org.apache.solr.util.TestInjection; | ||
|
||
/** | ||
* V2 API implementation for unloading a Solr core. | ||
* | ||
* <p>The API (POST /v2/cores/coreName/unload is equivalent to the v1 /admin/cores?action=unload | ||
* command. | ||
*/ | ||
public class UnloadCore extends CoreAdminAPIBase implements UnloadCoreApi { | ||
|
||
@Inject | ||
public UnloadCore( | ||
CoreContainer coreContainer, | ||
CoreAdminHandler.CoreAdminAsyncTracker coreAdminAsyncTracker, | ||
SolrQueryRequest solrQueryRequest, | ||
SolrQueryResponse solrQueryResponse) { | ||
super(coreContainer, coreAdminAsyncTracker, solrQueryRequest, solrQueryResponse); | ||
} | ||
|
||
@PermissionName(CORE_EDIT_PERM) | ||
@Override | ||
public SolrJerseyResponse unloadCore(String coreName, UnloadCoreRequestBody requestBody) | ||
throws Exception { | ||
ensureRequiredParameterProvided("coreName", coreName); | ||
SolrJerseyResponse solrJerseyResponse = instantiateJerseyResponse(SolrJerseyResponse.class); | ||
if (requestBody == null) { | ||
requestBody = new UnloadCoreRequestBody(); | ||
} | ||
final var requestBodyFinal = requestBody; // Lambda below requires a 'final' variable | ||
return handlePotentiallyAsynchronousTask( | ||
solrJerseyResponse, | ||
coreName, | ||
requestBody.async, | ||
"unload", | ||
() -> { | ||
CoreDescriptor cdescr = coreContainer.getCoreDescriptor(coreName); | ||
coreContainer.unload( | ||
coreName, | ||
requestBodyFinal.deleteIndex == null ? false : requestBodyFinal.deleteIndex, | ||
requestBodyFinal.deleteDataDir == null ? false : requestBodyFinal.deleteDataDir, | ||
requestBodyFinal.deleteInstanceDir == null | ||
? false | ||
: requestBodyFinal.deleteInstanceDir); | ||
assert TestInjection.injectNonExistentCoreExceptionAfterUnload(coreName); | ||
return solrJerseyResponse; | ||
}); | ||
} | ||
} |
Oops, something went wrong.