This is an automated email from the ASF dual-hosted git repository.

mjk pushed a commit to branch service-test
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo-ops.git


The following commit(s) were added to refs/heads/service-test by this push:
     new 833caa8  service test execute
833caa8 is described below

commit 833caa8a776ea4af5f033aae06450c3f552e4ecb
Author: Jinkai Ma <m...@vip.qq.com>
AuthorDate: Fri Dec 7 13:22:42 2018 +0800

    service test execute
---
 dubbo-admin-backend/pom.xml                        |   4 +
 .../admin/controller/ServiceTestController.java    |  16 ++-
 .../dubbo/admin/model/dto/ServiceTestDTO.java      |  40 +++++++
 .../admin/service/impl/GenericServiceImpl.java     |  42 +++++++
 .../src/components/ServiceTest.vue                 | 127 ++++++++++++++++-----
 .../src/components/public/JsonEditor.vue           |   1 +
 pom.xml                                            |  11 ++
 7 files changed, 210 insertions(+), 31 deletions(-)

diff --git a/dubbo-admin-backend/pom.xml b/dubbo-admin-backend/pom.xml
index 7986fbd..d2510ae 100644
--- a/dubbo-admin-backend/pom.xml
+++ b/dubbo-admin-backend/pom.xml
@@ -92,6 +92,10 @@
             </exclusions>
         </dependency>
         <dependency>
+            <groupId>org.apache.curator</groupId>
+            <artifactId>curator-recipes</artifactId>
+        </dependency>
+        <dependency>
             <groupId>com.alibaba</groupId>
             <artifactId>fastjson</artifactId>
         </dependency>
diff --git 
a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/ServiceTestController.java
 
b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/ServiceTestController.java
index dfe14c4..3ded7c2 100644
--- 
a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/ServiceTestController.java
+++ 
b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/controller/ServiceTestController.java
@@ -1,10 +1,20 @@
 package org.apache.dubbo.admin.controller;
 
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.apache.dubbo.admin.model.dto.ServiceTestDTO;
+import org.apache.dubbo.admin.service.impl.GenericServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
 
 @RestController
 @RequestMapping("/api/{env}/test")
 public class ServiceTestController {
-    
+
+    @Autowired
+    private GenericServiceImpl genericService;
+
+    @RequestMapping(method = RequestMethod.POST)
+    public Object test(@PathVariable String env, @RequestBody ServiceTestDTO 
serviceTestDTO) {
+        return genericService.invoke(serviceTestDTO.getService(), 
serviceTestDTO.getMethod(), serviceTestDTO.getTypes(), null);
+//        return null;
+    }
 }
diff --git 
a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/model/dto/ServiceTestDTO.java
 
b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/model/dto/ServiceTestDTO.java
new file mode 100644
index 0000000..7934e7c
--- /dev/null
+++ 
b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/model/dto/ServiceTestDTO.java
@@ -0,0 +1,40 @@
+package org.apache.dubbo.admin.model.dto;
+
+public class ServiceTestDTO {
+    private String service;
+    private String method;
+    private String[] types;
+    private String params;
+
+    public String getService() {
+        return service;
+    }
+
+    public void setService(String service) {
+        this.service = service;
+    }
+
+    public String getMethod() {
+        return method;
+    }
+
+    public void setMethod(String method) {
+        this.method = method;
+    }
+
+    public String[] getTypes() {
+        return types;
+    }
+
+    public void setTypes(String[] types) {
+        this.types = types;
+    }
+
+    public String getParams() {
+        return params;
+    }
+
+    public void setParams(String params) {
+        this.params = params;
+    }
+}
diff --git 
a/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/service/impl/GenericServiceImpl.java
 
b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/service/impl/GenericServiceImpl.java
new file mode 100644
index 0000000..6b6e748
--- /dev/null
+++ 
b/dubbo-admin-backend/src/main/java/org/apache/dubbo/admin/service/impl/GenericServiceImpl.java
@@ -0,0 +1,42 @@
+package org.apache.dubbo.admin.service.impl;
+
+import org.apache.dubbo.config.ApplicationConfig;
+import org.apache.dubbo.config.ReferenceConfig;
+import org.apache.dubbo.config.RegistryConfig;
+import org.apache.dubbo.registry.Registry;
+import org.apache.dubbo.rpc.service.GenericService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+
+@Component
+public class GenericServiceImpl {
+
+    private ReferenceConfig<GenericService> reference;
+
+    @Autowired
+    private Registry registry;
+
+    @PostConstruct
+    public void init() {
+        reference = new ReferenceConfig<>();
+        reference.setGeneric(true);
+
+        RegistryConfig registryConfig = new RegistryConfig();
+        registryConfig.setAddress(registry.getUrl().getProtocol() + "://" + 
registry.getUrl().getAddress());
+
+        ApplicationConfig applicationConfig = new ApplicationConfig();
+        applicationConfig.setName("dubbo-admin");
+        applicationConfig.setRegistry(registryConfig);
+
+        reference.setApplication(applicationConfig);
+    }
+
+    public Object invoke(String service, String method, String[] 
parameterTypes, Object[] params) {
+
+        reference.setInterface(service);
+        GenericService genericService = reference.get();
+        return genericService.$invoke(method, parameterTypes, params);
+    }
+}
diff --git a/dubbo-admin-frontend/src/components/ServiceTest.vue 
b/dubbo-admin-frontend/src/components/ServiceTest.vue
index d4711cd..b1f05b2 100644
--- a/dubbo-admin-frontend/src/components/ServiceTest.vue
+++ b/dubbo-admin-frontend/src/components/ServiceTest.vue
@@ -20,28 +20,55 @@
       <v-flex xs12>
         <search v-model="filter" label="Search by service name" 
