You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2018/09/10 08:35:22 UTC

[GitHub] nzomkxia closed pull request #104: Develop

nzomkxia closed pull request #104: Develop
URL: https://github.com/apache/incubator-dubbo-ops/pull/104
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 @@
 
     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 void setEnabled(boolean enabled) {
         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 String getRule() {
 
     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 String toString() {
     }
 
     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"-->
-          <!--&gt;</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: [
         {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org