Apache Solr open-source search software
SOLR-15745: Convert remaining 'core-admin' v2 APIs to annotations (#577)
Jason Gerlowski1cce4b66c559
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.javaindex 27e6116c5fa..088de638b4c 100644--- a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java+++ b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java@@ -37,13 +37,19 @@ import org.apache.solr.core.CoreContainer;import org.apache.solr.core.CoreDescriptor;import org.apache.solr.handler.RequestHandlerBase;import org.apache.solr.handler.admin.api.AllCoresStatusAPI;+import org.apache.solr.handler.admin.api.RequestCoreCommandStatusAPI;import org.apache.solr.handler.admin.api.CreateCoreAPI;import org.apache.solr.handler.admin.api.InvokeClassAPI;import org.apache.solr.handler.admin.api.MergeIndexesAPI;import org.apache.solr.handler.admin.api.OverseerOperationAPI;+import org.apache.solr.handler.admin.api.PrepareCoreRecoveryAPI;import org.apache.solr.handler.admin.api.RejoinLeaderElectionAPI;import org.apache.solr.handler.admin.api.ReloadCoreAPI;import org.apache.solr.handler.admin.api.RenameCoreAPI;+import org.apache.solr.handler.admin.api.RequestApplyCoreUpdatesAPI;+import org.apache.solr.handler.admin.api.RequestBufferUpdatesAPI;+import org.apache.solr.handler.admin.api.RequestCoreRecoveryAPI;+import org.apache.solr.handler.admin.api.RequestSyncShardAPI;import org.apache.solr.handler.admin.api.SingleCoreStatusAPI;import org.apache.solr.handler.admin.api.SplitCoreAPI;import org.apache.solr.handler.admin.api.SwapCoresAPI;@@ -86,7 +92,6 @@ public class CoreAdminHandler extends RequestHandlerBase implements PermissionNaprivate static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());protected final CoreContainer coreContainer;protected final Map<String, Map<String, TaskObject>> requestStatusMap;- private final CoreAdminHandlerApi coreAdminHandlerApi;protected ExecutorService parallelExecutor = ExecutorUtil.newMDCAwareFixedThreadPool(50,new SolrNamedThreadFactory("parallelCoreAdminExecutor"));@@ -109,7 +114,6 @@ public class CoreAdminHandler extends RequestHandlerBase implements PermissionNamap.put(COMPLETED, Collections.synchronizedMap(new LinkedHashMap<String, TaskObject>()));map.put(FAILED, Collections.synchronizedMap(new LinkedHashMap<String, TaskObject>()));requestStatusMap = Collections.unmodifiableMap(map);- coreAdminHandlerApi = new CoreAdminHandlerApi(this);}@@ -125,7 +129,6 @@ public class CoreAdminHandler extends RequestHandlerBase implements PermissionNamap.put(COMPLETED, Collections.synchronizedMap(new LinkedHashMap<String, TaskObject>()));map.put(FAILED, Collections.synchronizedMap(new LinkedHashMap<String, TaskObject>()));requestStatusMap = Collections.unmodifiableMap(map);- coreAdminHandlerApi = new CoreAdminHandlerApi(this);}@@ -427,8 +430,7 @@ public class CoreAdminHandler extends RequestHandlerBase implements PermissionNa@Overridepublic Collection<Api> getApis() {- final List<Api> apis = Lists.newArrayList(coreAdminHandlerApi.getApis());- // Only some core-admin APIs use the v2 AnnotatedApi framework+ final List<Api> apis = Lists.newArrayList();apis.addAll(AnnotatedApi.getApis(new AllCoresStatusAPI(this)));apis.addAll(AnnotatedApi.getApis(new SingleCoreStatusAPI(this)));apis.addAll(AnnotatedApi.getApis(new CreateCoreAPI(this)));@@ -441,6 +443,14 @@ public class CoreAdminHandler extends RequestHandlerBase implements PermissionNaapis.addAll(AnnotatedApi.getApis(new UnloadCoreAPI(this)));apis.addAll(AnnotatedApi.getApis(new MergeIndexesAPI(this)));apis.addAll(AnnotatedApi.getApis(new SplitCoreAPI(this)));+ apis.addAll(AnnotatedApi.getApis(new RequestCoreCommandStatusAPI(this)));+ // Internal APIs+ apis.addAll(AnnotatedApi.getApis(new RequestCoreRecoveryAPI(this)));+ apis.addAll(AnnotatedApi.getApis(new PrepareCoreRecoveryAPI(this)));+ apis.addAll(AnnotatedApi.getApis(new RequestApplyCoreUpdatesAPI(this)));+ apis.addAll(AnnotatedApi.getApis(new RequestSyncShardAPI(this)));+ apis.addAll(AnnotatedApi.getApis(new RequestBufferUpdatesAPI(this)));+return apis;}diff --git a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandlerApi.java b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandlerApi.javadeleted file mode 100644index ca14ba2fd01..00000000000--- a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandlerApi.java+++ /dev/null@@ -1,85 +0,0 @@-/*- * 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.Arrays;-import java.util.Collection;-import java.util.EnumMap;-import java.util.Map;--import org.apache.solr.client.solrj.request.ApiMapping.CommandMeta;-import org.apache.solr.client.solrj.request.ApiMapping.V2EndPoint;-import org.apache.solr.client.solrj.request.CoreApiMapping;-import org.apache.solr.request.SolrQueryRequest;-import org.apache.solr.response.SolrQueryResponse;--public class CoreAdminHandlerApi extends BaseHandlerApiSupport {- private final CoreAdminHandler handler;- static Collection<ApiCommand> apiCommands = createMapping();-- private static Collection<ApiCommand> createMapping() {- Map<CoreApiMapping.Meta, ApiCommand> result = new EnumMap<>(CoreApiMapping.Meta.class);-- for (CoreApiMapping.Meta meta : CoreApiMapping.Meta.values()) {-- for (CoreAdminOperation op : CoreAdminOperation.values()) {- if (op.action == meta.action) {- result.put(meta, new ApiCommand() {- @Override- public CommandMeta meta() {- return meta;- }-- @Override- public void invoke(SolrQueryRequest req, SolrQueryResponse rsp, BaseHandlerApiSupport apiHandler) throws Exception {- op.execute(new CoreAdminHandler.CallInfo(((CoreAdminHandlerApi) apiHandler).handler,- req,- rsp,- op));- }- });- }- }- }-- for (CoreApiMapping.Meta meta : CoreApiMapping.Meta.values()) {- if (result.get(meta) == null) {- throw new RuntimeException("No implementation for " + meta.name());- }- }-- return result.values();- }-- public CoreAdminHandlerApi(CoreAdminHandler handler) {- this.handler = handler;- }--- @Override- protected Collection<ApiCommand> getCommands() {- return apiCommands;- }-- @Override- protected Collection<V2EndPoint> getEndPoints() {- return Arrays.asList(CoreApiMapping.EndPoint.values());- }---}diff --git a/solr/core/src/java/org/apache/solr/handler/admin/api/PrepareCoreRecoveryAPI.java b/solr/core/src/java/org/apache/solr/handler/admin/api/PrepareCoreRecoveryAPI.javanew file mode 100644index 00000000000..29cd5cc7830--- /dev/null+++ b/solr/core/src/java/org/apache/solr/handler/admin/api/PrepareCoreRecoveryAPI.java@@ -0,0 +1,66 @@+/*+ * 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 org.apache.solr.api.Command;+import org.apache.solr.api.EndPoint;+import org.apache.solr.api.PayloadObj;+import org.apache.solr.client.solrj.request.beans.PrepareCoreRecoveryPayload;+import org.apache.solr.handler.admin.CoreAdminHandler;++import java.util.HashMap;+import java.util.Locale;+import java.util.Map;++import static org.apache.solr.client.solrj.SolrRequest.METHOD.POST;+import static org.apache.solr.common.params.CoreAdminParams.ACTION;+import static org.apache.solr.common.params.CoreAdminParams.CORE;+import static org.apache.solr.common.params.CoreAdminParams.CoreAdminAction.PREPRECOVERY;+import static org.apache.solr.handler.ClusterAPI.wrapParams;+import static org.apache.solr.security.PermissionNameProvider.Name.CORE_EDIT_PERM;++/**+ * Internal V2 API used to prepare a core for recovery.+ *+ * Only valid in SolrCloud mode. This API (POST /v2/cores/coreName {'prep-recovery': {...}}) is analogous to the v1+ * /admin/cores?action=PREPRECOVERY command.+ *+ * @see PrepareCoreRecoveryPayload+ */+@EndPoint(path = {"/cores/{core}"},+ method = POST,+ permission = CORE_EDIT_PERM)+public class PrepareCoreRecoveryAPI {+ public static final String V2_PREP_RECOVERY_CMD = "prep-recovery";++ private final CoreAdminHandler coreAdminHandler;++ public PrepareCoreRecoveryAPI(CoreAdminHandler coreAdminHandler) {+ this.coreAdminHandler = coreAdminHandler;+ }++ @Command(name = V2_PREP_RECOVERY_CMD)+ public void prepareCoreForRecovery(PayloadObj<PrepareCoreRecoveryPayload> obj) throws Exception {+ final PrepareCoreRecoveryPayload v2Body = obj.get();+ final Map<String, Object> v1Params = v2Body.toMap(new HashMap<>());+ v1Params.put(ACTION, PREPRECOVERY.name().toLowerCase(Locale.ROOT));+ v1Params.put(CORE, obj.getRequest().getPathTemplateValues().get("core"));++ coreAdminHandler.handleRequestBody(wrapParams(obj.getRequest(), v1Params), obj.getResponse());+ }+}diff --git a/solr/core/src/java/org/apache/solr/handler/admin/api/RequestApplyCoreUpdatesAPI.java b/solr/core/src/java/org/apache/solr/handler/admin/api/RequestApplyCoreUpdatesAPI.javanew file mode 100644index 00000000000..db89f5f6e3b--- /dev/null+++ b/solr/core/src/java/org/apache/solr/handler/admin/api/RequestApplyCoreUpdatesAPI.java@@ -0,0 +1,66 @@+/*+ * 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 org.apache.solr.api.Command;+import org.apache.solr.api.EndPoint;+import org.apache.solr.api.PayloadObj;+import org.apache.solr.client.solrj.request.beans.RequestApplyCoreUpdatesPayload;+import org.apache.solr.handler.admin.CoreAdminHandler;++import java.util.HashMap;+import java.util.Locale;+import java.util.Map;++import static org.apache.solr.client.solrj.SolrRequest.METHOD.POST;+import static org.apache.solr.common.params.CoreAdminParams.ACTION;+import static org.apache.solr.common.params.CoreAdminParams.CoreAdminAction.REQUESTAPPLYUPDATES;+import static org.apache.solr.common.params.CoreAdminParams.NAME;+import static org.apache.solr.handler.ClusterAPI.wrapParams;+import static org.apache.solr.security.PermissionNameProvider.Name.CORE_EDIT_PERM;++/**+ * Internal V2 API used to apply updates to a core.+ *+ * Only valid in SolrCloud mode. This API (POST /v2/cores/coreName {'request-apply-updates': {}}) is analogous to the v1+ * /admin/cores?action=REQUESTAPPLYUPDATES command.+ *+ * @see org.apache.solr.client.solrj.request.beans.RequestApplyCoreUpdatesPayload+ */+@EndPoint(path = {"/cores/{core}"},+ method = POST,+ permission = CORE_EDIT_PERM)+public class RequestApplyCoreUpdatesAPI {+ public static final String V2_APPLY_CORE_UPDATES_CMD = "request-apply-updates";++ private final CoreAdminHandler coreAdminHandler;++ public RequestApplyCoreUpdatesAPI(CoreAdminHandler coreAdminHandler) {+ this.coreAdminHandler = coreAdminHandler;+ }++ @Command(name = V2_APPLY_CORE_UPDATES_CMD)+ public void requestApplyCoreUpdates(PayloadObj<RequestApplyCoreUpdatesPayload> obj) throws Exception {+ final RequestApplyCoreUpdatesPayload v2Body = obj.get();+ final Map<String, Object> v1Params = v2Body.toMap(new HashMap<>());+ v1Params.put(ACTION, REQUESTAPPLYUPDATES.name().toLowerCase(Locale.ROOT));+ v1Params.put(NAME, obj.getRequest().getPathTemplateValues().get("core"));++ coreAdminHandler.handleRequestBody(wrapParams(obj.getRequest(), v1Params), obj.getResponse());+ }+}diff --git a/solr/core/src/java/org/apache/solr/handler/admin/api/RequestBufferUpdatesAPI.java b/solr/core/src/java/org/apache/solr/handler/admin/api/RequestBufferUpdatesAPI.javanew file mode 100644index 00000000000..579339a52d7--- /dev/null+++ b/solr/core/src/java/org/apache/solr/handler/admin/api/RequestBufferUpdatesAPI.java@@ -0,0 +1,66 @@+/*+ * 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 org.apache.solr.api.Command;+import org.apache.solr.api.EndPoint;+import org.apache.solr.api.PayloadObj;+import org.apache.solr.client.solrj.request.beans.RequestBufferUpdatesPayload;+import org.apache.solr.common.params.CoreAdminParams;+import org.apache.solr.handler.admin.CoreAdminHandler;++import java.util.HashMap;+import java.util.Locale;+import java.util.Map;++import static org.apache.solr.client.solrj.SolrRequest.METHOD.POST;+import static org.apache.solr.common.params.CoreAdminParams.ACTION;+import static org.apache.solr.common.params.CoreAdminParams.CoreAdminAction.REQUESTBUFFERUPDATES;+import static org.apache.solr.handler.ClusterAPI.wrapParams;+import static org.apache.solr.security.PermissionNameProvider.Name.CORE_EDIT_PERM;++/**+ * Internal V2 API used to start update-buffering on the specified core.+ *+ * Only valid in SolrCloud mode. This API (POST /v2/cores/coreName {'request-buffer-updates': {}}) is analogous to the v1+ * /admin/cores?action=REQUESTBUFFERUPDATES command.+ *+ * @see org.apache.solr.client.solrj.request.beans.RequestSyncShardPayload+ */+@EndPoint(path = {"/cores/{core}"},+ method = POST,+ permission = CORE_EDIT_PERM)+public class RequestBufferUpdatesAPI {+ public static final String V2_REQUEST_BUFFER_UPDATES_CMD = "request-buffer-updates";++ private final CoreAdminHandler coreAdminHandler;++ public RequestBufferUpdatesAPI(CoreAdminHandler coreAdminHandler) {+ this.coreAdminHandler = coreAdminHandler;+ }++ @Command(name = V2_REQUEST_BUFFER_UPDATES_CMD)+ public void requestBufferUpdates(PayloadObj<RequestBufferUpdatesPayload> obj) throws Exception {+ final RequestBufferUpdatesPayload v2Body = obj.get();+ final Map<String, Object> v1Params = v2Body.toMap(new HashMap<>());+ v1Params.put(ACTION, REQUESTBUFFERUPDATES.name().toLowerCase(Locale.ROOT));+ v1Params.put(CoreAdminParams.NAME, obj.getRequest().getPathTemplateValues().get("core"));++ coreAdminHandler.handleRequestBody(wrapParams(obj.getRequest(), v1Params), obj.getResponse());+ }+}diff --git a/solr/core/src/java/org/apache/solr/handler/admin/api/RequestCoreCommandStatusAPI.java b/solr/core/src/java/org/apache/solr/handler/admin/api/RequestCoreCommandStatusAPI.javanew file mode 100644index 00000000000..ee7cce113cd--- /dev/null+++ b/solr/core/src/java/org/apache/solr/handler/admin/api/RequestCoreCommandStatusAPI.java@@ -0,0 +1,62 @@+/*+ * 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 com.google.common.collect.Maps;+import org.apache.solr.api.EndPoint;+import org.apache.solr.common.params.CoreAdminParams;+import org.apache.solr.handler.admin.CoreAdminHandler;+import org.apache.solr.request.SolrQueryRequest;+import org.apache.solr.response.SolrQueryResponse;++import java.util.Locale;+import java.util.Map;++import static org.apache.solr.client.solrj.SolrRequest.METHOD.GET;+import static org.apache.solr.common.params.CollectionParams.ACTION;+import static org.apache.solr.handler.ClusterAPI.wrapParams;+import static org.apache.solr.security.PermissionNameProvider.Name.CORE_READ_PERM;++/**+ * V2 API for checking the status of a core-level asynchronous command.+ *+ * This API (GET /v2/cores/command-status/someId is analogous to the v1 /admin/cores?action=REQUESTSTATUS command. It is+ * not to be confused with the more robust asynchronous command support offered under the v2 `/cluster/command-status`+ * path (or the corresponding v1 path `/solr/admin/collections?action=REQUESTSTATUS`). Async support at the core level+ * differs in that command IDs are local to individual Solr nodes and are not persisted across restarts.+ *+ * @see org.apache.solr.client.solrj.request.beans.RequestSyncShardPayload+ */+public class RequestCoreCommandStatusAPI {++ private final CoreAdminHandler coreAdminHandler;++ public RequestCoreCommandStatusAPI(CoreAdminHandler coreAdminHandler) {+ this.coreAdminHandler = coreAdminHandler;+ }++ @EndPoint(method = GET,+ path = "/cores/{core}/command-status/{id}",+ permission = CORE_READ_PERM)+ public void getCommandStatus(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {+ final Map<String, Object> v1Params = Maps.newHashMap();+ v1Params.put(ACTION, CoreAdminParams.CoreAdminAction.REQUESTSTATUS.name().toLowerCase(Locale.ROOT));+ v1Params.put(CoreAdminParams.REQUESTID, req.getPathTemplateValues().get("id"));+ coreAdminHandler.handleRequestBody(wrapParams(req, v1Params), rsp);+ }+}diff --git a/solr/core/src/java/org/apache/solr/handler/admin/api/RequestCoreRecoveryAPI.java b/solr/core/src/java/org/apache/solr/handler/admin/api/RequestCoreRecoveryAPI.javanew file mode 100644index 00000000000..a476fd9a607--- /dev/null+++ b/solr/core/src/java/org/apache/solr/handler/admin/api/RequestCoreRecoveryAPI.java@@ -0,0 +1,66 @@+/*+ * 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 org.apache.solr.api.Command;+import org.apache.solr.api.EndPoint;+import org.apache.solr.api.PayloadObj;+import org.apache.solr.client.solrj.request.beans.RequestCoreRecoveryPayload;+import org.apache.solr.handler.admin.CoreAdminHandler;++import java.util.HashMap;+import java.util.Locale;+import java.util.Map;++import static org.apache.solr.client.solrj.SolrRequest.METHOD.POST;+import static org.apache.solr.common.params.CoreAdminParams.ACTION;+import static org.apache.solr.common.params.CoreAdminParams.CORE;+import static org.apache.solr.common.params.CoreAdminParams.CoreAdminAction.REQUESTRECOVERY;+import static org.apache.solr.handler.ClusterAPI.wrapParams;+import static org.apache.solr.security.PermissionNameProvider.Name.CORE_EDIT_PERM;++/**+ * Internal V2 API triggering recovery on a core.+ *+ * Only valid in SolrCloud mode. This API (POST /v2/cores/coreName {'request-recovery': {}}) is analogous to the v1+ * /admin/cores?action=REQUESTRECOVERY command.+ *+ * @see RequestCoreRecoveryPayload+ */+@EndPoint(path = {"/cores/{core}"},+ method = POST,+ permission = CORE_EDIT_PERM)+public class RequestCoreRecoveryAPI {+ public static final String V2_REQUEST_RECOVERY_CMD = "request-recovery";++ private final CoreAdminHandler coreAdminHandler;++ public RequestCoreRecoveryAPI(CoreAdminHandler coreAdminHandler) {+ this.coreAdminHandler = coreAdminHandler;+ }++ @Command(name = V2_REQUEST_RECOVERY_CMD)+ public void requestCoreRecovery(PayloadObj<RequestCoreRecoveryPayload> obj) throws Exception {+ final RequestCoreRecoveryPayload v2Body = obj.get();+ final Map<String, Object> v1Params = v2Body.toMap(new HashMap<>());+ v1Params.put(ACTION, REQUESTRECOVERY.name().toLowerCase(Locale.ROOT));+ v1Params.put(CORE, obj.getRequest().getPathTemplateValues().get("core"));++ coreAdminHandler.handleRequestBody(wrapParams(obj.getRequest(), v1Params), obj.getResponse());+ }+}diff --git a/solr/core/src/java/org/apache/solr/handler/admin/api/RequestSyncShardAPI.java b/solr/core/src/java/org/apache/solr/handler/admin/api/RequestSyncShardAPI.javanew file mode 100644index 00000000000..e37f65b2920--- /dev/null+++ b/solr/core/src/java/org/apache/solr/handler/admin/api/RequestSyncShardAPI.java@@ -0,0 +1,66 @@+/*+ * 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 org.apache.solr.api.Command;+import org.apache.solr.api.EndPoint;+import org.apache.solr.api.PayloadObj;+import org.apache.solr.client.solrj.request.beans.RequestSyncShardPayload;+import org.apache.solr.handler.admin.CoreAdminHandler;++import java.util.HashMap;+import java.util.Locale;+import java.util.Map;++import static org.apache.solr.client.solrj.SolrRequest.METHOD.POST;+import static org.apache.solr.common.params.CoreAdminParams.ACTION;+import static org.apache.solr.common.params.CoreAdminParams.CORE;+import static org.apache.solr.common.params.CoreAdminParams.CoreAdminAction.REQUESTSYNCSHARD;+import static org.apache.solr.handler.ClusterAPI.wrapParams;+import static org.apache.solr.security.PermissionNameProvider.Name.CORE_EDIT_PERM;++/**+ * Internal V2 API used to request a core sync with its shard leader.+ *+ * Only valid in SolrCloud mode. This API (POST /v2/cores/coreName {'request-sync-shard': {}}) is analogous to the v1+ * /admin/cores?action=REQUESTSYNCSHARD command.+ *+ * @see org.apache.solr.client.solrj.request.beans.RequestSyncShardPayload+ */+@EndPoint(path = {"/cores/{core}"},+ method = POST,+ permission = CORE_EDIT_PERM)+public class RequestSyncShardAPI {+ public static final String V2_REQUEST_SYNC_SHARD_CMD = "request-sync-shard";++ private final CoreAdminHandler coreAdminHandler;++ public RequestSyncShardAPI(CoreAdminHandler coreAdminHandler) {+ this.coreAdminHandler = coreAdminHandler;+ }++ @Command(name = V2_REQUEST_SYNC_SHARD_CMD)+ public void requestSyncShard(PayloadObj<RequestSyncShardPayload> obj) throws Exception {+ final RequestSyncShardPayload v2Body = obj.get();+ final Map<String, Object> v1Params = v2Body.toMap(new HashMap<>());+ v1Params.put(ACTION, REQUESTSYNCSHARD.name().toLowerCase(Locale.ROOT));+ v1Params.put(CORE, obj.getRequest().getPathTemplateValues().get("core"));++ coreAdminHandler.handleRequestBody(wrapParams(obj.getRequest(), v1Params), obj.getResponse());+ }+}diff --git a/solr/core/src/test/org/apache/solr/handler/admin/api/V2CoreAPIMappingTest.java b/solr/core/src/test/org/apache/solr/handler/admin/api/V2CoreAPIMappingTest.javaindex 7dbd3f7401e..0f83e1692cc 100644--- a/solr/core/src/test/org/apache/solr/handler/admin/api/V2CoreAPIMappingTest.java+++ b/solr/core/src/test/org/apache/solr/handler/admin/api/V2CoreAPIMappingTest.java@@ -21,6 +21,7 @@ import com.google.common.collect.Maps;import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.api.Api;import org.apache.solr.api.ApiBag;+import org.apache.solr.common.cloud.ZkStateReader;import org.apache.solr.common.params.SolrParams;import org.apache.solr.common.params.UpdateParams;import org.apache.solr.common.util.CommandOperation;@@ -80,6 +81,12 @@ public class V2CoreAPIMappingTest extends SolrTestCaseJ4 {apiBag.registerObject(new UnloadCoreAPI(mockCoreHandler));apiBag.registerObject(new MergeIndexesAPI(mockCoreHandler));apiBag.registerObject(new SplitCoreAPI(mockCoreHandler));+ apiBag.registerObject(new RequestCoreRecoveryAPI(mockCoreHandler));+ apiBag.registerObject(new PrepareCoreRecoveryAPI(mockCoreHandler));+ apiBag.registerObject(new RequestApplyCoreUpdatesAPI(mockCoreHandler));+ apiBag.registerObject(new RequestSyncShardAPI(mockCoreHandler));+ apiBag.registerObject(new RequestBufferUpdatesAPI(mockCoreHandler));+ apiBag.registerObject(new RequestCoreCommandStatusAPI(mockCoreHandler));}@Test@@ -173,6 +180,75 @@ public class V2CoreAPIMappingTest extends SolrTestCaseJ4 {assertTrue(targetCoreEntries.containsAll(List.of("core1", "core2")));}+ @Test+ public void testRequestCoreRecoveryAllParams() throws Exception {+ final SolrParams v1Params = captureConvertedV1Params("/cores/coreName", "POST",+ "{\"request-recovery\": {}}");++ assertEquals("requestrecovery", v1Params.get(ACTION));+ assertEquals("coreName", v1Params.get(CORE));+ }++ @Test+ public void testPrepareCoreRecoveryAllParams() throws Exception {+ final SolrParams v1Params = captureConvertedV1Params("/cores/coreName", "POST",+ "{\"prep-recovery\": {" ++ "\"nodeName\": \"someNodeName\", " ++ "\"coreNodeName\": \"someCoreNodeName\", " ++ "\"state\": \"someState\", " ++ "\"checkLive\": true, " ++ "\"onlyIfLeader\": true" ++ "\"onlyIfLeaderActive\": true " ++ "}}");++ assertEquals("preprecovery", v1Params.get(ACTION));+ assertEquals("coreName", v1Params.get(CORE));+ assertEquals("someNodeName", v1Params.get("nodeName"));+ assertEquals("someCoreNodeName", v1Params.get(CORE_NODE_NAME));+ assertEquals("someState", v1Params.get(ZkStateReader.STATE_PROP));+ assertEquals(true, v1Params.getPrimitiveBool("checkLive"));+ assertEquals(true, v1Params.getPrimitiveBool("onlyIfLeader"));+ assertEquals(true, v1Params.getPrimitiveBool("onlyIfLeaderActive"));+ }++ @Test+ public void testApplyCoreUpdatesAllParams() throws Exception {+ final SolrParams v1Params = captureConvertedV1Params("/cores/coreName", "POST",+ "{\"request-apply-updates\": {}}");++ assertEquals("requestapplyupdates", v1Params.get(ACTION));+ assertEquals("coreName", v1Params.get(NAME));+ }++ @Test+ public void testSyncShardAllParams() throws Exception {+ final SolrParams v1Params = captureConvertedV1Params("/cores/coreName", "POST",+ "{\"request-sync-shard\": {}}");++ assertEquals("requestsyncshard", v1Params.get(ACTION));+ assertEquals("coreName", v1Params.get(CORE));+ }++ @Test+ public void testRequestBufferUpdatesAllParams() throws Exception {+ final SolrParams v1Params = captureConvertedV1Params("/cores/coreName", "POST",+ "{\"request-buffer-updates\": {}}");++ assertEquals("requestbufferupdates", v1Params.get(ACTION));+ assertEquals("coreName", v1Params.get(NAME));+ }++ // Strictly speaking, this API isn't at the /cores/coreName path, but as the only API at its path+ // (/cores/coreName/command-status/requestId) it doesn't merit its own test class.+ @Test+ public void testRequestCommandStatusAllParams() throws Exception {+ final SolrParams v1Params = captureConvertedV1Params("/cores/coreName/command-status/someId", "GET",+ null);++ assertEquals("requeststatus", v1Params.get(ACTION));+ assertEquals("someId", v1Params.get(REQUESTID));+ }+private SolrParams captureConvertedV1Params(String path, String method, String v2RequestBody) throws Exception {final HashMap<String, String> parts = new HashMap<>();final Api api = apiBag.lookup(path, method, parts);diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreApiMapping.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreApiMapping.javadeleted file mode 100644index fbd8444d324..00000000000--- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreApiMapping.java+++ /dev/null@@ -1,95 +0,0 @@-/*- * 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.solrj.request;---import org.apache.solr.client.solrj.SolrRequest;-import org.apache.solr.client.solrj.request.ApiMapping.CommandMeta;-import org.apache.solr.common.params.CoreAdminParams.CoreAdminAction;--import java.util.Collections;-import java.util.Map;--import static org.apache.solr.client.solrj.SolrRequest.METHOD.GET;-import static org.apache.solr.client.solrj.SolrRequest.METHOD.POST;-import static org.apache.solr.client.solrj.request.CoreApiMapping.EndPoint.*;--/** stores the mapping of v1 API parameters to v2 API parameters- * for core admin API- *- */-public class CoreApiMapping {- public enum Meta implements CommandMeta {- PREPRECOVERY(PER_CORE_COMMANDS, POST, CoreAdminAction.PREPRECOVERY, "prep-recovery", null),- REQUESTRECOVERY(PER_CORE_COMMANDS, POST, CoreAdminAction.REQUESTRECOVERY, "request-recovery", null),- REQUESTSYNCSHARD(PER_CORE_COMMANDS, POST, CoreAdminAction.REQUESTSYNCSHARD, "request-sync-shard", null),- REQUESTBUFFERUPDATES(PER_CORE_COMMANDS, POST, CoreAdminAction.REQUESTBUFFERUPDATES, "request-buffer-updates", null),- REQUESTAPPLYUPDATES(PER_CORE_COMMANDS, POST, CoreAdminAction.REQUESTAPPLYUPDATES, "request-apply-updates", null),- REQUESTSTATUS(PER_CORE_COMMANDS, GET, CoreAdminAction.REQUESTSTATUS, "request-status", null)/*TODO*/;-- public final String commandName;- public final EndPoint endPoint;- public final SolrRequest.METHOD method;- public final CoreAdminAction action;- public final Map<String, String> paramstoAttr;-- Meta(EndPoint endPoint, SolrRequest.METHOD method, CoreAdminAction action, String commandName,- Map<String,String> paramstoAttr) {- this.commandName = commandName;- this.endPoint = endPoint;- this.method = method;- this.paramstoAttr = paramstoAttr == null ? Collections.emptyMap() : paramstoAttr; // expect this to be immutable- this.action = action;- }-- @Override- public String getName() {- return commandName;- }-- @Override- public SolrRequest.METHOD getHttpMethod() {- return method;- }-- @Override- public ApiMapping.V2EndPoint getEndPoint() {- return endPoint;- }-- @Override- public String getParamSubstitute(String param) {- return paramstoAttr.containsKey(param) ? paramstoAttr.get(param) : param;- }- }-- public enum EndPoint implements ApiMapping.V2EndPoint {- PER_CORE_COMMANDS("cores.core.Commands");-- final String specName;-- EndPoint(String specName) {- this.specName = specName;- }-- @Override- public String getSpecName() {- return specName;- }- }-}diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/beans/PrepareCoreRecoveryPayload.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/beans/PrepareCoreRecoveryPayload.javanew file mode 100644index 00000000000..788576f9bbc--- /dev/null+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/beans/PrepareCoreRecoveryPayload.java@@ -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.solrj.request.beans;++import org.apache.solr.common.annotation.JsonProperty;+import org.apache.solr.common.util.ReflectMapWriter;++public class PrepareCoreRecoveryPayload implements ReflectMapWriter {+ @JsonProperty+ public String nodeName;++ @JsonProperty+ public String coreNodeName;++ @JsonProperty+ public String state;++ @JsonProperty+ public Boolean checkLive;++ @JsonProperty+ public Boolean onlyIfLeader;++ @JsonProperty+ public Boolean onlyIfLeaderActive;+}diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/beans/RequestApplyCoreUpdatesPayload.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/beans/RequestApplyCoreUpdatesPayload.javanew file mode 100644index 00000000000..184b912da03--- /dev/null+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/beans/RequestApplyCoreUpdatesPayload.java@@ -0,0 +1,22 @@+/*+ * 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.solrj.request.beans;++import org.apache.solr.common.util.ReflectMapWriter;++public class RequestApplyCoreUpdatesPayload implements ReflectMapWriter {}diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/beans/RequestBufferUpdatesPayload.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/beans/RequestBufferUpdatesPayload.javanew file mode 100644index 00000000000..f2a08d29d0d--- /dev/null+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/beans/RequestBufferUpdatesPayload.java@@ -0,0 +1,22 @@+/*+ * 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.solrj.request.beans;++import org.apache.solr.common.util.ReflectMapWriter;++public class RequestBufferUpdatesPayload implements ReflectMapWriter {}diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/beans/RequestCoreRecoveryPayload.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/beans/RequestCoreRecoveryPayload.javanew file mode 100644index 00000000000..241d2719395--- /dev/null+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/beans/RequestCoreRecoveryPayload.java@@ -0,0 +1,22 @@+/*+ * 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.solrj.request.beans;++import org.apache.solr.common.util.ReflectMapWriter;++public class RequestCoreRecoveryPayload implements ReflectMapWriter { }diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/beans/RequestSyncShardPayload.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/beans/RequestSyncShardPayload.javanew file mode 100644index 00000000000..b1fb8b9c785--- /dev/null+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/beans/RequestSyncShardPayload.java@@ -0,0 +1,22 @@+/*+ * 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.solrj.request.beans;++import org.apache.solr.common.util.ReflectMapWriter;++public class RequestSyncShardPayload implements ReflectMapWriter { }diff --git a/solr/solrj/src/resources/apispec/cores.core.Commands.json b/solr/solrj/src/resources/apispec/cores.core.Commands.jsondeleted file mode 100644index 0afe98142f0..00000000000--- a/solr/solrj/src/resources/apispec/cores.core.Commands.json+++ /dev/null@@ -1,43 +0,0 @@-{- "documentation": "https://solr.apache.org/guide/coreadmin-api.html",- "description": "Actions that are peformed on individual cores, such as reloading, swapping cores, renaming, and others.",- "methods": [- "POST"- ],- "url": {- "paths": [- "/cores/{core}"- ]- },- "commands": {- "request-recovery": {- "type":"object",- "documentation": "https://solr.apache.org/guide/coreadmin-api.html#coreadmin-requestrecovery",- "description": "Manually asks a core to recover by synching with a leader. It may help SolrCloud clusters where a node refuses to come back up. However, it is considered an expert-level command, and should be used very carefully."- },- "force-prepare-for-leadership": {- "type": "object",- "description": "An internal API used by the Collections API to force leader election. This should not be used directly by end-users."- },- "prep-recovery": {- "type": "object",- "additionalProperties": true,- "description": "An internal API used by the Collections API. This should not be used directly by end-users."- },- "request-apply-updates": {- "type": "object",- "additionalProperties": true,- "description": "An internal API used by the Collections API. This should not be used directly by end-users."- },- "request-sync-shard": {- "type": "object",- "additionalProperties": true,- "description": "An internal API used by the Collections API. This should not be used directly by end-users."- },- "request-buffer-updates": {- "type": "object",- "additionalProperties": true,- "description": "An internal API used by the Collections API. This should not be used directly by end-users."- }- }-}diff --git a/solr/solrj/src/test/org/apache/solr/common/util/JsonValidatorTest.java b/solr/solrj/src/test/org/apache/solr/common/util/JsonValidatorTest.javaindex e4c280e58d2..86d01f9d00a 100644--- a/solr/solrj/src/test/org/apache/solr/common/util/JsonValidatorTest.java+++ b/solr/solrj/src/test/org/apache/solr/common/util/JsonValidatorTest.java@@ -25,7 +25,6 @@ import java.util.Map;public class JsonValidatorTest extends SolrTestCaseJ4 {public void testSchema() {- checkSchema("cores.core.Commands");checkSchema("cluster.security.BasicAuth.Commands");checkSchema("cluster.security.RuleBasedAuthorization");checkSchema("core.config.Commands");