Skip to content

Commit

Permalink
ok
Browse files Browse the repository at this point in the history
  • Loading branch information
upliveapp committed Mar 31, 2019
1 parent bb22c84 commit 3a6e0af
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*/.classpath
/*/.project
/*/.settings
/.classpath
/.project
/.settings
/jswitcher-api/target/
/jswitcher-service/target/
/jswitcher-cli/target/
Expand All @@ -11,4 +17,4 @@
/jswitcher-core/bin/target/
/jswitcher-sample/bin/target/
/jswitcher-spring-boot-starter/bin/target/
/jswitcher-ui/bin/target/
/jswitcher-ui/bin/target/
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class SwitcherController {

/**
* 开关列表
*
*
* @return 开关
*/
@GetMapping("keys")
Expand All @@ -78,10 +78,10 @@ public ResponseEntity<List<Map<String, Object>>> keys() {

/**
* 获取开关列表
*
*
* @return 开关列表
*/
private List<Map<String, Object>> getKeys () {
private List<Map<String, Object>> getKeys() {
try {
List<Endpoint> endpoints = discoveryService.query(SwitcherService.class.getTypeName());
if (endpoints == null || endpoints.isEmpty()) {
Expand All @@ -102,6 +102,29 @@ private List<Map<String, Object>> getKeys () {
keys.add(v0);
});
}
Collections.sort(keys, (Map<String, Object> o1, Map<String, Object> o2) -> {
String application1 = String.valueOf(o1.get("application"));
String application2 = String.valueOf(o2.get("application"));
if (!application1.equalsIgnoreCase(application2)) {
return application1.compareTo(application2);
}
String key1 = String.valueOf(o1.get("key"));
String key2 = String.valueOf(o2.get("key"));
if (!key1.equalsIgnoreCase(key2)) {
return key1.compareTo(key2);
}
String host1 = String.valueOf(o1.get("host"));
String host2 = String.valueOf(o2.get("host"));
if (!host1.equalsIgnoreCase(host2)) {
return host1.compareTo(host2);
}
String port1 = String.valueOf(o1.get("port"));
String port2 = String.valueOf(o2.get("port"));
if (!port1.equalsIgnoreCase(port2)) {
return port1.compareTo(port2);
}
return 0;
});
return keys;
} catch (Throwable e) {
LOGGER.error(e.getMessage());
Expand All @@ -111,7 +134,7 @@ private List<Map<String, Object>> getKeys () {

/**
* 开关列表
*
*
* @return 开关
*/
@GetMapping("tree")
Expand Down Expand Up @@ -191,12 +214,12 @@ public ResponseEntity<List<Switcher>> endpointKeys(@PathVariable String host, @P

/**
* 开关列表
*
*
* @param host 主机
* @param port 端口
* @return 开关列表
*/
private List<Switcher> getKeysByHostAndPort (String host, Integer port) {
private List<Switcher> getKeysByHostAndPort(String host, Integer port) {
StringBuilder method = new StringBuilder();
method.append(SwitcherService.class.getTypeName())
.append('.')
Expand Down

0 comments on commit 3a6e0af

Please sign in to comment.