Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doujutun3207
flink
提交
98063ff6
F
flink
项目概览
doujutun3207
/
flink
与 Fork 源项目一致
从无法访问的项目Fork
通知
24
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
flink
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
98063ff6
编写于
7月 14, 2014
作者:
Y
Yingjun Wu
提交者:
Stephan Ewen
8月 18, 2014
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[streaming] solve issue #3
上级
4116c4bc
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
150 addition
and
72 deletion
+150
-72
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/StreamComponentFactory.java
...eu/stratosphere/streaming/api/StreamComponentFactory.java
+70
-9
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/StreamSink.java
...c/main/java/eu/stratosphere/streaming/api/StreamSink.java
+16
-16
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/StreamSource.java
...main/java/eu/stratosphere/streaming/api/StreamSource.java
+27
-22
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/StreamTask.java
...c/main/java/eu/stratosphere/streaming/api/StreamTask.java
+37
-25
未找到文件。
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/StreamComponentFactory.java
浏览文件 @
98063ff6
package
eu.stratosphere.streaming.api
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
eu.stratosphere.configuration.Configuration
;
import
eu.stratosphere.nephele.event.task.EventListener
;
import
eu.stratosphere.nephele.io.ChannelSelector
;
import
eu.stratosphere.nephele.io.RecordReader
;
import
eu.stratosphere.nephele.io.RecordWriter
;
import
eu.stratosphere.nephele.template.AbstractTask
;
import
eu.stratosphere.streaming.partitioner.DefaultPartitioner
;
import
eu.stratosphere.streaming.partitioner.FieldsPartitioner
;
import
eu.stratosphere.types.Key
;
...
...
@@ -14,7 +17,7 @@ import eu.stratosphere.types.Record;
import
eu.stratosphere.types.StringValue
;
public
final
class
StreamComponentFactory
{
//TODO: put setConfigInputs here
//
TODO: put setConfigInputs here
public
static
void
setAckListener
(
Map
<
String
,
StreamRecord
>
recordBuffer
,
String
sourceInstanceID
,
List
<
RecordWriter
<
Record
>>
outputs
)
{
...
...
@@ -26,27 +29,85 @@ public final class StreamComponentFactory {
}
}
public
static
int
setConfigInputs
(
StreamTask
taskBase
,
Configuration
taskConfiguration
,
List
<
RecordReader
<
Record
>>
inputs
)
{
int
numberOfInputs
=
taskConfiguration
.
getInteger
(
"numberOfInputs"
,
0
);
for
(
int
i
=
0
;
i
<
numberOfInputs
;
i
++)
{
inputs
.
add
(
new
RecordReader
<
Record
>(
taskBase
,
Record
.
class
));
}
return
numberOfInputs
;
}
// this function can be removed as duplication of the above function if
// modification on kernel is allowed.
public
static
int
setConfigInputs
(
StreamSink
taskBase
,
Configuration
taskConfiguration
,
List
<
RecordReader
<
Record
>>
inputs
)
{
int
numberOfInputs
=
taskConfiguration
.
getInteger
(
"numberOfInputs"
,
0
);
for
(
int
i
=
0
;
i
<
numberOfInputs
;
i
++)
{
inputs
.
add
(
new
RecordReader
<
Record
>(
taskBase
,
Record
.
class
));
}
return
numberOfInputs
;
}
public
static
int
setConfigOutputs
(
StreamTask
taskBase
,
Configuration
taskConfiguration
,
List
<
RecordWriter
<
Record
>>
outputs
,
List
<
ChannelSelector
<
Record
>>
partitioners
)
{
int
numberOfOutputs
=
taskConfiguration
.
getInteger
(
"numberOfOutputs"
,
0
);
for
(
int
i
=
1
;
i
<=
numberOfOutputs
;
i
++)
{
StreamComponentFactory
.
setPartitioner
(
taskConfiguration
,
i
,
partitioners
);
}
for
(
ChannelSelector
<
Record
>
outputPartitioner
:
partitioners
)
{
outputs
.
add
(
new
RecordWriter
<
Record
>(
taskBase
,
Record
.
class
,
outputPartitioner
));
}
return
numberOfOutputs
;
}
// this function can be removed as duplication of the above function if
// modification on kernel is allowed.
public
static
int
setConfigOutputs
(
StreamSource
taskBase
,
Configuration
taskConfiguration
,
List
<
RecordWriter
<
Record
>>
outputs
,
List
<
ChannelSelector
<
Record
>>
partitioners
)
{
int
numberOfOutputs
=
taskConfiguration
.
getInteger
(
"numberOfOutputs"
,
0
);
for
(
int
i
=
1
;
i
<=
numberOfOutputs
;
i
++)
{
StreamComponentFactory
.
setPartitioner
(
taskConfiguration
,
i
,
partitioners
);
}
for
(
ChannelSelector
<
Record
>
outputPartitioner
:
partitioners
)
{
outputs
.
add
(
new
RecordWriter
<
Record
>(
taskBase
,
Record
.
class
,
outputPartitioner
));
}
return
numberOfOutputs
;
}
public
static
void
setPartitioner
(
Configuration
taskConfiguration
,
int
nrOutput
,
List
<
ChannelSelector
<
Record
>>
partitioners
)
{
Class
<?
extends
ChannelSelector
<
Record
>>
partitioner
=
taskConfiguration
.
getClass
(
"partitionerClass_"
+
nrOutput
,
DefaultPartitioner
.
class
,
ChannelSelector
.
class
);
.
getClass
(
"partitionerClass_"
+
nrOutput
,
DefaultPartitioner
.
class
,
ChannelSelector
.
class
);
try
{
if
(
partitioner
.
equals
(
FieldsPartitioner
.
class
))
{
int
keyPosition
=
taskConfiguration
.
getInteger
(
"partitionerIntParam_"
+
nrOutput
,
1
);
int
keyPosition
=
taskConfiguration
.
getInteger
(
"partitionerIntParam_"
+
nrOutput
,
1
);
Class
<?
extends
Key
>
keyClass
=
taskConfiguration
.
getClass
(
"partitionerClassParam_"
+
nrOutput
,
StringValue
.
class
,
Key
.
class
);
"partitionerClassParam_"
+
nrOutput
,
StringValue
.
class
,
Key
.
class
);
partitioners
.
add
(
partitioner
.
getConstructor
(
int
.
class
,
Class
.
class
)
.
newInstance
(
keyPosition
,
keyClass
));
partitioners
.
add
(
partitioner
.
getConstructor
(
int
.
class
,
Class
.
class
)
.
newInstance
(
keyPosition
,
keyClass
));
}
else
{
partitioners
.
add
(
partitioner
.
newInstance
());
}
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"partitioner error"
+
" "
+
"partitioner_"
+
nrOutput
);
System
.
out
.
println
(
"partitioner error"
+
" "
+
"partitioner_"
+
nrOutput
);
System
.
out
.
println
(
e
);
}
}
...
...
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/StreamSink.java
浏览文件 @
98063ff6
...
...
@@ -38,23 +38,19 @@ public class StreamSink extends AbstractOutputTask {
numberOfInputs
=
0
;
}
private
void
setConfigInputs
()
{
Configuration
taskConfiguration
=
getTaskConfiguration
();
numberOfInputs
=
taskConfiguration
.
getInteger
(
"numberOfInputs"
,
0
);
for
(
int
i
=
0
;
i
<
numberOfInputs
;
i
++)
{
inputs
.
add
(
new
RecordReader
<
Record
>(
this
,
Record
.
class
));
}
setUserFunction
(
taskConfiguration
);
}
// alternative: remove the comments on this function as well as the
// statement in cregisterInputOuput functions.
// private void setConfigInputs(Configuration taskConfiguration) {
// numberOfInputs = taskConfiguration.getInteger("numberOfInputs", 0);
// for (int i = 0; i < numberOfInputs; i++) {
// inputs.add(new RecordReader<Record>(this, Record.class));
// }
// }
public
void
setUserFunction
(
Configuration
taskConfiguration
)
{
Class
<?
extends
UserSinkInvokable
>
userFunctionClass
;
userFunctionClass
=
taskConfiguration
.
getClass
(
"userfunction"
,
DefaultSinkInvokable
.
class
,
UserSinkInvokable
.
class
);
Class
<?
extends
UserSinkInvokable
>
userFunctionClass
=
taskConfiguration
.
getClass
(
"userfunction"
,
DefaultSinkInvokable
.
class
,
UserSinkInvokable
.
class
);
try
{
userFunction
=
userFunctionClass
.
newInstance
();
}
catch
(
Exception
e
)
{
...
...
@@ -64,7 +60,11 @@ public class StreamSink extends AbstractOutputTask {
@Override
public
void
registerInputOutput
()
{
setConfigInputs
();
Configuration
taskConfiguration
=
getTaskConfiguration
();
// setConfigInputs(taskConfiguration);
numberOfInputs
=
StreamComponentFactory
.
setConfigInputs
(
this
,
taskConfiguration
,
inputs
);
setUserFunction
(
taskConfiguration
);
}
@Override
...
...
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/StreamSource.java
浏览文件 @
98063ff6
...
...
@@ -35,7 +35,7 @@ public class StreamSource extends AbstractInputTask<RandIS> {
private
List
<
ChannelSelector
<
Record
>>
partitioners
;
private
UserSourceInvokable
userFunction
;
private
int
numberOfOutputs
;
private
static
int
numSources
=
0
;
private
String
sourceInstanceID
;
private
Map
<
String
,
StreamRecord
>
recordBuffer
;
...
...
@@ -49,6 +49,7 @@ public class StreamSource extends AbstractInputTask<RandIS> {
numSources
++;
sourceInstanceID
=
Integer
.
toString
(
numSources
);
recordBuffer
=
new
TreeMap
<
String
,
StreamRecord
>();
}
@Override
...
...
@@ -61,39 +62,43 @@ public class StreamSource extends AbstractInputTask<RandIS> {
return
null
;
}
private
void
setConfigInputs
()
{
Configuration
taskConfiguration
=
getTaskConfiguration
();
numberOfOutputs
=
taskConfiguration
.
getInteger
(
"numberOfOutputs"
,
0
);
for
(
int
i
=
1
;
i
<=
numberOfOutputs
;
i
++)
{
StreamComponentFactory
.
setPartitioner
(
taskConfiguration
,
i
,
partitioners
);
}
for
(
ChannelSelector
<
Record
>
outputPartitioner
:
partitioners
)
{
outputs
.
add
(
new
RecordWriter
<
Record
>(
this
,
Record
.
class
,
outputPartitioner
));
}
setUserFunction
(
taskConfiguration
);
StreamComponentFactory
.
setAckListener
(
recordBuffer
,
sourceInstanceID
,
outputs
);
}
// alternative: remove the comments on this function as well as the
// statement in cregisterInputOuput functions.
// private void setConfigOutputs(Configuration taskConfiguration) {
// numberOfOutputs = taskConfiguration.getInteger("numberOfOutputs", 0);
// for (int i = 1; i <= numberOfOutputs; i++) {
// StreamComponentFactory.setPartitioner(taskConfiguration, i,
// partitioners);
// }
// for (ChannelSelector<Record> outputPartitioner : partitioners) {
// outputs.add(new RecordWriter<Record>(this, Record.class,
// outputPartitioner));
// }
// }
public
void
setUserFunction
(
Configuration
taskConfiguration
)
{
Class
<?
extends
UserSourceInvokable
>
userFunctionClass
=
taskConfiguration
.
getClass
(
"userfunction"
,
DefaultSourceInvokable
.
class
,
UserSourceInvokable
.
class
);
try
{
this
.
userFunction
=
userFunctionClass
.
newInstance
();
this
.
userFunction
.
declareOutputs
(
outputs
,
sourceInstanceID
,
recordBuffer
);
userFunction
=
userFunctionClass
.
newInstance
();
userFunction
.
declareOutputs
(
outputs
,
sourceInstanceID
,
recordBuffer
);
}
catch
(
Exception
e
)
{
}
}
@Override
public
void
registerInputOutput
()
{
setConfigInputs
();
Configuration
taskConfiguration
=
getTaskConfiguration
();
// setConfigOutputs(taskConfiguration);
numberOfOutputs
=
StreamComponentFactory
.
setConfigOutputs
(
this
,
taskConfiguration
,
outputs
,
partitioners
);
setUserFunction
(
taskConfiguration
);
StreamComponentFactory
.
setAckListener
(
recordBuffer
,
sourceInstanceID
,
outputs
);
}
@Override
...
...
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/StreamTask.java
浏览文件 @
98063ff6
...
...
@@ -56,28 +56,27 @@ public class StreamTask extends AbstractTask {
recordBuffer
=
new
TreeMap
<
String
,
StreamRecord
>();
}
private
void
setConfigInputs
()
{
Configuration
taskConfiguration
=
getTaskConfiguration
();
numberOfInputs
=
taskConfiguration
.
getInteger
(
"numberOfInputs"
,
0
);
for
(
int
i
=
0
;
i
<
numberOfInputs
;
i
++)
{
inputs
.
add
(
new
RecordReader
<
Record
>(
this
,
Record
.
class
));
}
numberOfOutputs
=
taskConfiguration
.
getInteger
(
"numberOfOutputs"
,
0
);
for
(
int
i
=
1
;
i
<=
numberOfOutputs
;
i
++)
{
StreamComponentFactory
.
setPartitioner
(
taskConfiguration
,
i
,
partitioners
);
}
for
(
ChannelSelector
<
Record
>
outputPartitioner
:
partitioners
)
{
outputs
.
add
(
new
RecordWriter
<
Record
>(
this
,
Record
.
class
,
outputPartitioner
));
}
setUserFunction
(
taskConfiguration
);
StreamComponentFactory
.
setAckListener
(
recordBuffer
,
taskInstanceID
,
outputs
);
}
// alternative: remove the comments on these two functions as well as the
// two statements in registerInputOuput functions.
// private void setConfigInputs(Configuration taskConfiguration) {
// numberOfInputs = taskConfiguration.getInteger("numberOfInputs", 0);
// for (int i = 0; i < numberOfInputs; i++) {
// inputs.add(new RecordReader<Record>(this, Record.class));
// }
// }
//
// private void setConfigOutputs(Configuration taskConfiguration) {
// numberOfOutputs = taskConfiguration.getInteger("numberOfOutputs", 0);
// for (int i = 1; i <= numberOfOutputs; i++) {
// StreamComponentFactory.setPartitioner(taskConfiguration, i,
// partitioners);
// }
// for (ChannelSelector<Record> outputPartitioner : partitioners) {
// outputs.add(new RecordWriter<Record>(this, Record.class,
// outputPartitioner));
// }
// }
public
void
setUserFunction
(
Configuration
taskConfiguration
)
{
Class
<?
extends
UserTaskInvokable
>
userFunctionClass
=
taskConfiguration
...
...
@@ -93,7 +92,18 @@ public class StreamTask extends AbstractTask {
@Override
public
void
registerInputOutput
()
{
setConfigInputs
();
Configuration
taskConfiguration
=
getTaskConfiguration
();
// setConfigInputs(taskConfiguration);
// setConfigOutputs(taskConfiguration);
numberOfInputs
=
StreamComponentFactory
.
setConfigInputs
(
this
,
taskConfiguration
,
inputs
);
numberOfOutputs
=
StreamComponentFactory
.
setConfigOutputs
(
this
,
taskConfiguration
,
outputs
,
partitioners
);
setUserFunction
(
taskConfiguration
);
StreamComponentFactory
.
setAckListener
(
recordBuffer
,
taskInstanceID
,
outputs
);
}
@Override
...
...
@@ -106,9 +116,11 @@ public class StreamTask extends AbstractTask {
hasInput
=
true
;
StreamRecord
streamRecord
=
new
StreamRecord
(
input
.
next
());
String
id
=
streamRecord
.
popId
();
// TODO: Enclose invoke in try-catch to properly fail records
// TODO: Enclose invoke in try-catch to properly fail
// records
userFunction
.
invoke
(
streamRecord
.
getRecord
());
System
.
out
.
println
(
this
.
getClass
().
getName
()
+
"-"
+
taskInstanceID
);
System
.
out
.
println
(
this
.
getClass
().
getName
()
+
"-"
+
taskInstanceID
);
System
.
out
.
println
(
recordBuffer
.
toString
());
System
.
out
.
println
(
"---------------------"
);
input
.
publishEvent
(
new
AckEvent
(
id
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录