|
@ -1,6 +1,7 @@
|
|
|
package com.yihu.hos.arbiter.services;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.yihu.hos.arbiter.models.ArbiterServer;
|
|
|
import com.yihu.hos.arbiter.models.BrokerServer;
|
|
|
import com.yihu.hos.core.http.HTTPResponse;
|
|
|
import com.yihu.hos.core.http.HttpClientKit;
|
|
@ -33,13 +34,15 @@ import java.util.Map;
|
|
|
@Service("serviceFlowService")
|
|
|
public class ServiceFlowService {
|
|
|
private static final Logger logger = LogManager.getLogger(BrokerServerService.class);
|
|
|
|
|
|
@Autowired
|
|
|
private MongoOperations mongoOperations;
|
|
|
@Autowired
|
|
|
private ObjectMapper objectMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private BrokerServerService brokerServerService;
|
|
|
@Autowired
|
|
|
private ArbiterServerService arbiterServerService;
|
|
|
|
|
|
|
|
|
public void save(ServiceFlow serviceFlow) {
|
|
@ -76,17 +79,24 @@ public class ServiceFlowService {
|
|
|
return mongoOperations.findAll(ServiceFlow.class);
|
|
|
}
|
|
|
|
|
|
public String put(String serviceName, String ClientInfo) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* admin发过来的服务流程启动事件处理。
|
|
|
*
|
|
|
* @param msg serviceFlow
|
|
|
*/
|
|
|
public void serviceFlowStarted(String msg) {
|
|
|
flowController("post", "/esb/serviceFlow/start", msg);
|
|
|
}
|
|
|
|
|
|
// public void serviceFlowStarted(String msg, BrokerServer brokerServer) {
|
|
|
// flowController("post", "/esb/serviceFlow/start", msg, brokerServer);
|
|
|
// }
|
|
|
/**
|
|
|
* 没有使用重载,是因为Camel在判断路由时会产生歧义,而无法路由。
|
|
|
*
|
|
|
* @param msg serviceFlow
|
|
|
* @param brokerServer brokerServer Info
|
|
|
*/
|
|
|
public void serviceFlowStart(String msg, BrokerServer brokerServer) {
|
|
|
flowController("post", "/esb/serviceFlow/start", msg, brokerServer);
|
|
|
}
|
|
|
|
|
|
public void serviceFlowStopped(String msg) {
|
|
|
flowController("post", "/esb/serviceFlow/stop", msg);
|
|
@ -114,7 +124,7 @@ public class ServiceFlowService {
|
|
|
try {
|
|
|
BrokerServer brokerServer = objectMapper.readValue(msg, BrokerServer.class);
|
|
|
String serviceFlowMsg = objectMapper.writeValueAsString(serviceFlow);
|
|
|
serviceFlowStarted(serviceFlowMsg);
|
|
|
serviceFlowStart(serviceFlowMsg, brokerServer);
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@ -133,7 +143,11 @@ public class ServiceFlowService {
|
|
|
* @param header 消息头部信息
|
|
|
* @param msg 消息
|
|
|
*/
|
|
|
public void proxy(Map<String, Object> header, String msg) {
|
|
|
public void proxy(Map<String, String> header, String msg) {
|
|
|
String tenant = header.get("tenant");
|
|
|
ArbiterServer arbiterServer = arbiterServerService.get(tenant);
|
|
|
header.remove("tenant");
|
|
|
HttpClientKit.post(arbiterServer.getUrl(), msg, header);
|
|
|
}
|
|
|
|
|
|
private void flowController(String method, String path, String msg) {
|