You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by "stillalex (via GitHub)" <gi...@apache.org> on 2023/03/14 17:11:05 UTC

[GitHub] [solr] stillalex commented on a diff in pull request #1459: SOLR-16393 Alias properties management

stillalex commented on code in PR #1459:
URL: https://github.com/apache/solr/pull/1459#discussion_r1135927504


##########
solr/core/src/java/org/apache/solr/handler/admin/api/AliasPropertyAPI.java:
##########
@@ -0,0 +1,262 @@
+/*
+ * 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.client.solrj.impl.BinaryResponseParser.BINARY_CONTENT_TYPE_V2;
+import static org.apache.solr.cloud.Overseer.QUEUE_OPERATION;
+import static org.apache.solr.common.params.CommonAdminParams.ASYNC;
+import static org.apache.solr.common.params.CommonParams.NAME;
+import static org.apache.solr.handler.admin.CollectionsHandler.DEFAULT_COLLECTION_OP_TIMEOUT;
+import static org.apache.solr.security.PermissionNameProvider.Name.COLL_EDIT_PERM;
+import static org.apache.solr.security.PermissionNameProvider.Name.COLL_READ_PERM;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.parameters.RequestBody;
+import java.util.HashMap;
+import java.util.Map;
+import javax.inject.Inject;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import org.apache.solr.client.solrj.SolrResponse;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.cloud.Aliases;
+import org.apache.solr.common.cloud.ZkNodeProps;
+import org.apache.solr.common.cloud.ZkStateReader;
+import org.apache.solr.common.params.CollectionParams;
+import org.apache.solr.core.CoreContainer;
+import org.apache.solr.handler.admin.CollectionsHandler;
+import org.apache.solr.jersey.JacksonReflectMapWriter;
+import org.apache.solr.jersey.PermissionName;
+import org.apache.solr.jersey.SolrJerseyResponse;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.response.SolrQueryResponse;
+
+/** V2 APIs for managing and inspecting properties for collection aliases */
+@Path("/aliases/{aliasName}/properties")
+public class AliasPropertyAPI extends AdminAPIBase {
+
+  @Inject
+  public AliasPropertyAPI(
+      CoreContainer coreContainer,
+      SolrQueryRequest solrQueryRequest,
+      SolrQueryResponse solrQueryResponse) {
+    super(coreContainer, solrQueryRequest, solrQueryResponse);
+  }
+
+  @GET
+  @PermissionName(COLL_READ_PERM)
+  @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, BINARY_CONTENT_TYPE_V2})
+  @Operation(
+      summary = "Get properties for a collection alias.",
+      tags = {"aliases"})
+  public GetAllAliasPropertiesResponse getAllAliasProperties(
+      @Parameter(description = "Alias Name") @PathParam("aliasName") String aliasName)
+      throws Exception {
+    recordCollectionForLogAndTracing(null, solrQueryRequest);
+
+    final GetAllAliasPropertiesResponse response =
+        instantiateJerseyResponse(GetAllAliasPropertiesResponse.class);
+    final Aliases aliases = readAliasesFromZk();
+    if (aliases != null) {
+      response.properties = aliases.getCollectionAliasProperties(aliasName);
+    }
+
+    return response;
+  }
+
+  @GET
+  @Path("/{propName}")
+  @PermissionName(COLL_READ_PERM)
+  @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, BINARY_CONTENT_TYPE_V2})
+  @Operation(
+      summary = "Get a specific property for a collection alias.",
+      tags = {"aliases"})
+  public GetAliasPropertyResponse getAliasProperty(
+      @Parameter(description = "Alias Name") @PathParam("aliasName") String aliasName,
+      @Parameter(description = "Property Name") @PathParam("propName") String propName)
+      throws Exception {
+    recordCollectionForLogAndTracing(null, solrQueryRequest);
+
+    final GetAliasPropertyResponse response =
+        instantiateJerseyResponse(GetAliasPropertyResponse.class);
+    final Aliases aliases = readAliasesFromZk();
+    if (aliases != null) {
+      response.property = propName;
+      response.value = aliases.getCollectionAliasProperties(aliasName).get(propName);
+    }
+
+    return response;
+  }
+
+  private Aliases readAliasesFromZk() throws Exception {
+    final CoreContainer coreContainer = fetchAndValidateZooKeeperAwareCoreContainer();
+    final ZkStateReader zkStateReader = coreContainer.getZkController().getZkStateReader();
+    // Make sure we have the latest alias info, since a user has explicitly invoked an alias API
+    zkStateReader.getAliasesManager().update();
+    return zkStateReader.getAliases();
+  }
+
+  @PUT
+  @PermissionName(COLL_EDIT_PERM)
+  @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, BINARY_CONTENT_TYPE_V2})
+  @Operation(
+      summary = "Update properties for a collection alias.",
+      tags = {"aliases"})
+  public SolrJerseyResponse updateAliasProperties(
+      @Parameter(description = "Alias Name") @PathParam("aliasName") String aliasName,
+      @RequestBody(description = "Properties that need to be updated", required = true)
+          UpdateAliasPropertiesRequestBody requestBody)
+      throws Exception {
+
+    if (requestBody == null) {

Review Comment:
   @gerlowskija leaving a comment for you here. I am fuzzy on how enforcing the not-null param works here. I realized the annotations with 'required=true' are just for docs, the actual null check is not performed by the framework. checked some of the other apis and I could not find details. please let me know your thoughts.



-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org