pinot-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-pinot] fx19880617 commented on a change in pull request #5073: Adding PinotClusterConfig APIs in controller and corresponding Pinot Admin SubCommands
Date Thu, 27 Feb 2020 00:44:25 GMT
fx19880617 commented on a change in pull request #5073: Adding PinotClusterConfig APIs in controller
and corresponding Pinot Admin SubCommands
URL: https://github.com/apache/incubator-pinot/pull/5073#discussion_r384853298
 
 

 ##########
 File path: pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotClusterConfigs.java
 ##########
 @@ -0,0 +1,123 @@
+/**
+ * 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.pinot.controller.api.resources;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import javax.inject.Inject;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.apache.helix.HelixAdmin;
+import org.apache.helix.model.HelixConfigScope;
+import org.apache.helix.model.builder.HelixConfigScopeBuilder;
+import org.apache.pinot.controller.helix.core.PinotHelixResourceManager;
+import org.apache.pinot.spi.utils.JsonUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+@Api(tags = Constants.CLUSTER_TAG)
+@Path("/")
+public class PinotClusterConfigs {
+  private static final Logger LOGGER = LoggerFactory.getLogger(PinotClusterConfigs.class);
+
+  @Inject
+  PinotHelixResourceManager pinotHelixResourceManager;
+
+  @GET
+  @Path("/cluster/configs")
+  @Produces(MediaType.APPLICATION_JSON)
+  @ApiOperation(value = "List cluster configurations", notes = "List cluster level configurations")
+  @ApiResponses(value = {@ApiResponse(code = 200, message = "Success"), @ApiResponse(code
= 500, message = "Internal server error")})
+  public String listClusterConfigs() {
+    HelixAdmin helixAdmin = pinotHelixResourceManager.getHelixAdmin();
+    HelixConfigScope configScope = new HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.CLUSTER)
+        .forCluster(pinotHelixResourceManager.getHelixClusterName()).build();
+    List<String> configKeys = helixAdmin.getConfigKeys(configScope);
+    ObjectNode ret = JsonUtils.newObjectNode();
+    Map<String, String> configs = helixAdmin.getConfig(configScope, configKeys);
+    for (String key : configs.keySet()) {
+      ret.put(key, configs.get(key));
+    }
+    return ret.toString();
+  }
+
+  @POST
+  @Path("/cluster/configs")
+  @ApiOperation(value = "Update cluster configuration")
+  @Produces(MediaType.APPLICATION_JSON)
+  @ApiResponses(value = {@ApiResponse(code = 200, message = "Success"), @ApiResponse(code
= 500, message = "Server error updating configuration")})
+  public SuccessResponse updateClusterConfig(String body) {
+    try {
+      JsonNode jsonNode = JsonUtils.stringToJsonNode(body);
+      HelixAdmin admin = pinotHelixResourceManager.getHelixAdmin();
+      HelixConfigScope configScope = new HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.CLUSTER)
+          .forCluster(pinotHelixResourceManager.getHelixClusterName()).build();
+      Iterator<String> fieldNamesIterator = jsonNode.fieldNames();
+      while (fieldNamesIterator.hasNext()) {
+        String key = fieldNamesIterator.next();
+        String value = jsonNode.get(key).textValue();
+        admin.setConfig(configScope, Collections.singletonMap(key, value));
+      }
+      return new SuccessResponse("Updated cluster config.");
+    } catch (IOException e) {
+      String errStr = "Error converting request to cluster config.";
 
 Review comment:
   Copy pasted template from other file, updated it.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


Mime
View raw message