Skip to content

Commit 50b6868

Browse files
merge 1.0.0
2 parents 8080aa5 + 3f4d2d3 commit 50b6868

26 files changed

+957
-440
lines changed

TODO.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+
技术架构模型调整

pom.xml

+5-5
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@
5151

5252
<properties>
5353
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
54-
54+
<!--
5555
<kafka-version>0.9.0.1</kafka-version>
56-
<elasticsearch-version>2.3.4</elasticsearch-version>
57-
<jruby-version>2.1.6</jruby-version>
56+
<elasticsearch-version>2.3.4</elasticsearch-version> -->
57+
<!-- <jruby-version>2.1.6</jruby-version> -->
5858
<joda-time-version>2.8.2</joda-time-version>
5959
<freemarker-gae-version>2.3.23</freemarker-gae-version>
6060
<common-cli-version>1.2</common-cli-version>
@@ -78,11 +78,11 @@
7878
</dependency>
7979

8080

81-
<dependency>
81+
<!-- <dependency>
8282
<groupId>org.jruby.joni</groupId>
8383
<artifactId>joni</artifactId>
8484
<version>${jruby-version}</version>
85-
</dependency>
85+
</dependency> -->
8686

8787
<dependency>
8888
<groupId>joda-time</groupId>

src/main/java/com/dtstack/logstash/Main.java

+13-11
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import org.apache.commons.cli.ParseException;
88
import org.slf4j.Logger;
99
import org.slf4j.LoggerFactory;
10+
1011
import com.dtstack.logstash.assembly.AssemblyPipeline;
11-
import com.dtstack.logstash.assembly.InputQueueList;
12-
import com.dtstack.logstash.assembly.ShutDownHook;
12+
import com.dtstack.logstash.exception.ExceptionUtil;
1313
import com.dtstack.logstash.log.LogComponent;
1414
import com.dtstack.logstash.log.LogbackComponent;
1515

@@ -33,6 +33,7 @@ public class Option {
3333

3434
public Option(String flag, String opt) {
3535
this.flag = flag;
36+
3637
this.opt = opt;
3738
}
3839
}
@@ -43,8 +44,11 @@ private static CommandLine parseArg(String[] args) throws ParseException {
4344
options.addOption("help", false, "usage help");
4445
options.addOption("f", true, "configuration file");
4546
options.addOption("l", true, "log file");
46-
options.addOption("w", true, "filter worker number");
47-
options.addOption("q", true, "input queue size");
47+
options.addOption("t", false, "logqueue start");
48+
options.addOption("w", false, "filter worker number");
49+
options.addOption("o", false, "output worker number");
50+
options.addOption("c", false, "output queue size coefficient");
51+
options.addOption("i", false, "input queue size coefficient");
4852
options.addOption("v", false, "print info log");
4953
options.addOption("vv", false, "print debug log");
5054
options.addOption("vvvv", false, "print trace log");
@@ -71,8 +75,10 @@ private static void usage() {
7175
.append("-f").append("\t\t\trequired config, indicate config file").append("\n")
7276
.append("-l").append("\t\t\tlog file that store the output").append("\n")
7377
.append("-w").append("\t\t\tfilter worker numbers").append("\n")
74-
.append("-q").append("\t\t\tinput queue size").append("\n")
78+
.append("-o").append("\t\t\toutput worker numbers").append("\n")
7579
.append("-t").append("\t\t\tlog input queue size").append("\n")
80+
.append("-c").append("\t\t\t output queue size coefficient").append("\n")
81+
.append("-i").append("\t\t\t input queue size coefficient").append("\n")
7682
.append("-v").append("\t\t\tprint info log").append("\n")
7783
.append("-vv").append("\t\t\tprint debug log").append("\n")
7884
.append("-vvvv").append("\t\t\tprint trace log").append("\n");
@@ -82,18 +88,14 @@ private static void usage() {
8288

8389
public static void main(String[] args) {
8490
CommandLine cmdLine = null;
85-
InputQueueList inputQueueList = null;
8691
try {
8792
cmdLine = parseArg(args);
8893
//logger config
8994
logbackComponent.setupLogger(cmdLine);
9095
//assembly pipeline
91-
inputQueueList =assemblyPipeline.assemblyPipeline(cmdLine);
92-
//add shutdownhook
93-
ShutDownHook shutDownHook = new ShutDownHook(inputQueueList, assemblyPipeline.getBaseInputs(),assemblyPipeline.getAllBaseOutputs());
94-
shutDownHook.addShutDownHook();
96+
assemblyPipeline.assemblyPipeline(cmdLine);
9597
} catch (Exception e) {
96-
logger.error("jlogstash_start error:{}",e.getCause());
98+
logger.error("jlogstash_start error:{}",ExceptionUtil.getErrorMessage(e));
9799
System.exit(-1);
98100
}
99101
}

src/main/java/com/dtstack/logstash/assembly/AssemblyPipeline.java

+41-113
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,19 @@
33
import java.io.IOException;
44
import java.util.List;
55
import java.util.Map;
6-
import java.util.concurrent.ExecutorService;
7-
import java.util.concurrent.Executors;
8-
import java.util.concurrent.LinkedBlockingQueue;
96
import org.apache.commons.cli.CommandLine;
10-
import org.apache.commons.lang3.StringUtils;
117
import org.slf4j.Logger;
128
import org.slf4j.LoggerFactory;
9+
import com.dtstack.logstash.assembly.pthread.FilterThread;
10+
import com.dtstack.logstash.assembly.pthread.InputThread;
11+
import com.dtstack.logstash.assembly.pthread.OutputThread;
12+
import com.dtstack.logstash.assembly.qlist.InputQueueList;
13+
import com.dtstack.logstash.assembly.qlist.OutPutQueueList;
1314
import com.dtstack.logstash.configs.YamlConfig;
14-
import com.dtstack.logstash.factory.FilterFactory;
15+
import com.dtstack.logstash.exception.ExceptionUtil;
1516
import com.dtstack.logstash.factory.InputFactory;
16-
import com.dtstack.logstash.factory.OutputFactory;
17-
import com.dtstack.logstash.filters.BaseFilter;
1817
import com.dtstack.logstash.inputs.BaseInput;
1918
import com.dtstack.logstash.outputs.BaseOutput;
20-
import com.dtstack.logstash.property.SystemProperty;
21-
import com.dtstack.logstash.utils.Machine;
2219
import com.google.common.collect.Lists;
2320

2421
/**
@@ -32,140 +29,71 @@
3229
public class AssemblyPipeline {
3330

3431
private static Logger logger = LoggerFactory.getLogger(AssemblyPipeline.class);
32+
33+
private InputQueueList initInputQueueList;
3534

36-
private static ExecutorService filterOutputExecutor =null;
37-
38-
private static ExecutorService inputExecutor =null;
39-
40-
private InputQueueList initInputQueueList =null;
41-
42-
private List<BaseInput> baseInputs =null;
35+
private OutPutQueueList initOutputQueueList;
36+
37+
private List<BaseInput> baseInputs;
4338

4439
private List<BaseOutput> allBaseOutputs = Lists.newCopyOnWriteArrayList();
4540

41+
4642
/**
4743
* 组装管道
4844
* @param cmdLine
4945
* @return
5046
* @throws IOException
5147
*/
5248
@SuppressWarnings({ "unchecked", "rawtypes" })
53-
public InputQueueList assemblyPipeline(CommandLine cmdLine) throws IOException{
49+
public void assemblyPipeline(CommandLine cmdLine) throws IOException{
5450
try{
5551
logger.debug("load config start ...");
5652
Map configs = new YamlConfig().parse(cmdLine.getOptionValue("f"));
5753
logger.debug(configs.toString());
5854
logger.debug("initInputQueueList start ...");
59-
initInputQueueList=initInputQueueList(cmdLine);
55+
initInputQueueList=InputQueueList.getInputQueueListInstance(CmdLineParams.getFilterWork(cmdLine), CmdLineParams.getInputQueueSize(cmdLine));
56+
if(initInputQueueList==null||initInputQueueList.getQueueList().size()==0){
57+
logger.error("init inputQueueList is error");
58+
System.exit(1);
59+
}
6060
List<Map> inputs = (List<Map>) configs.get("inputs");
6161
if(inputs==null||inputs.size()==0){
6262
logger.error("input plugin is not empty");
6363
System.exit(1);
6464
}
65-
66-
List<Map> outputs = (List<Map>) configs.get("outputs");
65+
logger.debug("initOutputQueueList start ...");
66+
initOutputQueueList = OutPutQueueList.getOutPutQueueListInstance(CmdLineParams.getOutputWork(cmdLine), CmdLineParams.getOutputQueueSize(cmdLine));
67+
if(initOutputQueueList==null||initOutputQueueList.getQueueList().size()==0){
68+
logger.error("init outputQueueList is error");
69+
System.exit(1);
70+
}
71+
List<Map> outputs = (List<Map>) configs.get("outputs");
6772
if(outputs==null||outputs.size()==0){
6873
logger.error("output plugin is not empty");
6974
System.exit(1);
7075
}
7176
List<Map> filters = (List<Map>) configs.get("filters");
7277
logger.debug("init input plugin start ...");
73-
baseInputs =InputFactory.getBatchInstance(inputs, initInputQueueList);
78+
baseInputs =InputFactory.getBatchInstance(inputs,initInputQueueList);
7479
initInputQueueList.startElectionIdleQueue();
75-
if(isInputQueueSizeLog(cmdLine))initInputQueueList.startLogQueueSize();
80+
initOutputQueueList.startElectionIdleQueue();
81+
if(CmdLineParams.isQueueSizeLog(cmdLine)){
82+
initInputQueueList.startLogQueueSize();
83+
initOutputQueueList.startLogQueueSize();
84+
}
7685
logger.debug("input thread start ...");
77-
initInputPutThread(baseInputs);
78-
logger.debug("FilterAndOutput thread start ...");
79-
initFilterAndOutputThread(outputs,filters,initInputQueueList.getQueueList(),getOutBatchSize(cmdLine));
86+
InputThread.initInputThread(baseInputs);
87+
logger.debug("filter thread start ...");
88+
FilterThread.initFilterThread(filters,initInputQueueList,initOutputQueueList);
89+
logger.debug("output thread start ...");
90+
OutputThread.initOutPutThread(outputs,initOutputQueueList,allBaseOutputs);
91+
//add shutdownhook
92+
ShutDownHook shutDownHook = new ShutDownHook(initInputQueueList,initOutputQueueList,baseInputs,allBaseOutputs);
93+
shutDownHook.addShutDownHook();
8094
}catch(Exception t){
81-
logger.error("assemblyPipeline is error:{}", t.getCause());
95+
logger.error("assemblyPipeline is error:{}",ExceptionUtil.getErrorMessage(t));
8296
System.exit(1);
8397
}
84-
return initInputQueueList;
8598
}
86-
87-
88-
protected InputQueueList initInputQueueList(CommandLine cmdLine){
89-
int filterWorks = getFilterWork(cmdLine);
90-
int queueSize = getInputQueueSize(cmdLine);
91-
InputQueueList queueList = new InputQueueList();
92-
List<LinkedBlockingQueue<Map<String,Object>>> list =queueList.getQueueList();
93-
for(int i=0;i<filterWorks;i++){
94-
list.add(new LinkedBlockingQueue<Map<String,Object>>(queueSize));
95-
}
96-
return queueList;
97-
}
98-
99-
100-
protected void initInputPutThread(List<BaseInput> baseInputs) {
101-
// TODO Auto-generated method stub
102-
inputExecutor= Executors.newFixedThreadPool(baseInputs.size());
103-
for(BaseInput input:baseInputs){
104-
inputExecutor.submit(new InputThread(input));
105-
}
106-
}
107-
108-
@SuppressWarnings("rawtypes")
109-
protected void initFilterAndOutputThread(List<Map> outputs, List<Map> filters, List<LinkedBlockingQueue<Map<String,Object>>> queues,int batchSize) throws Exception{
110-
filterOutputExecutor= Executors.newFixedThreadPool(queues.size());
111-
for(LinkedBlockingQueue<Map<String,Object>> queue:queues){
112-
List<BaseOutput> baseOutputs = OutputFactory.getBatchInstance(outputs);
113-
List<BaseFilter> baseFilters = FilterFactory.getBatchInstance(filters);
114-
filterOutputExecutor.submit(new FilterAndOutputThread(queue,baseFilters,baseOutputs,batchSize));
115-
allBaseOutputs.addAll(baseOutputs);
116-
}
117-
}
118-
119-
/**
120-
* 获取filter线程数
121-
* @param line
122-
* @return
123-
*/
124-
protected static int getFilterWork(CommandLine line){
125-
String number =line.getOptionValue("w");
126-
int works =StringUtils.isNotBlank(number)?Integer.parseInt(number):Machine.availableProcessors();
127-
logger.warn("getFilterWork--->"+works);
128-
return works;
129-
}
130-
131-
/**
132-
*获取queue size的大小
133-
* @param line
134-
* @return
135-
*/
136-
protected static int getInputQueueSize(CommandLine line){
137-
String number =line.getOptionValue("q");
138-
return StringUtils.isNotBlank(number)?Integer.parseInt(number):Integer.parseInt(SystemProperty.getSystemProperty("inputQueueSize"));
139-
}
140-
141-
/**
142-
* 获取batch size的大小
143-
* @param line
144-
* @return
145-
*/
146-
protected static int getOutBatchSize(CommandLine line){
147-
String number =line.getOptionValue("b");
148-
return StringUtils.isNotBlank(number)?Integer.parseInt(number):Integer.parseInt(SystemProperty.getSystemProperty("batchSize"));
149-
}
150-
151-
152-
/**
153-
* 是否开启InputQueueSize log日志标准输出
154-
* @param line
155-
* @return
156-
*/
157-
protected static boolean isInputQueueSizeLog(CommandLine line){
158-
return line.hasOption("t");
159-
}
160-
161-
162-
public List<BaseInput> getBaseInputs() {
163-
return this.baseInputs;
164-
}
165-
166-
167-
public List<BaseOutput> getAllBaseOutputs() {
168-
return allBaseOutputs;
169-
}
170-
171-
}
99+
}

0 commit comments

Comments
 (0)