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/10 08:35:22 UTC
[incubator-dubbo-ops] branch develop updated: Develop (#104)
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 67a9ff8 Develop (#104)
67a9ff8 is described below
commit 67a9ff838f9932fea5b11d4f0863d85b9084cc99
Author: min <z8...@gmail.com>
AuthorDate: Mon Sep 10 16:35:20 2018 +0800
Develop (#104)
* add codemirror
* remove unused import
* add yaml parser& routing rule
* add yaml parser& routing rule
---
dubbo-admin/dubbo-admin-backend/pom.xml | 6 ++
.../dubbo/admin/controller/RoutesController.java | 75 +++++++++++++++++++++-
.../dubbo/admin/registry/common/domain/Route.java | 75 +++++++++++++++-------
.../src/components/RoutingRule.vue | 22 ++-----
4 files changed, 138 insertions(+), 40 deletions(-)
diff --git a/dubbo-admin/dubbo-admin-backend/pom.xml b/dubbo-admin/dubbo-admin-backend/pom.xml
index 11bd8eb..5b12ca6 100644
--- a/dubbo-admin/dubbo-admin-backend/pom.xml
+++ b/dubbo-admin/dubbo-admin-backend/pom.xml
@@ -70,6 +70,12 @@
<version>1.2.46</version>
</dependency>
+ <dependency>
+ <groupId>org.yaml</groupId>
+ <artifactId>snakeyaml</artifactId>
+ <version>1.22</version>
+ </dependency>
+
</dependencies>
<build>
diff --git a/dubbo-admin/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/RoutesController.java b/dubbo-admin/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/RoutesController.java
index 3928d5f..e93dbdf 100644
--- a/dubbo-admin/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/RoutesController.java
+++ b/dubbo-admin/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/RoutesController.java
@@ -1,17 +1,90 @@
package org.apache.dubbo.admin.controller;
+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.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.yaml.snakeyaml.Yaml;
+
+import java.util.List;
+import java.util.Map;
@RestController
@RequestMapping("/api/routes")
public class RoutesController {
+ @Autowired
+ private RouteService routeService;
+ @Autowired
+ private ProviderService providerService;
@RequestMapping("/create")
- public void createRule(@RequestParam String serviceName, @RequestParam String rule) {
+ public void createRule(@RequestParam(required = false) String serviceName,
+ @RequestParam(required = false) String app,
+ @RequestParam String rule) {
+ if (serviceName == null && app == null) {
+
+ }
+ Yaml yaml = new Yaml();
+ Map<String, Object> result = yaml.load(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;
+ if (serviceName.contains(":") && !serviceName.endsWith(":")) {
+ version = serviceName.split(":")[1];
+ service = serviceName.split(":")[0];
+ }
+
+ List<String> conditions = (List)result.get("conditions");
+ 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.setRule(condition);
+ routeService.createRoute(route);
+ }
+
+
+ } else {
+ //new feature in 2.7
+ result.put("scope", "application");
+ result.put("appname", app);
+ }
+
+ }
+
+ private Object getParameter(Map<String, Object> result, String key, Object defaultValue) {
+ if (result.get(key) != null) {
+ return result.get(key);
+ }
+ return defaultValue;
+ }
+ public static void main(String[] args) {
+ String yaml =
+ "enable: true\n" +
+ "priority: 0\n" +
+ "runtime: true\n" +
+ "category: routers\n" +
+ "dynamic: true\n" +
+ "conditions:\n" +
+ " - '=> host != 172.22.3.91'\n" +
+ " - 'host != 10.20.153.10,10.20.153.11 =>'\n" +
+ " - 'host = 10.20.153.10,10.20.153.11 =>'\n" +
+ " - 'application != kylin => host != 172.22.3.95,172.22.3.96'\n" +
+ " - 'method = find*,list*,get*,is* => host = 172.22.3.94,172.22.3.95,172.22.3.96'";
}
}
\ No newline at end of file
diff --git a/dubbo-admin/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/registry/common/domain/Route.java b/dubbo-admin/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/registry/common/domain/Route.java
index 3b389fc..a3240b1 100644
--- a/dubbo-admin/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/registry/common/domain/Route.java
+++ b/dubbo-admin/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/registry/common/domain/Route.java
@@ -65,6 +65,14 @@ public class Route extends Entity {
private boolean force;
+ private String version;
+
+ private String group;
+
+ private boolean dynamic;
+
+ private boolean runtime;
+
private List<Route> children;
public Route() {
@@ -122,6 +130,38 @@ public class Route extends Entity {
this.enabled = enabled;
}
+ public boolean isDynamic() {
+ return dynamic;
+ }
+
+ public void setDynamic(boolean dynamic) {
+ this.dynamic = dynamic;
+ }
+
+ public boolean isRuntime() {
+ return runtime;
+ }
+
+ public void setRuntime(boolean runtime) {
+ this.runtime = runtime;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ public String getGroup() {
+ return group;
+ }
+
+ public void setGroup(String group) {
+ this.group = group;
+ }
+
public boolean isForce() {
return force;
}
@@ -144,12 +184,12 @@ public class Route extends Entity {
public void setRule(String rule) {
this.rule = rule;
- String[] rules = rule.split(" => ");
- if (rules.length != 2) {
- throw new IllegalArgumentException("Illegal Route Condition Rule");
- }
- this.matchRule = rules[0];
- this.filterRule = rules[1];
+// String[] rules = rule.split(" => ");
+// if (rules.length != 2) {
+// throw new IllegalArgumentException("Illegal Route Condition Rule");
+// }
+// this.matchRule = rules[0];
+// this.filterRule = rules[1];
}
public String getMatchRule() {
@@ -177,25 +217,12 @@ public class Route extends Entity {
}
public URL toUrl() {
- String group = null;
- String version = null;
- String path = service;
- int i = path.indexOf("/");
- if (i > 0) {
- group = path.substring(0, i);
- path = path.substring(i + 1);
- }
- i = path.lastIndexOf(":");
- if (i > 0) {
- version = path.substring(i + 1);
- path = path.substring(0, i);
- }
- return URL.valueOf(Constants.ROUTE_PROTOCOL + "://" + Constants.ANYHOST_VALUE + "/" + path
+ return URL.valueOf(Constants.ROUTE_PROTOCOL + "://" + Constants.ANYHOST_VALUE + "/" + getService()
+ "?" + Constants.CATEGORY_KEY + "=" + Constants.ROUTERS_CATEGORY
- + "&router=condition&runtime=false&enabled=" + isEnabled() + "&priority=" + getPriority() + "&force=" + isForce() + "&dynamic=false"
- + "&name=" + getName() + "&" + Constants.RULE_KEY + "=" + URL.encode(getMatchRule() + " => " + getFilterRule())
- + (group == null ? "" : "&" + Constants.GROUP_KEY + "=" + group)
- + (version == null ? "" : "&" + Constants.VERSION_KEY + "=" + version));
+ + "&router=condition&runtime=false&enabled=" + isEnabled() + "&priority=" + getPriority() + "&force=" + isForce() + "&dynamic=" + isDynamic()
+ + "&name=" + getName() + "&" + Constants.RULE_KEY + "=" + URL.encode(getRule())
+ + (getGroup() == null ? "" : "&" + Constants.GROUP_KEY + "=" + getGroup())
+ + (getVersion() == null ? "" : "&" + Constants.VERSION_KEY + "=" + getVersion()));
}
}
diff --git a/dubbo-admin/dubbo-admin-frontend/src/components/RoutingRule.vue b/dubbo-admin/dubbo-admin-frontend/src/components/RoutingRule.vue
index 01b46ac..ab86275 100644
--- a/dubbo-admin/dubbo-admin-frontend/src/components/RoutingRule.vue
+++ b/dubbo-admin/dubbo-admin-frontend/src/components/RoutingRule.vue
@@ -88,23 +88,15 @@
</v-card-title>
<v-card-text >
<v-text-field
- placeholder="service:version or application, version is optional"
+ placeholder="service:version, version is optional"
required
- ref="scope"
- :rules="[() => !!scope || 'This field is required']"
- v-model="scope"
+ v-model="service"
></v-text-field>
<v-text-field
- placeholder="group, only effective on service"
- v-model="group"
+ placeholder="application name"
+ required
+ v-model="application"
></v-text-field>
- <!--<v-textarea-->
- <!--id="rule-content"-->
- <!--name="input-7-1"-->
- <!--box-->
- <!--:height="height"-->
- <!--:placeholder="placeholder"-->
- <!--></v-textarea>-->
<codemirror :placeholder='placeholder' :options="cmOption"></codemirror>
</v-card-text>
<v-card-actions>
@@ -131,8 +123,8 @@
pattern: 'Service',
filter: '',
dialog: false,
- group: '',
- scope: '',
+ application: '',
+ service: '',
height: 0,
routingRules: [
{