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/10/11 07:15:42 UTC

[GitHub] nzomkxia closed pull request #135: Change API to restful

nzomkxia closed pull request #135: Change API to restful
URL: https://github.com/apache/incubator-dubbo-ops/pull/135
 
 
   

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-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 12828c6..3e03aeb 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
@@ -20,7 +20,6 @@
 import com.alibaba.dubbo.common.logger.LoggerFactory;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.dubbo.admin.dto.AccessDTO;
-import org.apache.dubbo.admin.dto.BaseDTO;
 import org.apache.dubbo.admin.governance.service.RouteService;
 import org.apache.dubbo.admin.registry.common.domain.Route;
 import org.apache.dubbo.admin.registry.common.route.RouteRule;
@@ -31,15 +30,15 @@
 import java.util.*;
 
 @RestController
-@RequestMapping("/api/access")
+@RequestMapping("/api/{env}/rules/access")
 public class AccessesController {
     private static final Logger logger = LoggerFactory.getLogger(AccessesController.class);
 
     @Resource
     private RouteService routeService;
 
-    @RequestMapping(value = "/search", method = RequestMethod.GET)
-    public List<AccessDTO> searchAccess(@RequestParam(required = false) String service) throws ParseException {
+    @RequestMapping(method = RequestMethod.GET)
+    public List<AccessDTO> searchAccess(@RequestParam(required = false) String service, @PathVariable String env) throws ParseException {
         List<AccessDTO> result = new ArrayList<>();
         List<Route> routes = new ArrayList<>();
         if (StringUtils.isNotBlank(service)) {
@@ -47,6 +46,8 @@
             if (route != null) {
                 routes.add(route);
             }
+        } else {
+            routes = routeService.findAllForceRoute();
         }
 
         for (Route route : routes) {
@@ -67,8 +68,8 @@
         return result;
     }
 
-    @RequestMapping(value = "/detail", method = RequestMethod.GET)
-    public AccessDTO detailAccess(@RequestParam String id) throws ParseException {
+    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
+    public AccessDTO detailAccess(@PathVariable String id, @PathVariable String env) throws ParseException {
         Route route = routeService.findRoute(id);
         if (route.getName().endsWith(AccessDTO.KEY_BLACK_WHITE_LIST)) {
             AccessDTO accessDTO = new AccessDTO();
@@ -85,16 +86,16 @@ public AccessDTO detailAccess(@RequestParam String id) throws ParseException {
         }
     }
 
-    @RequestMapping(value = "/delete", method = RequestMethod.POST)
-    public void deleteAccess(@RequestBody BaseDTO baseDTO) {
-        if (baseDTO.getId() == null) {
+    @RequestMapping(value = "{id}", method = RequestMethod.DELETE)
+    public void deleteAccess(@PathVariable String id, @PathVariable String env) {
+        if (id == null) {
             throw new IllegalArgumentException("Argument of id is null!");
         }
-        routeService.deleteRoute(baseDTO.getId());
+        routeService.deleteRoute(id);
     }
 
-    @RequestMapping(value = "/create", method = RequestMethod.POST)
-    public void createAccess(@RequestBody AccessDTO accessDTO) {
+    @RequestMapping(method = RequestMethod.POST)
+    public void createAccess(@RequestBody AccessDTO accessDTO, @PathVariable String env) {
         if (StringUtils.isBlank(accessDTO.getService())) {
             throw new IllegalArgumentException("Service is required.");
         }
@@ -132,9 +133,9 @@ public void createAccess(@RequestBody AccessDTO accessDTO) {
         routeService.createRoute(route);
     }
 
-    @RequestMapping(value = "/update", method = RequestMethod.POST)
-    public void updateAccess(@RequestBody AccessDTO accessDTO) {
-        Route route = routeService.findRoute(accessDTO.getId());
+    @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
+    public void updateAccess(@PathVariable String id, @RequestBody AccessDTO accessDTO, @PathVariable String env) {
+        Route route = routeService.findRoute(id);
         Map<String, RouteRule.MatchPair> when = new HashMap<>();
         RouteRule.MatchPair matchPair = new RouteRule.MatchPair(new HashSet<>(), new HashSet<>());
         when.put(Route.KEY_CONSUMER_HOST, matchPair);
diff --git a/dubbo-admin-frontend/src/components/governance/AccessControl.vue b/dubbo-admin-frontend/src/components/governance/AccessControl.vue
index 8b9486c..905d5b4 100644
--- a/dubbo-admin-frontend/src/components/governance/AccessControl.vue
+++ b/dubbo-admin-frontend/src/components/governance/AccessControl.vue
@@ -21,7 +21,9 @@
     <v-layout row
               wrap>
       <v-flex xs12>
-        <search v-model="filter" :submit="submit" label="Search Access Controls by service name"></search>
+        <search v-model="filter"
+                :submit="search"
+                label="Search Access Controls by service name"></search>
       </v-flex>
     </v-layout>
 
@@ -136,7 +138,7 @@
 
 <script>
 import yaml from 'js-yaml'
-import { AXIOS } from '../http-common'
+import { AXIOS } from '@/components/http-common'
 import AceEditor from '@/components/public/AceEditor'
 import Search from '@/components/public/Search'
 
@@ -189,18 +191,15 @@ export default {
     }
   }),
   methods: {
-    submit () {
+    search () {
       if (this.filter == null) {
         this.filter = ''
       }
-      this.search(this.filter)
-    },
-    search (filter) {
       this.loading = true
-      this.$router.push({path: 'access', query: (filter !== '' ? {service: filter} : null)})
-      AXIOS.get('/access/search', {
+      this.$router.push({path: 'access', query: (this.filter !== '' ? {service: this.filter} : null)})
+      AXIOS.get('/rules/access', {
         params: {
-          service: filter
+          service: this.filter
         }
       }).then(response => {
         this.accesses = response.data
@@ -226,8 +225,8 @@ export default {
     },
     createItem () {
       let doc = yaml.load(this.modal.content)
-      this.filter = this.modal.service
-      AXIOS.post('/access/create', {
+      this.filter = ''
+      AXIOS.post('/rules/access', {
         service: this.modal.service,
         whitelist: doc.whitelist,
         blacklist: doc.blacklist
@@ -250,8 +249,7 @@ export default {
     },
     editItem () {
       let doc = yaml.load(this.modal.content)
-      AXIOS.post('/access/update', {
-        id: this.modal.id,
+      AXIOS.put('/rules/access/' + this.modal.id, {
         whitelist: doc.whitelist,
         blacklist: doc.blacklist
       }).then(response => {
@@ -269,9 +267,8 @@ export default {
       })
     },
     deleteItem (id) {
-      AXIOS.post('/access/delete', {
-        id: id
-      }).then(response => {
+      AXIOS.delete('/rules/access/' + id)
+      .then(response => {
         this.showSnackbar('success', 'Delete success')
         this.search(this.filter)
       }).catch(error => this.showSnackbar('error', error.response.data.message))
@@ -288,16 +285,10 @@ export default {
   },
   mounted () {
     let query = this.$route.query
-    let service = ''
-    Object.keys(query).forEach(function (key) {
-      if (key === 'service') {
-        service = query[key]
-      }
-    })
-    if (service !== '') {
-      this.filter = service
-      this.search(this.filter)
+    if ('service' in query) {
+      this.filter = query['service']
     }
+    this.search()
   },
   components: {
     AceEditor,
diff --git a/dubbo-admin-frontend/src/components/http-common.js b/dubbo-admin-frontend/src/components/http-common.js
index c9d86cd..5c44c9a 100644
--- a/dubbo-admin-frontend/src/components/http-common.js
+++ b/dubbo-admin-frontend/src/components/http-common.js
@@ -17,5 +17,5 @@
 import axios from 'axios'
 
 export const AXIOS = axios.create({
-  baseURL: 'http://localhost:8080/api'
+  baseURL: 'http://localhost:8080/api/dev'
 })


 

----------------------------------------------------------------
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