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 aee9607 Change API to restful (#135)
aee9607 is described below
commit aee960790dcecf197bef4df6ade44654e73ff58b
Author: 马金凯 <[email protected]>
AuthorDate: Thu Oct 11 15:15:40 2018 +0800
Change API to restful (#135)
Examples: https://restfulapi.net/rest-api-design-tutorial-with-example/
---
.../dubbo/admin/controller/AccessesController.java | 31 ++++++++--------
.../src/components/governance/AccessControl.vue | 41 +++++++++-------------
dubbo-admin-frontend/src/components/http-common.js | 2 +-
3 files changed, 33 insertions(+), 41 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 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.Logger;
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.text.ParseException;
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 @@ public class AccessesController {
if (route != null) {
routes.add(route);
}
+ } else {
+ routes = routeService.findAllForceRoute();
}
for (Route route : routes) {
@@ -67,8 +68,8 @@ public class AccessesController {
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 class AccessesController {
}
}
- @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 class AccessesController {
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'
})