|
@ -5,12 +5,12 @@ import com.mongodb.client.MongoDatabase;
|
|
|
import com.yihu.hos.broker.configurations.MongoConfiguration;
|
|
|
import com.yihu.hos.broker.models.SystemCamelContext;
|
|
|
import com.yihu.hos.broker.models.SystemClassMapping;
|
|
|
import com.yihu.hos.web.framework.model.bo.ServiceFlow;
|
|
|
import com.yihu.hos.core.constants.CoreConstant;
|
|
|
import com.yihu.hos.core.datatype.ClassFileUtil;
|
|
|
import com.yihu.hos.core.datatype.StringUtil;
|
|
|
import com.yihu.hos.core.encrypt.DES;
|
|
|
import com.yihu.hos.web.framework.model.Result;
|
|
|
import com.yihu.hos.web.framework.model.bo.ServiceFlow;
|
|
|
import com.yihu.hos.web.framework.util.GridFSUtil;
|
|
|
import org.apache.camel.builder.RouteBuilder;
|
|
|
import org.apache.log4j.LogManager;
|
|
@ -55,6 +55,7 @@ public class ESBCamelService {
|
|
|
ServiceFlowValid serviceFlowValid = new ServiceFlowValid(msg).invoke();
|
|
|
if (serviceFlowValid.is()) return Result.error("必要的入参数据不正确,请检查!");
|
|
|
|
|
|
ServiceFlow serviceFlow = serviceFlowValid.getServiceFlow();
|
|
|
ServiceFlow.HandleFile handleFile = serviceFlowValid.getHandleFile();
|
|
|
boolean created;
|
|
|
if ("java".equals(handleFile.getFileType())) {
|
|
@ -66,7 +67,8 @@ public class ESBCamelService {
|
|
|
return Result.error("服务流程变更增加失败!");
|
|
|
}
|
|
|
|
|
|
this.startRouter(handleFile);
|
|
|
this.addRouter(handleFile);
|
|
|
this.startRouter(serviceFlow.getRouteCode());
|
|
|
|
|
|
return Result.error("服务流程变更增加成功!");
|
|
|
} catch (Exception e) {
|
|
@ -97,7 +99,8 @@ public class ESBCamelService {
|
|
|
|
|
|
this.stopRouter(serviceFlow.getRouteCode());
|
|
|
this.removeRouter(serviceFlow.getRouteCode());
|
|
|
this.startRouter(handleFile);
|
|
|
this.addRouter(handleFile);
|
|
|
this.startRouter(serviceFlow.getRouteCode());
|
|
|
|
|
|
return Result.error("服务流程变更增加成功!");
|
|
|
} catch (Exception e) {
|
|
@ -120,7 +123,8 @@ public class ESBCamelService {
|
|
|
SystemCamelContext.getContext().stopRoute(routeCode);
|
|
|
SystemCamelContext.getContext().removeRoute(routeCode);
|
|
|
this.deleteClassFile(handleFile);
|
|
|
this.startRouter(handleFile);
|
|
|
this.addRouter(handleFile);
|
|
|
this.startRouter(serviceFlow.getRouteCode());
|
|
|
|
|
|
return Result.success("服务流程变更减少成功!");
|
|
|
} catch (Exception e) {
|
|
@ -167,8 +171,12 @@ public class ESBCamelService {
|
|
|
if (!created) {
|
|
|
return Result.error("服务流程启动失败!");
|
|
|
}
|
|
|
|
|
|
this.addRouter(handleFile);
|
|
|
}
|
|
|
SystemCamelContext.getContext().startRoute(routeCode);
|
|
|
|
|
|
this.startRouter(serviceFlow.getRouteCode());
|
|
|
|
|
|
return Result.success("服务流程启动成功!");
|
|
|
} catch (Exception e) {
|
|
|
return Result.error("服务流程启动失败!");
|
|
@ -193,6 +201,9 @@ public class ESBCamelService {
|
|
|
}
|
|
|
|
|
|
private boolean createClassFile(ServiceFlow.HandleFile handleFile) throws Exception {
|
|
|
if (handleFile == null) {
|
|
|
return false;
|
|
|
}
|
|
|
SystemClassMapping.put(handleFile.getRouteCode(), handleFile.getPackageName(), handleFile.getClassName(), handleFile.getUsage());
|
|
|
URL resource = SystemClassMapping.getResource(this);
|
|
|
FileOutputStream outputStream = ClassFileUtil.createFile(resource, handleFile.getPackageName(), handleFile.getClassName(), ClassFileUtil.CLASS_FILE);
|
|
@ -200,10 +211,18 @@ public class ESBCamelService {
|
|
|
String fileName = DES.decrypt(handleFile.getFilePath(), DES.COMMON_PASSWORD);
|
|
|
MongoDatabase db = mongoConfig.mongoClient().getDatabase(dbName);
|
|
|
|
|
|
return GridFSUtil.readFile(db, outputStream, fileName);
|
|
|
boolean read = GridFSUtil.readFile(db, outputStream, fileName);
|
|
|
if (!read) {
|
|
|
logger.error("not mongo file, fileName:" + fileName);
|
|
|
}
|
|
|
|
|
|
return read;
|
|
|
}
|
|
|
|
|
|
private boolean generateClassFile(ServiceFlow.HandleFile handleFile) throws Exception {
|
|
|
if (handleFile == null) {
|
|
|
return false;
|
|
|
}
|
|
|
SystemClassMapping.put(handleFile.getRouteCode(), handleFile.getPackageName(), handleFile.getClassName(), handleFile.getUsage());
|
|
|
URL resource = SystemClassMapping.getResource(this);
|
|
|
FileOutputStream outputStream = ClassFileUtil.createFile(resource, handleFile.getPackageName(), handleFile.getClassName(), ClassFileUtil.JAVA_FILE);
|
|
@ -213,10 +232,12 @@ public class ESBCamelService {
|
|
|
|
|
|
boolean read = GridFSUtil.readFile(db, outputStream, fileName);
|
|
|
if (!read) {
|
|
|
logger.error("not mongo file, fileName:" + fileName);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
String sourcePath = ClassFileUtil.getFilePath(resource, handleFile.getPackageName(), handleFile.getClassName(), ClassFileUtil.JAVA_FILE);
|
|
|
logger.info(sourcePath);
|
|
|
return CamelCompiler.compile(sourcePath, resource.toString());
|
|
|
}
|
|
|
|
|
@ -237,7 +258,18 @@ public class ESBCamelService {
|
|
|
logger.info("===================" + handleFile.getPackageName() + CoreConstant.DOT + className + ".class 删除过程结束");
|
|
|
}
|
|
|
|
|
|
private void startRouter(ServiceFlow.HandleFile handleFile) throws Exception {
|
|
|
private void addRouter(ArrayList<ServiceFlow.HandleFile> handleFiles) throws Exception {
|
|
|
handleFiles.forEach(handleFile -> {
|
|
|
try {
|
|
|
addRouter(handleFile);
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage());
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
private void addRouter(ServiceFlow.HandleFile handleFile) throws Exception {
|
|
|
CamelClassLoader classLoader = new CamelClassLoader(CamelClassLoader.class.getClassLoader());
|
|
|
String path = ClassLoader.getSystemResource(CoreConstant.EMPTY).getPath();
|
|
|
String className = SystemClassMapping.get(handleFile.getRouteCode(), handleFile.getUsage(), handleFile.getClassName());
|
|
@ -248,6 +280,10 @@ public class ESBCamelService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void startRouter(String routeCode) throws Exception {
|
|
|
SystemCamelContext.getContext().startRoute(routeCode);
|
|
|
}
|
|
|
|
|
|
private void stopRouter(String routeCode) throws Exception {
|
|
|
SystemCamelContext.getContext().stopRoute(routeCode);
|
|
|
}
|