Browse Source

任务配置修改生成camel文件逻辑修改

demon 8 years ago
parent
commit
f7ea1771e5

+ 10 - 0
hos-arbiter/src/main/java/com/yihu/hos/arbiter/models/ServiceFlow.java

@ -16,6 +16,16 @@ public class ServiceFlow {
    private String path;
    private String path;
    private Date updateTime;
    private Date updateTime;
    private String cron;
    public String getCron() {
        return cron;
    }
    public void setCron(String cron) {
        this.cron = cron;
    }
    public String getEvent() {
    public String getEvent() {
        return event;
        return event;
    }
    }

+ 23 - 0
hos-arbiter/src/main/java/com/yihu/hos/arbiter/services/ServiceFlowService.java

@ -61,6 +61,7 @@ public class ServiceFlowService {
            nameValuePairList.add(new BasicNameValuePair("packageName", serviceFlow.getPackageName()));
            nameValuePairList.add(new BasicNameValuePair("packageName", serviceFlow.getPackageName()));
            nameValuePairList.add(new BasicNameValuePair("className", serviceFlow.getClassName()));
            nameValuePairList.add(new BasicNameValuePair("className", serviceFlow.getClassName()));
            nameValuePairList.add(new BasicNameValuePair("path", serviceFlow.getPath()));
            nameValuePairList.add(new BasicNameValuePair("path", serviceFlow.getPath()));
            nameValuePairList.add(new BasicNameValuePair("cron", serviceFlow.getCron()));
            CloseableHttpClient httpclient = HttpClients.createDefault();
            CloseableHttpClient httpclient = HttpClients.createDefault();
            switch (serviceFlow.getEvent()) {
            switch (serviceFlow.getEvent()) {
@ -116,6 +117,28 @@ public class ServiceFlowService {
                    break;
                    break;
                }
                }
                case "routeClassAdded": {
                    HttpPost httpPost = new HttpPost(brokerServer.getURL()  + "/esb/genRoute");
                    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairList, Consts.UTF_8));
                    CloseableHttpResponse response = httpclient.execute(httpPost);
                    response.close();
                    break;
                }
                case "routeClassChanged": {
                    HttpPut httpPut = new HttpPut(brokerServer.getURL() + "/esb/updateRoute");
                    httpPut.setEntity(new UrlEncodedFormEntity(nameValuePairList, Consts.UTF_8));
                    CloseableHttpResponse response = httpclient.execute(httpPut);
                    response.close();
                    break;
                }
                case "processorClassAdded": {
                    HttpPost httpPost = new HttpPost(brokerServer.getURL()+ "/esb/genProcessor");
                    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairList, Consts.UTF_8));
                    CloseableHttpResponse response = httpclient.execute(httpPost);
                    response.close();
                    break;
                }
                default:
                default:
                    break;
                    break;
            }
            }

+ 38 - 144
hos-broker/src/main/java/com/yihu/hos/common/compiler/CamelCompiler.java

@ -2,7 +2,10 @@
package com.yihu.hos.common.compiler;
package com.yihu.hos.common.compiler;
import com.yihu.hos.common.constants.BrokerConstant;
import com.yihu.hos.core.file.FileUtil;
import com.yihu.hos.core.file.FileUtil;
import com.yihu.hos.models.SystemClassMapping;
import org.apache.commons.io.FileUtils;
import javax.tools.*;
import javax.tools.*;
import java.io.File;
import java.io.File;
@ -27,20 +30,18 @@ public class CamelCompiler {
    /**
    /**
     * 编译java文件
     * 编译java文件
     * @param packageName     java包路径
     * @param oldClassName   旧java文件名
     * @param newClassName   新java文件名
     * @param newCron         新cron表达式
     * @param params     java包路径
     * @throws IOException
     * @throws IOException
     */
     */
    public static String compiler(String filePath,String packageName,String oldClassName,String newClassName,String newCron) throws IOException {
    public static String compiler(ClassParams params) throws IOException {
        String classPath = CamelCompiler.class.getProtectionDomain().getCodeSource().getLocation().getPath() ;
        String classPath = CamelCompiler.class.getProtectionDomain().getCodeSource().getLocation().getPath() ;
        String toClassPath = params.getFilePath().replace(".java",".class");
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        // 建立DiagnosticCollector对象
        // 建立DiagnosticCollector对象
        DiagnosticCollector diagnostics = new DiagnosticCollector();
        DiagnosticCollector diagnostics = new DiagnosticCollector();
        StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null,  Charset.forName("UTF-8"));
        StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null,  Charset.forName("UTF-8"));
        // 建立源文件对象,每个文件被保存在一个从JavaFileObject继承的类中
        // 建立源文件对象,每个文件被保存在一个从JavaFileObject继承的类中
        File file = genNewJava(filePath,packageName, oldClassName,newClassName, newCron);
        File file = genNewJava(params);
        if (file!=null){
        if (file!=null){
            Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjects(file.getAbsolutePath());
            Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjects(file.getAbsolutePath());
            // options命令行选项
            // options命令行选项
@ -52,95 +53,96 @@ public class CamelCompiler {
            fileManager.close();
            fileManager.close();
            System.out.println((success) ? "编译成功" : "编译失败");
            System.out.println((success) ? "编译成功" : "编译失败");
            if (!success){
            if (!success){
                //错误信息打印
                List diagnostics1 = diagnostics.getDiagnostics();
                List diagnostics1 = diagnostics.getDiagnostics();
                for (int i=0;i<diagnostics1.size();i++){
                for (int i=0;i<diagnostics1.size();i++){
                    System.out.println(diagnostics1.get(i).toString());
                    System.out.println(diagnostics1.get(i).toString());
                }
                }
                return null;
                return null;
            }else {
            }else {
                //添加加载类
                String dotPackageName = params.getPackageName().replace("/",".");
                SystemClassMapping.getSystemClassNameMapping().put(params.getRouteId() + BrokerConstant.ROUTE + params.getNewClassName(),dotPackageName  + params.getNewClassName());
                String className = file.getName().replace(".java", ".class");
                String className = file.getName().replace(".java", ".class");
                classPath = classPath.substring(1);
                classPath = classPath.substring(1);
                return classPath  + packageName  + className;
                String oldClassPath = classPath  + params.getPackageName()  + className;
                File oldClassFile = new File(oldClassPath);
                FileUtils.copyFile(oldClassFile,new File(toClassPath));
                return toClassPath;
            }
            }
        }
        }
        return null;
        return null;
    }
    }
    public static String copyProcess (String filePath,String packageName,String oldClassName) throws IOException {
    public static String copyProcess (String routeId ,String filePath,String packageName,String oldClassName) throws IOException {
        String classPath = CamelCompiler.class.getProtectionDomain().getCodeSource().getLocation().getPath() ;
        String classPath = CamelCompiler.class.getProtectionDomain().getCodeSource().getLocation().getPath() ;
        String newPath = String.format(classPathTemplate, packageName, oldClassName);
        String toClassPath = filePath.replace(".java",".class");
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        // 建立DiagnosticCollector对象
        // 建立DiagnosticCollector对象
        DiagnosticCollector diagnostics = new DiagnosticCollector();
        DiagnosticCollector diagnostics = new DiagnosticCollector();
        StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null,  Charset.forName("UTF-8"));
        StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null,  Charset.forName("UTF-8"));
        // 建立源文件对象,每个文件被保存在一个从JavaFileObject继承的类中
        // 建立源文件对象,每个文件被保存在一个从JavaFileObject继承的类中
