diff --git a/xxl-job-core/pom.xml b/xxl-job-core/pom.xml
index cb18fc10..d3788249 100644
--- a/xxl-job-core/pom.xml
+++ b/xxl-job-core/pom.xml
@@ -79,6 +79,13 @@
2.4.5
+
+
+ org.apache.commons
+ commons-exec
+ 1.3
+
+
\ No newline at end of file
diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/biz/impl/ExecutorBizImpl.java b/xxl-job-core/src/main/java/com/xxl/job/core/biz/impl/ExecutorBizImpl.java
index f110e4f3..d4b4c752 100644
--- a/xxl-job-core/src/main/java/com/xxl/job/core/biz/impl/ExecutorBizImpl.java
+++ b/xxl-job-core/src/main/java/com/xxl/job/core/biz/impl/ExecutorBizImpl.java
@@ -11,9 +11,13 @@ import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.impl.GlueJobHandler;
import com.xxl.job.core.log.XxlJobFileAppender;
import com.xxl.job.core.thread.JobThread;
+import com.xxl.job.core.util.ScriptUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
import java.util.Date;
/**
@@ -103,7 +107,63 @@ public class ExecutorBizImpl implements ExecutorBiz {
}
jobThread = XxlJobExecutor.registJobThread(triggerParam.getJobId(), new GlueJobHandler(jobHandler, triggerParam.getGlueUpdatetime()));
}
+ } else if (GlueTypeEnum.GLUE_SHELL==GlueTypeEnum.match(triggerParam.getGlueType())) {
+ // make path
+ String scriptPath = XxlJobFileAppender.filePath + "gluesource/";
+ String scriptFileName = triggerParam.getJobId() + "_" + triggerParam.getGlueUpdatetime() + ".sh";
+
+ // valid file
+ File scriptFile = new File(scriptPath, scriptFileName);
+ if (!scriptFile.exists()) {
+ // valid glue source
+ if (triggerParam.getGlueSource()==null) {
+ return new ReturnT(ReturnT.FAIL_CODE, "glueSource is null.");
+ }
+
+ // .../gluesource/
+ File scriptPathDir = new File(scriptPath);
+ if (!scriptPathDir.exists()) {
+ scriptPathDir.mkdirs();
+ }
+
+ // .../gluesource/666-156465656.sh
+ scriptFile = new File(scriptPath, scriptFileName);
+ FileOutputStream fos = null;
+ try {
+ scriptFile.createNewFile();
+
+ fos = new FileOutputStream(scriptFile, true);
+ fos.write(triggerParam.getGlueSource().getBytes("utf-8"));
+ fos.flush();
+ } catch (IOException e) {
+ logger.error(e.getMessage(), e);
+ return new ReturnT(ReturnT.FAIL_CODE, e.getMessage());
+ } finally {
+ if (fos != null) {
+ try {
+ fos.close();
+ } catch (IOException e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+ }
+
+ }
+
+ // log File
+ String logFileName = XxlJobFileAppender.makeLogFileName(new Date(triggerParam.getLogDateTim()), triggerParam.getLogId());
+
+ // run script
+ ScriptUtil.execToFile("python", scriptFile.getName(), (XxlJobFileAppender.filePath + logFileName) );
+
+ return ReturnT.FAIL;
+ } else if (GlueTypeEnum.GLUE_PYTHON==GlueTypeEnum.match(triggerParam.getGlueType())) {
+ String scriptFilePath = XxlJobFileAppender.filePath + "gluesource/" + triggerParam.getJobId() + "_" + triggerParam.getGlueUpdatetime() + ".py";
+
+
+ } else {
+ return new ReturnT(ReturnT.FAIL_CODE, "glueType[" + triggerParam.getGlueType() + "] is not valid.");
}
// push data to queue
diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java b/xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java
index d2339e2c..ad1655c9 100644
--- a/xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java
+++ b/xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java
@@ -78,8 +78,10 @@ public class XxlJobExecutor implements ApplicationContextAware, ApplicationListe
}
// ---------------------------------- init job handler ------------------------------------
+ public static ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+ XxlJobExecutor.applicationContext = applicationContext;
// init job handler action
Map serviceBeanMap = applicationContext.getBeansWithAnnotation(JobHander.class);
diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/glue/GlueFactory.java b/xxl-job-core/src/main/java/com/xxl/job/core/glue/GlueFactory.java
index 0ac26e98..e16ccf0a 100644
--- a/xxl-job-core/src/main/java/com/xxl/job/core/glue/GlueFactory.java
+++ b/xxl-job-core/src/main/java/com/xxl/job/core/glue/GlueFactory.java
@@ -1,14 +1,12 @@
package com.xxl.job.core.glue;
+import com.xxl.job.core.executor.XxlJobExecutor;
import com.xxl.job.core.handler.IJobHandler;
import groovy.lang.GroovyClassLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
import org.springframework.core.annotation.AnnotationUtils;
import javax.annotation.Resource;
@@ -19,7 +17,7 @@ import java.lang.reflect.Modifier;
* glue factory, product class/object by name
* @author xuxueli 2016-1-2 20:02:27
*/
-public class GlueFactory implements ApplicationContextAware {
+public class GlueFactory {
private static Logger logger = LoggerFactory.getLogger(GlueFactory.class);
/**
@@ -28,18 +26,11 @@ public class GlueFactory implements ApplicationContextAware {
private GroovyClassLoader groovyClassLoader = new GroovyClassLoader();
// ----------------------------- spring support -----------------------------
- private static ApplicationContext applicationContext;
- private static GlueFactory glueFactory;
+ private static GlueFactory glueFactory = new GlueFactory();
public static GlueFactory getInstance(){
return glueFactory;
}
-
- @Override
- public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
- GlueFactory.applicationContext = applicationContext;
- GlueFactory.glueFactory = (GlueFactory) applicationContext.getBean("glueFactory");
- }
-
+
/**
* inject action of spring
* @param instance
@@ -61,21 +52,21 @@ public class GlueFactory implements ApplicationContextAware {
try {
Resource resource = AnnotationUtils.getAnnotation(field, Resource.class);
if (resource.name()!=null && resource.name().length()>0){
- fieldBean = applicationContext.getBean(resource.name());
+ fieldBean = XxlJobExecutor.applicationContext.getBean(resource.name());
} else {
- fieldBean = applicationContext.getBean(field.getName());
+ fieldBean = XxlJobExecutor.applicationContext.getBean(field.getName());
}
} catch (Exception e) {
}
if (fieldBean==null ) {
- fieldBean = applicationContext.getBean(field.getType());
+ fieldBean = XxlJobExecutor.applicationContext.getBean(field.getType());
}
} else if (AnnotationUtils.getAnnotation(field, Autowired.class) != null) {
Qualifier qualifier = AnnotationUtils.getAnnotation(field, Qualifier.class);
if (qualifier!=null && qualifier.value()!=null && qualifier.value().length()>0) {
- fieldBean = applicationContext.getBean(qualifier.value());
+ fieldBean = XxlJobExecutor.applicationContext.getBean(qualifier.value());
} else {
- fieldBean = applicationContext.getBean(field.getType());
+ fieldBean = XxlJobExecutor.applicationContext.getBean(field.getType());
}
}
diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/glue/loader/GlueLoader.java b/xxl-job-core/src/main/java/com/xxl/job/core/glue/loader/GlueLoader.java
index 04a4d7e7..244648ec 100644
--- a/xxl-job-core/src/main/java/com/xxl/job/core/glue/loader/GlueLoader.java
+++ b/xxl-job-core/src/main/java/com/xxl/job/core/glue/loader/GlueLoader.java
@@ -1,16 +1,16 @@
-package com.xxl.job.core.glue.loader;
-
-/**
- * code source loader
- * @author xuxueli 2016-1-2 20:01:39
- */
-public interface GlueLoader {
-
- /**
- * load code source by name, ensure every load is the latest.
- * @param jobId
- * @return code source
- */
- public String load(int jobId);
-
-}
+//package com.xxl.job.core.glue.loader;
+//
+///**
+// * code source loader
+// * @author xuxueli 2016-1-2 20:01:39
+// */
+//public interface GlueLoader {
+//
+// /**
+// * load code source by name, ensure every load is the latest.
+// * @param jobId
+// * @return code source
+// */
+// public String load(int jobId);
+//
+//}
diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/glue/loader/impl/DbGlueLoader.java b/xxl-job-core/src/main/java/com/xxl/job/core/glue/loader/impl/DbGlueLoader.java
index 2d23516b..8587d79c 100644
--- a/xxl-job-core/src/main/java/com/xxl/job/core/glue/loader/impl/DbGlueLoader.java
+++ b/xxl-job-core/src/main/java/com/xxl/job/core/glue/loader/impl/DbGlueLoader.java
@@ -1,30 +1,30 @@
-package com.xxl.job.core.glue.loader.impl;
-
-import com.xxl.job.core.glue.loader.GlueLoader;
-import com.xxl.job.core.util.DBUtil;
-
-import javax.sql.DataSource;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Created by xuxueli on 16/9/30.
- */
-public class DbGlueLoader implements GlueLoader {
-
- private DataSource dataSource;
- public void setDataSource(DataSource dataSource) {
- this.dataSource = dataSource;
- }
-
- @Override
- public String load(int jobId) {
- String sql = "SELECT glue_source FROM XXL_JOB_QRTZ_TRIGGER_INFO WHERE id = ?";
- List