You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by ji...@apache.org on 2021/11/04 01:21:30 UTC
[incubator-doris] branch master updated: [HTTP][API] Add Backend By
Rest API (#6999)
This is an automated email from the ASF dual-hosted git repository.
jiafengzheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
The following commit(s) were added to refs/heads/master by this push:
new f509e93 [HTTP][API] Add Backend By Rest API (#6999)
f509e93 is described below
commit f509e936573f8d6fdaf4de036bc3c6abef26a182
Author: wudi <67...@qq.com>
AuthorDate: Thu Nov 4 09:21:07 2021 +0800
[HTTP][API] Add Backend By Rest API (#6999)
* [HTTP][API] add backend rest api
* [HTTP][API] add backends rest api
* change api response
Co-authored-by: wudi <wu...@shuhaisc.com>
---
.../doris/httpv2/rest/manager/ClusterAction.java | 41 ++++++++++++++++++----
1 file changed, 35 insertions(+), 6 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/ClusterAction.java b/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/ClusterAction.java
index 9b4af46..ac46aae 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/ClusterAction.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/ClusterAction.java
@@ -17,27 +17,30 @@
package org.apache.doris.httpv2.rest.manager;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
import org.apache.doris.catalog.Catalog;
import org.apache.doris.common.Config;
+import org.apache.doris.common.Pair;
+import org.apache.doris.common.UserException;
import org.apache.doris.httpv2.entity.ResponseEntityBuilder;
import org.apache.doris.httpv2.rest.RestBaseController;
import org.apache.doris.mysql.privilege.PrivPredicate;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.system.Frontend;
-
-import com.google.common.collect.Maps;
-
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
/*
* Used to return the cluster information for the manager.
*/
@@ -45,6 +48,8 @@ import javax.servlet.http.HttpServletResponse;
@RequestMapping("/rest/v2/manager/cluster")
public class ClusterAction extends RestBaseController {
+ private static final Logger LOG = LogManager.getLogger(ClusterAction.class);
+
// Returns mysql and http connection information for the cluster.
// {
// "mysql":[
@@ -69,4 +74,28 @@ public class ClusterAction extends RestBaseController {
result.put("http", frontends.stream().map(ip -> ip + ":" + Config.http_port).collect(Collectors.toList()));
return ResponseEntityBuilder.ok(result);
}
+
+ /**
+ * add backend like execute alter system add backend "host:port"
+ */
+ @RequestMapping(path = "/add_backends", method = RequestMethod.POST)
+ public Object addBackends(HttpServletRequest request, HttpServletResponse response,
+ @RequestBody Map<String, Integer> hostPorts) {
+ executeCheckPassword(request, response);
+ checkGlobalAuth(ConnectContext.get().getCurrentUserIdentity(), PrivPredicate.ADMIN);
+
+ Map<String, Boolean> result = Maps.newHashMap();
+ for (Map.Entry<String, Integer> backend : hostPorts.entrySet()) {
+ List<Pair<String, Integer>> newBackend = Lists.newArrayList();
+ newBackend.add(Pair.create(backend.getKey(), backend.getValue()));
+ try {
+ Catalog.getCurrentSystemInfo().addBackends(newBackend, false);
+ result.put(backend.getKey(), true);
+ } catch (UserException e) {
+ LOG.error("Failed to add backend node: {}:{}", backend.getKey(), backend.getValue(), e);
+ result.put(backend.getKey(), false);
+ }
+ }
+ return ResponseEntityBuilder.ok(result);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org