-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
bd66562
commit c738f53
Showing
12 changed files
with
357 additions
and
46 deletions.
There are no files selected for viewing
41 changes: 19 additions & 22 deletions
41
...-governance/src/main/java/com/webank/weevent/governance/controller/ForwardController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,45 @@ | ||
package com.webank.weevent.governance.controller; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import com.webank.weevent.governance.exception.GovernanceException; | ||
import com.webank.weevent.governance.service.CommonService; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.http.client.methods.CloseableHttpResponse; | ||
import org.apache.http.util.EntityUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.web.bind.annotation.CrossOrigin; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.client.RestTemplate; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@CrossOrigin | ||
@Slf4j | ||
@RestController | ||
public class ForwardController { | ||
|
||
|
||
@Autowired | ||
private RestTemplate restTemplate; | ||
private CommonService commonService; | ||
|
||
@Value("${weevent.url}") | ||
private String url; | ||
|
||
@RequestMapping(value = "/weevent/{path1}/{path2}", method = RequestMethod.GET) | ||
public Object forward(@PathVariable(name = "path1") String path1, @PathVariable(name = "path2") String path2) { | ||
public Object forward(HttpServletRequest request, HttpServletResponse response, @PathVariable(name = "path1") String path1, @PathVariable(name = "path2") String path2)throws GovernanceException { | ||
log.info("weevent url: /wevent/ {} \"/\" {}", path1, path2); | ||
String forwarUrl = new StringBuffer(this.url).append("/").append(path1).append("/").append(path2).toString(); | ||
Object result = restTemplate.getForEntity(forwarUrl, Object.class).getBody(); | ||
return result; | ||
try { | ||
CloseableHttpResponse closeResponse = commonService.getCloseResponse(request, forwarUrl); | ||
return EntityUtils.toString(closeResponse.getEntity()); | ||
} catch (Exception e) { | ||
throw new GovernanceException(e.getMessage()); | ||
} | ||
} | ||
|
||
@RequestMapping(value = "/weevent/admin/deploy_topic_control", method = RequestMethod.GET) | ||
public Object forward() { | ||
log.info("wevent url: /weevent/admin/deploy_topic_control"); | ||
String forwarUrl = new StringBuffer(this.url).append("/admin/deploy_topic_control").toString(); | ||
String result = restTemplate.getForEntity(forwarUrl, String.class).getBody(); | ||
return result; | ||
} | ||
|
||
@RequestMapping(value = "/weevent/{path1}/{path2}") | ||
public Object forward(@PathVariable(name = "path1") String path1, @PathVariable(name = "path2") String path2, | ||
@RequestParam String topic) { | ||
log.info("weevent url: /wevent/ {} \"/\" {}", path1, path2); | ||
|
||
String forwarUrl = new StringBuffer(this.url).append("/").append(path1).append("/").append(path2).append("?topic=").append(topic).toString(); | ||
Object result = restTemplate.getForEntity(forwarUrl, Object.class).getBody(); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
weevent-governance/src/main/java/com/webank/weevent/governance/utils/DAGDetectUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.webank.weevent.governance.utils; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.Stack; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
@SuppressWarnings("unchecked") | ||
@Component | ||
public class DAGDetectUtil { | ||
private Stack<String> stack = new Stack<>(); | ||
|
||
public boolean checkLoop(Map<String, Set<String>> map, Set<String> topicSet) { | ||
Map start = createNode("start"); | ||
Map<String, Map> nodeMap = new HashMap<>(); | ||
topicSet.forEach(it -> { | ||
Map node = createNode(it); | ||
((List) start.get("child")).add(node); | ||
nodeMap.put(it, node); | ||
}); | ||
map.forEach((k, v) -> { | ||
v.forEach(it -> { | ||
if (nodeMap.containsKey(it)) { | ||
((List) nodeMap.get(k).get("child")).add(nodeMap.get(it)); | ||
} | ||
}); | ||
}); | ||
return checkChild(start); | ||
} | ||
|
||
private Map createNode(String name) { | ||
HashMap node = new HashMap(); | ||
node.put("topic", name); | ||
node.put("child", new ArrayList()); | ||
return node; | ||
} | ||
|
||
|
||
private boolean checkChild(Map cursor) { | ||
if (stack.contains(cursor.get("topic"))) { | ||
stack = new Stack<>(); | ||
return false; | ||
} | ||
stack.push((String) cursor.get("topic")); | ||
List childs = (List) cursor.get("child"); | ||
if (childs != null) { | ||
for (Object child : childs) { | ||
if (!checkChild((Map) child)) { | ||
return false; | ||
} | ||
} | ||
} | ||
stack.pop(); | ||
return true; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.