:submit="search"></search>
       </v-flex>
+      <v-flex xs12>
+        <h3>Methods</h3>
+      </v-flex>
+      <v-flex xs12>
+        <v-data-table :headers="headers" :items="methods" hide-actions 
class="elevation-1">
+          <template slot="items" slot-scope="props">
+            <td>{{ props.item.name }}</td>
+            <td><v-chip xs v-for="(type, index) in props.item.parameterTypes" 
:key="index" label>{{ type }}</v-chip></td>
+            <td><v-chip label>{{ props.item.returnType }}</v-chip></td>
+            <td class="text-xs-right">
+              <v-tooltip bottom>
+                <v-icon small
+                        class="mr-2"
+                        color="blue"
+                        slot="activator"
+                        @click="toTest(props.item)">input</v-icon>
+                <span>Try it</span>
+              </v-tooltip>
+            </td>
+          </template>
+        </v-data-table>
+      </v-flex>
     </v-layout>
 
-    <v-card>
-      <v-card-text>
-        <v-layout row>
-          <v-flex xs6>
-            <v-data-table :headers="headers" :items="methods" hide-actions>
-              <template slot="items" slot-scope="props">
-                <td>
-                  <div>Name: {{ props.item.name }}</div>
-                  <div>Return: {{ props.item.returnType }}</div>
-                </td>
-                <td></td>
-              </template>
-            </v-data-table>
-          </v-flex>
-          <v-flex xs6>
-            <json-editor v-model="json" />
-          </v-flex>
-        </v-layout>
-      </v-card-text>
-    </v-card>
+    <v-dialog v-model="modal.enable" width="1000px" persistent>
+      <v-card>
+        <v-card-title>
+          <span class="headline">Test {{ modal.method }}</span>
+        </v-card-title>
+        <v-container grid-list-xl fluid>
+          <v-layout row>
+            <v-flex lg6>
+              <json-editor v-model="modal.json" />
+            </v-flex>
+            <v-flex lg6>
+            </v-flex>
+          </v-layout>
+        </v-container>
+        <v-card-actions>
+          <v-spacer></v-spacer>
+          <v-btn color="darken-1"
+                 flat
+                 @click="modal.enable = false">Close</v-btn>
+          <v-btn color="primary"
+                 depressed
+                 @click="test">Execute</v-btn>
+        </v-card-actions>
+      </v-card>
+    </v-dialog>
   </v-container>
 </template>
 
@@ -53,23 +80,37 @@
     name: 'ServiceTest',
     data () {
       return {
-        filter: null,
+        filter: 'org.apache.dubbo.demo.api.DemoService',
         headers: [
           {
-            text: 'Method',
-            value: 'name',
-            align: 'left'
+            text: 'Method Name',
+            value: 'method',
+            sortable: false
           },
           {
-            text: 'Operation',
+            text: 'Parameter List',
+            value: 'parameter',
+            sortable: false
+          },
+          {
+            text: 'Return Type',
+            value: 'returnType',
+            sortable: false
+          },
+          {
+            text: '',
             value: 'operation',
-            sortable: false,
-            width: '115px'
+            sortable: false
           }
         ],
         service: null,
         methods: [],
-        json: {}
+        modal: {
+          method: null,
+          enable: false,
+          types: null,
+          json: []
+        }
       }
     },
     methods: {
@@ -89,6 +130,36 @@
         }).catch(error => {
           this.showSnackbar('error', error.response.data.message)
         })
+      },
+      toTest (item) {
+        Object.assign(this.modal, {
+          enable: true,
+          method: item.name
+        })
+        this.modal.json = []
+        this.modal.types = item.parameterTypes
+        item.parameterTypes.forEach((i, index) => {
+          this.modal.json.push(this.getType(i))
+        })
+      },
+      test () {
+        this.$axios.post('/test', {
+          service: this.service.metadata.canonicalName,
+          method: this.modal.method,
+          types: this.modal.types,
+          params: JSON.stringify(this.modal.json)
+        }).then(response => {
+          console.log(response)
+        })
+      },
+      getType (type) {
+        if (type.indexOf('java.util.List') === 0) {
+          return []
+        } else if (type.indexOf('java.util.Map') === 0) {
+          return []
+        } else {
+          return ''
+        }
       }
     },
     components: {
diff --git a/dubbo-admin-frontend/src/components/public/JsonEditor.vue 
b/dubbo-admin-frontend/src/components/public/JsonEditor.vue
index 2891879..c4cbbf5 100644
--- a/dubbo-admin-frontend/src/components/public/JsonEditor.vue
+++ b/dubbo-admin-frontend/src/components/public/JsonEditor.vue
@@ -52,6 +52,7 @@
       const options = {
         name: 'Parameters',
         navigationBar: false,
+        search: false,
         mode: this.mode,
         modes: this.modes,
         onChange: () => {
diff --git a/pom.xml b/pom.xml
index c87b23f..e975680 100644
--- a/pom.xml
+++ b/pom.xml
@@ -109,6 +109,17 @@
                                <version>${curator-version}</version>
                        </dependency>
                        <dependency>
+                               <groupId>org.apache.curator</groupId>
+                               <artifactId>curator-recipes</artifactId>
+                               <version>${curator-version}</version>
+                               <exclusions>
+                                       <exclusion>
+                                               
<groupId>org.apache.zookeeper</groupId>
+                                               
<artifactId>zookeeper</artifactId>
+                                       </exclusion>
+                               </exclusions>
+                       </dependency>
+                       <dependency>
                                <groupId>com.alibaba</groupId>
                                <artifactId>fastjson</artifactId>
                                <version>${fastjson-version}</version>

Reply via email to