diff --git a/branch-dianping/dianping-job/README.md b/branch-dianping/dianping-job/README.md new file mode 100644 index 0000000000000000000000000000000000000000..89fa00edcdcacfe8a81f844a357abdd111fd066b --- /dev/null +++ b/branch-dianping/dianping-job/README.md @@ -0,0 +1,11 @@ +## dianping-job[任务调度平台] + + 分层: 调度和任务拆分, 支持动态扩充, 管理任务 + 1. 调度模块:dianping-job-web, 维护任务的调度信息,负责定时/周期性的发出调度请求. + 2. 任务模块:dianping-job-client, 具体的任务逻辑,负责接收调度模块的调度请求,执行任务逻辑. + 3. 通讯模块:dianping-job-client, 负责调度模块和任务模块之间的通讯. + + 说明: + 1. 调度模块集群部署[HA]. + 2. 任务串行执行. + 3. 记录调度日系. \ No newline at end of file diff --git a/branch-dianping/dianping-job/dianping-job-client-demo/pom.xml b/branch-dianping/dianping-job/dianping-job-client-demo/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..cbfbdaac12f3b2029444f3495ef6318ceb59263e --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-client-demo/pom.xml @@ -0,0 +1,87 @@ + + 4.0.0 + + com.dianping + dianping-job + 0.0.1-SNAPSHOT + + dianping-job-client-demo + war + dianping-job-client-demo + http://maven.apache.org + + + 3.2.14.RELEASE + + + + + + org.springframework + spring-webmvc + ${spring.version} + + + org.springframework + spring-context-support + ${spring.version} + + + org.springframework + spring-orm + ${spring.version} + + + org.springframework + spring-test + ${spring.version} + + + + + org.aspectj + aspectjweaver + 1.8.7 + + + + + org.slf4j + slf4j-log4j12 + 1.7.5 + + + + + com.dianping + dianping-job-client + 1.0.1-SNAPSHOT + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.6 + 1.6 + UTF8 + + + + org.apache.maven.plugins + maven-war-plugin + 2.2 + + true + + + + + + \ No newline at end of file diff --git a/branch-dianping/dianping-job/dianping-job-client-demo/src/main/java/com/dianping/job/service/handler/DemoJobHandler.java b/branch-dianping/dianping-job/dianping-job-client-demo/src/main/java/com/dianping/job/service/handler/DemoJobHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..a3d83885ac716e0b97e39b7ca99da2d6d5740273 --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-client-demo/src/main/java/com/dianping/job/service/handler/DemoJobHandler.java @@ -0,0 +1,38 @@ +package com.dianping.job.service.handler; + +import java.util.Map; +import java.util.Random; +import java.util.concurrent.TimeUnit; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import com.dianping.job.client.handler.HandlerRepository; +import com.dianping.job.client.handler.IJobHandler; + +/** + * demo job handler + * @author xuxueli 2015-12-19 19:43:36 + */ +@Service +public class DemoJobHandler extends IJobHandler { + private static transient Logger logger = LoggerFactory.getLogger(DemoJobHandler.class); + + public DemoJobHandler() { + HandlerRepository.regist(DemoJobHandler.class.getName(), this); + } + + @Override + public JobHandleStatus handle(Map param) throws Exception { + logger.info(" ... param:{}", param); + TimeUnit.SECONDS.sleep(new Random().nextInt(5)); + return JobHandleStatus.SUCCESS; + } + + public static void main(String[] args) { + System.out.println(DemoJobHandler.class.getName()); + System.out.println(DemoJobHandler.class); + } + +} diff --git a/branch-dianping/dianping-job/dianping-job-client-demo/src/main/resources/applicationcontext-base.xml b/branch-dianping/dianping-job/dianping-job-client-demo/src/main/resources/applicationcontext-base.xml new file mode 100644 index 0000000000000000000000000000000000000000..55e2d377a897e9b471e579d7f233c525c2af4d11 --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-client-demo/src/main/resources/applicationcontext-base.xml @@ -0,0 +1,15 @@ + + + + + + + \ No newline at end of file diff --git a/branch-dianping/dianping-job/dianping-job-client-demo/src/main/resources/log4j.properties b/branch-dianping/dianping-job/dianping-job-client-demo/src/main/resources/log4j.properties new file mode 100644 index 0000000000000000000000000000000000000000..b02f63d054f659e6497aebe700d20122e3c03b43 --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-client-demo/src/main/resources/log4j.properties @@ -0,0 +1,10 @@ +log4j.rootLogger=info,console + +log4j.appender.console=org.apache.log4j.ConsoleAppender +log4j.appender.console.layout=org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern=%d - dianping-job-client-demo - %p [%c] - <%m>%n + +log4j.appender.logFile=org.apache.log4j.DailyRollingFileAppender +log4j.appender.logFile.File=${catalina.base}/logs/dianping-job-client-demo.log +log4j.appender.logFile.layout=org.apache.log4j.PatternLayout +log4j.appender.logFile.layout.ConversionPattern=%d - dianping-job-client-demo - %p [%c] - <%m>%n diff --git a/branch-dianping/dianping-job/dianping-job-client-demo/src/main/webapp/WEB-INF/web.xml b/branch-dianping/dianping-job/dianping-job-client-demo/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000000000000000000000000000000000..2c747e73af99c1c7db68228a858778828e2593de --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-client-demo/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,35 @@ + + + + + contextConfigLocation + classpath*:applicationcontext-*.xml + + + + org.springframework.web.util.Log4jConfigListener + + + org.springframework.web.context.ContextLoaderListener + + + + + DianpingJobServlet + com.dianping.job.client.netcom.http.DianpingJobServlet + 1 + + + DianpingJobServlet + /dianpingJobServlet + + + clock-job-web + + index.html + + + \ No newline at end of file diff --git a/branch-dianping/dianping-job/dianping-job-client-demo/src/main/webapp/index.html b/branch-dianping/dianping-job/dianping-job-client-demo/src/main/webapp/index.html new file mode 100644 index 0000000000000000000000000000000000000000..ae4ee13c08e7628701b925b8962108bd7643bf6e --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-client-demo/src/main/webapp/index.html @@ -0,0 +1 @@ +200 \ No newline at end of file diff --git a/branch-dianping/dianping-job/dianping-job-client/pom.xml b/branch-dianping/dianping-job/dianping-job-client/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..8c1a5779bc5180a4245effc79660f7b4fa9fed01 --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-client/pom.xml @@ -0,0 +1,83 @@ + + 4.0.0 + + com.dianping + dianping-job + 0.0.1-SNAPSHOT + + dianping-job-client + 1.0.1-SNAPSHOT + dianping-job-client + http://maven.apache.org + + + + + + javax.servlet + servlet-api + 2.5 + provided + + + javax.servlet.jsp + jsp-api + 2.1 + provided + + + + + org.slf4j + slf4j-log4j12 + 1.7.5 + + + + + org.codehaus.jackson + jackson-mapper-asl + 1.9.13 + + + + + org.apache.httpcomponents + httpclient + 4.3.6 + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.6 + 1.6 + UTF8 + + + + + + + + jdk-1.6 + + true + 1.6 + + + 1.6 + 1.6 + 1.6 + + + + + \ No newline at end of file diff --git a/branch-dianping/dianping-job/dianping-job-client/src/main/java/com/dianping/job/client/handler/HandlerRepository.java b/branch-dianping/dianping-job/dianping-job-client/src/main/java/com/dianping/job/client/handler/HandlerRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..2050f542097bdc43cfea69495cc89ba34c5b9e41 --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-client/src/main/java/com/dianping/job/client/handler/HandlerRepository.java @@ -0,0 +1,140 @@ +package com.dianping.job.client.handler; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.dianping.job.client.handler.IJobHandler.JobHandleStatus; +import com.dianping.job.client.handler.IJobHandler.JobTriggerStatus; + +/** + * handler repository + * @author xuxueli 2015-12-19 19:28:44 + */ +public class HandlerRepository { + private static Logger logger = LoggerFactory.getLogger(HandlerRepository.class); + + public static final String triggerUuid = "triggerUuid"; + public static final String handleName = "handleName"; + + // handler class map + private static ConcurrentHashMap handlerClassMap = new ConcurrentHashMap(); + // handler thread map + private static ConcurrentHashMap handlerTreadMap = new ConcurrentHashMap(); + // handler date queue map + private static ConcurrentHashMap>> handlerDataQueueMap = new ConcurrentHashMap>>(); + + // regist handler + public static void regist(String handleName, IJobHandler handler){ + handlerClassMap.put(handleName, handler); + LinkedBlockingQueue> handlerDateQueue = new LinkedBlockingQueue>(); + handlerDataQueueMap.put(handleName, handlerDateQueue); + HandlerThread handlerThread = new HandlerThread(handleName); + handlerThread.start(); + handlerTreadMap.put(handleName, handlerThread); + logger.info(">>>>>>>>>>> dianping-job regist handler success, handleName:{}, handler:{}, handlerDateQueue:{}, handlerThread:{}", + new Object[]{handleName, handler, handlerDateQueue, handlerThread}); + } + + // create handler thread + static class HandlerThread extends Thread{ + private String _handleName; + public HandlerThread(String _handleName) { + this._handleName = _handleName; + } + public boolean isValid = true; + public void stopThread(){ + isValid = false; + } + @Override + public void run() { + while (isValid) { + LinkedBlockingQueue> handlerDateQueue = handlerDataQueueMap.get(_handleName); + Map handlerDate = handlerDateQueue.poll(); + if (handlerDate!=null) { + JobHandleStatus jobHandleStatus = null; + String jobHandleDetail = null; + try { + IJobHandler handler = handlerClassMap.get(_handleName); + jobHandleStatus = handler.handle(handlerDate); + } catch (Exception e) { + e.printStackTrace(); + jobHandleStatus = JobHandleStatus.FAIL; + StringWriter out = new StringWriter(); + e.printStackTrace(new PrintWriter(out)); + jobHandleDetail = out.toString(); + } + String _triggerUuid = handlerDate.get(triggerUuid); + logger.info("<<<<<<<<<<< dianping-job thread handle, _triggerUuid:{}, _handleName:{}, jobHandleStatus:{}, jobHandleDetail:{}, thread:{}", + new Object[]{_triggerUuid, _handleName, jobHandleStatus, jobHandleDetail, this}); + } else { + try { + TimeUnit.SECONDS.sleep(3); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + } + + // handler push to queue + public static String pushHandleQueue(String triggerUuid, String handleName, Map _param) { + JobTriggerStatus _triggerStatus = JobTriggerStatus.FAIL; + String _triggerDetailLog = null; + + try { + if (handleName!=null && handleName.trim().length()>0) { + IJobHandler handler = handlerClassMap.get(handleName); + if (handler != null) { + // push data to handler queue + LinkedBlockingQueue> handlerDateQueue = handlerDataQueueMap.get(handleName); + if (handlerDateQueue == null) { + handlerDateQueue = new LinkedBlockingQueue>(); + handlerDataQueueMap.put(handleName, handlerDateQueue); + logger.info(">>>>>>>>>>> dianping-job handler lazy fresh handlerDateQueue, handleName:{}, handler:{}, handlerDateQueue:{}", + new Object[]{handleName, handler, handlerDateQueue}); + } + handlerDateQueue.offer(_param); + // check handler thread + HandlerThread handlerThreadOld = handlerTreadMap.get(handleName); + if (!handlerThreadOld.isAlive()) { + handlerThreadOld.stopThread(); + HandlerThread handlerThread = new HandlerThread(handleName); + handlerThread.start(); + handlerTreadMap.put(handleName, handlerThread); + logger.info(">>>>>>>>>>> dianping-job handler lazy fresh thread, handleName:{}, handler:{}, handlerThread:{}", + new Object[]{handleName, handler, handlerThread}); + } + _triggerStatus = JobTriggerStatus.SUCCESS; + } + } + } catch (Exception e) { + e.printStackTrace(); + _triggerStatus = JobTriggerStatus.FAIL; + StringWriter out = new StringWriter(); + e.printStackTrace(new PrintWriter(out)); + _triggerDetailLog = out.toString(); + } + logger.info(">>>>>>>>>>> dianping-job pushHandleQueue, triggerUuid:{}, handleName, _triggerStatus:{}, _triggerDetailLog", + new Object[]{triggerUuid, handleName, _triggerStatus, _triggerDetailLog}); + + String responseBody = _triggerStatus.name(); + if (JobTriggerStatus.SUCCESS != _triggerStatus) { + responseBody += "#" + _triggerDetailLog; + } + return responseBody; + /** + * trigger-log : + * trigger side : store trigger-info >> trigger request >> update trigger-response-status + * job side : handler trigger >> update trigger-result + */ + } + +} diff --git a/branch-dianping/dianping-job/dianping-job-client/src/main/java/com/dianping/job/client/handler/IJobHandler.java b/branch-dianping/dianping-job/dianping-job-client/src/main/java/com/dianping/job/client/handler/IJobHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..fb25271b568a45a6cc7ed235a716c2740d7a73d4 --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-client/src/main/java/com/dianping/job/client/handler/IJobHandler.java @@ -0,0 +1,46 @@ +package com.dianping.job.client.handler; + +import java.util.Map; + +/** + * remote job handler + * @author xuxueli 2015-12-19 19:06:38 + */ +public abstract class IJobHandler extends HandlerRepository{ + + /** + * job handler + * the return Object will be and stored + * @param param + * @return + * @throws Exception + */ + public abstract JobHandleStatus handle(Map param) throws Exception; + + public enum JobHandleStatus{ + /** + * handle success + */ + SUCCESS, + /** + * handle fail + */ + FAIL, + /** + * handle not found + */ + NOT_FOUND; + } + + public enum JobTriggerStatus{ + /** + * trigger success + */ + SUCCESS, + /** + * trigger fail + */ + FAIL; + } + +} diff --git a/branch-dianping/dianping-job/dianping-job-client/src/main/java/com/dianping/job/client/netcom/http/DianpingJobServlet.java b/branch-dianping/dianping-job/dianping-job-client/src/main/java/com/dianping/job/client/netcom/http/DianpingJobServlet.java new file mode 100644 index 0000000000000000000000000000000000000000..f5d31fc92ceb17d373c8e6a32711e006c1b38add --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-client/src/main/java/com/dianping/job/client/netcom/http/DianpingJobServlet.java @@ -0,0 +1,61 @@ +package com.dianping.job.client.netcom.http; + + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.dianping.job.client.handler.HandlerRepository; + +/** + * remote job client on http + * @author xuxueli 2015-12-19 18:36:47 + */ +public class DianpingJobServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + + /** + * Default constructor. + */ + public DianpingJobServlet() { + // TODO Auto-generated constructor stub + } + + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding("UTF-8"); + + Map _param = new HashMap(); + if (request.getParameterMap()!=null && request.getParameterMap().size()>0) { + for (Object paramKey : request.getParameterMap().keySet()) { + if (paramKey!=null) { + String paramKeyStr = paramKey.toString(); + _param.put(paramKeyStr, request.getParameter(paramKeyStr)); + } + } + } + String _triggerUuid = _param.get(HandlerRepository.triggerUuid); + String _handleName = _param.get(HandlerRepository.handleName); + + String resp = HandlerRepository.pushHandleQueue(_triggerUuid, _handleName, _param); + response.getWriter().append(resp); + return; + } + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // TODO Auto-generated method stub + doGet(request, response); + } + +} diff --git a/branch-dianping/dianping-job/dianping-job-client/src/main/java/com/dianping/job/client/util/HttpUtil.java b/branch-dianping/dianping-job/dianping-job-client/src/main/java/com/dianping/job/client/util/HttpUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..8fe9cd682e4149712d1abcdd65f6a9d7a1c4c3ba --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-client/src/main/java/com/dianping/job/client/util/HttpUtil.java @@ -0,0 +1,59 @@ +package com.dianping.job.client.util; + +import java.io.IOException; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; + +/** + * http util to send hex data + * @author xuxueli + * @version 2015-11-28 15:30:59 + */ +public class HttpUtil { + + public static String sendHex(String reqURL, String queryString) { + + String responseContent = null; + if (queryString != null && !queryString.equals("")) { + reqURL = reqURL + "?data=" + queryString; + } + + HttpGet httpGet = new HttpGet(reqURL); + CloseableHttpClient httpClient = HttpClients.createDefault(); + try { + RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(3000).setConnectTimeout(3000).build(); + httpGet.setConfig(requestConfig); + + HttpResponse response = httpClient.execute(httpGet); + + HttpEntity entity = response.getEntity(); + if (null != entity) { + responseContent = EntityUtils.toString(entity, "UTF-8"); + EntityUtils.consume(entity); + if (responseContent!=null) { + responseContent = responseContent.trim(); + } + } + } catch (ClientProtocolException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + httpGet.releaseConnection(); + try { + httpClient.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseContent; + } + +} diff --git a/branch-dianping/dianping-job/dianping-job-web/pom.xml b/branch-dianping/dianping-job/dianping-job-web/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..780c15cfaaf197f33b67180d1cbab6d2cd4035f5 --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-web/pom.xml @@ -0,0 +1,174 @@ + + 4.0.0 + + com.dianping + dianping-job + 0.0.1-SNAPSHOT + + dianping-job-web + 1.0.1-SNAPSHOT + war + dianping-job-web + http://maven.apache.org + + + 3.2.14.RELEASE + + + + + + org.springframework + spring-webmvc + ${spring.version} + + + org.springframework + spring-context-support + ${spring.version} + + + org.springframework + spring-orm + ${spring.version} + + + org.springframework + spring-test + ${spring.version} + + + + + org.aspectj + aspectjweaver + 1.8.7 + + + + org.codehaus.jackson + jackson-mapper-asl + 1.9.13 + + + + + org.slf4j + slf4j-log4j12 + 1.7.5 + + + + + org.freemarker + freemarker + 2.3.20 + + + + + commons-beanutils + commons-beanutils + 1.9.2 + + + + commons-lang + commons-lang + 2.6 + + + + + javax.servlet + servlet-api + 2.5 + provided + + + javax.servlet.jsp + jsp-api + 2.1 + provided + + + + + junit + junit + 4.11 + test + + + + + c3p0 + c3p0 + 0.9.1.2 + + + + org.mybatis + mybatis-spring + 1.2.2 + + + org.mybatis + mybatis + 3.2.8 + + + + mysql + mysql-connector-java + 5.1.29 + + + + + org.quartz-scheduler + quartz + 2.2.1 + + + + + org.apache.httpcomponents + httpclient + 4.3.6 + + + + + com.dianping + dianping-job-client + 1.0.1-SNAPSHOT + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.6 + 1.6 + UTF8 + + + + org.apache.maven.plugins + maven-war-plugin + 2.2 + + true + + + + + + diff --git a/branch-dianping/dianping-job/dianping-job-web/src/main/java/com/dianping/job/controller/IndexController.java b/branch-dianping/dianping-job/dianping-job-web/src/main/java/com/dianping/job/controller/IndexController.java new file mode 100644 index 0000000000000000000000000000000000000000..fb2036c5fb3fa7898f61dd4e3fc1383606ee0376 --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-web/src/main/java/com/dianping/job/controller/IndexController.java @@ -0,0 +1,180 @@ +package com.dianping.job.controller; + +import java.io.UnsupportedEncodingException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.lang.StringUtils; +import org.quartz.CronExpression; +import org.quartz.Job; +import org.quartz.SchedulerException; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.dianping.job.client.handler.HandlerRepository; +import com.dianping.job.core.model.ReturnT; +import com.dianping.job.core.util.DynamicSchedulerUtil; +import com.dianping.job.service.job.HttpJobBean; + +/** + * index controller + * @author xuxueli 2015-12-19 16:13:16 + */ +@Controller +public class IndexController { + + + @RequestMapping("") + public String index(Model model) { + List> jobList = DynamicSchedulerUtil.getJobList(); + model.addAttribute("jobList", jobList); + return "job/index"; + } + + @RequestMapping("/help") + public String help(Model model) { + return "job/help"; + } + + @RequestMapping("/job/add") + @ResponseBody + public ReturnT add(HttpServletRequest request) { + String triggerKeyName = null; + String cronExpression = null; + Map jobData = new HashMap(); + + try { + request.setCharacterEncoding("utf-8"); + } catch (UnsupportedEncodingException e1) { + e1.printStackTrace(); + } + @SuppressWarnings("unchecked") + Set> paramSet = request.getParameterMap().entrySet(); + for (Entry param : paramSet) { + if (param.getKey().equals("triggerKeyName")) { + triggerKeyName = param.getValue()[0]; + } else if (param.getKey().equals("cronExpression")) { + cronExpression = param.getValue()[0]; + } else { + jobData.put(param.getKey(), param.getValue().length>0?param.getValue()[0]:param.getValue()); + } + } + + // triggerKeyName + if (StringUtils.isBlank(triggerKeyName)) { + return new ReturnT(500, "请输入“任务key”"); + } + + // cronExpression + if (StringUtils.isBlank(cronExpression)) { + return new ReturnT(500, "请输入“任务corn”"); + } + if (!CronExpression.isValidExpression(cronExpression)) { + return new ReturnT(500, "“任务corn”不合法"); + } + + // jobData + if (jobData.get(DynamicSchedulerUtil.job_desc)==null || jobData.get(DynamicSchedulerUtil.job_desc).toString().trim().length()==0) { + return new ReturnT(500, "请输入“任务描述”"); + } + if (jobData.get(DynamicSchedulerUtil.job_url)==null || jobData.get(DynamicSchedulerUtil.job_url).toString().trim().length()==0) { + return new ReturnT(500, "请输入“任务URL”"); + } + if (jobData.get(HandlerRepository.handleName)==null || jobData.get(HandlerRepository.handleName).toString().trim().length()==0) { + return new ReturnT(500, "请输入“任务handler”"); + } + + // jobClass + Class extends Job> jobClass = HttpJobBean.class; + + try { + boolean result = DynamicSchedulerUtil.addJob(triggerKeyName, cronExpression, jobClass, jobData); + if (!result) { + return new ReturnT(500, "任务ID重复,请更换确认"); + } + return ReturnT.SUCCESS; + } catch (SchedulerException e) { + e.printStackTrace(); + } + return ReturnT.FAIL; + } + + @RequestMapping("/job/reschedule") + @ResponseBody + public ReturnT reschedule(String triggerKeyName, String cronExpression) { + // triggerKeyName + if (StringUtils.isBlank(triggerKeyName)) { + return new ReturnT(500, "请输入“任务key”"); + } + // cronExpression + if (StringUtils.isBlank(cronExpression)) { + return new ReturnT(500, "请输入“任务corn”"); + } + if (!CronExpression.isValidExpression(cronExpression)) { + return new ReturnT(500, "“任务corn”不合法"); + } + try { + DynamicSchedulerUtil.rescheduleJob(triggerKeyName, cronExpression); + return ReturnT.SUCCESS; + } catch (SchedulerException e) { + e.printStackTrace(); + } + return ReturnT.FAIL; + } + + @RequestMapping("/job/remove") + @ResponseBody + public ReturnT remove(String triggerKeyName) { + try { + DynamicSchedulerUtil.removeJob(triggerKeyName); + return ReturnT.SUCCESS; + } catch (SchedulerException e) { + e.printStackTrace(); + return ReturnT.FAIL; + } + } + + @RequestMapping("/job/pause") + @ResponseBody + public ReturnT pause(String triggerKeyName) { + try { + DynamicSchedulerUtil.pauseJob(triggerKeyName); + return ReturnT.SUCCESS; + } catch (SchedulerException e) { + e.printStackTrace(); + return ReturnT.FAIL; + } + } + + @RequestMapping("/job/resume") + @ResponseBody + public ReturnT resume(String triggerKeyName) { + try { + DynamicSchedulerUtil.resumeJob(triggerKeyName); + return ReturnT.SUCCESS; + } catch (SchedulerException e) { + e.printStackTrace(); + return ReturnT.FAIL; + } + } + + @RequestMapping("/job/trigger") + @ResponseBody + public ReturnT triggerJob(String triggerKeyName) { + try { + DynamicSchedulerUtil.triggerJob(triggerKeyName); + return ReturnT.SUCCESS; + } catch (SchedulerException e) { + e.printStackTrace(); + return ReturnT.FAIL; + } + } + +} diff --git a/branch-dianping/dianping-job/dianping-job-web/src/main/java/com/dianping/job/core/model/DianpingJobLog.java b/branch-dianping/dianping-job/dianping-job-web/src/main/java/com/dianping/job/core/model/DianpingJobLog.java new file mode 100644 index 0000000000000000000000000000000000000000..00671ad0de75d50fde9276d4f0e30c9841b146dc --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-web/src/main/java/com/dianping/job/core/model/DianpingJobLog.java @@ -0,0 +1,79 @@ +package com.dianping.job.core.model; + +import java.util.Date; + +/** + * dianping job log, used to track trigger process + * @author xuxueli 2015-12-19 23:19:09 + */ +public class DianpingJobLog { + + private String jobTriggerUuid; + private String jobHandleName; + // trigger info + private Date triggerTime; + private String triggerStatus; + private String triggerDetailLog; + // handle info + private Date handleTime; + private String handleStatus; + private String handleDetailLog; + + public String getJobTriggerUuid() { + return jobTriggerUuid; + } + public void setJobTriggerUuid(String jobTriggerUuid) { + this.jobTriggerUuid = jobTriggerUuid; + } + public String getJobHandleName() { + return jobHandleName; + } + public void setJobHandleName(String jobHandleName) { + this.jobHandleName = jobHandleName; + } + public Date getTriggerTime() { + return triggerTime; + } + public void setTriggerTime(Date triggerTime) { + this.triggerTime = triggerTime; + } + public String getTriggerStatus() { + return triggerStatus; + } + public void setTriggerStatus(String triggerStatus) { + this.triggerStatus = triggerStatus; + } + public String getTriggerDetailLog() { + return triggerDetailLog; + } + public void setTriggerDetailLog(String triggerDetailLog) { + this.triggerDetailLog = triggerDetailLog; + } + public Date getHandleTime() { + return handleTime; + } + public void setHandleTime(Date handleTime) { + this.handleTime = handleTime; + } + public String getHandleStatus() { + return handleStatus; + } + public void setHandleStatus(String handleStatus) { + this.handleStatus = handleStatus; + } + public String getHandleDetailLog() { + return handleDetailLog; + } + public void setHandleDetailLog(String handleDetailLog) { + this.handleDetailLog = handleDetailLog; + } + + @Override + public String toString() { + return "DianpingJobLog [jobTriggerUuid=" + jobTriggerUuid + ", jobHandleName=" + jobHandleName + + ", triggerTime=" + triggerTime + ", triggerStatus=" + triggerStatus + ", triggerDetailLog=" + + triggerDetailLog + ", handleTime=" + handleTime + ", handleStatus=" + handleStatus + + ", handleDetailLog=" + handleDetailLog + "]"; + } + +} diff --git a/branch-dianping/dianping-job/dianping-job-web/src/main/java/com/dianping/job/core/model/ReturnT.java b/branch-dianping/dianping-job/dianping-job-web/src/main/java/com/dianping/job/core/model/ReturnT.java new file mode 100644 index 0000000000000000000000000000000000000000..b09d49f1ca791de5819502829d82cf2a3ef3c4a5 --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-web/src/main/java/com/dianping/job/core/model/ReturnT.java @@ -0,0 +1,50 @@ +package com.dianping.job.core.model; + +/** + * common return + * @author xuxueli 2015-12-4 16:32:31 + * @param + */ +public class ReturnT { + public static final ReturnT SUCCESS = new ReturnT(null); + public static final ReturnT FAIL = new ReturnT(500, null); + + private int code; + private String msg; + private T content; + + public ReturnT(int code, String msg) { + this.code = code; + this.msg = msg; + } + public ReturnT(T content) { + this.code = 200; + this.content = content; + } + + public int getCode() { + return code; + } + public void setCode(int code) { + this.code = code; + } + public String getMsg() { + return msg; + } + public void setMsg(String msg) { + this.msg = msg; + } + public T getContent() { + return content; + } + public void setContent(T content) { + this.content = content; + } + + @Override + public String toString() { + return "ReturnT [code=" + code + ", msg=" + msg + ", content=" + + content + "]"; + } + +} diff --git a/branch-dianping/dianping-job/dianping-job-web/src/main/java/com/dianping/job/core/util/DynamicSchedulerUtil.java b/branch-dianping/dianping-job/dianping-job-web/src/main/java/com/dianping/job/core/util/DynamicSchedulerUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..c995b5c938281247c5f300980053a4814cb90706 --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-web/src/main/java/com/dianping/job/core/util/DynamicSchedulerUtil.java @@ -0,0 +1,199 @@ +package com.dianping.job.core.util; + +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.quartz.CronScheduleBuilder; +import org.quartz.CronTrigger; +import org.quartz.Job; +import org.quartz.JobBuilder; +import org.quartz.JobDataMap; +import org.quartz.JobDetail; +import org.quartz.JobKey; +import org.quartz.Scheduler; +import org.quartz.SchedulerException; +import org.quartz.Trigger; +import org.quartz.Trigger.TriggerState; +import org.quartz.TriggerBuilder; +import org.quartz.TriggerKey; +import org.quartz.impl.matchers.GroupMatcher; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; + +/** + * base quartz scheduler util + * @author xuxueli 2015-12-19 16:13:53 + */ +public final class DynamicSchedulerUtil implements InitializingBean { + private static final Logger logger = LoggerFactory.getLogger(DynamicSchedulerUtil.class); + + // Scheduler + private static Scheduler scheduler; + public static void setScheduler(Scheduler scheduler) { + DynamicSchedulerUtil.scheduler = scheduler; + } + + @Override + public void afterPropertiesSet() throws Exception { + Assert.notNull(scheduler, "quartz scheduler is null"); + logger.info(">>>>>>>>> init quartz scheduler success.[{}]", scheduler); + } + + // getJobKeys + public static List> getJobList(){ + List> jobList = new ArrayList>(); + + try { + if (scheduler.getJobGroupNames()==null || scheduler.getJobGroupNames().size()==0) { + return null; + } + String groupName = scheduler.getJobGroupNames().get(0); + Set jobKeys = scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName)); + if (jobKeys!=null && jobKeys.size()>0) { + for (JobKey jobKey : jobKeys) { + TriggerKey triggerKey = TriggerKey.triggerKey(jobKey.getName(), Scheduler.DEFAULT_GROUP); + Trigger trigger = scheduler.getTrigger(triggerKey); + JobDetail jobDetail = scheduler.getJobDetail(jobKey); + TriggerState triggerState = scheduler.getTriggerState(triggerKey); + Map jobMap = new HashMap(); + jobMap.put("TriggerKey", triggerKey); + jobMap.put("Trigger", trigger); + jobMap.put("JobDetail", jobDetail); + jobMap.put("TriggerState", triggerState); + jobList.add(jobMap); + } + } + + } catch (SchedulerException e) { + e.printStackTrace(); + return null; + } + return jobList; + } + + public static final String job_desc = "job_desc"; + public static final String job_url = "job_url"; + // addJob 新增 + public static boolean addJob(String triggerKeyName, String cronExpression, Class extends Job> jobClass, Map jobData) throws SchedulerException { + // TriggerKey : name + group + String group = Scheduler.DEFAULT_GROUP; + TriggerKey triggerKey = TriggerKey.triggerKey(triggerKeyName, group); + + // TriggerKey valid if_exists + if (scheduler.checkExists(triggerKey)) { + Trigger trigger = scheduler.getTrigger(triggerKey); + logger.info(">>>>>>>>> Already exist trigger [" + trigger + "] by key [" + triggerKey + "] in Scheduler"); + return false; + } + + // CronTrigger : TriggerKey + cronExpression + CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression); + CronTrigger cronTrigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).withSchedule(cronScheduleBuilder).build(); + + // JobDetail : jobClass + JobDetail jobDetail = JobBuilder.newJob(jobClass).withIdentity(triggerKeyName, group).build(); + if (jobData!=null && jobData.size() > 0) { + JobDataMap jobDataMap = jobDetail.getJobDataMap(); + jobDataMap.putAll(jobData); // JobExecutionContext context.getMergedJobDataMap().get("mailGuid"); + } + + // schedule : jobDetail + cronTrigger + Date date = scheduler.scheduleJob(jobDetail, cronTrigger); + + logger.info(">>>>>>>>>>> addJob success, jobDetail:{}, cronTrigger:{}, date:{}", jobDetail, cronTrigger, date); + return true; + } + + // reschedule 重置cron + public static boolean rescheduleJob(String triggerKeyName, String cronExpression) throws SchedulerException { + // TriggerKey : name + group + String group = Scheduler.DEFAULT_GROUP; + TriggerKey triggerKey = TriggerKey.triggerKey(triggerKeyName, group); + + boolean result = false; + if (scheduler.checkExists(triggerKey)) { + // CronTrigger : TriggerKey + cronExpression + CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression); + CronTrigger cronTrigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).withSchedule(cronScheduleBuilder).build(); + + Date date = scheduler.rescheduleJob(triggerKey, cronTrigger); + result = true; + logger.info(">>>>>>>>>>> resumeJob success, triggerKey:{}, cronExpression:{}, date:{}", triggerKey, cronExpression, date); + } else { + logger.info(">>>>>>>>>>> resumeJob fail, triggerKey:{}, cronExpression:{}", triggerKey, cronExpression); + } + return result; + } + + // unscheduleJob 删除 + public static boolean removeJob(String triggerKeyName) throws SchedulerException { + // TriggerKey : name + group + String group = Scheduler.DEFAULT_GROUP; + TriggerKey triggerKey = TriggerKey.triggerKey(triggerKeyName, group); + + boolean result = false; + if (scheduler.checkExists(triggerKey)) { + result = scheduler.unscheduleJob(triggerKey); + } + logger.info(">>>>>>>>>>> removeJob, triggerKey:{}, result [{}]", triggerKey, result); + return result; + } + + // Pause 暂停 + public static boolean pauseJob(String triggerKeyName) throws SchedulerException { + // TriggerKey : name + group + String group = Scheduler.DEFAULT_GROUP; + TriggerKey triggerKey = TriggerKey.triggerKey(triggerKeyName, group); + + boolean result = false; + if (scheduler.checkExists(triggerKey)) { + scheduler.pauseTrigger(triggerKey); + result = true; + logger.info(">>>>>>>>>>> pauseJob success, triggerKey:{}", triggerKey); + } else { + logger.info(">>>>>>>>>>> pauseJob fail, triggerKey:{}", triggerKey); + } + return result; + } + + // resume 重启 + public static boolean resumeJob(String triggerKeyName) throws SchedulerException { + // TriggerKey : name + group + String group = Scheduler.DEFAULT_GROUP; + TriggerKey triggerKey = TriggerKey.triggerKey(triggerKeyName, group); + + boolean result = false; + if (scheduler.checkExists(triggerKey)) { + scheduler.resumeTrigger(triggerKey); + result = true; + logger.info(">>>>>>>>>>> resumeJob success, triggerKey:{}", triggerKey); + } else { + logger.info(">>>>>>>>>>> resumeJob fail, triggerKey:{}", triggerKey); + } + return result; + } + + // run 执行一次 + public static boolean triggerJob(String triggerKeyName) throws SchedulerException { + // TriggerKey : name + group + String group = Scheduler.DEFAULT_GROUP; + JobKey jobKey = JobKey.jobKey(triggerKeyName, group); + + boolean result = false; + if (scheduler.checkExists(jobKey)) { + scheduler.triggerJob(jobKey); + result = true; + logger.info(">>>>>>>>>>> runJob success, jobKey:{}", jobKey); + } else { + logger.info(">>>>>>>>>>> runJob fail, jobKey:{}", jobKey); + } + return result; + } + +} \ No newline at end of file diff --git a/branch-dianping/dianping-job/dianping-job-web/src/main/java/com/dianping/job/service/ITriggerService.java b/branch-dianping/dianping-job/dianping-job-web/src/main/java/com/dianping/job/service/ITriggerService.java new file mode 100644 index 0000000000000000000000000000000000000000..a7ce637c9264382d786f09f31689f841004feb4d --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-web/src/main/java/com/dianping/job/service/ITriggerService.java @@ -0,0 +1,11 @@ +package com.dianping.job.service; + +/** + * local trigger, only exists in local jvm + * @author xuxueli 2015-12-17 17:29:23 + */ +public interface ITriggerService { + + public void beat(); + +} diff --git a/branch-dianping/dianping-job/dianping-job-web/src/main/java/com/dianping/job/service/impl/TriggerServiceImpl.java b/branch-dianping/dianping-job/dianping-job-web/src/main/java/com/dianping/job/service/impl/TriggerServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..361c2a445f346931bbd6c87e91baf83ca0536cd9 --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-web/src/main/java/com/dianping/job/service/impl/TriggerServiceImpl.java @@ -0,0 +1,21 @@ +package com.dianping.job.service.impl; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import com.dianping.job.service.ITriggerService; + +/** + * local trigger, only exists in local jvm + * @author xuxueli 2015-12-17 17:31:24 + */ +@Service("triggerService") +public class TriggerServiceImpl implements ITriggerService { + private static transient Logger logger = LoggerFactory.getLogger(TriggerServiceImpl.class); + + public void beat() { + logger.info(">>>>>>>>>>> dianping-clock beat success."); + } + +} diff --git a/branch-dianping/dianping-job/dianping-job-web/src/main/java/com/dianping/job/service/job/HttpJobBean.java b/branch-dianping/dianping-job/dianping-job-web/src/main/java/com/dianping/job/service/job/HttpJobBean.java new file mode 100644 index 0000000000000000000000000000000000000000..101cc3968df3c9c765a48c109186c7f8aa60a387 --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-web/src/main/java/com/dianping/job/service/job/HttpJobBean.java @@ -0,0 +1,137 @@ +package com.dianping.job.service.job; + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.UUID; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.NameValuePair; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.message.BasicNameValuePair; +import org.apache.http.util.EntityUtils; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.scheduling.quartz.QuartzJobBean; + +import com.dianping.job.client.handler.HandlerRepository; +import com.dianping.job.client.handler.IJobHandler.JobTriggerStatus; +import com.dianping.job.core.model.DianpingJobLog; +import com.dianping.job.core.util.DynamicSchedulerUtil; + +/** + * http job bean + * @author xuxueli 2015-12-17 18:20:34 + */ +public class HttpJobBean extends QuartzJobBean { + private static Logger logger = LoggerFactory.getLogger(HttpJobBean.class); + + @Override + protected void executeInternal(JobExecutionContext context) + throws JobExecutionException { + + String triggerKey = context.getTrigger().getKey().getName(); + String triggerGroup = context.getTrigger().getKey().getGroup(); + Map jobDataMap = context.getMergedJobDataMap().getWrappedMap(); + + // jobDataMap 2 params + Map params = new HashMap(); + if (jobDataMap!=null && jobDataMap.size()>0) { + for (Entry item : jobDataMap.entrySet()) { + params.put(item.getKey(), String.valueOf(item.getValue())); + } + } + + String job_url = params.get(DynamicSchedulerUtil.job_url); + triggerPost(job_url, params); + + logger.info(">>>>>>>>>>> dianping-clock run :jobId:{}, group:{}, jobDataMap:{}", + new Object[]{triggerKey, triggerGroup, jobDataMap}); + } + + public static void triggerPost(String reqURL, Map params){ + // save log + DianpingJobLog jobLog = new DianpingJobLog(); + jobLog.setJobTriggerUuid(UUID.randomUUID().toString()); + jobLog.setJobHandleName(params.get(HandlerRepository.handleName)); + jobLog.setTriggerTime(new Date()); + logger.info(">>>>>>>>>>> dianping-clock trigger start :jobLog:{}", jobLog); + + // post + String responseContent = null; + HttpPost httpPost = new HttpPost(reqURL); + CloseableHttpClient httpClient = HttpClients.createDefault(); + try{ + if (params != null && !params.isEmpty()) { + List formParams = new ArrayList(); + for(Map.Entry entry : params.entrySet()){ + formParams.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); + } + httpPost.setEntity(new UrlEncodedFormEntity(formParams, "UTF-8")); + } + RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000).build(); + httpPost.setConfig(requestConfig); + + HttpResponse response = httpClient.execute(httpPost); + HttpEntity entity = response.getEntity(); + if (null != entity) { + responseContent = EntityUtils.toString(entity, "UTF-8"); + EntityUtils.consume(entity); + } + logger.info(">>>>>>>>>>> dianping-clock trigger ing :jobLog:{}, response:{}, responseContent:{}", jobLog, response, responseContent); + } catch (Exception e) { + e.printStackTrace(); + + StringWriter out = new StringWriter(); + e.printStackTrace(new PrintWriter(out)); + responseContent = out.toString(); + } finally{ + httpPost.releaseConnection(); + try { + httpClient.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + // update trigger status + if (responseContent!=null && responseContent.equals(JobTriggerStatus.SUCCESS.name())) { + jobLog.setTriggerStatus(JobTriggerStatus.SUCCESS.name()); + } else { + jobLog.setTriggerStatus(JobTriggerStatus.FAIL.name()); + } + jobLog.setTriggerDetailLog(responseContent); + if (jobLog.getTriggerDetailLog()!=null && jobLog.getTriggerDetailLog().length()>1000) { + jobLog.setTriggerDetailLog(jobLog.getTriggerDetailLog().substring(0, 1000)); + } + + logger.info(">>>>>>>>>>> dianping-clock trigger end :jobLog:{}", jobLog); + } + + } + + public static void main(String[] args) { + String url = "http://localhost:8080/dianping-job-client-demo/dianpingJobServlet"; + + for (int i = 0; i < 3; i++) { + Map params = new HashMap(); + params.put(HandlerRepository.handleName, "com.dianping.job.service.handler.DemoJobHandler"); + params.put(HandlerRepository.triggerUuid, i+""); + params.put("key", i+""); + + triggerPost(url, params); + } + } +} \ No newline at end of file diff --git a/branch-dianping/dianping-job/dianping-job-web/src/main/resources/applicationcontext-base.xml b/branch-dianping/dianping-job/dianping-job-web/src/main/resources/applicationcontext-base.xml new file mode 100644 index 0000000000000000000000000000000000000000..a8344895db55332573410a31ab6eb297fb235b5c --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-web/src/main/resources/applicationcontext-base.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + classpath*:jdbc.properties + + + + + \ No newline at end of file diff --git a/branch-dianping/dianping-job/dianping-job-web/src/main/resources/applicationcontext-database.xml b/branch-dianping/dianping-job/dianping-job-web/src/main/resources/applicationcontext-database.xml new file mode 100644 index 0000000000000000000000000000000000000000..a72057d16529b5782d26f1a5c3a5aa48f4a39ed1 --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-web/src/main/resources/applicationcontext-database.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/branch-dianping/dianping-job/dianping-job-web/src/main/resources/applicationcontext-trigger-db.xml b/branch-dianping/dianping-job/dianping-job-web/src/main/resources/applicationcontext-trigger-db.xml new file mode 100644 index 0000000000000000000000000000000000000000..51c15a2787364197adb0692875cbfc7eda2f1d0b --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-web/src/main/resources/applicationcontext-trigger-db.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/branch-dianping/dianping-job/dianping-job-web/src/main/resources/applicationcontext-trigger-local.xml b/branch-dianping/dianping-job/dianping-job-web/src/main/resources/applicationcontext-trigger-local.xml new file mode 100644 index 0000000000000000000000000000000000000000..911aba64a40dc562a170c504043f0d717fdca087 --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-web/src/main/resources/applicationcontext-trigger-local.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branch-dianping/dianping-job/dianping-job-web/src/main/resources/applicationcontext-tx.xml b/branch-dianping/dianping-job/dianping-job-web/src/main/resources/applicationcontext-tx.xml new file mode 100644 index 0000000000000000000000000000000000000000..709ad8ca52667058cc5712cd029138c6f0340fd2 --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-web/src/main/resources/applicationcontext-tx.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/branch-dianping/dianping-job/dianping-job-web/src/main/resources/freemarker.properties b/branch-dianping/dianping-job/dianping-job-web/src/main/resources/freemarker.properties new file mode 100644 index 0000000000000000000000000000000000000000..fbc42ea550d237e082ae3ddf90fd7aa53e482f54 --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-web/src/main/resources/freemarker.properties @@ -0,0 +1,10 @@ +template_update_delay=0 +default_encoding=UTF-8 +output_encoding=UTF-8 +locale=zh_CN +number_format=0.########## +date_format=yyyy-MM-dd +time_format=HH:mm:ss +datetime_format=yyyy-MM-dd HH:mm:s +classic_compatible=true +template_exception_handler=ignore \ No newline at end of file diff --git a/branch-dianping/dianping-job/dianping-job-web/src/main/resources/jdbc.properties b/branch-dianping/dianping-job/dianping-job-web/src/main/resources/jdbc.properties new file mode 100644 index 0000000000000000000000000000000000000000..ff308dab935ea18d57c384bc56d04bd0bbe4035c --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-web/src/main/resources/jdbc.properties @@ -0,0 +1,4 @@ +c3p0.driverClass=com.mysql.jdbc.Driver +c3p0.url=jdbc:mysql://localhost:3306/test?Unicode=true&characterEncoding=UTF-8 +c3p0.user=root +c3p0.password=root_pwd \ No newline at end of file diff --git a/branch-dianping/dianping-job/dianping-job-web/src/main/resources/log4j.properties b/branch-dianping/dianping-job/dianping-job-web/src/main/resources/log4j.properties new file mode 100644 index 0000000000000000000000000000000000000000..7ae3b7995b308201671ebe1ee6ba0d3a1429cb8d --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-web/src/main/resources/log4j.properties @@ -0,0 +1,10 @@ +log4j.rootLogger=info,console,logFile + +log4j.appender.console=org.apache.log4j.ConsoleAppender +log4j.appender.console.layout=org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern=%d - dianping-job-web - %p [%c] - <%m>%n + +log4j.appender.logFile=org.apache.log4j.DailyRollingFileAppender +log4j.appender.logFile.File=${catalina.base}/logs/dianping-job-web.log +log4j.appender.logFile.layout=org.apache.log4j.PatternLayout +log4j.appender.logFile.layout.ConversionPattern=%d - dianping-job-web - %p [%c] - <%m>%n diff --git a/branch-dianping/dianping-job/dianping-job-web/src/main/resources/quartz.properties b/branch-dianping/dianping-job/dianping-job-web/src/main/resources/quartz.properties new file mode 100644 index 0000000000000000000000000000000000000000..99409e5d503d61033ca244d17310b66929ccb87d --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-web/src/main/resources/quartz.properties @@ -0,0 +1,25 @@ +# Default Properties file for use by StdSchedulerFactory +# to create a Quartz Scheduler Instance, if a different +# properties file is not explicitly specified. +# + +org.quartz.scheduler.instanceName: DefaultQuartzScheduler +org.quartz.scheduler.rmi.export: false +org.quartz.scheduler.rmi.proxy: false +org.quartz.scheduler.wrapJobExecutionInUserTransaction: false + +org.quartz.threadPool.class: org.quartz.simpl.SimpleThreadPool +org.quartz.threadPool.threadCount: 10 +org.quartz.threadPool.threadPriority: 5 +org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread: true + +org.quartz.jobStore.misfireThreshold: 60000 + +#org.quartz.jobStore.class: org.quartz.simpl.RAMJobStore + +# for cluster +org.quartz.jobStore.tablePrefix = WED_qrtz_ +org.quartz.scheduler.instanceId: AUTO +org.quartz.jobStore.class: org.quartz.impl.jdbcjobstore.JobStoreTX +org.quartz.jobStore.isClustered: true +org.quartz.jobStore.clusterCheckinInterval: 1000 diff --git a/branch-dianping/dianping-job/dianping-job-web/src/main/resources/springmvc-context.xml b/branch-dianping/dianping-job/dianping-job-web/src/main/resources/springmvc-context.xml new file mode 100644 index 0000000000000000000000000000000000000000..a2a4d85e5732d839b6945af83a75738bd031e72b --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-web/src/main/resources/springmvc-context.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/branch-dianping/dianping-job/dianping-job-web/src/main/webapp/500.html b/branch-dianping/dianping-job/dianping-job-web/src/main/webapp/500.html new file mode 100644 index 0000000000000000000000000000000000000000..eb1f49486af7c892e115f610fa32b505125766fc --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-web/src/main/webapp/500.html @@ -0,0 +1 @@ +500 \ No newline at end of file diff --git a/branch-dianping/dianping-job/dianping-job-web/src/main/webapp/WEB-INF/template/common/common.exception.ftl b/branch-dianping/dianping-job/dianping-job-web/src/main/webapp/WEB-INF/template/common/common.exception.ftl new file mode 100644 index 0000000000000000000000000000000000000000..016f78b05e054a16d519c12f0f4cbd11ec87574e --- /dev/null +++ b/branch-dianping/dianping-job/dianping-job-web/src/main/webapp/WEB-INF/template/common/common.exception.ftl @@ -0,0 +1,39 @@ + + + + + 应用程序异常 (500) + + + + + + + + 应用程序异常 + 抱歉!您访问的页面出现异常,请稍后重试或联系管理员。 + 详 情 + 返 回 + + ${exceptionMsg} + + + + + +
抱歉!您访问的页面出现异常,请稍后重试或联系管理员。
详 情 + 返 回 +