parent
abf21f1828
commit
87ce15368e
@ -1 +1,2 @@
|
||||
/target/
|
||||
/.settings/
|
||||
|
@ -1,2 +1,3 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=UTF8
|
||||
encoding//src/test/java=UTF8
|
||||
|
@ -0,0 +1,40 @@
|
||||
package com.xxl.job.controller;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.xxl.job.core.model.ReturnT;
|
||||
import com.xxl.job.core.model.XxlJobLog;
|
||||
import com.xxl.job.dao.IXxlJobLogDao;
|
||||
|
||||
/**
|
||||
* index controller
|
||||
* @author xuxueli 2015-12-19 16:13:16
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/joblog")
|
||||
public class JobLogController {
|
||||
|
||||
@Resource
|
||||
public IXxlJobLogDao xxlJobLogDao;
|
||||
|
||||
@RequestMapping("/save")
|
||||
@ResponseBody
|
||||
public ReturnT<String> triggerLog(int triggerLogId, String status, String msg) {
|
||||
XxlJobLog log = xxlJobLogDao.load(triggerLogId);
|
||||
if (log!=null) {
|
||||
log.setHandleTime(new Date());
|
||||
log.setHandleStatus(status);
|
||||
log.setHandleMsg(msg);
|
||||
xxlJobLogDao.updateHandleInfo(log);
|
||||
return ReturnT.SUCCESS;
|
||||
}
|
||||
return ReturnT.FAIL;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="XxlJobLogMapper">
|
||||
|
||||
<resultMap id="XxlJobLog" type="com.xxl.job.core.model.XxlJobLog" >
|
||||
<result column="id" property="id" />
|
||||
|
||||
<result column="job_name" property="jobName" />
|
||||
<result column="job_cron" property="jobCron" />
|
||||
<result column="job_class" property="jobClass" />
|
||||
<result column="job_data" property="jobData" />
|
||||
|
||||
<result column="trigger_time" property="triggerTime" />
|
||||
<result column="trigger_status" property="triggerStatus" />
|
||||
<result column="trigger_msg" property="triggerMsg" />
|
||||
|
||||
<result column="handle_time" property="handleTime" />
|
||||
<result column="handle_status" property="handleStatus" />
|
||||
<result column="handle_msg" property="handleMsg" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
t.id,
|
||||
t.job_name,
|
||||
t.job_cron,
|
||||
t.job_class,
|
||||
t.job_data,
|
||||
t.trigger_time,
|
||||
t.trigger_status,
|
||||
t.trigger_msg,
|
||||
t.handle_time,
|
||||
t.handle_status,
|
||||
t.handle_msg
|
||||
</sql>
|
||||
|
||||
<insert id="save" parameterType="com.xxl.job.core.model.XxlJobLog" useGeneratedKeys="true" keyProperty="id" >
|
||||
INSERT INTO `qrtz_trigger_log` (
|
||||
`job_name`,
|
||||
`job_cron`,
|
||||
`job_class`,
|
||||
`job_data`
|
||||
) VALUES (
|
||||
#{jobName},
|
||||
#{jobCron},
|
||||
#{jobClass},
|
||||
#{jobData}
|
||||
);
|
||||
<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id">
|
||||
SELECT LAST_INSERT_ID()
|
||||
</selectKey>
|
||||
</insert>
|
||||
|
||||
<select id="load" parameterType="java.lang.Integer" resultMap="XxlJobLog">
|
||||
SELECT <include refid="Base_Column_List" />
|
||||
FROM qrtz_trigger_log AS t
|
||||
WHERE t.id = #{id}
|
||||
</select>
|
||||
|
||||
<update id="updateTriggerInfo">
|
||||
UPDATE `qrtz_trigger_log`
|
||||
SET
|
||||
`trigger_time`= #{triggerTime},
|
||||
`trigger_status`= #{triggerStatus},
|
||||
`trigger_msg`= #{triggerMsg}
|
||||
WHERE `id`= #{id}
|
||||
</update>
|
||||
|
||||
<update id="updateHandleInfo">
|
||||
UPDATE `qrtz_trigger_log`
|
||||
SET
|
||||
`handle_time`= #{handleTime},
|
||||
`handle_status`= #{handleStatus},
|
||||
`handle_msg`= #{handleMsg}
|
||||
WHERE `id`= #{id}
|
||||
</update>
|
||||
|
||||
<select id="pageList" parameterType="java.util.HashMap" resultMap="XxlJobLog">
|
||||
SELECT <include refid="Base_Column_List" />
|
||||
FROM qrtz_trigger_log AS t
|
||||
<if test="jobName != null and jobName!=''">
|
||||
WHERE t.job_name = #{jobName}
|
||||
</if>
|
||||
LIMIT #{offset}, #{pagesize}
|
||||
</select>
|
||||
|
||||
<select id="pageListCount" parameterType="java.util.HashMap" resultType="int">
|
||||
SELECT count(1)
|
||||
FROM qrtz_trigger_log AS t
|
||||
<if test="jobName != null and jobName!=''">
|
||||
WHERE t.job_name = #{jobName}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
</mapper>
|
@ -0,0 +1,61 @@
|
||||
package com.xxl.job.core.util;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* properties util
|
||||
* @author xuxueli 2015-8-28 10:35:53
|
||||
*/
|
||||
public class PropertiesUtil {
|
||||
private static Logger logger = LoggerFactory.getLogger(PropertiesUtil.class);
|
||||
private static final String file_name = "config.properties";
|
||||
|
||||
/**
|
||||
* load properties
|
||||
* @param propertyFileName
|
||||
* @param ifClassPath
|
||||
* @return
|
||||
*/
|
||||
public static Properties loadProperties(String propertyFileName) {
|
||||
Properties prop = new Properties();
|
||||
InputStreamReader in = null;
|
||||
try {
|
||||
URL url = null;
|
||||
ClassLoader loder = Thread.currentThread().getContextClassLoader();
|
||||
url = loder.getResource(propertyFileName);
|
||||
in = new InputStreamReader(new FileInputStream(url.getPath()), "UTF-8");
|
||||
prop.load(in);
|
||||
} catch (IOException e) {
|
||||
logger.error("load {} error!", propertyFileName);
|
||||
} finally {
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
logger.error("close {} error!", propertyFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return prop;
|
||||
}
|
||||
|
||||
public static String getString(String key) {
|
||||
Properties prop = loadProperties(file_name);
|
||||
if (prop!=null) {
|
||||
return prop.getProperty(key);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(getString("triggerLogUrl"));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.xxl.job.dao;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.xxl.job.core.model.XxlJobLog;
|
||||
|
||||
public interface IXxlJobLogDao {
|
||||
|
||||
public int save(XxlJobLog xxlJobLog);
|
||||
|
||||
public XxlJobLog load(int id);
|
||||
|
||||
public int updateTriggerInfo(XxlJobLog xxlJobLog);
|
||||
|
||||
public int updateHandleInfo(XxlJobLog xxlJobLog);
|
||||
|
||||
public List<XxlJobLog> pageList(int offset, int pagesize,String jobName);
|
||||
|
||||
public int pageListCount(int offset, int pagesize,String jobName);
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package com.xxl.job.dao.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.mybatis.spring.SqlSessionTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.xxl.job.core.model.XxlJobLog;
|
||||
import com.xxl.job.dao.IXxlJobLogDao;
|
||||
|
||||
@Repository
|
||||
public class XxlJobLogDaoImpl implements IXxlJobLogDao {
|
||||
|
||||
@Resource
|
||||
public SqlSessionTemplate sqlSessionTemplate;
|
||||
|
||||
@Override
|
||||
public int save(XxlJobLog xxlJobLog) {
|
||||
return sqlSessionTemplate.insert("XxlJobLogMapper.save", xxlJobLog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XxlJobLog load(int id) {
|
||||
return sqlSessionTemplate.selectOne("XxlJobLogMapper.load", id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateTriggerInfo(XxlJobLog xxlJobLog) {
|
||||
return sqlSessionTemplate.update("XxlJobLogMapper.updateTriggerInfo", xxlJobLog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateHandleInfo(XxlJobLog xxlJobLog) {
|
||||
return sqlSessionTemplate.update("XxlJobLogMapper.updateHandleInfo", xxlJobLog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<XxlJobLog> pageList(int offset, int pagesize, String jobName) {
|
||||
HashMap<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("offset", offset);
|
||||
params.put("pagesize", pagesize);
|
||||
params.put("jobName", jobName);
|
||||
return sqlSessionTemplate.selectList("XxlJobLogMapper.pageList", params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int pageListCount(int offset, int pagesize, String jobName) {
|
||||
HashMap<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("offset", offset);
|
||||
params.put("pagesize", pagesize);
|
||||
params.put("jobName", jobName);
|
||||
return sqlSessionTemplate.selectOne("XxlJobLogMapper.pageListCount", params);
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package com.xxl.job.service;
|
||||
|
||||
/**
|
||||
* local trigger, only exists in local jvm
|
||||
* @author xuxueli 2015-12-17 17:29:23
|
||||
*/
|
||||
public interface ITriggerService {
|
||||
|
||||
public void beat();
|
||||
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package com.xxl.job.service.impl;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.xxl.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(">>>>>>>>>>> xxl-job beat success.");
|
||||
}
|
||||
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd
|
||||
http://www.springframework.org/schema/util
|
||||
http://www.springframework.org/schema/util/spring-util.xsd">
|
||||
|
||||
<bean id="beatJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
|
||||
<property name="targetObject" ref="triggerService" />
|
||||
<property name="targetMethod" value="beat" />
|
||||
<property name="concurrent" value="false" />
|
||||
</bean>
|
||||
|
||||
<bean id="beatTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
|
||||
<property name="jobDetail" ref="beatJobDetail" />
|
||||
<property name="cronExpression" value="0/10 * * * * ? *" />
|
||||
</bean>
|
||||
|
||||
<!-- 进程-调度器 -->
|
||||
<bean name="jvmQuertz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
|
||||
<property name="triggers">
|
||||
<list>
|
||||
<!-- <ref bean="beatTrigger" /> -->
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
@ -0,0 +1 @@
|
||||
triggerLogUrl=http://localhost:8080/xxl-job-admin/joblog/save
|
@ -0,0 +1,67 @@
|
||||
package com.xxl.job.dao.impl;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.xxl.job.client.handler.IJobHandler;
|
||||
import com.xxl.job.client.util.HttpUtil;
|
||||
import com.xxl.job.core.model.XxlJobLog;
|
||||
import com.xxl.job.dao.IXxlJobLogDao;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "classpath*:applicationcontext-*.xml")
|
||||
public class XxlJobLogTest {
|
||||
|
||||
@Resource
|
||||
private IXxlJobLogDao xxlJobLogDao;
|
||||
|
||||
@Test
|
||||
public void save_load(){
|
||||
XxlJobLog xxlJobLog = new XxlJobLog();
|
||||
xxlJobLog.setJobName("job_name");
|
||||
xxlJobLog.setJobCron("jobCron");
|
||||
xxlJobLog.setJobClass("jobClass");
|
||||
xxlJobLog.setJobData("jobData");
|
||||
int count = xxlJobLogDao.save(xxlJobLog);
|
||||
System.out.println(count);
|
||||
System.out.println(xxlJobLog.getId());
|
||||
|
||||
XxlJobLog item = xxlJobLogDao.load(xxlJobLog.getId());
|
||||
System.out.println(item);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateTriggerInfo(){
|
||||
XxlJobLog xxlJobLog = xxlJobLogDao.load(29);
|
||||
xxlJobLog.setTriggerTime(new Date());
|
||||
xxlJobLog.setTriggerStatus(HttpUtil.SUCCESS);
|
||||
xxlJobLog.setTriggerMsg("trigger msg");
|
||||
xxlJobLogDao.updateTriggerInfo(xxlJobLog);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateHandleInfo(){
|
||||
XxlJobLog xxlJobLog = xxlJobLogDao.load(29);
|
||||
xxlJobLog.setHandleTime(new Date());
|
||||
xxlJobLog.setHandleStatus(IJobHandler.JobHandleStatus.SUCCESS.name());
|
||||
xxlJobLog.setHandleMsg("handle msg");
|
||||
xxlJobLogDao.updateHandleInfo(xxlJobLog);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pageList(){
|
||||
List<XxlJobLog> list = xxlJobLogDao.pageList(0, 20, null);
|
||||
int list_count = xxlJobLogDao.pageListCount(0, 20, null);
|
||||
|
||||
System.out.println(list);
|
||||
System.out.println(list_count);
|
||||
}
|
||||
|
||||
}
|
@ -1,59 +1,84 @@
|
||||
package com.xxl.job.client.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
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;
|
||||
|
||||
/**
|
||||
* http util to send hex data
|
||||
* http util to send data
|
||||
* @author xuxueli
|
||||
* @version 2015-11-28 15:30:59
|
||||
*/
|
||||
public class HttpUtil {
|
||||
|
||||
public static String sendHex(String reqURL, String queryString) {
|
||||
// response param
|
||||
public static final String status = "status";
|
||||
public static final String msg = "msg";
|
||||
// response status enum
|
||||
public static final String SUCCESS = "SUCCESS";
|
||||
public static final String FAIL = "FAIL";
|
||||
|
||||
String responseContent = null;
|
||||
if (queryString != null && !queryString.equals("")) {
|
||||
reqURL = reqURL + "?data=" + queryString;
|
||||
}
|
||||
/**
|
||||
* http post request
|
||||
* @param reqURL
|
||||
* @param params
|
||||
* @return [0]=responseMsg, [1]=exceptionMsg
|
||||
*/
|
||||
public static String[] post(String reqURL, Map<String, String> params){
|
||||
String responseMsg = null;
|
||||
String exceptionMsg = null;
|
||||
|
||||
HttpGet httpGet = new HttpGet(reqURL);
|
||||
// do post
|
||||
HttpPost httpPost = new HttpPost(reqURL);
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
try{
|
||||
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(3000).setConnectTimeout(3000).build();
|
||||
httpGet.setConfig(requestConfig);
|
||||
|
||||
HttpResponse response = httpClient.execute(httpGet);
|
||||
if (params != null && !params.isEmpty()) {
|
||||
List<NameValuePair> formParams = new ArrayList<NameValuePair>();
|
||||
for(Map.Entry<String,String> 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");
|
||||
responseMsg = EntityUtils.toString(entity, "UTF-8");
|
||||
EntityUtils.consume(entity);
|
||||
if (responseContent!=null) {
|
||||
responseContent = responseContent.trim();
|
||||
}
|
||||
}
|
||||
} catch (ClientProtocolException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
StringWriter out = new StringWriter();
|
||||
e.printStackTrace(new PrintWriter(out));
|
||||
exceptionMsg = out.toString();
|
||||
} finally{
|
||||
httpGet.releaseConnection();
|
||||
httpPost.releaseConnection();
|
||||
try {
|
||||
httpClient.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return responseContent;
|
||||
}
|
||||
|
||||
String[] result = new String[2];
|
||||
result[0] = responseMsg;
|
||||
result[1] = exceptionMsg;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue