madrob commented on code in PR #955:
URL: https://github.com/apache/solr/pull/955#discussion_r934745731


##########
solr/core/src/test/org/apache/solr/handler/admin/TestConfigsApi.java:
##########
@@ -17,19 +17,11 @@
 
 package org.apache.solr.handler.admin;
 
-import static org.apache.solr.client.solrj.SolrRequest.METHOD.DELETE;
-import static org.apache.solr.cloud.Overseer.QUEUE_OPERATION;
-import static org.apache.solr.handler.admin.TestCollectionAPIs.compareOutput;
-
-import java.util.Map;
 import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.api.ApiBag;
-import org.apache.solr.common.cloud.ZkNodeProps;
-import org.apache.solr.handler.ClusterAPI;
-import org.apache.solr.response.SolrQueryResponse;
 
 public class TestConfigsApi extends SolrTestCaseJ4 {
 
+    /*

Review Comment:
   Are there any tests left in this class?



##########
solr/core/src/java/org/apache/solr/core/CoreContainer.java:
##########
@@ -801,7 +815,11 @@ public void load() {
     ClusterAPI clusterAPI = new ClusterAPI(collectionsHandler, 
configSetsHandler);
     containerHandlers.getApiBag().registerObject(clusterAPI);
     containerHandlers.getApiBag().registerObject(clusterAPI.commands);
-    containerHandlers.getApiBag().registerObject(clusterAPI.configSetCommands);
+    containerHandlers.getApiBag().registerObject(new CreateConfigSetAPI(this));
+    containerHandlers.getApiBag().registerObject(new DeleteConfigSetAPI(this));
+    containerHandlers.getApiBag().registerObject(new ListConfigSetsAPI(this));
+    containerHandlers.getApiBag().registerObject(new UploadConfigSetAPI(this));
+    containerHandlers.getApiBag().registerObject(new 
UploadConfigSetFileAPI(this));

Review Comment:
   This is fine for now, but I think we're going to want a better approach for 
it, as we convert more APIs I suspect the list will get long and unwieldy and 
easy to miss something or make mistakes. Maybe an annotation based discovery 
framework, hopefully that won't make startup time too long.



##########
solr/core/src/java/org/apache/solr/request/DelegatingSolrQueryRequest.java:
##########
@@ -0,0 +1,173 @@
+/*
+ * 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.request;
+
+import io.opentracing.Span;
+import io.opentracing.Tracer;
+import org.apache.solr.cloud.CloudDescriptor;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.CommandOperation;
+import org.apache.solr.common.util.ContentStream;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.schema.IndexSchema;
+import org.apache.solr.search.SolrIndexSearcher;
+import org.apache.solr.servlet.HttpSolrCall;
+import org.apache.solr.util.RTimerTree;
+
+import java.security.Principal;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A {@link SolrQueryRequest} implementation that defers to a delegate in all 
cases.
+ *
+ * Used primarily in cases where developers want to customize one or more 
SolrQueryRequest methods while deferring the
+ * remainder to an existing instances.
+ */
+public class DelegatingSolrQueryRequest implements SolrQueryRequest {

Review Comment:
   This feels like something that should be in SolrJ



##########
solr/core/src/java/org/apache/solr/handler/configsets/CreateConfigSetAPI.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.configsets;
+
+import com.google.common.collect.Maps;
+import org.apache.commons.collections4.MapUtils;
+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.CreateConfigPayload;
+import org.apache.solr.cloud.ConfigSetCmds;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.params.ConfigSetParams;
+import org.apache.solr.core.CoreContainer;
+
+import java.util.Map;
+
+import static org.apache.solr.client.solrj.SolrRequest.METHOD.POST;
+import static org.apache.solr.common.params.CommonParams.NAME;
+import static 
org.apache.solr.handler.admin.ConfigSetsHandler.DEFAULT_CONFIGSET_NAME;
+import static 
org.apache.solr.handler.admin.ConfigSetsHandler.DISABLE_CREATE_AUTH_CHECKS;
+import static 
org.apache.solr.security.PermissionNameProvider.Name.CONFIG_EDIT_PERM;
+
+/**
+ * V2 API for creating a new configset as a copy of an existing one.
+ *
+ * <p>This API (POST /v2/cluster/configs {"create": {...}}) is analogous to
+ * the v1 /admin/configs?action=CREATE command.
+ *
+ */
+@EndPoint(method = POST, path = "/cluster/configs", permission = 
CONFIG_EDIT_PERM)
+public class CreateConfigSetAPI extends ConfigSetAPIBase {
+
+    public CreateConfigSetAPI(CoreContainer coreContainer) {
+        super(coreContainer);
+    }
+
+    @Command(name = "create")
+    @SuppressWarnings("unchecked")

Review Comment:
   Do we have to have this?



##########
solr/core/src/java/org/apache/solr/handler/configsets/CreateConfigSetAPI.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.configsets;
+
+import com.google.common.collect.Maps;
+import org.apache.commons.collections4.MapUtils;
+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.CreateConfigPayload;
+import org.apache.solr.cloud.ConfigSetCmds;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.params.ConfigSetParams;
+import org.apache.solr.core.CoreContainer;
+
+import java.util.Map;
+
+import static org.apache.solr.client.solrj.SolrRequest.METHOD.POST;
+import static org.apache.solr.common.params.CommonParams.NAME;
+import static 
org.apache.solr.handler.admin.ConfigSetsHandler.DEFAULT_CONFIGSET_NAME;
+import static 
org.apache.solr.handler.admin.ConfigSetsHandler.DISABLE_CREATE_AUTH_CHECKS;
+import static 
org.apache.solr.security.PermissionNameProvider.Name.CONFIG_EDIT_PERM;
+
+/**
+ * V2 API for creating a new configset as a copy of an existing one.
+ *
+ * <p>This API (POST /v2/cluster/configs {"create": {...}}) is analogous to
+ * the v1 /admin/configs?action=CREATE command.
+ *
+ */
+@EndPoint(method = POST, path = "/cluster/configs", permission = 
CONFIG_EDIT_PERM)
+public class CreateConfigSetAPI extends ConfigSetAPIBase {
+
+    public CreateConfigSetAPI(CoreContainer coreContainer) {
+        super(coreContainer);
+    }
+
+    @Command(name = "create")
+    @SuppressWarnings("unchecked")
+    public void create(PayloadObj<CreateConfigPayload> obj) throws Exception {
+        final CreateConfigPayload createConfigPayload = obj.get();
+        final String baseConfigSetName = (createConfigPayload.baseConfigSet != 
null) ? createConfigPayload.baseConfigSet : DEFAULT_CONFIGSET_NAME;
+        if (configSetService.checkConfigExists(createConfigPayload.name)) {
+            throw new SolrException(
+                    SolrException.ErrorCode.BAD_REQUEST, "ConfigSet already 
exists: " + createConfigPayload.name);
+        }
+
+        // is there a base config that already exists
+        if (! configSetService.checkConfigExists(baseConfigSetName)) {
+            throw new SolrException(
+                    SolrException.ErrorCode.BAD_REQUEST, "Base ConfigSet does 
not exist: " + baseConfigSetName);
+        }
+
+        if (!DISABLE_CREATE_AUTH_CHECKS
+                && !isTrusted(obj.getRequest().getUserPrincipal(), 
coreContainer.getAuthenticationPlugin())
+                && isCurrentlyTrusted(baseConfigSetName)) {
+            throw new SolrException(
+                    SolrException.ErrorCode.UNAUTHORIZED,
+                    "Can't create a configset with an unauthenticated request 
from a trusted "
+                            + ConfigSetCmds.BASE_CONFIGSET);
+        }
+
+        final Map<String, Object> configsetCommandMsg = Maps.newHashMap();

Review Comment:
   `new HashMap<>()` is simpler.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to