sigram commented on a change in pull request #1100: SOLR-13579: Create resource 
management API
URL: https://github.com/apache/lucene-solr/pull/1100#discussion_r363811813
 
 

 ##########
 File path: 
solr/core/src/java/org/apache/solr/handler/admin/ResourceManagerHandler.java
 ##########
 @@ -0,0 +1,334 @@
+/*
+ * 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.lang.invoke.MethodHandles;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.params.CommonParams;
+import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.common.util.SimpleOrderedMap;
+import org.apache.solr.handler.RequestHandlerBase;
+import org.apache.solr.managed.ChangeListener;
+import org.apache.solr.managed.ManagedComponent;
+import org.apache.solr.managed.ResourceManager;
+import org.apache.solr.managed.ResourceManagerPool;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.response.SolrQueryResponse;
+import org.apache.solr.security.AuthorizationContext;
+import org.apache.solr.security.PermissionNameProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Request handler to access and modify pools and their resource limits.
+ */
+public class ResourceManagerHandler extends RequestHandlerBase implements 
PermissionNameProvider {
+  private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  public static final String POOL_PARAM = "pool";
+  public static final String LIMIT_PREFIX_PARAM = "limit.";
+  public static final String ARG_PREFIX_PARAM = "arg.";
+  public static final String POOL_ACTION_PARAM = "poolAction";
+  public static final String RES_ACTION_PARAM = "resAction";
+
+  public enum PoolOp {
+    LIST,
+    STATUS,
+    CREATE,
+    DELETE,
+    SETLIMITS;
+
+    public static PoolOp get(String p) {
+      if (p != null) {
+        try {
+          return PoolOp.valueOf(p.toUpperCase(Locale.ROOT));
+        } catch (Exception e) {
+          return null;
+        }
+      }
+      return null;
+    }
+  }
+
+  public enum ResOp {
+    LIST,
+    STATUS,
+    DELETE,
+    GETLIMITS,
+    SETLIMITS;
+
+    public static ResOp get(String p) {
+      if (p != null) {
+        try {
+          return ResOp.valueOf(p.toUpperCase(Locale.ROOT));
+        } catch (Exception e) {
+          return null;
+        }
+      }
+      return null;
+    }
+  }
+
+  private final ResourceManager resourceManager;
+
+  public ResourceManagerHandler(ResourceManager resourceManager) {
+    this.resourceManager = resourceManager;
+  }
+
+  @Override
+  public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) 
throws Exception {
+    if (resourceManager == null) {
+      throw new SolrException(SolrException.ErrorCode.INVALID_STATE, 
"ResourceManager instance not initialized.");
+    }
+    String poolAction = req.getParams().get(POOL_ACTION_PARAM);
+    String resAction = req.getParams().get(RES_ACTION_PARAM);
+    if (poolAction != null) {
+      handlePoolRequest(req, rsp);
+    } else if (resAction != null) {
+      handleResourceRequest(req, rsp);
+    } else {
+      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Missing " 
+ POOL_ACTION_PARAM + " and " + RES_ACTION_PARAM + ": " + req.getParams());
+    }
 
 Review comment:
   Good point, I think we should throw an exception.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to