//        File file = new File(filePath);
//        File toFIle = new File(newPath);
        String text = FileUtil.readFileText(new File(filePath));
        File fPath = new File(packagePathTemplate+packageName);
        File fPath = new File(packagePathTemplate+packageName);
        if (!fPath.exists()) fPath.mkdirs();
        if (!fPath.exists()) fPath.mkdirs();
        File toFIle = genProcessor(filePath,packageName,oldClassName);
        File toFIle = genProcessor(filePath,packageName,oldClassName);
        if (toFIle.exists()){
        if (toFIle.exists()){
            if (!toFIle.getParentFile().exists()) toFIle.getParentFile().mkdirs();
            //复制
//            FileUtils.copyFile(file, toFIle);
            if (toFIle!=null){
                Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjects(toFIle.getAbsolutePath());
                Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjects(toFIle.getAbsolutePath());
                // options命令行选项
                // options命令行选项
                Iterable<String> options = Arrays.asList("-d",classPath,"-sourcepath", classPath);// 指定的路径一定要存在,javac不会自己创建文件夹
                Iterable<String> options = Arrays.asList("-d",classPath,"-sourcepath", classPath);// 指定的路径一定要存在,javac不会自己创建文件夹
                JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, options, null, compilationUnits);
                JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, options, null, compilationUnits);
                // 编译源程序
                // 编译源程序
                boolean success = task.call();
                boolean success = task.call();
                fileManager.close();
                System.out.println((success) ? "编译成功" : "编译失败");
                if (!success){
                System.out.println((success) ? oldClassName+"编译成功" : "编译失败");
            fileManager.close();
            if (!success){
                    List diagnostics1 = diagnostics.getDiagnostics();
                    List diagnostics1 = diagnostics.getDiagnostics();
                    for (int i=0;i<diagnostics1.size();i++){
                    for (int i=0;i<diagnostics1.size();i++){
                        System.out.println(diagnostics1.get(i).toString());
                        System.out.println(diagnostics1.get(i).toString());
                    }
                    }
                    return null;
                    return null;
                }else {
                }else {
                String dotPackageName = packageName.replace("/", ".");
                SystemClassMapping.getSystemClassNameMapping().put(routeId+ BrokerConstant.PROCESSOR + oldClassName,dotPackageName  + oldClassName);
                    String resultPath = toFIle.getName().replace(".java", ".class");
                    String resultPath = toFIle.getName().replace(".java", ".class");
                    classPath = classPath.substring(1);
                    classPath = classPath.substring(1);
                    return classPath + packageName  + resultPath;
                     String oldClassPath = classPath + packageName  + resultPath;
                File classFile = new File(oldClassPath);
                FileUtils.copyFile(classFile,new File(toClassPath));
                    return toClassPath;
                }
                }
            }else {
                return null;
            }
        }
        }
        System.out.println("生成processor的java文件失败");
        return null;
        return null;
    }
    }
    /**
    /**
     *  修改cron表达式,生成新java文件
     *  修改cron表达式,生成新java文件
     * @param packageName   包名
     * @param oldClassName  旧类名
     * @param newClassName  新类名
     * @param newContent    新cron表达式
     * @param params   生成camel的参数
     */
     */
    public static File genNewJava(String filePath,String packageName, String oldClassName,String newClassName, String newContent) {
    public static File genNewJava(ClassParams params) {
        try {
        try {
//            String oldPath = String.format(classPathTemplate, packageName, oldClassName);
//            String oldPath = String.format(classPathTemplate, packageName, oldClassName);
            String newPath = String.format(classPathTemplate, packageName, newClassName);
            String newPath = String.format(classPathTemplate, params.getPackageName(), params.getOldClassName()+params.getRouteId());
            String text = FileUtil.readFileText(new File(filePath));
            String text = FileUtil.readFileText(new File(params.getFilePath()));
            if (text.contains("?cron=")){
            if (text.contains("?cron=")){
                String oldStr = text.substring(text.indexOf("?cron=")+6);
                String oldStr = text.substring(text.indexOf("?cron=")+6);
                String cron = oldStr.substring(0,oldStr.indexOf("\""));
                String cron = oldStr.substring(0,oldStr.indexOf("\""));
                text = text.replace(cron,newContent);
                text = text.replace(cron,params.getCron());
            }
            }
            if (text.contains(oldClassName)){
                text = text.replace(oldClassName,newClassName);
            if (text.contains(params.getOldClassName())){
                text = text.replace(params.getOldClassName(), params.getNewClassName());
            }
            }
            //修改routeId;模板规则 routeId("routeId")
            text = text.replace("routeId(\"routeId\")","routeId(\""+params.getRouteId() +"\")" );
            File fPath = new File(packagePathTemplate+packageName);
            File fPath = new File(packagePathTemplate+params.getPackageName());
            if (!fPath.exists()) fPath.mkdirs();
            if (!fPath.exists()) fPath.mkdirs();
            File f = new File(newPath);
            File f = new File(newPath);
@ -160,9 +162,7 @@ public class CamelCompiler {
    public static File genProcessor(String filePath,String packageName,String newClassName) {
    public static File genProcessor(String filePath,String packageName,String newClassName) {
        try {
        try {
//            String oldPath = String.format(classPathTemplate, packageName, oldClassName);
            String newPath = String.format(classPathTemplate, packageName, newClassName);
            String newPath = String.format(classPathTemplate, packageName, newClassName);
            String text = FileUtil.readFileText(new File(filePath));
            String text = FileUtil.readFileText(new File(filePath));
            File fPath = new File(packagePathTemplate+packageName);
            File fPath = new File(packagePathTemplate+packageName);
@ -183,110 +183,4 @@ public class CamelCompiler {
    }
    }
    public static void compiler2(String packageName,String className) throws IOException {
        String classPath = CamelCompiler.class.getProtectionDomain().getCodeSource().getLocation().getPath() ;
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        // 建立DiagnosticCollector对象
        DiagnosticCollector diagnostics = new DiagnosticCollector();
        StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
        // 建立源文件对象,每个文件被保存在一个从JavaFileObject继承的类中
        Iterable compilationUnits = fileManager.getJavaFileObjects(String.format(classPathTemplate, packageName, className));
        // options命令行选项
        // 指定的路径一定要存在,javac不会自己创建文件夹
        Iterable<String> options = Arrays.asList(  "-d", classPath);
        JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, options, null, compilationUnits);
        // 编译源程序
        boolean success = task.call();
        if (!success){
            List diagnostics1 = diagnostics.getDiagnostics();
            for (int i=0;i<diagnostics1.size();i++){
                System.out.println(diagnostics1.get(i).toString());
            }
        }
        fileManager.close();
        System.out.println((success) ? "编译成功" : "编译失败");
    }
    public static String compiler3(String filePath,String packageName,String oldClassName,String newClassName,String newCron) throws IOException {
        String classPath = CamelCompiler.class.getProtectionDomain().getCodeSource().getLocation().getPath() ;
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        // 建立DiagnosticCollector对象
        DiagnosticCollector diagnostics = new DiagnosticCollector();
        StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
        // 建立源文件对象,每个文件被保存在一个从JavaFileObject继承的类中
        File file = genNewJava(filePath,packageName, oldClassName,newClassName, newCron);
        if (file!=null){
            Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjects(file.getAbsolutePath());
            // options命令行选项
            Iterable<String> options = Arrays.asList("-d",classPath);// 指定的路径一定要存在,javac不会自己创建文件夹
            JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, options, null, compilationUnits);
            fileManager.close();
            // 编译源程序
            boolean success = task.call();
            System.out.println((success) ? "编译成功" : "编译失败");
            if (!success){
                List diagnostics1 = diagnostics.getDiagnostics();
                for (int i=0;i<diagnostics1.size();i++){
                    System.out.println(diagnostics1.get(i).toString());
                }
                return null;
            }else {
                String className = file.getName().replace(".java", ".class");
                return classPath  + packageName  + className;
            }
        }else{
            return null;
        }
    }
    public static void copyCompiler (String filePath,String packageName,String oldClassName) throws IOException {
        String classPath = "D:\\" ;
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        // 建立DiagnosticCollector对象
        DiagnosticCollector diagnostics = new DiagnosticCollector();
        StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
        // 建立源文件对象,每个文件被保存在一个从JavaFileObject继承的类中
        File file = new File(filePath);
        if (file.exists()){
            Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjects(file.getAbsolutePath());
            // options命令行选项
            Iterable<String> options = Arrays.asList("-d",classPath);// 指定的路径一定要存在,javac不会自己创建文件夹
            JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, options, null, compilationUnits);
            // 编译源程序
            boolean success = task.call();
            if (!success){
                List diagnostics1 = diagnostics.getDiagnostics();
                for (int i=0;i<diagnostics1.size();i++){
                    System.out.println(diagnostics1.get(i).toString());
                }
            }
            fileManager.close();
            System.out.println((success) ? "编译成功" : "编译失败");
        }
    }
    public static void main(String[] args) {
        try {
//            copyCompiler("E:\\crawler\\processor\\Processor0.java", "/crawler/processor", "Processor0");
//            copyCompiler("E:\\crawler\\route\\QuartzRoute.java","/crawler/route", "QuartzRoute");
//            copyProcess("E:\\crawler\\processor\\Processor0.java", "/crawler/processor", "Processor0");
           String classPath=  compiler3("E:\\crawler\\route\\QuartzRoute.java","/crawler/route", "QuartzRoute","QuartzRoute1479","textxtxt");
            String text = FileUtil.readFileText(new File(classPath));
            System.out.println(text);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
}

+ 66 - 0
hos-broker/src/main/java/com/yihu/hos/common/compiler/ClassParams.java

@ -0,0 +1,66 @@
package com.yihu.hos.common.compiler;
/**
 *  请求参数封装类-(camel文件生成)
 * @author HZY
 * @vsrsion 1.0
 * Created at 2016/11/25.
 */
public class ClassParams {
    private String routeId;             //routeId
    private String filePath;            //原java文件路径
    private String packageName;        //包名
    private String oldClassName;      //旧java文件名
    private String newClassName;      //新java文件名
    private String cron;               //新cron表达式
    public String getRouteId() {
        return routeId;
    }
    public void setRouteId(String routeId) {
        this.routeId = routeId;
    }
    public String getFilePath() {
        return filePath;
    }
    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }
    public String getPackageName() {
        return packageName;
    }
    public void setPackageName(String packageName) {
        this.packageName = packageName;
    }
    public String getOldClassName() {
        return oldClassName;
    }
    public void setOldClassName(String oldClassName) {
        this.oldClassName = oldClassName;
    }
    public String getNewClassName() {
        return newClassName;
    }
    public void setNewClassName(String newClassName) {
        this.newClassName = newClassName;
    }
    public String getCron() {
        return cron;
    }
    public void setCron(String cron) {
        this.cron = cron;
    }
}

+ 3 - 3
hos-broker/src/main/java/com/yihu/hos/common/listener/ApplicationStartListener.java

@ -82,7 +82,7 @@ public class ApplicationStartListener implements ApplicationListener<ContextRefr
                    Boolean flag = ClassFileUtil.createClassfile(systemClassFlowPath.toURI().toURL(), packageName, className, classPath);
                    Boolean flag = ClassFileUtil.createClassfile(systemClassFlowPath.toURI().toURL(), packageName, className, classPath);
                    // 记录到工具类中,以便其它线程需要时进行取用
                    // 记录到工具类中,以便其它线程需要时进行取用
                    if (flag) {
                    if (flag) {
                        SystemClassMapping.getSystemClassNameMapping().put(code + BrokerConstant.PROCESSOR, packageName + CoreConstant.DOT + className);
                        SystemClassMapping.getSystemClassNameMapping().put(code + BrokerConstant.PROCESSOR+className, packageName + CoreConstant.DOT + className);
                    } else {
                    } else {
                        isCorrectClassMap.put(code, flag);
                        isCorrectClassMap.put(code, flag);
                    }
                    }
@ -98,14 +98,14 @@ public class ApplicationStartListener implements ApplicationListener<ContextRefr
                    Boolean flag =ClassFileUtil.createClassfile(systemClassFlowPath.toURI().toURL(), packageName, className, classPath);
                    Boolean flag =ClassFileUtil.createClassfile(systemClassFlowPath.toURI().toURL(), packageName, className, classPath);
                    // 记录到工具类中,以便其它线程需要时进行取用
                    // 记录到工具类中,以便其它线程需要时进行取用
                    if (flag) {
                    if (flag) {
                        SystemClassMapping.getSystemClassNameMapping().put(code + BrokerConstant.ROUTE, packageName + CoreConstant.DOT + className);
                        SystemClassMapping.getSystemClassNameMapping().put(code + BrokerConstant.ROUTE+className, packageName + CoreConstant.DOT + className);
                    } else {
                    } else {
                        isCorrectClassMap.put(code, flag);
                        isCorrectClassMap.put(code, flag);
                    }
                    }
                    if (isCorrectClassMap.get(code)) {
                    if (isCorrectClassMap.get(code)) {
                        ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
                        ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
                        try {
                        try {
                            Class<RouteBuilder> routeBuilderClass = (Class<RouteBuilder>) currentClassLoader.loadClass(SystemClassMapping.getSystemClassNameMapping().get(code + BrokerConstant.ROUTE));
                            Class<RouteBuilder> routeBuilderClass = (Class<RouteBuilder>) currentClassLoader.loadClass(SystemClassMapping.getSystemClassNameMapping().get(code + BrokerConstant.ROUTE+className));
                            if (routeBuilderClass != null) {
                            if (routeBuilderClass != null) {
                                RouteBuilder routeBuilder = routeBuilderClass.newInstance();
                                RouteBuilder routeBuilder = routeBuilderClass.newInstance();
                                alreadyRouteBuilders.add(routeBuilder);
                                alreadyRouteBuilders.add(routeBuilder);

+ 57 - 26
hos-broker/src/main/java/com/yihu/hos/controllers/ESBCamelController.java

@ -1,5 +1,6 @@
package com.yihu.hos.controllers;
package com.yihu.hos.controllers;
import com.yihu.hos.common.compiler.ClassParams;
import com.yihu.hos.services.ESBCamelService;
import com.yihu.hos.services.ESBCamelService;
import com.yihu.hos.web.framework.model.Result;
import com.yihu.hos.web.framework.model.Result;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperation;
@ -119,42 +120,72 @@ public class ESBCamelController {
        return esbCamelService.onRouteDefineStop(serviceFlow);
        return esbCamelService.onRouteDefineStop(serviceFlow);
    }
    }
    @RequestMapping(value = "/genRoute", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "生成新的route文件", produces = "application/json", notes = "生成新的camel文件")
    public Result genRoute(
            @ApiParam(name = "serviceFlow", value = "服务名称", required = true)
            @RequestParam(value = "serviceFlow",required = true) String serviceFlow,
            @ApiParam(name = "path", value = "文件路径", required = true)
            @RequestParam(value = "path",required = true) String path,
            @ApiParam(name = "packageName", value = "包名", required = true)
            @RequestParam(value = "packageName") String packageName,
            @ApiParam(name = "className", value = "类名", required = true)
            @RequestParam(value = "className") String className,
            @ApiParam(name = "cron", value = "新cron表达式", required = true)
            @RequestParam(value = "cron") String cron) {
        ClassParams params = new ClassParams();
        params.setRouteId(serviceFlow);
        params.setPackageName(packageName);
        params.setFilePath(path);
        params.setOldClassName(className);
        params.setNewClassName(className+serviceFlow);
        params.setCron(cron);
        return esbCamelService.onRouteClassAdded(params);
    }
    @RequestMapping(value = "/genCamelFile", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    @RequestMapping(value = "/updateRoute", produces = "application/json;charset=UTF-8", method = RequestMethod.PUT)
    @ResponseBody
    @ResponseBody
    @ApiOperation(value = "生成新的camel文件", produces = "application/json", notes = "生成新的camel文件")
    public Result genCamelFile(
            @ApiParam(name = "type", value = "camel文件类型,route;processor", required = false)
            @RequestParam(value = "type",required = false) String type,
            @ApiParam(name = "filePath", value = "文件路径", required = false)
            @RequestParam(value = "filePath",required = false) String filePath,
    @ApiOperation(value = "修改route文件", produces = "application/json", notes = "生成新的camel文件")
    public Result updateRoute(
            @ApiParam(name = "serviceFlow", value = "服务名称", required = true)
            @RequestParam(value = "serviceFlow",required = true) String serviceFlow,
            @ApiParam(name = "path", value = "文件路径", required = true)
            @RequestParam(value = "path",required = true) String path,
            @ApiParam(name = "packageName", value = "包名", required = true)
            @ApiParam(name = "packageName", value = "包名", required = true)
            @RequestParam(value = "packageName") String packageName,
            @RequestParam(value = "packageName") String packageName,
            @ApiParam(name = "oldClassName", value = "旧类名", required = true)
            @RequestParam(value = "oldClassName") String oldClassName,
            @ApiParam(name = "newClassName", value = "新类名", required = true)
            @RequestParam(value = "newClassName") String newClassName,
            @ApiParam(name = "newCron", value = "新cron表达式", required = true)
            @RequestParam(value = "newCron") String newCron) {
        return esbCamelService.genNewClassfile(type,filePath, packageName, oldClassName, newClassName, newCron);
            @ApiParam(name = "className", value = "类名", required = true)
            @RequestParam(value = "className") String className,
            @ApiParam(name = "cron", value = "新cron表达式", required = true)
            @RequestParam(value = "cron") String cron) {
        ClassParams params = new ClassParams();
        params.setRouteId(serviceFlow);
        params.setPackageName(packageName);
        params.setFilePath(path);
        params.setOldClassName(className);
        params.setNewClassName(className+serviceFlow);
        params.setCron(cron);
        return esbCamelService.onRouteClassChanged(params);
    }
    }
    @RequestMapping(value = "/copyProcessor", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    @RequestMapping(value = "/genProcessor", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    @ResponseBody
    @ResponseBody
    @ApiOperation(value = "复制processor文件", produces = "application/json", notes = "生成新的camel文件")
    public Result copyProcessor(
            @ApiParam(name = "type", value = "camel文件类型,route;processor", required = false)
            @RequestParam(value = "type",required = false) String type,
            @ApiParam(name = "filePath", value = "文件路径", required = false)
            @RequestParam(value = "filePath",required = false) String filePath,
    @ApiOperation(value = "生成新的processor文件", produces = "application/json", notes = "生成新的camel文件")
    public Result genProcessor(
            @ApiParam(name = "serviceFlow", value = "服务名称", required = true)
            @RequestParam(value = "serviceFlow",required = true) String serviceFlow,
            @ApiParam(name = "path", value = "文件路径", required = true)
            @RequestParam(value = "path",required = true) String path,
            @ApiParam(name = "packageName", value = "包名", required = true)
            @ApiParam(name = "packageName", value = "包名", required = true)
            @RequestParam(value = "packageName") String packageName,
            @RequestParam(value = "packageName") String packageName,
            @ApiParam(name = "oldClassName", value = "旧类名", required = true)
            @RequestParam(value = "oldClassName") String oldClassName) {
            @ApiParam(name = "className", value = "类名", required = true)
            @RequestParam(value = "className") String className,
            @ApiParam(name = "cron", value = "新cron表达式", required = true)
            @RequestParam(value = "cron") String cron) {
        return esbCamelService.copyProcessor(filePath, packageName, oldClassName);
        return esbCamelService.onProcessorClassAdded(serviceFlow, packageName, className,path);
    }
    }
}
}

+ 94 - 19
hos-broker/src/main/java/com/yihu/hos/services/ESBCamelService.java

@ -2,6 +2,7 @@ package com.yihu.hos.services;
import com.yihu.hos.common.classLoader.DynamicClassLoader;
import com.yihu.hos.common.classLoader.DynamicClassLoader;
import com.yihu.hos.common.compiler.CamelCompiler;
import com.yihu.hos.common.compiler.CamelCompiler;
import com.yihu.hos.common.compiler.ClassParams;
import com.yihu.hos.common.constants.BrokerConstant;
import com.yihu.hos.common.constants.BrokerConstant;
import com.yihu.hos.core.constants.CoreConstant;
import com.yihu.hos.core.constants.CoreConstant;
import com.yihu.hos.core.datatype.ClassFileUtil;
import com.yihu.hos.core.datatype.ClassFileUtil;
@ -64,8 +65,8 @@ public class ESBCamelService {
            SystemCamelContext.getDefaultCamelContext().removeRoute(serviceFlow);
            SystemCamelContext.getDefaultCamelContext().removeRoute(serviceFlow);
            DynamicClassLoader classLoader = new DynamicClassLoader(DynamicClassLoader.class.getClassLoader());
            DynamicClassLoader classLoader = new DynamicClassLoader(DynamicClassLoader.class.getClassLoader());
            Class<RouteBuilder> routeBuilderClass = (Class<RouteBuilder>) classLoader.loadClass(this.getClass().getProtectionDomain().getClassLoader().getResource("").getPath(), SystemClassMapping.getSystemClassNameMapping().get(serviceFlow + BrokerConstant.ROUTE));
            classLoader.loadClass(ClassLoader.getSystemResource(CoreConstant.EMPTY).getPath(), SystemClassMapping.getSystemClassNameMapping().get(serviceFlow + BrokerConstant.PROCESSOR));
            Class<RouteBuilder> routeBuilderClass = (Class<RouteBuilder>) classLoader.loadClass(this.getClass().getProtectionDomain().getClassLoader().getResource("").getPath(), SystemClassMapping.getSystemClassNameMapping().get(serviceFlow + BrokerConstant.ROUTE + className));
            classLoader.loadClass(ClassLoader.getSystemResource(CoreConstant.EMPTY).getPath(), SystemClassMapping.getSystemClassNameMapping().get(serviceFlow + BrokerConstant.PROCESSOR + className));
            if (routeBuilderClass != null) {
            if (routeBuilderClass != null) {
                RouteBuilder routeBuilder = routeBuilderClass.newInstance();
                RouteBuilder routeBuilder = routeBuilderClass.newInstance();
@ -93,7 +94,7 @@ public class ESBCamelService {
            // 3、===============加载到CamelContext中
            // 3、===============加载到CamelContext中
            ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
            ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
            Class<RouteBuilder> routeBuilderClass = (Class<RouteBuilder>) currentClassLoader.loadClass(SystemClassMapping.getSystemClassNameMapping().get(serviceFlow + BrokerConstant.ROUTE));
            Class<RouteBuilder> routeBuilderClass = (Class<RouteBuilder>) currentClassLoader.loadClass(SystemClassMapping.getSystemClassNameMapping().get(serviceFlow + BrokerConstant.ROUTE + className));
            if(routeBuilderClass != null) {
            if(routeBuilderClass != null) {
                RouteBuilder routeBuilder = routeBuilderClass.newInstance();
                RouteBuilder routeBuilder = routeBuilderClass.newInstance();
                SystemCamelContext.getDefaultCamelContext().addRoutes(routeBuilder);
                SystemCamelContext.getDefaultCamelContext().addRoutes(routeBuilder);
@ -120,7 +121,7 @@ public class ESBCamelService {
            this.updateClassfile(serviceFlow, packageName, className, path, BrokerConstant.ROUTE);
            this.updateClassfile(serviceFlow, packageName, className, path, BrokerConstant.ROUTE);
            // 3、===============加载到CamelContext中
            // 3、===============加载到CamelContext中
            DynamicClassLoader classLoader = new DynamicClassLoader(DynamicClassLoader.class.getClassLoader());
            DynamicClassLoader classLoader = new DynamicClassLoader(DynamicClassLoader.class.getClassLoader());
            Class<RouteBuilder> routeBuilderClass = (Class<RouteBuilder>) classLoader.loadClass(ClassLoader.getSystemResource(CoreConstant.EMPTY).getPath(), SystemClassMapping.getSystemClassNameMapping().get(serviceFlow + BrokerConstant.ROUTE));
            Class<RouteBuilder> routeBuilderClass = (Class<RouteBuilder>) classLoader.loadClass(ClassLoader.getSystemResource(CoreConstant.EMPTY).getPath(), SystemClassMapping.getSystemClassNameMapping().get(serviceFlow + BrokerConstant.ROUTE+className));
            if (routeBuilderClass != null) {
            if (routeBuilderClass != null) {
                RouteBuilder routeBuilder = routeBuilderClass.newInstance();
                RouteBuilder routeBuilder = routeBuilderClass.newInstance();
                SystemCamelContext.getDefaultCamelContext().addRoutes(routeBuilder);
                SystemCamelContext.getDefaultCamelContext().addRoutes(routeBuilder);
@ -203,7 +204,7 @@ public class ESBCamelService {
    private void updateClassfile(String serviceFlow, String packageName, String className, String path, String type) {
    private void updateClassfile(String serviceFlow, String packageName, String className, String path, String type) {
        // 1、============
        // 1、============
        Map<String, String> systemClassNameMapping = SystemClassMapping.getSystemClassNameMapping();
        Map<String, String> systemClassNameMapping = SystemClassMapping.getSystemClassNameMapping();
        String systemClassName = systemClassNameMapping.get(serviceFlow + type);
        String systemClassName = systemClassNameMapping.get(serviceFlow + type + className);
        if(StringUtil.isEmpty(systemClassName)) {
        if(StringUtil.isEmpty(systemClassName)) {
            return;
            return;
        }
        }
@ -218,7 +219,7 @@ public class ESBCamelService {
    private void deleteClassfile(String serviceFlow, String packageName, String className, String type) {
    private void deleteClassfile(String serviceFlow, String packageName, String className, String type) {
        // 1、============
        // 1、============
        Map<String, String> systemClassNameMapping = SystemClassMapping.getSystemClassNameMapping();
        Map<String, String> systemClassNameMapping = SystemClassMapping.getSystemClassNameMapping();
        String systemClassName = systemClassNameMapping.get(serviceFlow + type);
        String systemClassName = systemClassNameMapping.get(serviceFlow + type + className);
        if(StringUtil.isEmpty(systemClassName)) {
        if(StringUtil.isEmpty(systemClassName)) {
            return;
            return;
        }
        }
@ -235,32 +236,106 @@ public class ESBCamelService {
    /* **************************       修改任务cron生成新的camel文件 add by hzy   *********************************** */
    /* **************************       修改任务cron生成新的camel文件 add by hzy   *********************************** */
    public Result genNewClassfile(String type,String filePath, String packageName, String oldClassName, String newClassName,String newCron) {
    public Result onProcessorClassAdded(String serviceFlow, String packageName, String className, String path) {
        try {
        try {
            String path;
            if ("route".equals(type)){
                 path = CamelCompiler.compiler(filePath,packageName,oldClassName,newClassName,newCron);
            }else if ("processor".equals(type)){
                 path = CamelCompiler.copyProcess(filePath,packageName,oldClassName);
            if(StringUtil.isEmpty(serviceFlow) || StringUtil.isEmpty(packageName)
                    || StringUtil.isEmpty(className) || StringUtil.isEmpty(path)) {
                logger.error("必要的入参数据不正确,请检查!");
                return Result.error("必要的入参数据不正确,请检查!");
            }
            return this.genProcessorFile(serviceFlow, packageName, className, path);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e);
            return Result.error("新增处理器失败!");
        }
    }
    /**
     * 当外界组件通知一个新的RouteDefine路由被定义时,该事件被触发
     */
    public Result onRouteClassAdded(ClassParams params) {
        try {
            if(StringUtil.isEmpty(params.getRouteId()) || StringUtil.isEmpty(params.getPackageName())
                    || StringUtil.isEmpty(params.getOldClassName()) || StringUtil.isEmpty(params.getFilePath())) {
                logger.error("必要的入参数据不正确,请检查!");
                return Result.error("必要的入参数据不正确,请检查!");
            }
            // 第1、2两步处理过程,都是在这里完成
            this.genRouteFile(params);
            // 3、===============加载到CamelContext中
            Map<String, String> systemClassNameMapping = SystemClassMapping.getSystemClassNameMapping();
            ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
            Class<RouteBuilder> routeBuilderClass = (Class<RouteBuilder>) currentClassLoader.loadClass(SystemClassMapping.getSystemClassNameMapping().get(params.getRouteId() + BrokerConstant.ROUTE + params.getNewClassName()));
            if(routeBuilderClass != null) {
                RouteBuilder routeBuilder = routeBuilderClass.newInstance();
                SystemCamelContext.getDefaultCamelContext().addRoutes(routeBuilder);
            }
            return Result.success("新增路由成功!");
        } catch (Exception e) {
           e.printStackTrace();
            logger.error(e);
            return Result.error("新增路由失败!");
        }
    }
    public Result onRouteClassChanged(ClassParams params) {
        try {
            if(StringUtil.isEmpty(params.getRouteId()) || StringUtil.isEmpty(params.getPackageName())
                    || StringUtil.isEmpty(params.getOldClassName()) || StringUtil.isEmpty(params.getFilePath())) {
                logger.error("必要的入参数据不正确,请检查!");
                return Result.error("必要的入参数据不正确,请检查!");
            }
            // 第1、2两步处理过程,都是在这里完成
            SystemCamelContext.getDefaultCamelContext().stopRoute(params.getRouteId());
            SystemCamelContext.getDefaultCamelContext().removeRoute(params.getRouteId());
            this.genRouteFile(params);
            // 3、===============加载到CamelContext中
            DynamicClassLoader classLoader = new DynamicClassLoader(DynamicClassLoader.class.getClassLoader());
            Class<RouteBuilder> routeBuilderClass = (Class<RouteBuilder>) classLoader.loadClass(ClassLoader.getSystemResource(CoreConstant.EMPTY).getPath(), SystemClassMapping.getSystemClassNameMapping().get(params.getRouteId() + BrokerConstant.ROUTE + params.getNewClassName()));
            if (routeBuilderClass != null) {
                RouteBuilder routeBuilder = routeBuilderClass.newInstance();
                SystemCamelContext.getDefaultCamelContext().addRoutes(routeBuilder);
            }
            return Result.success("新增路由成功!");
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e);
            return Result.error("新增路由失败!");
        }
    }
    public Result genProcessorFile(String serviceFlow, String packageName, String className, String path) {
        try {
            String   filePath= CamelCompiler.copyProcess(serviceFlow,path,packageName,className);
            if (filePath !=null){
                return Result.success(filePath);
            }else {
            }else {
                return Result.error("传入类别参数有误!");
                return Result.error("生成新文件失败1!");
            }
            }
            return Result.success(path);
        } catch (IOException e) {
        } catch (IOException e) {
            e.printStackTrace();
            e.printStackTrace();
            return Result.error("生成新文件失败!");
            return Result.error("生成新文件失败2!");
        }
        }
    }
    }
    public Result copyProcessor(String filePath, String packageName, String oldClassName) {
    public Result genRouteFile(ClassParams params) {
        try {
        try {
            String path = CamelCompiler.copyProcess(filePath,packageName,oldClassName);
            String path = CamelCompiler.compiler(params);
            return Result.success(path);
            return Result.success(path);
        } catch (IOException e) {
        } catch (IOException e) {
            e.printStackTrace();
            e.printStackTrace();
            return Result.error("复制新文件失败!");
            return Result.error("生成新文件失败!");
        }
        }
    }
    }
    }
}

+ 1 - 1
hos-core/src/main/java/com/yihu/hos/core/http/DefaultClientImpl.java

@ -75,7 +75,7 @@ class DefaultClientImpl implements HTTPClient {
                    .url(url)
                    .url(url)
                    .post(requestBody)
                    .post(requestBody)
                    .build();
                    .build();
            httpClient.newBuilder().connectTimeout(60, TimeUnit.SECONDS);
            Response response = httpClient.newCall(request).execute();
            Response response = httpClient.newCall(request).execute();
            if (response.isSuccessful()) {
            if (response.isSuccessful()) {
                return new HTTPResponse(response.code(), response.body().string());
                return new HTTPResponse(response.code(), response.body().string());

+ 32 - 0
src/main/java/com/yihu/hos/services/ServiceFlowEventService.java

@ -67,6 +67,22 @@ public class ServiceFlowEventService {
        this.sendMsg("routeDefineDelete", serviceFlow, packageName, className, null);
        this.sendMsg("routeDefineDelete", serviceFlow, packageName, className, null);
    }
    }
    public void routeClassAdded(String serviceFlow, String packageName, String className, String path,String cron) {
        this.sendGenMsg("routeClassAdded", serviceFlow, packageName, className, path, cron);
    }
    public void routeClassChanged(String serviceFlow, String packageName, String className, String path,String cron) {
        this.sendGenMsg("routeClassChanged", serviceFlow, packageName, className, path, cron);
    }
    public void processorClassAdded(String serviceFlow, String packageName, String className, String path) {
        this.sendMsg("processorClassAdded", serviceFlow, packageName, className, path);
    }
    public void processorClassChanged(String serviceFlow, String packageName, String className, String path) {
        this.sendMsg("processorClassChanged", serviceFlow, packageName, className, path);
    }
    private void sendMsg(String event, String serviceFlow, String packageName, String className, String path) {
    private void sendMsg(String event, String serviceFlow, String packageName, String className, String path) {
        ObjectNode objectNode = objectMapper.createObjectNode();
        ObjectNode objectNode = objectMapper.createObjectNode();
        objectNode.put("event", event);
        objectNode.put("event", event);
@ -81,4 +97,20 @@ public class ServiceFlowEventService {
            e.printStackTrace();
            e.printStackTrace();
        }
        }
    }
    }
    private void sendGenMsg(String event, String serviceFlow, String packageName, String className, String path,String cron) {
        ObjectNode objectNode = objectMapper.createObjectNode();
        objectNode.put("event", event);
        objectNode.put("serviceFlow", serviceFlow);
        objectNode.put("packageName", packageName);
        objectNode.put("className", className);
        objectNode.put("path", path);
        objectNode.put("cron", cron);
        try {
            String msg = objectMapper.writeValueAsString(objectNode);
            this.jmsMessagingTemplate.convertAndSend(this.queue, msg);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    }
}
}

+ 169 - 69
src/main/java/com/yihu/hos/system/service/FlowManager.java

@ -307,12 +307,84 @@ public class FlowManager implements IFlowManage {
    /**
    /**
     * TODO 调用broker接口生成camel相关文件
     * TODO 调用broker接口生成camel相关文件
     * @param flowId
     * @param flowTempId
     * @param newCron
     * @param newCron
     * @throws Exception
     * @throws Exception
     */
     */
    public Integer genCamelFile(Integer flowId, String newCron) throws Exception {
    public Integer genCamelFile(Integer flowTempId, String newCron) throws Exception {
        Long timestamp = System.currentTimeMillis();
        Long timestamp = System.currentTimeMillis();
        Integer newFlowId = sendAddProcessore(flowTempId, timestamp);
        if (newFlowId != null){
            newFlowId = sendAddRoute(flowTempId, newFlowId, newCron, timestamp);
            if (newFlowId !=null){
                return newFlowId;
            }else {
                System.out.println("生成route文件失败");
                return null;
            }
        }else {
            System.out.println("生成processor文件失败");
            return null;
        }
    }
    public Integer addRouteFile(Integer tempId,Integer flowId, String newCron ,Long timestamp) throws Exception {
        ObjectMapper objectMapper = new ObjectMapper();
        List<SystemServiceFlowTemp> flowTempRouters = flowTempDao.getFlowTemps(tempId, Constants.FLOW_TYPE_ROUTE);
        SystemServiceFlow newFlow = getFlowById(flowId);
        //route模板文件记录是否存在。不存在就返回。
        if (!flowTempRouters.isEmpty()){
            Map<String,String> params = null;
            SystemServiceFlowTemp flowTemp =flowTempRouters.get(0);
            StringBuilder basePath = new StringBuilder();;
            if (flowTemp.getPackageName()!=null){
                String packagePath[] = flowTemp.getPackageName().split("\\.");
                for (int i=0;i<packagePath.length;i++){
                    basePath.append(packagePath[i]).append("/");
                }
            }
            //新增processor记录
                String newClassName = flowTemp.getClassName()+timestamp;
                String newRoutePath =null;
                params = new HashMap<>();
                params.put("routeId", newFlow.getCode());
                params.put("type",Constants.FLOW_TYPE_ROUTE);
                params.put("filePath", flowTemp.getClassPath());
                params.put("packageName", basePath.toString());
                params.put("oldClassName", flowTemp.getClassName());
                params.put("newClassName",newClassName);//原文件名加当前时间戳
                params.put("newCron",newCron);
                HTTPResponse response  = HttpClientKit.post(genCamelUrl, params);
                if (response.getStatusCode()==200 ){
                    Map<String,Object> body = objectMapper.readValue(response.getBody(),Map.class);
                    boolean succ = (boolean) body.get("successFlg");
                    if (succ){
                        newRoutePath = body.get("message").toString();
                    }else {
                        return null;
                    }
                    System.out.println(response.getBody());
                    SystemServiceFlowClass newFlowClass = new SystemServiceFlowClass();
                    newFlowClass.setPackageName(flowTemp.getPackageName());
                    newFlowClass.setClassName(newClassName);
                    newFlowClass.setClassPath(newRoutePath);
                    newFlowClass.setFlowId(newFlow.getId());
                    newFlowClass.setType(Constants.FLOW_TYPE_ROUTE);
                    flowClassDao.saveEntity(newFlowClass);
                    newFlowClass.setIsUpdate("1");
                    sendUpdateMessage(newFlow.getCode(), newFlowClass, Constants.FLOW_OP_ADD);
                }else {
                    return null;
                }
            return newFlow.getId();
        }
        return null;
    }
    public Integer addProcessorFile(Integer flowId, String newCron,Long timestamp) throws Exception {
        ObjectMapper objectMapper = new ObjectMapper();
        ObjectMapper objectMapper = new ObjectMapper();
        List<SystemServiceFlowTemp> flowClassRouters = flowTempDao.getFlowTemps(flowId, Constants.FLOW_TYPE_ROUTE);
        List<SystemServiceFlowTemp> flowClassRouters = flowTempDao.getFlowTemps(flowId, Constants.FLOW_TYPE_ROUTE);
        List<SystemServiceFlowTemp> flowClassProces = flowTempDao.getFlowTemps(flowId, Constants.FLOW_TYPE_PROCESSOR);
        List<SystemServiceFlowTemp> flowClassProces = flowTempDao.getFlowTemps(flowId, Constants.FLOW_TYPE_PROCESSOR);
@ -330,7 +402,6 @@ public class FlowManager implements IFlowManage {
                }
                }
            }
            }
            //成功生成文件后,添加flow和flowclass记录
            //成功生成文件后,添加flow和flowclass记录
            //生成新流程
            //生成新流程
            SystemServiceFlow newFlow = new SystemServiceFlow();
            SystemServiceFlow newFlow = new SystemServiceFlow();
@ -342,10 +413,7 @@ public class FlowManager implements IFlowManage {
            newFlow.setFileType(Constants.CLASS);
            newFlow.setFileType(Constants.CLASS);
            flowDao.saveEntity(newFlow);
            flowDao.saveEntity(newFlow);
            //新增processor记录
            //新增processor记录
            int sum = 0;
            for (SystemServiceFlowTemp process:flowClassProces){
            for (SystemServiceFlowTemp process:flowClassProces){
//                String newProcessName = process.getClassName()+timestamp;
//                String newProcessName = process.getClassName()+timestamp;
@ -359,6 +427,7 @@ public class FlowManager implements IFlowManage {
                }
                }
                params = new HashMap<>();
                params = new HashMap<>();
                params.put("routeId", newFlow.getCode());
                params.put("type",Constants.FLOW_TYPE_PROCESSOR);
                params.put("type",Constants.FLOW_TYPE_PROCESSOR);
                params.put("filePath", process.getClassPath());
                params.put("filePath", process.getClassPath());
                params.put("packageName", proPath.toString());
                params.put("packageName", proPath.toString());
@ -381,8 +450,6 @@ public class FlowManager implements IFlowManage {
                        flowClassDao.saveEntity(processClass);
                        flowClassDao.saveEntity(processClass);
                        processClass.setIsUpdate("1");
                        processClass.setIsUpdate("1");
                        sendUpdateMessage(newFlow.getCode(), processClass, Constants.FLOW_OP_ADD);
                        sendUpdateMessage(newFlow.getCode(), processClass, Constants.FLOW_OP_ADD);
                        sum++;
//                copyProcessor(process.getClassPath(),proPath.toString(),process.getClassName());
                    }else {
                    }else {
                        return null;
                        return null;
                    }
                    }
@ -390,46 +457,6 @@ public class FlowManager implements IFlowManage {
                    return null;
                    return null;
                }
                }
            }
            }
            if (sum == flowClassProces.size()){
                String newClassName = flowTemp.getClassName()+timestamp;
                String newRoutePath =null;
                params = new HashMap<>();
                params.put("type",Constants.FLOW_TYPE_ROUTE);
                params.put("filePath", flowTemp.getClassPath());
                params.put("packageName", basePath.toString());
                params.put("oldClassName", flowTemp.getClassName());
                params.put("newClassName",newClassName);//原文件名加当前时间戳
                params.put("newCron",newCron);
                HTTPResponse response  = HttpClientKit.post(genCamelUrl, params);
                if (response.getStatusCode()==200 ){
                    Map<String,Object> body = objectMapper.readValue(response.getBody(),Map.class);
                    boolean succ = (boolean) body.get("successFlg");
                    if (succ){
                        newRoutePath = body.get("message").toString();
                    }else {
                        return null;
                    }
                    System.out.println(response.getBody());
                    SystemServiceFlowClass newFlowClass = new SystemServiceFlowClass();
                    newFlowClass.setPackageName(flowTemp.getPackageName());
                    newFlowClass.setClassName(newClassName);
                    newFlowClass.setClassPath(newRoutePath);
                    newFlowClass.setFlowId(newFlow.getId());
                    newFlowClass.setType(Constants.FLOW_TYPE_ROUTE);
                    flowClassDao.saveEntity(newFlowClass);
                    newFlowClass.setIsUpdate("1");
                    sendUpdateMessage(newFlow.getCode(), newFlowClass, Constants.FLOW_OP_ADD);
                }else {
                    return null;
                }
            }else {
                System.out.println("生成processoer过程失败");
                return null;
            }
//            genNewRoutefile(flowTemp.getClassPath(),basePath.toString(),flowTemp.getClassName(),newClassName,newCron);
            return newFlow.getId();
            return newFlow.getId();
        }
        }
@ -463,35 +490,108 @@ public class FlowManager implements IFlowManage {
                    basePath.append(packagePath[i]).append("/");
                    basePath.append(packagePath[i]).append("/");
                }
                }
            }
            }
            Map<String,String> params  = new HashMap<>();
            params.put("type",Constants.FLOW_TYPE_ROUTE);
            params.put("filePath", flowTemp.getClassPath());
            params.put("packageName", basePath.toString());
            params.put("oldClassName", flowTemp.getClassName());
            params.put("newClassName", flowClass.getClassName());//原文件名加当前时间戳
            params.put("newCron",newCron);
            HTTPResponse response  = HttpClientKit.post(genCamelUrl, params);
            if (response.getStatusCode()==200 ){
                Map<String,Object> body = objectMapper.readValue(response.getBody(),Map.class);
                boolean succ = (boolean) body.get("successFlg");
                if (succ){
                    //route文件生成成功,发送消息
                    //route文件生成成功,发送消息
                    flowClass.setIsUpdate("1");
                    sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_UPDATE);
                    return flowId;
                }else {
                    return null;
//                    flowClass.setIsUpdate("1");
//                    sendUpdateMessage(flow.getCode(), flowClass, Constants.FLOW_OP_UPDATE);
            serviceFlowEventService.routeClassChanged(flow.getCode(),basePath.toString(), flowTemp.getClassName(), flowTemp.getClassPath(),newCron);
            return flowId;
//            genNewRoutefile(flowTemp.getClassPath(),basePath.toString(),flowTemp.getClassName(),newClassName,newCron);
        }
        return null;
    }
    /* *********************       发送消息方式生成文件   ********************************/
    public Integer sendAddRoute(Integer tempId, Integer flowId, String newCron, Long timestamp) throws Exception {
        List<SystemServiceFlowTemp> flowTempRouters = flowTempDao.getFlowTemps(tempId, Constants.FLOW_TYPE_ROUTE);
        SystemServiceFlow newFlow = getFlowById(flowId);
        //route模板文件记录是否存在。不存在就返回。
        if (!flowTempRouters.isEmpty()) {
            Map<String, String> params = null;
            SystemServiceFlowTemp flowTemp = flowTempRouters.get(0);
            StringBuilder basePath = new StringBuilder();
            ;
            if (flowTemp.getPackageName() != null) {
                String packagePath[] = flowTemp.getPackageName().split("\\.");
                for (int i = 0; i < packagePath.length; i++) {
                    basePath.append(packagePath[i]).append("/");
                }
                }
            }else {
                return null;
            }
            }
//            genNewRoutefile(flowTemp.getClassPath(),basePath.toString(),flowTemp.getClassName(),newClassName,newCron);
            //新增processor记录
            String newClassName = flowTemp.getClassName() + newFlow.getCode();
            String newRoutePath = flowTemp.getClassPath().replace(".java",".class");
            SystemServiceFlowClass newFlowClass = new SystemServiceFlowClass();
            newFlowClass.setPackageName(flowTemp.getPackageName());
            newFlowClass.setClassName(newClassName);
            newFlowClass.setClassPath(newRoutePath);
            newFlowClass.setFlowId(newFlow.getId());
            newFlowClass.setType(Constants.FLOW_TYPE_ROUTE);
            flowClassDao.saveEntity(newFlowClass);
            newFlowClass.setIsUpdate("1");
            serviceFlowEventService.routeClassAdded(newFlow.getCode(), basePath.toString(),  flowTemp.getClassName(), flowTemp.getClassPath(),newCron);
            return newFlow.getId();
        }
        }
        return null;
        return null;
    }
    }
    public Integer sendAddProcessore(Integer flowId, Long timestamp) throws Exception {
        List<SystemServiceFlowTemp> flowTempRouters = flowTempDao.getFlowTemps(flowId, Constants.FLOW_TYPE_ROUTE);
        List<SystemServiceFlowTemp> flowTempProces = flowTempDao.getFlowTemps(flowId, Constants.FLOW_TYPE_PROCESSOR);
        SystemServiceFlow oldFlow = getFlowById(flowId);
        //route模板文件记录是否存在。不存在就返回。
        if (!flowTempRouters.isEmpty()) {
            //成功生成文件后,添加flow和flowclass记录
            //生成新流程
            SystemServiceFlow newFlow = new SystemServiceFlow();
            newFlow.setName(oldFlow.getName() + timestamp);
            newFlow.setCode(oldFlow.getCode() + timestamp);
            newFlow.setChart(oldFlow.getChart());
            newFlow.setValid(1);
            newFlow.setCreateDate(new Date());
            newFlow.setFileType(Constants.CLASS);
            flowDao.saveEntity(newFlow);
            //新增processor记录
            for (SystemServiceFlowTemp process : flowTempProces) {
                String newProcessPath = null;
                StringBuilder proPath = new StringBuilder();
                ;
                if (process.getPackageName() != null) {
                    String packagePath[] = process.getPackageName().split("\\.");
                    for (int i = 0; i < packagePath.length; i++) {
                        proPath.append(packagePath[i]).append("/");
                    }
                }
                newProcessPath = process.getClassPath().replace(".java", ".class");
                SystemServiceFlowClass processClass = new SystemServiceFlowClass();
                processClass.setPackageName(process.getPackageName());
                processClass.setClassName(process.getClassName());
                processClass.setClassPath(newProcessPath);
                processClass.setFlowId(newFlow.getId());
                processClass.setType(Constants.FLOW_TYPE_PROCESSOR);
                processClass.setIsUpdate("1");
//                sendUpdateMessage(newFlow.getCode(), processClass, Constants.FLOW_OP_ADD);
                serviceFlowEventService.processorClassAdded(newFlow.getCode(),proPath.toString(), processClass.getClassName(), process.getClassPath());
                flowClassDao.saveEntity(processClass);
            }
            return newFlow.getId();
        }
        return null;
    }
}
}

+ 14 - 0
src/main/webapp/WEB-INF/ehr/jsp/system/app/editorAppService.jsp

@ -58,6 +58,13 @@
                <input type="text" id="healthReportType"  class="l-text-field required" placeholder="请选择监控类型 " name="healthReportType"/>
                <input type="text" id="healthReportType"  class="l-text-field required" placeholder="请选择监控类型 " name="healthReportType"/>
            </div>
            </div>
        </div>
        </div>
        <label id="label_health" style="width:110px;display: none"><span class="red">*&nbsp;</span>地址:</label>
        <div class="m-form-control" id="healthEndpoint" >
            <div class="l-text" >
                <input type="text"  class="l-text-field required" placeholder="请输入健康监控端点地址 " name="healthEndpoint"/>
            </div>
        </div>
    </div>
    </div>
    <div class="m-form-group" >
    <div class="m-form-group" >
@ -68,6 +75,13 @@
                <input type="text" id="metricsReportType" class="l-text-field required" placeholder="请选择监控类型 " name="metricsReportType"/>
                <input type="text" id="metricsReportType" class="l-text-field required" placeholder="请选择监控类型 " name="metricsReportType"/>
            </div>
            </div>
        </div>
        </div>
        <label id="label_metrics" style="width:110px;display: none"><span class="red">*&nbsp;</span>地址:</label>
        <div class="m-form-control"  id="metricsEndpoint" >
            <div class="l-text" >
                <input type="text"  class="l-text-field required" placeholder="请输入指标监控端点地址 " name="metricsEndpoint"/>
            </div>
        </div>
    </div>
    </div>
    <div class="m-form-group" >
    <div class="m-form-group" >

+ 23 - 0
src/main/webapp/WEB-INF/ehr/jsp/system/app/editorAppServiceJs.jsp

@ -114,6 +114,29 @@
                });
                });
            });
            });
            /* 监控类型为拉取的时候需要填写地址*/
            $("#healthReportType").bind('change', function (){
                var type = liger.get("healthReportType").selectedValue;
                if(type==0){
                    $("#label_health").css("display","");
                    $("#healthEndpoint").show();
                }else{
                    $("#label_health").css("display","none");
                    $("#healthEndpoint").hide();
                }
            });
            $("#metricsReportType").bind('change', function (){
                var type = liger.get("metricsReportType").selectedValue;
                if(type==0){
                    $("#label_metrics").css("display","");
                    $("#metricsEndpoint").show();
                }else{
                    $("#label_metrics").css("display","none");
                    $("#metricsEndpoint").hide();
                }
            });
            $(".m-form-bottom").on("click","#btnCancel",function () {
            $(".m-form-bottom").on("click","#btnCancel",function () {
                parent.appService.dialog.close();
                parent.appService.dialog.close();
            });
            });