Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持Windows/Linux下jetty启动 #388

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@ echo "LTS: After sub window finished, close it , and press any key to continue"
xcopy /e /y "%Startup_Dir%\target\lts-bin\lts\lib" "%LTS_Bin_Dir%\war\jetty\lib"
cd ..\..\

xcopy /e /y "%BASE_HOME%\lts-admin\target\lts-admin-%VERSION%.war" "%LTS_Bin_Dir%\war\lts-admin.war"
xcopy /e /y "%BASE_HOME%\lts-admin\target\lts-admin-%VERSION%.war" "%LTS_Bin_Dir%\war"
echo "LTS: rename war finished, close it , and press any key to continue" & pause>nul
cd %LTS_Bin_Dir%\war
ren lts-admin-%VERSION%.war lts-admin.war
cd ..\..\
5 changes: 4 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ cp -rf $Startup_Dir/target/lts-bin/lts/* $Dist_Bin_Dir
mkdir -p $Dist_Bin_Dir/war/jetty/lib
mvn clean assembly:assembly -DskipTests -Plts-admin
cp -rf $Startup_Dir/target/lts-bin/lts/lib $Dist_Bin_Dir/war/jetty
cp -rf $LTS_Bin_Dir/lts-admin/target/lts-admin-$VERSION.war $Dist_Bin_Dir/war/lts-admin.war

cp -rf $LTS_Bin_Dir/lts-admin/target/lts-admin-$VERSION.war $Dist_Bin_Dir/war
cd $Dist_Bin_Dir/war
mv lts-admin-$VERSION.war lts-admin.war

cd $LTS_Bin_Dir/dist
zip -r lts-$VERSION-bin.zip lts-$VERSION-bin/*
Expand Down
Binary file added docs/lts.pdf
Binary file not shown.
133 changes: 132 additions & 1 deletion lts-admin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,137 @@
</build>

<dependencies>
<dependency>
<groupId>com.github.ltsopensource</groupId>
<artifactId>lts</artifactId>
<version>${project.version}</version>
</dependency>
<!-- <dependency>
<groupId>com.github.ltsopensource</groupId>
<artifactId>lts-jobclient</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.github.ltsopensource</groupId>
<artifactId>lts-tasktracker</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.github.ltsopensource</groupId>
<artifactId>lts-jobtracker</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.github.ltsopensource</groupId>
<artifactId>lts-spring</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>

</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>

</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging-api</artifactId>

</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>

</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>

</dependency>
<dependency>
<groupId>org.fusesource.leveldbjni</groupId>
<artifactId>leveldbjni-all</artifactId>

</dependency>
<dependency>
<groupId>com.sleepycat</groupId>
<artifactId>je</artifactId>

</dependency>
<dependency>
<groupId>org.rocksdb</groupId>
<artifactId>rocksdbjni</artifactId>

</dependency>
<dependency>
<groupId>org.apache.mina</groupId>
<artifactId>mina-core</artifactId>

</dependency>
<dependency>
<groupId>com.caucho</groupId>
<artifactId>hessian</artifactId>

</dependency>
<dependency>
<groupId>org.mapdb</groupId>
<artifactId>mapdb</artifactId>

</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>

</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>

</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>

</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${springframework.version}</version>

</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${springframework.version}</version>

</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>${quartz.version}</version>

</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>

</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>

</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>${spring.boot.version}</version>

<optional>true</optional>
</dependency> -->

<dependency>
<groupId>com.github.ltsopensource</groupId>
<artifactId>lts-core</artifactId>
Expand Down Expand Up @@ -88,7 +219,7 @@
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>

</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.github.ltsopensource.handle;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.github.ltsopensource.core.commons.utils.CollectionUtils;
import com.github.ltsopensource.core.domain.JobResult;
import com.github.ltsopensource.jobclient.support.JobCompletedHandler;

/**
* @author Robert HG ([email protected]) on 4/17/16.
*/
public class JobClientCompletedHandler implements JobCompletedHandler {

@Override
public void onComplete(List<JobResult> jobResults) {
// 任务执行反馈结果处理
if (CollectionUtils.isNotEmpty(jobResults)) {
for (JobResult jobResult : jobResults) {
System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + " 任务执行完成:" + jobResult);
}
}
}
}
122 changes: 122 additions & 0 deletions lts-admin/src/main/java/com/github/ltsopensource/handle/JobHandle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package com.github.ltsopensource.handle;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.Random;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.github.ltsopensource.core.domain.Job;
import com.github.ltsopensource.jobclient.JobClient;
import com.github.ltsopensource.jobclient.domain.Response;
@Component
public class JobHandle {
public static String TASK_TRACKER_NODE_GROUP = "admin-task-tracker";
@SuppressWarnings("rawtypes")
@Autowired
private JobClient jobClient;
/**
* @decription 实时任务
* @author yi.zhang
* @time 2017年11月3日 上午11:23:15
* @param url 请求URL
* @param params 请求参数
* @return
*/
public Response handleRealtimeJob(String url,Map<String, String> params){
Job job = new Job();
job.setTaskId("realtime_"+taskId());
if(params!=null&&params.size()>0){
job.setExtParams(params);
}
job.setParam("url", url);
job.setTaskTrackerNodeGroup(TASK_TRACKER_NODE_GROUP);
job.setNeedFeedback(true);
job.setReplaceOnExist(true); // 当任务队列中存在这个任务的时候,是否替换更新
Response response = jobClient.submitJob(job);
return response;
}
/**
* @decription 重复任务
* @author yi.zhang
* @time 2017年11月3日 上午11:24:11
* @param url 请求URL
* @param params 请求参数
* @param repeatCount 重复次数
* @param intervalTime 重复间隔(单位:秒)
* @return
*/
public Response handleRepeatJob(String url,Map<String, String> params,int repeatCount,long intervalTime){
Job job = new Job();
job.setTaskId("repeat_"+taskId());
if(params!=null&&params.size()>0){
job.setExtParams(params);
}
job.setParam("url", url);
job.setTaskTrackerNodeGroup(TASK_TRACKER_NODE_GROUP);
job.setNeedFeedback(true);
job.setReplaceOnExist(true); // 当任务队列中存在这个任务的时候,是否替换更新
job.setRepeatCount(repeatCount); // 一共执行50次
job.setRepeatInterval(intervalTime * 1000L); // 50s 执行一次
Response response = jobClient.submitJob(job);
return response;
}
/**
* @decription 周期任务
* @author yi.zhang
* @time 2017年11月3日 上午11:25:25
* @param url 请求URL
* @param params 请求参数
* @param cron 周期表达式(例如:0 0/1 * * * ?)
* @return
*/
public Response handleCronJob(String url,Map<String, String> params,String cron){
Job job = new Job();
job.setTaskId("cron"+taskId());
if(params!=null&&params.size()>0){
job.setExtParams(params);
}
job.setParam("url", url);
job.setTaskTrackerNodeGroup(TASK_TRACKER_NODE_GROUP); // 执行要执行该任务的taskTracker的节点组名称
job.setNeedFeedback(true);
job.setReplaceOnExist(true); // 当任务队列中存在这个任务的时候,是否替换更新
job.setCronExpression("0 0/1 * * * ?");
Response response = jobClient.submitJob(job);
return response;
}
/**
* @decription 定时任务
* @author yi.zhang
* @time 2017年11月3日 上午11:26:43
* @param url 请求URL
* @param params 请求参数
* @param start 开始时间
* @param time 定时时间(单位:秒)
* @return
*/
public Response handleTriggerTimeJob(String url,Map<String, String> params,Date start,long time){
Job job = new Job();
job.setTaskId("trigger_"+taskId());
if(params!=null&&params.size()>0){
job.setExtParams(params);
}
if(start==null){
start = new Date();
}
job.setParam("url", url);
job.setTaskTrackerNodeGroup(TASK_TRACKER_NODE_GROUP);
job.setNeedFeedback(true);
job.setReplaceOnExist(true); // 当任务队列中存在这个任务的时候,是否替换更新
job.setTriggerTime(start.getTime()+time * 1000L); // 1 小时之后执行
Response response = jobClient.submitJob(job);
return response;
}

private String taskId(){
String time = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
String taskId = time+new Random().nextInt(1000);
return taskId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.github.ltsopensource.handle;

import com.github.ltsopensource.core.domain.Action;
import com.github.ltsopensource.core.domain.Job;
import com.github.ltsopensource.core.logger.Logger;
import com.github.ltsopensource.core.logger.LoggerFactory;
import com.github.ltsopensource.tasktracker.Result;
import com.github.ltsopensource.tasktracker.runner.JobContext;
import com.github.ltsopensource.tasktracker.runner.JobRunner;

/**
* @author Robert HG ([email protected]) on 4/17/16.
*/
public class TaskTrackerJobRunner implements JobRunner {

private static final Logger logger = LoggerFactory.getLogger(TaskTrackerJobRunner.class);

@Override
public Result run(JobContext ctx) throws Throwable {
try {
// BizLogger bizLogger = LtsLoggerFactory.getBizLogger();
// BizLogger log = ctx.getBizLogger();
Job job = ctx.getJob();
// TODO 业务逻辑
logger.info("Job Context:" + ctx);
// 会发送到 LTS (JobTracker上)
System.out.println("\n\n\n---------------------------------------------------------------------------------");
System.out.println("---------------------------------------------------------------------------------");
System.out.println("-admin-task-tracker--"+job.getTaskId()+"-->"+job.getTaskTrackerNodeGroup()+"-->"+job.getSubmitNodeGroup());
System.out.println("---------------------------------------------------------------------------------");
System.out.println("---------------------------------------------------------------------------------\n\n\n");
} catch (Exception e) {
logger.info("Admin Run job failed!", e);
return new Result(Action.EXECUTE_FAILED, e.getMessage());
}
return new Result(Action.EXECUTE_SUCCESS, "Admin Excute Success!");
}
}
22 changes: 12 additions & 10 deletions lts-admin/src/main/resources/log4j.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
log4j.rootLogger=INFO,CONSOLE,LOGFILE

log4j.rootLogger=INFO,stdout
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}|%-5p|[%c{1}(%L)-->%M] -- %m%n
#log4j.appender.CONSOLE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}|%-5p| [%l] --- %m%n

log4j.appender.stdout.Threshold=INFO
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%-5p] [%d{HH:mm:ss}] %c - %m%n

#log4j.logger.org.apache.zookeeper.ZooKeeper=WARN
#log4j.logger.org.apache.zookeeper.ClientCnxn=WARN
#log4j.logger.org.I0Itec.zkclient.ZkEventThread=WARN
#log4j.logger.org.I0Itec.zkclient.ZkClient=WARN
log4j.appender.LOGFILE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.LOGFILE.File=../logs/its.log
log4j.appender.logfile.encoding=UTF-8
log4j.appender.LOGFILE.Append=false
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %l --- %m%n
log4j.appender.LOGFILE.File.DatePattern='.'yyyy-MM-dd'.log'
2 changes: 1 addition & 1 deletion lts-admin/src/main/resources/lts-admin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ registryAddress=zookeeper://127.0.0.1:2181
# registryAddress=redis://127.0.0.1:6379

# 集群名称
clusterName=test_cluster
clusterName=css-vsim-web

# zk客户端,可选值 zkclient, curator
configs.zk.client=zkclient
Expand Down
Loading