You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by mi...@apache.org on 2018/09/26 06:46:37 UTC
[incubator-dubbo-ops] branch develop updated: access & load balance
This is an automated email from the ASF dual-hosted git repository.
min pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo-ops.git
The following commit(s) were added to refs/heads/develop by this push:
new 7d62197 access & load balance
7d62197 is described below
commit 7d62197aa767675e9aa1c5f274b44f2f9e8b872a
Author: nzomkxia <z8...@gmail.com>
AuthorDate: Wed Sep 26 14:46:24 2018 +0800
access & load balance
---
.../dubbo/admin/controller/AccessesController.java | 3 +-
.../admin/controller/LoadBalanceController.java | 27 +-
.../dubbo/admin/controller/RoutesController.java | 74 +--
.../dubbo/admin/controller/ServiceController.java | 15 +-
.../dubbo/admin/controller/WeightController.java | 97 ++++
.../org/apache/dubbo/admin/dto/BalancingDTO.java | 35 ++
.../java/org/apache/dubbo/admin/dto/RouteDTO.java | 111 ++++
.../java/org/apache/dubbo/admin/dto/WeightDTO.java | 60 +++
.../dubbo/admin/registry/common/domain/Route.java | 31 +-
.../admin/registry/common/util/OverrideUtils.java | 6 +-
.../web/mvc/governance/WeightsController.java | 576 ++++++++++-----------
.../src/components/AccessControl.vue | 6 +-
.../src/components/DynamicConfig.vue | 12 +
.../src/components/LoadBalance.vue | 32 +-
.../src/components/RoutingRule.vue | 31 +-
.../src/components/ServiceSearch.vue | 5 +-
dubbo-admin-frontend/src/components/VWidget.vue | 17 +
.../{LoadBalance.vue => WeightAdjust.vue} | 126 +++--
dubbo-admin-frontend/src/router/index.js | 6 +
19 files changed, 837 insertions(+), 433 deletions(-)
diff --git a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/AccessesController.java b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/AccessesController.java
index 184944e..027b583 100644
--- a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/AccessesController.java
+++ b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/AccessesController.java
@@ -50,7 +50,7 @@ public class AccessesController {
routes.add(route);
}
} else {
- routes = routeService.findAllForceRoute();
+ //TODO throw exception
}
for (Route route : routes) {
@@ -97,6 +97,7 @@ public class AccessesController {
route.setService(accessDTO.getService());
route.setForce(true);
route.setName(accessDTO.getService() + " " + AccessDTO.KEY_BLACK_WHITE_LIST);
+ route.setFilterRule("false");
route.setEnabled(true);
Map<String, RouteRule.MatchPair> when = new HashMap<>();
diff --git a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/LoadBalanceController.java b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/LoadBalanceController.java
index 2993c85..71b76c9 100644
--- a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/LoadBalanceController.java
+++ b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/LoadBalanceController.java
@@ -17,15 +17,14 @@
package org.apache.dubbo.admin.controller;
+import org.apache.dubbo.admin.dto.BalancingDTO;
import org.apache.dubbo.admin.governance.service.OverrideService;
import org.apache.dubbo.admin.registry.common.domain.LoadBalance;
import org.apache.dubbo.admin.registry.common.domain.Override;
import org.apache.dubbo.admin.registry.common.util.OverrideUtils;
import org.apache.dubbo.admin.util.YamlUtil;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
@@ -38,8 +37,10 @@ public class LoadBalanceController {
@Autowired
private OverrideService overrideService;
- @RequestMapping("/create")
- public boolean createLoadbalance(@RequestParam String serviceName, @RequestParam String rule) {
+ @RequestMapping(value = "/create", method = RequestMethod.POST)
+ public boolean createLoadbalance(@RequestBody BalancingDTO balancingDTO) {
+ String serviceName = balancingDTO.getServiceName();
+ String rule = balancingDTO.getRule();
if (serviceName == null || serviceName.length() == 0) {
//TODO throw exception
}
@@ -51,8 +52,10 @@ public class LoadBalanceController {
return true;
}
- @RequestMapping("/update")
- public boolean updateLoadbalance(@RequestParam Long id, @RequestParam String rule) {
+ @RequestMapping(value = "/update", method = RequestMethod.POST)
+ public boolean updateLoadbalance(@RequestBody BalancingDTO balancingDTO) {
+ Long id = balancingDTO.getId();
+ String rule = balancingDTO.getRule();
Override override = overrideService.findById(id);
if (override == null) {
//TODO throw exception
@@ -66,8 +69,9 @@ public class LoadBalanceController {
return true;
}
- @RequestMapping("/all")
- public List<LoadBalance> allLoadbalances(@RequestParam String serviceName) {
+ @RequestMapping(value = "/search", method = RequestMethod.POST)
+ public List<LoadBalance> allLoadbalances(@RequestBody Map<String, String> params) {
+ String serviceName = params.get(params);
if (serviceName == null || serviceName.length() == 0) {
//TODO throw Exception
}
@@ -93,8 +97,9 @@ public class LoadBalanceController {
return OverrideUtils.overrideToLoadBalance(override);
}
- @RequestMapping("/delete")
- public boolean delete(@RequestParam Long id) {
+ @RequestMapping(value = "/delete", method = RequestMethod.POST)
+ public boolean delete(@RequestBody Map<String, Long> params) {
+ Long id = params.get("id");
overrideService.deleteOverride(id);
return true;
}
diff --git a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/RoutesController.java b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/RoutesController.java
index e2a0f6e..445fb99 100644
--- a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/RoutesController.java
+++ b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/RoutesController.java
@@ -17,12 +17,14 @@
package org.apache.dubbo.admin.controller;
+import org.apache.dubbo.admin.dto.RouteDTO;
import org.apache.dubbo.admin.governance.service.ProviderService;
import org.apache.dubbo.admin.governance.service.RouteService;
import org.apache.dubbo.admin.registry.common.domain.Route;
import org.apache.dubbo.admin.util.YamlUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
+import org.yaml.snakeyaml.events.Event;
import java.util.List;
import java.util.Map;
@@ -36,17 +38,14 @@ public class RoutesController {
@Autowired
private ProviderService providerService;
- @RequestMapping("/create")
- public boolean createRule(@RequestParam(required = false) String serviceName,
- @RequestParam(required = false) String app,
- @RequestParam String rule) {
+ @RequestMapping(value = "/create", method = RequestMethod.POST)
+ public boolean createRule(@RequestBody RouteDTO routeDTO) {
+ String serviceName = routeDTO.getServiceName();
+ String app = routeDTO.getApp();
if (serviceName == null && app == null) {
}
- Map<String, Object> result = YamlUtil.loadString(rule);
if (serviceName != null) {
- result.put("scope", serviceName);
- result.put("group/service:version", result.get("group") + "/" + serviceName);
//2.6
String version = null;
String service = serviceName;
@@ -55,56 +54,54 @@ public class RoutesController {
service = serviceName.split(":")[0];
}
- List<String> conditions = (List)result.get("conditions");
+ String[] conditions = routeDTO.getConditions();
for (String condition : conditions) {
Route route = new Route();
route.setService(service);
route.setVersion(version);
- route.setEnabled((boolean)getParameter(result, "enabled", true));
- route.setForce((boolean)getParameter(result, "force", false));
- route.setGroup((String)getParameter(result, "group", null));
- route.setDynamic((boolean)getParameter(result, "dynamic", false));
- route.setRuntime((boolean)getParameter(result, "runtime", false));
- route.setPriority((int)getParameter(result, "priority", 0));
+ route.setEnabled(routeDTO.isEnabled());
+ route.setForce(routeDTO.isForce());
+ route.setGroup(routeDTO.getGroup());
+ route.setDynamic(routeDTO.isDynamic());
+ route.setRuntime(routeDTO.isRuntime());
+ route.setPriority(routeDTO.getPriority());
route.setRule(condition);
routeService.createRoute(route);
}
} else {
//new feature in 2.7
- result.put("scope", "application");
- result.put("appname", app);
}
return true;
}
- @RequestMapping("/update")
- public void updateRule(@RequestParam Long id, @RequestParam String rule) {
+ @RequestMapping(value = "/update", method = RequestMethod.POST)
+ public void updateRule(@RequestBody RouteDTO routeDTO) {
+ Long id = routeDTO.getId();
Route route = routeService.findRoute(id);
if (route == null) {
//TODO Exception
}
- rule = rule.replace("===", "\n");
- Map<String, Object> result = YamlUtil.loadString(rule);
- List<String> conditions = (List)result.get("conditions");
+ String[] conditions = routeDTO.getConditions();
for (String condition : conditions) {
Route newRoute = new Route();
newRoute.setService(route.getService());
newRoute.setVersion(route.getVersion());
- newRoute.setEnabled((boolean)getParameter(result, "enabled", true));
- newRoute.setForce((boolean)getParameter(result, "force", false));
- newRoute.setGroup((String)getParameter(result, "group", null));
- newRoute.setDynamic((boolean)getParameter(result, "dynamic", false));
- newRoute.setRuntime((boolean)getParameter(result, "runtime", false));
- newRoute.setPriority((int)getParameter(result, "priority", 0));
+ newRoute.setEnabled(routeDTO.isEnabled());
+ newRoute.setForce(routeDTO.isForce());
+ newRoute.setGroup(routeDTO.getGroup());
+ newRoute.setDynamic(routeDTO.isDynamic());
+ newRoute.setRuntime(routeDTO.isRuntime());
+ newRoute.setPriority(routeDTO.getPriority());
newRoute.setRule(condition);
routeService.updateRoute(newRoute);
}
}
- @RequestMapping("/all")
- public List<Route> allRoutes(@RequestParam(required = false) String serviceName,
- @RequestParam(required = false) String app) {
+ @RequestMapping(value = "/search", method = RequestMethod.POST)
+ public List<Route> allRoutes(@RequestBody Map<String, String> params) {
+ String app = params.get("app");
+ String serviceName = params.get("serviceName");
List<Route> routes = null;
if (app != null) {
// app scope in 2.7
@@ -128,14 +125,16 @@ public class RoutesController {
return route;
}
- @RequestMapping("/delete")
- public boolean deleteRoute(@RequestParam long id) {
+ @RequestMapping(value = "/delete", method = RequestMethod.POST)
+ public boolean deleteRoute(@RequestBody Map<String, Long> params) {
+ Long id = params.get("id");
routeService.deleteRoute(id);
return true;
}
- @RequestMapping("/edit")
- public Route editRule(@RequestParam long id) {
+ @RequestMapping(value = "/edit", method = RequestMethod.POST)
+ public Route editRule(@RequestBody Map<String, Long> params) {
+ Long id = params.get("id");
Route route = routeService.findRoute(id);
if (route == null) {
// TODO throw exception
@@ -143,8 +142,11 @@ public class RoutesController {
return route;
}
- @RequestMapping("/changeStatus")
- public boolean enableRoute(@RequestParam Long id, @RequestParam boolean enabled) {
+ @RequestMapping(value = "/changeStatus", method = RequestMethod.POST)
+ public boolean enableRoute(@RequestBody Map<String, Object> params) {
+ boolean enabled = (boolean)params.get("enabled");
+
+ long id = Long.parseLong(params.get("id").toString());
if (enabled) {
routeService.disableRoute(id);
} else {
diff --git a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/ServiceController.java b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/ServiceController.java
index cae1eb0..4bf3c2a 100644
--- a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/ServiceController.java
+++ b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/ServiceController.java
@@ -27,9 +27,7 @@ import org.apache.dubbo.admin.registry.common.domain.Consumer;
import org.apache.dubbo.admin.registry.common.domain.Provider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -48,11 +46,11 @@ public class ServiceController {
@Autowired
private ConsumerService consumerService;
- @RequestMapping("/search")
- public List<ServiceDO> search(@RequestParam String filter,
- @RequestParam String pattern,
- HttpServletRequest request,
- HttpServletResponse response, Model model) {
+ @RequestMapping(value = "/search", method = RequestMethod.POST)
+ public List<ServiceDO> search(@RequestBody Map<String, String> params) {
+
+ String pattern = params.get("pattern");
+ String filter = params.get("filter");
List<Provider> allProviders = providerService.findAll();
@@ -100,7 +98,6 @@ public class ServiceController {
}
}
- model.addAttribute("serviceDO", result);
return result;
}
diff --git a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/WeightController.java b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/WeightController.java
new file mode 100644
index 0000000..8c1516c
--- /dev/null
+++ b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/WeightController.java
@@ -0,0 +1,97 @@
+/*
+ * 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
+ * he 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.dubbo.admin.controller;
+
+import org.apache.dubbo.admin.governance.service.OverrideService;
+import org.apache.dubbo.admin.registry.common.domain.Override;
+import org.apache.dubbo.admin.registry.common.domain.Weight;
+import org.apache.dubbo.admin.registry.common.util.OverrideUtils;
+import org.apache.dubbo.admin.dto.WeightDTO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+@RestController
+@RequestMapping("/api/weight")
+public class WeightController {
+
+ @Autowired
+ private OverrideService overrideService;
+
+ @RequestMapping(value = "/create", method = RequestMethod.POST)
+ public boolean createWeight(@RequestBody WeightDTO weightDTO) {
+ String[] addresses = weightDTO.getProvider();
+ for (String address : addresses) {
+ Weight weight = new Weight();
+ weight.setService(weightDTO.getService());
+ weight.setWeight(weight.getWeight());
+ weight.setAddress(address);
+ overrideService.saveOverride(OverrideUtils.weightToOverride(weight));
+ }
+ return true;
+ }
+
+ @RequestMapping(value = "/update", method = RequestMethod.POST)
+ public boolean updateWeight(@RequestBody WeightDTO weightDTO) {
+ Long id = weightDTO.getId();
+ if (id == null) {
+ //TODO throw exception
+ }
+ Override override = overrideService.findById(id);
+ if (override == null) {
+ //TODO throw exception
+ }
+ Weight old = OverrideUtils.overrideToWeight(override);
+ old.setWeight(weightDTO.getWeight());
+ overrideService.updateOverride(OverrideUtils.weightToOverride(old));
+ return true;
+ }
+
+ @RequestMapping(value = "/search", method = RequestMethod.POST)
+ public List<Weight> allWeight(@RequestBody Map<String, String> params) {
+ String serviceName = params.get("serviceName");
+ List<Override> overrides = overrideService.findByService(serviceName);
+ List<Weight> weights = new ArrayList<>();
+ for (Override override : overrides) {
+ Weight w = OverrideUtils.overrideToWeight(override);
+ if (w != null) {
+ weights.add(w);
+ }
+ }
+ return weights;
+ }
+
+ @RequestMapping("/detail")
+ public Weight detail(@RequestParam Long id) {
+ Override override = overrideService.findById(id);
+ if (override != null) {
+ return OverrideUtils.overrideToWeight(override);
+ }
+ return null;
+ }
+
+ @RequestMapping(value = "/delete", method = RequestMethod.POST)
+ public boolean delete(@RequestBody Map<String, Long> params) {
+ Long id = params.get("id");
+ overrideService.deleteOverride(id);
+ return true;
+ }
+}
diff --git a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/dto/BalancingDTO.java b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/dto/BalancingDTO.java
new file mode 100644
index 0000000..9ef12e0
--- /dev/null
+++ b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/dto/BalancingDTO.java
@@ -0,0 +1,35 @@
+package org.apache.dubbo.admin.dto;
+
+/**
+ * @author zmx ON 2018/9/25
+ */
+public class BalancingDTO {
+
+ private Long id;
+ private String serviceName;
+ private String rule;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getServiceName() {
+ return serviceName;
+ }
+
+ public void setServiceName(String serviceName) {
+ this.serviceName = serviceName;
+ }
+
+ public String getRule() {
+ return rule;
+ }
+
+ public void setRule(String rule) {
+ this.rule = rule;
+ }
+}
diff --git a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/dto/RouteDTO.java b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/dto/RouteDTO.java
new file mode 100644
index 0000000..b3aad71
--- /dev/null
+++ b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/dto/RouteDTO.java
@@ -0,0 +1,111 @@
+/*
+ * 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
+ * he 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.dubbo.admin.dto;
+
+public class RouteDTO {
+ private Long id;
+ private String app;
+ private String serviceName;
+ private String group;
+ private boolean dynamic;
+ private int priority;
+ private boolean enabled;
+ private boolean force;
+ private boolean runtime;
+ private String[] conditions;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getApp() {
+ return app;
+ }
+
+ public void setApp(String app) {
+ this.app = app;
+ }
+
+ public String getServiceName() {
+ return serviceName;
+ }
+
+ public void setServiceName(String serviceName) {
+ this.serviceName = serviceName;
+ }
+
+ public String getGroup() {
+ return group;
+ }
+
+ public void setGroup(String group) {
+ this.group = group;
+ }
+
+ public boolean isDynamic() {
+ return dynamic;
+ }
+
+ public void setDynamic(boolean dynamic) {
+ this.dynamic = dynamic;
+ }
+
+ public int getPriority() {
+ return priority;
+ }
+
+ public void setPriority(int priority) {
+ this.priority = priority;
+ }
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ public boolean isForce() {
+ return force;
+ }
+
+ public void setForce(boolean force) {
+ this.force = force;
+ }
+
+ public boolean isRuntime() {
+ return runtime;
+ }
+
+ public void setRuntime(boolean runtime) {
+ this.runtime = runtime;
+ }
+
+ public String[] getConditions() {
+ return conditions;
+ }
+
+ public void setConditions(String[] conditions) {
+ this.conditions = conditions;
+ }
+}
diff --git a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/dto/WeightDTO.java b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/dto/WeightDTO.java
new file mode 100644
index 0000000..82024d2
--- /dev/null
+++ b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/dto/WeightDTO.java
@@ -0,0 +1,60 @@
+/*
+ * 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
+ * he 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.dubbo.admin.dto;
+
+import java.util.List;
+
+public class WeightDTO {
+
+ private String service;
+ private Long id;
+ private int weight;
+ private String[] provider;
+
+ public String getService() {
+ return service;
+ }
+
+ public void setService(String service) {
+ this.service = service;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public int getWeight() {
+ return weight;
+ }
+
+ public void setWeight(int weight) {
+ this.weight = weight;
+ }
+
+ public String[] getProvider() {
+ return provider;
+ }
+
+ public void setProvider(String[] provider) {
+ this.provider = provider;
+ }
+}
diff --git a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/registry/common/domain/Route.java b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/registry/common/domain/Route.java
index 91859b2..2b001cf 100644
--- a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/registry/common/domain/Route.java
+++ b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/registry/common/domain/Route.java
@@ -184,12 +184,18 @@ public class Route extends Entity {
public void setRule(String rule) {
this.rule = rule;
- String[] rules = rule.split(" => ");
+ String[] rules = rule.split("=>");
if (rules.length != 2) {
- throw new IllegalArgumentException("Illegal Route Condition Rule");
+ if (rule.endsWith("=>")) {
+ this.matchRule = rules[0].trim();
+ this.filterRule = "";
+ } else {
+ throw new IllegalArgumentException("Illegal Route Condition Rule");
+ }
+ } else {
+ this.matchRule = rules[0].trim();
+ this.filterRule = rules[1].trim();
}
- this.matchRule = rules[0];
- this.filterRule = rules[1];
}
public String getMatchRule() {
@@ -197,7 +203,11 @@ public class Route extends Entity {
}
public void setMatchRule(String matchRule) {
- this.matchRule = matchRule;
+ if (matchRule != null) {
+ this.matchRule = matchRule.trim();
+ } else {
+ this.matchRule = matchRule;
+ }
}
public String getFilterRule() {
@@ -205,7 +215,11 @@ public class Route extends Entity {
}
public void setFilterRule(String filterRule) {
- this.filterRule = filterRule;
+ if (filterRule != null) {
+ this.filterRule = filterRule.trim();
+ } else {
+ this.filterRule = filterRule;
+ }
}
@java.lang.Override
@@ -217,6 +231,11 @@ public class Route extends Entity {
}
public URL toUrl() {
+// if (filterRule != null && filterRule.endsWith("null")) {
+// filterRule = null;
+// } else {
+// filterRule = filterRule.trim();
+// }
return URL.valueOf(Constants.ROUTE_PROTOCOL + "://" + Constants.ANYHOST_VALUE + "/" + getService()
+ "?" + Constants.CATEGORY_KEY + "=" + Constants.ROUTERS_CATEGORY
+ "&router=condition&runtime=" + isRuntime() + "&enabled=" + isEnabled() + "&priority=" + getPriority() + "&force=" + isForce() + "&dynamic=" + isDynamic()
diff --git a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/registry/common/util/OverrideUtils.java b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/registry/common/util/OverrideUtils.java
index 96360bf..288d6f0 100644
--- a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/registry/common/util/OverrideUtils.java
+++ b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/registry/common/util/OverrideUtils.java
@@ -57,7 +57,11 @@ public class OverrideUtils {
}
public static Weight overrideToWeight(Override override) {
- return overridesToWeights(Arrays.asList(override)).get(0);
+ List<Weight> weights = OverrideUtils.overridesToWeights(Arrays.asList(override));
+ if (weights != null && weights.size() > 0) {
+ return overridesToWeights(Arrays.asList(override)).get(0);
+ }
+ return null;
}
public static Override weightToOverride(Weight weight) {
diff --git a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/web/mvc/governance/WeightsController.java b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/web/mvc/governance/WeightsController.java
index 86163bd..ca18add 100644
--- a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/web/mvc/governance/WeightsController.java
+++ b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/web/mvc/governance/WeightsController.java
@@ -1,288 +1,288 @@
-/*
- * 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.dubbo.admin.web.mvc.governance;
-
-import com.alibaba.dubbo.common.utils.CollectionUtils;
-import org.apache.dubbo.admin.governance.service.OverrideService;
-import org.apache.dubbo.admin.governance.service.ProviderService;
-import org.apache.dubbo.admin.registry.common.domain.Provider;
-import org.apache.dubbo.admin.registry.common.domain.Weight;
-import org.apache.dubbo.admin.registry.common.util.OverrideUtils;
-import org.apache.dubbo.admin.web.mvc.BaseController;
-import org.apache.dubbo.admin.web.pulltool.Tool;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.math.NumberUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-import org.springframework.ui.Model;
-import org.springframework.validation.support.BindingAwareModelMap;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.BufferedReader;
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.regex.Pattern;
-
-/**
- * ProvidersController.
- * URI: /services/$service/weights
- *
- */
-@Controller
-@RequestMapping("/governance/weights")
-public class WeightsController extends BaseController {
-
- private static final Pattern IP_PATTERN = Pattern.compile("\\d{1,3}(\\.\\d{1,3}){3}$");
- private static final Pattern LOCAL_IP_PATTERN = Pattern.compile("127(\\.\\d{1,3}){3}$");
- private static final Pattern ALL_IP_PATTERN = Pattern.compile("0{1,3}(\\.0{1,3}){3}$");
- @Autowired
- private OverrideService overrideService;
- @Autowired
- private ProviderService providerService;
-
- @RequestMapping("")
- public String index(HttpServletRequest request, HttpServletResponse response, Model model) {
- prepare(request, response, model, "index", "weights");
- BindingAwareModelMap newModel = (BindingAwareModelMap)model;
- String service = (String)newModel.get("service");
- String address = (String)newModel.get("address");
- service = StringUtils.trimToNull(service);
- address = Tool.getIP(address);
- List<Weight> weights;
- if (service != null && service.length() > 0) {
- weights = OverrideUtils.overridesToWeights(overrideService.findByService(service));
- } else if (address != null && address.length() > 0) {
- weights = OverrideUtils.overridesToWeights(overrideService.findByAddress(address));
- } else {
- weights = OverrideUtils.overridesToWeights(overrideService.findAll());
- }
- model.addAttribute("weights", weights);
- return "governance/screen/weights/index";
- }
-
- /**
- * load page for the adding
- *
- */
- @RequestMapping("/add")
- public String add(HttpServletRequest request, HttpServletResponse response, Model model) {
- prepare(request, response, model, "add", "weights");
- BindingAwareModelMap newModel = (BindingAwareModelMap)model;
- String service = (String)newModel.get("service");
- String input = request.getParameter("input");
- if (service != null && service.length() > 0 && !service.contains("*")) {
- List<Provider> providerList = providerService.findByService(service);
- List<String> addressList = new ArrayList<String>();
- for (Provider provider : providerList) {
- addressList.add(provider.getUrl().split("://")[1].split("/")[0]);
- }
- model.addAttribute("addressList", addressList);
- model.addAttribute("service", service);
- model.addAttribute("methods", CollectionUtils.sort(providerService.findMethodsByService(service)));
- } else {
- List<String> serviceList = Tool.sortSimpleName(providerService.findServices());
- model.addAttribute("serviceList", serviceList);
- }
- if (input != null) model.addAttribute("input", input);
- return "governance/screen/weights/add";
- }
-
-
- @RequestMapping("/create")
- public String create(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
- prepare(request, response, model, "create", "weights");
- String addr = request.getParameter("address");
- String services = request.getParameter("multiservice");
- if (services == null || services.trim().length() == 0) {
- services = request.getParameter("service");
- }
- String weight = request.getParameter("weight");
-
- int w = Integer.parseInt(weight);
-
- Set<String> addresses = new HashSet<String>();
- BufferedReader reader = new BufferedReader(new StringReader(addr));
- while (true) {
- String line = reader.readLine();
- if (null == line)
- break;
-
- String[] split = line.split("[\\s,;]+");
- for (String s : split) {
- if (s.length() == 0)
- continue;
-
- String ip = s;
- String port = null;
- if (s.indexOf(":") != -1) {
- ip = s.substring(0, s.indexOf(":"));
- port = s.substring(s.indexOf(":") + 1, s.length());
- if (port.trim().length() == 0) port = null;
- }
- if (!IP_PATTERN.matcher(ip).matches()) {
- model.addAttribute("message", "illegal IP: " + s);
- model.addAttribute("success", false);
- model.addAttribute("redirect", "../weights");
- return "governance/screen/redirect";
- }
- if (LOCAL_IP_PATTERN.matcher(ip).matches() || ALL_IP_PATTERN.matcher(ip).matches()) {
- model.addAttribute("message", "local IP or any host ip is illegal: " + s);
- model.addAttribute("success", false);
- model.addAttribute("redirect", "../weights");
- return "governance/screen/redirect";
- }
- if (port != null) {
- if (!NumberUtils.isDigits(port)) {
- model.addAttribute("message", "illegal port: " + s);
- model.addAttribute("success", false);
- model.addAttribute("redirect", "../weights");
- return "governance/screen/redirect";
- }
- }
- addresses.add(s);
- }
- }
-
- Set<String> aimServices = new HashSet<String>();
- reader = new BufferedReader(new StringReader(services));
- while (true) {
- String line = reader.readLine();
- if (null == line)
- break;
-
- String[] split = line.split("[\\s,;]+");
- for (String s : split) {
- if (s.length() == 0)
- continue;
- if (!super.currentUser.hasServicePrivilege(s)) {
- model.addAttribute("message", getMessage("HaveNoServicePrivilege", s));
- model.addAttribute("success", false);
- model.addAttribute("redirect", "../weights");
- return "governance/screen/redirect";
- }
- aimServices.add(s);
- }
- }
-
- for (String aimService : aimServices) {
- for (String a : addresses) {
- Weight wt = new Weight();
- wt.setUsername((String) ((BindingAwareModelMap)model).get("operator"));
- wt.setAddress(Tool.getIP(a));
- wt.setService(aimService);
- wt.setWeight(w);
- overrideService.saveOverride(OverrideUtils.weightToOverride(wt));
- }
- }
- model.addAttribute("success", true);
- model.addAttribute("redirect", "../weights");
- return "governance/screen/redirect";
- }
-
- @RequestMapping("/edit")
- public String edit(@RequestParam("id") Long id, HttpServletRequest request, HttpServletResponse response, Model model) {
- prepare(request, response, model, "edit", "weights");
- String service = request.getParameter("service");
- String input = request.getParameter("input");
-
- if (service != null && service.length() > 0 && !service.contains("*")) {
- List<Provider> providerList = providerService.findByService(service);
- List<String> addressList = new ArrayList<String>();
- for (Provider provider : providerList) {
- addressList.add(provider.getUrl().split("://")[1].split("/")[0]);
- }
- model.addAttribute("addressList", addressList);
- model.addAttribute("service", service);
- model.addAttribute("methods", CollectionUtils.sort(providerService.findMethodsByService(service)));
- } else {
- List<String> serviceList = Tool.sortSimpleName(providerService.findServices());
- model.addAttribute("serviceList", serviceList);
- }
- if (input != null) model.addAttribute("input", input);
- Weight weight = OverrideUtils.overrideToWeight(overrideService.findById(id));
- model.addAttribute("weight", weight);
- model.addAttribute("service", overrideService.findById(id).getService());
- return "governance/screen/weights/edit";
- }
-
- /**
- * load weight for editing
- *
- * @param id
-
- */
- @RequestMapping("/detail")
- public String show(@RequestParam("id") Long id, HttpServletRequest request, HttpServletResponse response, Model model) {
- prepare(request, response, model, "show", "weights");
- Weight weight = OverrideUtils.overrideToWeight(overrideService.findById(id));
- model.addAttribute("weight", weight);
- return "governance/screen/weights/show";
- }
-
- @RequestMapping(value = "/update", method = RequestMethod.POST) //post
- public String update(Weight weight, HttpServletRequest request, HttpServletResponse response, Model model) {
- prepare(request, response, model, "update", "weights");
- boolean success = true;
- if (!super.currentUser.hasServicePrivilege(weight.getService())) {
- model.addAttribute("message", getMessage("HaveNoServicePrivilege", weight.getService()));
- success = false;
- } else {
- weight.setAddress(Tool.getIP(weight.getAddress()));
- overrideService.updateOverride(OverrideUtils.weightToOverride(weight));
- }
- model.addAttribute("success", success);
- model.addAttribute("redirect", "governance/weights");
- return "governance/screen/redirect";
- }
-
- /**
- * delete
- *
- * @param ids
- * @return
- */
- @RequestMapping("/delete")
- public String delete(@RequestParam("ids") Long[] ids, HttpServletRequest request, HttpServletResponse response, Model model) {
- prepare(request, response, model, "delete", "weights");
- boolean success = true;
- for (Long id : ids) {
- Weight w = OverrideUtils.overrideToWeight(overrideService.findById(id));
- if (!super.currentUser.hasServicePrivilege(w.getService())) {
- model.addAttribute("message", getMessage("HaveNoServicePrivilege", w.getService()));
- success = false;
- model.addAttribute("success", success);
- model.addAttribute("redirect", "../../weights");
- return "governance/screen/redirect";
- }
- }
-
- for (Long id : ids) {
- overrideService.deleteOverride(id);
- }
- model.addAttribute("success", success);
- model.addAttribute("redirect", "../../weights");
- return "governance/screen/redirect";
- }
-
-}
+///*
+// * 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.dubbo.admin.web.mvc.governance;
+//
+//import com.alibaba.dubbo.common.utils.CollectionUtils;
+//import org.apache.dubbo.admin.governance.service.OverrideService;
+//import org.apache.dubbo.admin.governance.service.ProviderService;
+//import org.apache.dubbo.admin.registry.common.domain.Provider;
+//import org.apache.dubbo.admin.registry.common.domain.Weight;
+//import org.apache.dubbo.admin.registry.common.util.OverrideUtils;
+//import org.apache.dubbo.admin.web.mvc.BaseController;
+//import org.apache.dubbo.admin.web.pulltool.Tool;
+//import org.apache.commons.lang3.StringUtils;
+//import org.apache.commons.lang3.math.NumberUtils;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.stereotype.Controller;
+//import org.springframework.ui.Model;
+//import org.springframework.validation.support.BindingAwareModelMap;
+//import org.springframework.web.bind.annotation.RequestMapping;
+//import org.springframework.web.bind.annotation.RequestMethod;
+//import org.springframework.web.bind.annotation.RequestParam;
+//
+//import javax.servlet.http.HttpServletRequest;
+//import javax.servlet.http.HttpServletResponse;
+//import java.io.BufferedReader;
+//import java.io.StringReader;
+//import java.util.ArrayList;
+//import java.util.HashSet;
+//import java.util.List;
+//import java.util.Set;
+//import java.util.regex.Pattern;
+//
+///**
+// * ProvidersController.
+// * URI: /services/$service/weights
+// *
+// */
+//@Controller
+//@RequestMapping("/governance/weights")
+//public class WeightsController extends BaseController {
+//
+// private static final Pattern IP_PATTERN = Pattern.compile("\\d{1,3}(\\.\\d{1,3}){3}$");
+// private static final Pattern LOCAL_IP_PATTERN = Pattern.compile("127(\\.\\d{1,3}){3}$");
+// private static final Pattern ALL_IP_PATTERN = Pattern.compile("0{1,3}(\\.0{1,3}){3}$");
+// @Autowired
+// private OverrideService overrideService;
+// @Autowired
+// private ProviderService providerService;
+//
+// @RequestMapping("")
+// public String index(HttpServletRequest request, HttpServletResponse response, Model model) {
+// prepare(request, response, model, "index", "weights");
+// BindingAwareModelMap newModel = (BindingAwareModelMap)model;
+// String service = (String)newModel.get("service");
+// String address = (String)newModel.get("address");
+// service = StringUtils.trimToNull(service);
+// address = Tool.getIP(address);
+// List<Weight> weights;
+// if (service != null && service.length() > 0) {
+// weights = OverrideUtils.overridesToWeights(overrideService.findByService(service));
+// } else if (address != null && address.length() > 0) {
+// weights = OverrideUtils.overridesToWeights(overrideService.findByAddress(address));
+// } else {
+// weights = OverrideUtils.overridesToWeights(overrideService.findAll());
+// }
+// model.addAttribute("weights", weights);
+// return "governance/screen/weights/index";
+// }
+//
+// /**
+// * load page for the adding
+// *
+// */
+// @RequestMapping("/add")
+// public String add(HttpServletRequest request, HttpServletResponse response, Model model) {
+// prepare(request, response, model, "add", "weights");
+// BindingAwareModelMap newModel = (BindingAwareModelMap)model;
+// String service = (String)newModel.get("service");
+// String input = request.getParameter("input");
+// if (service != null && service.length() > 0 && !service.contains("*")) {
+// List<Provider> providerList = providerService.findByService(service);
+// List<String> addressList = new ArrayList<String>();
+// for (Provider provider : providerList) {
+// addressList.add(provider.getUrl().split("://")[1].split("/")[0]);
+// }
+// model.addAttribute("addressList", addressList);
+// model.addAttribute("service", service);
+// model.addAttribute("methods", CollectionUtils.sort(providerService.findMethodsByService(service)));
+// } else {
+// List<String> serviceList = Tool.sortSimpleName(providerService.findServices());
+// model.addAttribute("serviceList", serviceList);
+// }
+// if (input != null) model.addAttribute("input", input);
+// return "governance/screen/weights/add";
+// }
+//
+//
+// @RequestMapping("/create")
+// public String create(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
+// prepare(request, response, model, "create", "weights");
+// String addr = request.getParameter("address");
+// String services = request.getParameter("multiservice");
+// if (services == null || services.trim().length() == 0) {
+// services = request.getParameter("service");
+// }
+// String weight = request.getParameter("weight");
+//
+// int w = Integer.parseInt(weight);
+//
+// Set<String> addresses = new HashSet<String>();
+// BufferedReader reader = new BufferedReader(new StringReader(addr));
+// while (true) {
+// String line = reader.readLine();
+// if (null == line)
+// break;
+//
+// String[] split = line.split("[\\s,;]+");
+// for (String s : split) {
+// if (s.length() == 0)
+// continue;
+//
+// String ip = s;
+// String port = null;
+// if (s.indexOf(":") != -1) {
+// ip = s.substring(0, s.indexOf(":"));
+// port = s.substring(s.indexOf(":") + 1, s.length());
+// if (port.trim().length() == 0) port = null;
+// }
+// if (!IP_PATTERN.matcher(ip).matches()) {
+// model.addAttribute("message", "illegal IP: " + s);
+// model.addAttribute("success", false);
+// model.addAttribute("redirect", "../weights");
+// return "governance/screen/redirect";
+// }
+// if (LOCAL_IP_PATTERN.matcher(ip).matches() || ALL_IP_PATTERN.matcher(ip).matches()) {
+// model.addAttribute("message", "local IP or any host ip is illegal: " + s);
+// model.addAttribute("success", false);
+// model.addAttribute("redirect", "../weights");
+// return "governance/screen/redirect";
+// }
+// if (port != null) {
+// if (!NumberUtils.isDigits(port)) {
+// model.addAttribute("message", "illegal port: " + s);
+// model.addAttribute("success", false);
+// model.addAttribute("redirect", "../weights");
+// return "governance/screen/redirect";
+// }
+// }
+// addresses.add(s);
+// }
+// }
+//
+// Set<String> aimServices = new HashSet<String>();
+// reader = new BufferedReader(new StringReader(services));
+// while (true) {
+// String line = reader.readLine();
+// if (null == line)
+// break;
+//
+// String[] split = line.split("[\\s,;]+");
+// for (String s : split) {
+// if (s.length() == 0)
+// continue;
+// if (!super.currentUser.hasServicePrivilege(s)) {
+// model.addAttribute("message", getMessage("HaveNoServicePrivilege", s));
+// model.addAttribute("success", false);
+// model.addAttribute("redirect", "../weights");
+// return "governance/screen/redirect";
+// }
+// aimServices.add(s);
+// }
+// }
+//
+// for (String aimService : aimServices) {
+// for (String a : addresses) {
+// Weight wt = new Weight();
+// wt.setUsername((String) ((BindingAwareModelMap)model).get("operator"));
+// wt.setAddress(Tool.getIP(a));
+// wt.setService(aimService);
+// wt.setWeight(w);
+// overrideService.saveOverride(OverrideUtils.weightToOverride(wt));
+// }
+// }
+// model.addAttribute("success", true);
+// model.addAttribute("redirect", "../weights");
+// return "governance/screen/redirect";
+// }
+//
+// @RequestMapping("/edit")
+// public String edit(@RequestParam("id") Long id, HttpServletRequest request, HttpServletResponse response, Model model) {
+// prepare(request, response, model, "edit", "weights");
+// String service = request.getParameter("service");
+// String input = request.getParameter("input");
+//
+// if (service != null && service.length() > 0 && !service.contains("*")) {
+// List<Provider> providerList = providerService.findByService(service);
+// List<String> addressList = new ArrayList<String>();
+// for (Provider provider : providerList) {
+// addressList.add(provider.getUrl().split("://")[1].split("/")[0]);
+// }
+// model.addAttribute("addressList", addressList);
+// model.addAttribute("service", service);
+// model.addAttribute("methods", CollectionUtils.sort(providerService.findMethodsByService(service)));
+// } else {
+// List<String> serviceList = Tool.sortSimpleName(providerService.findServices());
+// model.addAttribute("serviceList", serviceList);
+// }
+// if (input != null) model.addAttribute("input", input);
+// Weight weight = OverrideUtils.overrideToWeight(overrideService.findById(id));
+// model.addAttribute("weight", weight);
+// model.addAttribute("service", overrideService.findById(id).getService());
+// return "governance/screen/weights/edit";
+// }
+//
+// /**
+// * load weight for editing
+// *
+// * @param id
+//
+// */
+// @RequestMapping("/detail")
+// public String show(@RequestParam("id") Long id, HttpServletRequest request, HttpServletResponse response, Model model) {
+// prepare(request, response, model, "show", "weights");
+// Weight weight = OverrideUtils.overrideToWeight(overrideService.findById(id));
+// model.addAttribute("weight", weight);
+// return "governance/screen/weights/show";
+// }
+//
+// @RequestMapping(value = "/update", method = RequestMethod.POST) //post
+// public String update(Weight weight, HttpServletRequest request, HttpServletResponse response, Model model) {
+// prepare(request, response, model, "update", "weights");
+// boolean success = true;
+// if (!super.currentUser.hasServicePrivilege(weight.getService())) {
+// model.addAttribute("message", getMessage("HaveNoServicePrivilege", weight.getService()));
+// success = false;
+// } else {
+// weight.setAddress(Tool.getIP(weight.getAddress()));
+// overrideService.updateOverride(OverrideUtils.weightToOverride(weight));
+// }
+// model.addAttribute("success", success);
+// model.addAttribute("redirect", "governance/weights");
+// return "governance/screen/redirect";
+// }
+//
+// /**
+// * delete
+// *
+// * @param ids
+// * @return
+// */
+// @RequestMapping("/delete")
+// public String delete(@RequestParam("ids") Long[] ids, HttpServletRequest request, HttpServletResponse response, Model model) {
+// prepare(request, response, model, "delete", "weights");
+// boolean success = true;
+// for (Long id : ids) {
+// Weight w = OverrideUtils.overrideToWeight(overrideService.findById(id));
+// if (!super.currentUser.hasServicePrivilege(w.getService())) {
+// model.addAttribute("message", getMessage("HaveNoServicePrivilege", w.getService()));
+// success = false;
+// model.addAttribute("success", success);
+// model.addAttribute("redirect", "../../weights");
+// return "governance/screen/redirect";
+// }
+// }
+//
+// for (Long id : ids) {
+// overrideService.deleteOverride(id);
+// }
+// model.addAttribute("success", success);
+// model.addAttribute("redirect", "../../weights");
+// return "governance/screen/redirect";
+// }
+//
+//}
diff --git a/dubbo-admin-frontend/src/components/AccessControl.vue b/dubbo-admin-frontend/src/components/AccessControl.vue
index bae3492..1f271b5 100644
--- a/dubbo-admin-frontend/src/components/AccessControl.vue
+++ b/dubbo-admin-frontend/src/components/AccessControl.vue
@@ -305,8 +305,10 @@ export default {
service = query[key]
}
})
- this.filter = service
- this.search(this.filter)
+ if (service !== '') {
+ this.filter = service
+ this.search(this.filter)
+ }
},
components: {
AceEditor
diff --git a/dubbo-admin-frontend/src/components/DynamicConfig.vue b/dubbo-admin-frontend/src/components/DynamicConfig.vue
new file mode 100644
index 0000000..75ea3fa
--- /dev/null
+++ b/dubbo-admin-frontend/src/components/DynamicConfig.vue
@@ -0,0 +1,12 @@
+<template>
+
+</template>
+
+<script>
+ export default {
+ }
+</script>
+
+<style scoped>
+
+</style>
diff --git a/dubbo-admin-frontend/src/components/LoadBalance.vue b/dubbo-admin-frontend/src/components/LoadBalance.vue
index 6c84ef8..8397419 100644
--- a/dubbo-admin-frontend/src/components/LoadBalance.vue
+++ b/dubbo-admin-frontend/src/components/LoadBalance.vue
@@ -196,7 +196,9 @@
this.search(this.filter, true)
},
search: function (filter, rewrite) {
- AXIOS.get('/balancing/all?serviceName=' + filter)
+ let params = {}
+ params.serviceName = filter
+ AXIOS.post('/balancing/search', params)
.then(response => {
this.loadBalances = response.data
if (rewrite) {
@@ -206,19 +208,11 @@
},
handleRule: function (route) {
let result = {}
- let conditions = []
for (let property in route) {
if (this.ruleKeys.includes(property)) {
- if (property === 'rule') {
- conditions.push(route[property])
- } else {
- result[property] = route[property]
- }
+ result[property] = route[property]
}
}
- if (conditions.length > 0) {
- result['conditions'] = conditions
- }
return yaml.safeDump(result)
},
closeDialog: function () {
@@ -242,7 +236,10 @@
},
saveItem: function () {
let text = encodeURIComponent(this.ruleText) // contains illegal url character, need encode
- AXIOS.get('/balancing/create?serviceName=' + this.service + '&rule=' + text)
+ let rule = {}
+ rule.serviceName = this.service
+ rule.rule = text
+ AXIOS.post('/balancing/create', rule)
.then(response => {
if (response.data) {
this.search(this.service, true)
@@ -263,7 +260,9 @@
})
break
case 'edit':
- AXIOS.get('/balancing/edit?id=' + item.id)
+ let edit = {}
+ edit.id = item.id
+ AXIOS.post('/balancing/edit', edit)
.then(response => {
let loadbalance = response.data
let result = this.handleRule(loadbalance)
@@ -284,13 +283,18 @@
},
deleteItem: function (warnStatus) {
if (warnStatus.operation === 'delete') {
- AXIOS.get('/balancing/delete?id=' + warnStatus.id)
+ let id = {}
+ id.id = warnStatus.id
+ AXIOS.post('/balancing/delete', id)
.then(response => {
this.warn = false
this.search(this.filter, false)
})
} else if (warnStatus.operation === 'block') {
- AXIOS.get('/routes/changeStatus?id=' + warnStatus.id + '&enabled=' + warnStatus.enabled)
+ let status = {}
+ status.enabled = warnStatus.enabled
+ status.id = warnStatus.id
+ AXIOS.post('/routes/changeStatus', status)
.then(response => {
this.warn = false
this.search(this.filter, false)
diff --git a/dubbo-admin-frontend/src/components/RoutingRule.vue b/dubbo-admin-frontend/src/components/RoutingRule.vue
index c0e3fb6..0803bf6 100644
--- a/dubbo-admin-frontend/src/components/RoutingRule.vue
+++ b/dubbo-admin-frontend/src/components/RoutingRule.vue
@@ -134,7 +134,7 @@
},
data: () => ({
dropdown_font: [ 'Service', 'App', 'IP' ],
- ruleKeys: ['service', 'enabled', 'force', 'dynamic', 'runtime', 'group', 'version', 'rule', 'priority'],
+ ruleKeys: ['enabled', 'force', 'dynamic', 'runtime', 'group', 'version', 'rule', 'priority'],
pattern: 'Service',
filter: '',
dialog: false,
@@ -184,7 +184,7 @@
routingRules: [
],
template:
- 'enable: true/false\n' +
+ 'enabled: true/false\n' +
'priority:\n' +
'runtime: false/true\n' +
'force: true/false\n' +
@@ -237,7 +237,10 @@
this.search(this.filter, true)
},
search: function (filter, rewrite) {
- AXIOS.get('/routes/all?serviceName=' + filter)
+ let params = {}
+ params.serviceName = filter
+
+ AXIOS.post('/routes/search', params)
.then(response => {
this.routingRules = response.data
if (rewrite) {
@@ -246,6 +249,7 @@
})
},
handleRule: function (route) {
+ console.log(route)
let result = {}
let conditions = []
for (let property in route) {
@@ -260,6 +264,8 @@
if (conditions.length > 0) {
result['conditions'] = conditions
}
+ console.log('result====')
+ console.log(result)
return yaml.safeDump(result)
},
closeDialog: function () {
@@ -282,12 +288,14 @@
this.warn = false
},
saveItem: function () {
- let text = encodeURIComponent(this.ruleText)
- AXIOS.get('/routes/create?serviceName=' + this.service + '&rule=' + text)
+ let rule = yaml.safeLoad(this.ruleText)
+ rule.serviceName = this.service
+ AXIOS.post('/routes/create', rule)
.then(response => {
if (response.data) {
this.search(this.service, true)
}
+ this.closeDialog()
})
},
itemOperation: function (icon, item) {
@@ -304,7 +312,9 @@
})
break
case 'edit':
- AXIOS.get('/routes/edit?id=' + item.id)
+ let id = {}
+ id.id = item.id
+ AXIOS.post('/routes/edit', id)
.then(response => {
let route = response.data
let result = this.handleRule(route)
@@ -332,13 +342,18 @@
},
deleteItem: function (warnStatus) {
if (warnStatus.operation === 'delete') {
- AXIOS.get('/routes/delete?id=' + warnStatus.id)
+ let id = {}
+ id.id = warnStatus.id
+ AXIOS.post('/routes/delete', id)
.then(response => {
this.warn = false
this.search(this.filter, false)
})
} else if (warnStatus.operation === 'block') {
- AXIOS.get('/routes/changeStatus?id=' + warnStatus.id + '&enabled=' + warnStatus.enabled)
+ let status = {}
+ status.id = warnStatus.id
+ status.enabled = warnStatus.enabled
+ AXIOS.post('/routes/changeStatus', status)
.then(response => {
this.warn = false
this.search(this.filter, false)
diff --git a/dubbo-admin-frontend/src/components/ServiceSearch.vue b/dubbo-admin-frontend/src/components/ServiceSearch.vue
index 44280ab..73dca5f 100644
--- a/dubbo-admin-frontend/src/components/ServiceSearch.vue
+++ b/dubbo-admin-frontend/src/components/ServiceSearch.vue
@@ -144,7 +144,10 @@
this.search(this.filter, pattern, true)
},
search: function (filter, pattern, rewrite) {
- AXIOS.get('service/search?' + 'filter=' + filter + '&pattern=' + pattern)
+ let service = {}
+ service.filter = filter
+ service.pattern = pattern
+ AXIOS.post('service/search', service)
.then(response => {
this.services = response.data
if (rewrite) {
diff --git a/dubbo-admin-frontend/src/components/VWidget.vue b/dubbo-admin-frontend/src/components/VWidget.vue
index cbce0b4..c87977a 100644
--- a/dubbo-admin-frontend/src/components/VWidget.vue
+++ b/dubbo-admin-frontend/src/components/VWidget.vue
@@ -1,3 +1,20 @@
+<!--
+ - 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
+ - he 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.
+ -->
+
<template>
<div id="v-widget">
<v-card>
diff --git a/dubbo-admin-frontend/src/components/LoadBalance.vue b/dubbo-admin-frontend/src/components/WeightAdjust.vue
similarity index 77%
copy from dubbo-admin-frontend/src/components/LoadBalance.vue
copy to dubbo-admin-frontend/src/components/WeightAdjust.vue
index 6c84ef8..63cafd6 100644
--- a/dubbo-admin-frontend/src/components/LoadBalance.vue
+++ b/dubbo-admin-frontend/src/components/WeightAdjust.vue
@@ -71,7 +71,7 @@
<v-dialog v-model="dialog" width="800px" persistent >
<v-card>
<v-card-title class="justify-center">
- <span class="headline">Create New LoadBalance Rule</span>
+ <span class="headline">Create New Weight Rule</span>
</v-card-title>
<v-card-text >
<v-text-field
@@ -108,8 +108,8 @@
</v-dialog>
</v-container>
-
</template>
+
<script>
import { codemirror } from 'vue-codemirror'
import 'codemirror/lib/codemirror.css'
@@ -125,7 +125,7 @@
},
data: () => ({
dropdown_font: [ 'Service', 'App', 'IP' ],
- ruleKeys: ['method', 'strategy'],
+ ruleKeys: ['weight', 'address'],
pattern: 'Service',
filter: '',
dialog: false,
@@ -162,8 +162,10 @@
loadBalances: [
],
template:
- 'methodName: sayHello # 0 for all methods\n' +
- 'strategy: # leastactive, random, roundrobin',
+ 'weight: 100 # 100 for default\n' +
+ 'provider: # provider\'s ip\n' +
+ ' - 192.168.0.1\n' +
+ ' - 192.168.0.2',
ruleText: '',
cmOption: {
theme: 'paraiso-light',
@@ -179,8 +181,8 @@
align: 'left'
},
{
- text: 'Method',
- value: 'method',
+ text: 'Weight',
+ value: 'weight',
align: 'left'
},
@@ -196,28 +198,30 @@
this.search(this.filter, true)
},
search: function (filter, rewrite) {
- AXIOS.get('/balancing/all?serviceName=' + filter)
- .then(response => {
- this.loadBalances = response.data
- if (rewrite) {
- this.$router.push({path: 'loadbalance', query: {serviceName: filter}})
- }
- })
+ let params = {}
+ params.serviceName = filter
+ AXIOS.post('/weight/search', params)
+ .then(response => {
+ this.loadBalances = response.data
+ if (rewrite) {
+ this.$router.push({path: 'weight', query: {serviceName: filter}})
+ }
+ })
},
- handleRule: function (route) {
+ handleRule: function (weight) {
let result = {}
- let conditions = []
- for (let property in route) {
+ let provider = []
+ for (let property in weight) {
if (this.ruleKeys.includes(property)) {
- if (property === 'rule') {
- conditions.push(route[property])
+ if (property === 'address') {
+ provider.push(weight[property])
} else {
- result[property] = route[property]
+ result[property] = weight[property]
}
}
}
- if (conditions.length > 0) {
- result['conditions'] = conditions
+ if (provider.length > 0) {
+ result['provider'] = provider
}
return yaml.safeDump(result)
},
@@ -241,37 +245,39 @@
this.warn = false
},
saveItem: function () {
- let text = encodeURIComponent(this.ruleText) // contains illegal url character, need encode
- AXIOS.get('/balancing/create?serviceName=' + this.service + '&rule=' + text)
+ let weight = yaml.safeLoad(this.ruleText)
+ weight.service = this.service
+ AXIOS.post('/weight/create', weight)
.then(response => {
- if (response.data) {
- this.search(this.service, true)
- }
+ this.search(this.service, true)
+ this.closeDialog()
})
},
itemOperation: function (icon, item) {
switch (icon) {
case 'visibility':
- AXIOS.get('/balancing/detail?id=' + item.id)
- .then(response => {
- let balancing = response.data
- let result = this.handleRule(balancing)
- this.service = balancing.service
- this.ruleText = result
- this.cmOption.readOnly = true
- this.dialog = true
- })
+ AXIOS.get('/weight/detail?id=' + item.id)
+ .then(response => {
+ let weight = response.data
+ let result = this.handleRule(weight)
+ this.service = weight.service
+ this.ruleText = result
+ this.cmOption.readOnly = true
+ this.dialog = true
+ })
break
case 'edit':
- AXIOS.get('/balancing/edit?id=' + item.id)
- .then(response => {
- let loadbalance = response.data
- let result = this.handleRule(loadbalance)
- this.service = loadbalance.service
- this.ruleText = result
- this.cmOption.readOnly = false
- this.dialog = true
- })
+ let id = {}
+ id.id = item.id
+ AXIOS.post('/weight/edit' + id)
+ .then(response => {
+ let weight = response.data
+ let result = this.handleRule(weight)
+ this.service = weight.service
+ this.ruleText = result
+ this.cmOption.readOnly = false
+ this.dialog = true
+ })
break
case 'delete':
this.openWarn(' Are you sure to Delete Routing Rule', 'serviceName: ' + item.service)
@@ -284,17 +290,22 @@
},
deleteItem: function (warnStatus) {
if (warnStatus.operation === 'delete') {
- AXIOS.get('/balancing/delete?id=' + warnStatus.id)
- .then(response => {
- this.warn = false
- this.search(this.filter, false)
- })
+ let id = {}
+ id.id = warnStatus.id
+ AXIOS.post('/weight/delete', id)
+ .then(response => {
+ this.warn = false
+ this.search(this.filter, false)
+ })
} else if (warnStatus.operation === 'block') {
- AXIOS.get('/routes/changeStatus?id=' + warnStatus.id + '&enabled=' + warnStatus.enabled)
- .then(response => {
- this.warn = false
- this.search(this.filter, false)
- })
+ let status = {}
+ status.enabled = warnStatus.enabled
+ status.id = warnStatus.id
+ AXIOS.post('/weight/changeStatus', status)
+ .then(response => {
+ this.warn = false
+ this.search(this.filter, false)
+ })
}
}
},
@@ -320,6 +331,9 @@
this.search(service, false)
}
}
-
}
</script>
+
+<style scoped>
+
+</style>
diff --git a/dubbo-admin-frontend/src/router/index.js b/dubbo-admin-frontend/src/router/index.js
index f1d3055..6cf8f67 100644
--- a/dubbo-admin-frontend/src/router/index.js
+++ b/dubbo-admin-frontend/src/router/index.js
@@ -22,6 +22,7 @@ import ServiceDetail from '@/components/ServiceDetail'
import RoutingRule from '@/components/RoutingRule'
import AccessControl from '@/components/AccessControl'
import LoadBalance from '@/components/LoadBalance'
+import WeightAdjust from '@/components/WeightAdjust'
Vue.use(Router)
@@ -51,6 +52,11 @@ export default new Router({
path: '/governance/loadbalance',
name: 'LoadBalance',
component: LoadBalance
+ },
+ {
+ path: '/governance/weight',
+ name: 'WeightAdjust',
+ component: WeightAdjust
}
]
})