Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
S
seatunnel-web
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
宋勇
seatunnel-web
Commits
390785bd
提交
390785bd
authored
4月 24, 2024
作者:
胡伟
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
opc ua kepserver代码提交
上级
528d6584
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
460 行增加
和
3 行删除
+460
-3
pom.xml
...nel-datasource-plugins/datasource-opcua-kepserver/pom.xml
+62
-0
KeyStoreLoader.java
...che/seatunnel/datasource/plugin/opcua/KeyStoreLoader.java
+3
-3
OpcUaClientService.java
...seatunnel/datasource/plugin/opcua/OpcUaClientService.java
+0
-0
OpcuaDataSourceChannel.java
...unnel/datasource/plugin/opcua/OpcuaDataSourceChannel.java
+234
-0
OpcuaDataSourceFactory.java
...unnel/datasource/plugin/opcua/OpcuaDataSourceFactory.java
+58
-0
OpcuaOptionRule.java
...he/seatunnel/datasource/plugin/opcua/OpcuaOptionRule.java
+54
-0
OpcuaRequestParamsUtils.java
...nnel/datasource/plugin/opcua/OpcuaRequestParamsUtils.java
+49
-0
没有找到文件。
seatunnel-datasource/seatunnel-datasource-plugins/datasource-opcua-kepserver/pom.xml
0 → 100644
浏览文件 @
390785bd
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
org.apache.seatunnel
</groupId>
<artifactId>
seatunnel-datasource-plugins
</artifactId>
<version>
1.0.0-SNAPSHOT
</version>
</parent>
<artifactId>
datasource-opcua-kepserver
</artifactId>
<properties>
<kafka.client.version>
3.2.0
</kafka.client.version>
</properties>
<dependencies>
<dependency>
<groupId>
org.apache.seatunnel
</groupId>
<artifactId>
datasource-plugins-api
</artifactId>
<version>
${project.version}
</version>
<scope>
provided
</scope>
<exclusions>
<exclusion>
<groupId>
org.apache.commons
</groupId>
<artifactId>
common-lang3
</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.auto.service/auto-service -->
<dependency>
<groupId>
org.eclipse.milo
</groupId>
<artifactId>
sdk-client
</artifactId>
<version>
0.2.4
</version>
</dependency>
<dependency>
<groupId>
org.bouncycastle
</groupId>
<artifactId>
bcpkix-jdk15on
</artifactId>
<version>
1.57
</version>
</dependency>
<dependency>
<groupId>
org.eclipse.milo
</groupId>
<artifactId>
sdk-server
</artifactId>
<version>
0.2.4
</version>
</dependency>
</dependencies>
</project>
seatunnel-datasource/seatunnel-datasource-plugins/datasource-opcua-kepserver/src/main/java/org/apache/seatunnel/datasource/plugin/opcua/KeyStoreLoader.java
浏览文件 @
390785bd
...
...
@@ -39,7 +39,7 @@ class KeyStoreLoader {
private
X509Certificate
clientCertificate
;
private
KeyPair
clientKeyPair
;
KeyStoreLoader
load
(
Path
baseDir
,
String
endPoint
)
throws
Exception
{
public
KeyStoreLoader
load
(
Path
baseDir
,
String
endPoint
)
throws
Exception
{
KeyStore
keyStore
=
KeyStore
.
getInstance
(
"PKCS12"
);
Path
serverKeyStore
=
baseDir
.
resolve
(
"example-client.pfx"
);
...
...
@@ -104,7 +104,7 @@ class KeyStoreLoader {
return
this
;
}
X509Certificate
getClientCertificate
()
{
public
X509Certificate
getClientCertificate
()
{
return
clientCertificate
;
}
...
...
@@ -112,7 +112,7 @@ class KeyStoreLoader {
return
clientCertificateChain
;
}
KeyPair
getClientKeyPair
()
{
public
KeyPair
getClientKeyPair
()
{
return
clientKeyPair
;
}
}
seatunnel-datasource/seatunnel-datasource-plugins/datasource-opcua-kepserver/src/main/java/org/apache/seatunnel/datasource/plugin/opcua/OpcUaClientService.java
0 → 100644
浏览文件 @
390785bd
差异被折叠。
点击展开。
seatunnel-datasource/seatunnel-datasource-plugins/datasource-opcua-kepserver/src/main/java/org/apache/seatunnel/datasource/plugin/opcua/OpcuaDataSourceChannel.java
0 → 100644
浏览文件 @
390785bd
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
seatunnel
.
datasource
.
plugin
.
opcua
;
import
org.apache.seatunnel.api.configuration.util.OptionRule
;
import
org.apache.seatunnel.datasource.plugin.api.DataSourceChannel
;
import
org.apache.seatunnel.datasource.plugin.api.DataSourcePluginException
;
import
org.apache.seatunnel.datasource.plugin.api.model.TableField
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.eclipse.milo.opcua.stack.core.NamespaceTable
;
import
org.eclipse.milo.opcua.stack.core.types.builtin.NodeId
;
import
org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UShort
;
import
com.alibaba.fastjson2.JSONObject
;
import
lombok.NonNull
;
import
lombok.extern.slf4j.Slf4j
;
import
java.util.*
;
@Slf4j
public
class
OpcuaDataSourceChannel
implements
DataSourceChannel
{
private
static
final
String
DATABASE
=
"default"
;
public
static
class
Holder
{
private
static
final
OpcuaDataSourceChannel
INSTANCE
=
new
OpcuaDataSourceChannel
();
}
public
static
OpcuaDataSourceChannel
getInstance
()
{
return
Holder
.
INSTANCE
;
}
@Override
public
OptionRule
getDataSourceOptions
(
@NonNull
String
pluginName
)
{
return
OpcuaOptionRule
.
optionRule
();
}
@Override
public
OptionRule
getDatasourceMetadataFieldsByDataSourceName
(
@NonNull
String
pluginName
)
{
return
OpcuaOptionRule
.
metadataRule
();
}
@Override
public
List
<
String
>
getTables
(
@NonNull
String
pluginName
,
Map
<
String
,
String
>
requestParams
,
String
database
,
Map
<
String
,
String
>
option
)
{
// checkArgument(StringUtils.equalsIgnoreCase(database, DATABASE), "database must be
// default");
try
{
if
(
requestParams
.
isEmpty
())
{
return
new
ArrayList
<>();
}
OpcUaClientService
opcClient
=
createOpcClient
(
requestParams
);
if
(
Objects
.
nonNull
(
opcClient
))
{
String
ns
=
requestParams
.
get
(
"ns"
)
+
""
;
String
id
=
requestParams
.
get
(
"id"
)
+
""
;
NodeId
nodeId
=
new
NodeId
(
UShort
.
valueOf
(
ns
),
id
);
return
Arrays
.
asList
(
nodeId
.
toString
());
}
return
new
ArrayList
<>();
}
catch
(
Exception
ex
)
{
throw
new
DataSourcePluginException
(
"check kafka connectivity failed, "
+
ex
.
getMessage
(),
ex
);
}
}
@Override
public
List
<
String
>
getDatabases
(
@NonNull
String
pluginName
,
@NonNull
Map
<
String
,
String
>
requestParams
)
{
String
suffix
=
requestParams
.
get
(
"suffix"
);
if
(
StringUtils
.
isNotEmpty
(
suffix
))
{
return
Arrays
.
asList
(
suffix
);
}
return
DEFAULT_DATABASES
;
}
@Override
public
boolean
checkDataSourceConnectivity
(
@NonNull
String
pluginName
,
@NonNull
Map
<
String
,
String
>
requestParams
)
{
try
{
OpcUaClientService
opcClient
=
createOpcClient
(
requestParams
);
// just test the connection
NamespaceTable
namespaceTable
=
opcClient
.
getClient
().
getNamespaceTable
();
return
Objects
.
nonNull
(
namespaceTable
);
}
catch
(
Exception
ex
)
{
throw
new
DataSourcePluginException
(
"check kafka connectivity failed, "
+
ex
.
getMessage
(),
ex
);
}
}
@Override
public
List
<
TableField
>
getTableFields
(
@NonNull
String
pluginName
,
@NonNull
Map
<
String
,
String
>
requestParams
,
@NonNull
String
database
,
@NonNull
String
table
)
{
// checkArgument(StringUtils.equalsIgnoreCase(database, DATABASE), "database must be
// default");
// checkArgument(StringUtils.equalsIgnoreCase(database, DATABASE), "database must be
// default");
try
{
List
<
TableField
>
tableFields
=
new
ArrayList
<>();
OpcUaClientService
opcClient
=
createOpcClient
(
requestParams
);
NodeId
nodeId
=
null
;
// just test the connection
if
(
StringUtils
.
isNotEmpty
(
table
))
{
try
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
table
);
UShort
uShort
=
UShort
.
valueOf
(
jsonObject
.
getString
(
"ns"
));
Object
id
=
jsonObject
.
get
(
"id"
);
if
(
id
instanceof
Integer
)
{
nodeId
=
new
NodeId
(
uShort
,
(
Integer
)
id
);
}
else
{
nodeId
=
new
NodeId
(
uShort
,
id
+
""
);
}
}
catch
(
Exception
e
)
{
String
[]
split
=
table
.
replace
(
"NodeId{"
,
""
)
.
replace
(
"{"
,
""
)
.
replace
(
"}"
,
""
)
.
split
(
","
);
UShort
uShort
=
null
;
String
id
=
""
;
for
(
String
s
:
split
)
{
String
[]
split1
=
s
.
split
(
":|="
);
if
(
split1
.
length
==
2
)
{
if
(
split1
[
0
].
toLowerCase
().
indexOf
(
"ns"
)
>
-
1
)
{
uShort
=
UShort
.
valueOf
(
split1
[
1
]);
}
if
(
split1
[
0
].
toLowerCase
().
indexOf
(
"id"
)
>
-
1
)
{
id
=
split1
[
1
];
}
}
}
if
(
uShort
!=
null
&&
StringUtils
.
isNotEmpty
(
id
))
{
try
{
// 如果是int
Integer
idn
=
Integer
.
parseInt
(
id
);
nodeId
=
new
NodeId
(
uShort
,
idn
);
}
catch
(
Exception
ex
)
{
nodeId
=
new
NodeId
(
uShort
,
id
);
}
}
}
}
if
(
Objects
.
isNull
(
nodeId
))
{
return
new
ArrayList
<>();
}
Object
objects
=
opcClient
.
readNodeObject
(
nodeId
);
try
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
objects
.
toString
());
// 获取所有key的迭代器
Iterator
<
String
>
keys
=
jsonObject
.
keySet
().
iterator
();
while
(
keys
.
hasNext
())
{
String
key
=
keys
.
next
();
Object
value
=
jsonObject
.
get
(
key
);
TableField
tableField
=
new
TableField
();
tableField
.
setName
(
key
);
tableField
.
setType
(
value
.
getClass
().
getTypeName
());
tableFields
.
add
(
tableField
);
}
return
tableFields
;
}
catch
(
Exception
e
)
{
// 不是json
TableField
tableField
=
new
TableField
();
tableField
.
setName
(
nodeId
.
getIdentifier
()
+
""
);
tableField
.
setType
(
"String"
);
tableFields
.
add
(
tableField
);
return
tableFields
;
}
}
catch
(
Exception
ex
)
{
throw
new
DataSourcePluginException
(
"check mqtt getTableFields failed, "
+
ex
.
getMessage
(),
ex
);
}
}
@Override
public
Map
<
String
,
List
<
TableField
>>
getTableFields
(
@NonNull
String
pluginName
,
@NonNull
Map
<
String
,
String
>
requestParams
,
@NonNull
String
database
,
@NonNull
List
<
String
>
tables
)
{
// checkArgument(StringUtils.equalsIgnoreCase(database, DATABASE), "database must be
// default");
Map
<
String
,
List
<
TableField
>>
map
=
new
HashMap
<>();
if
(
CollectionUtils
.
isNotEmpty
(
tables
))
{
for
(
String
table
:
tables
)
{
map
.
put
(
table
,
getTableFields
(
pluginName
,
requestParams
,
database
,
table
));
}
}
return
map
;
}
private
OpcUaClientService
createOpcClient
(
Map
<
String
,
String
>
requestParams
)
{
String
host
=
requestParams
.
get
(
"host"
)
+
""
;
String
port
=
requestParams
.
get
(
"port"
)
+
""
;
String
suffix
=
requestParams
.
get
(
"suffix"
)
+
""
;
try
{
OpcUaClientService
opcUaClientService
=
new
OpcUaClientService
(
host
,
Integer
.
parseInt
(
port
),
suffix
);
return
opcUaClientService
;
}
catch
(
Exception
e
)
{
throw
new
DataSourcePluginException
(
"OpcUa插件 创建链接错误!"
,
e
);
}
}
}
seatunnel-datasource/seatunnel-datasource-plugins/datasource-opcua-kepserver/src/main/java/org/apache/seatunnel/datasource/plugin/opcua/OpcuaDataSourceFactory.java
0 → 100644
浏览文件 @
390785bd
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
seatunnel
.
datasource
.
plugin
.
opcua
;
import
org.apache.seatunnel.datasource.plugin.api.DataSourceChannel
;
import
org.apache.seatunnel.datasource.plugin.api.DataSourceFactory
;
import
org.apache.seatunnel.datasource.plugin.api.DataSourcePluginInfo
;
import
org.apache.seatunnel.datasource.plugin.api.DatasourcePluginTypeEnum
;
import
com.google.auto.service.AutoService
;
import
com.google.common.collect.Sets
;
import
java.util.Set
;
@AutoService
(
DataSourceFactory
.
class
)
public
class
OpcuaDataSourceFactory
implements
DataSourceFactory
{
public
static
final
String
OPCUA_PLUGIN_NAME
=
"Opcua"
;
public
static
final
String
OPCUA_PLUGIN_ICON
=
"opcua"
;
public
static
final
String
OPCUA_PLUGIN_VERSION
=
"1.0.0"
;
@Override
public
String
factoryIdentifier
()
{
return
OPCUA_PLUGIN_NAME
;
}
@Override
public
Set
<
DataSourcePluginInfo
>
supportedDataSources
()
{
return
Sets
.
newHashSet
(
DataSourcePluginInfo
.
builder
()
.
name
(
OPCUA_PLUGIN_NAME
)
.
icon
(
OPCUA_PLUGIN_ICON
)
.
version
(
OPCUA_PLUGIN_VERSION
)
.
supportVirtualTables
(
false
)
.
type
(
DatasourcePluginTypeEnum
.
NO_STRUCTURED
.
getCode
())
.
build
());
}
@Override
public
DataSourceChannel
createChannel
()
{
return
OpcuaDataSourceChannel
.
getInstance
();
}
}
seatunnel-datasource/seatunnel-datasource-plugins/datasource-opcua-kepserver/src/main/java/org/apache/seatunnel/datasource/plugin/opcua/OpcuaOptionRule.java
0 → 100644
浏览文件 @
390785bd
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
seatunnel
.
datasource
.
plugin
.
opcua
;
import
org.apache.seatunnel.api.configuration.Option
;
import
org.apache.seatunnel.api.configuration.Options
;
import
org.apache.seatunnel.api.configuration.util.OptionRule
;
public
class
OpcuaOptionRule
{
public
static
final
Option
<
String
>
HOST
=
Options
.
key
(
"host"
).
stringType
().
noDefaultValue
().
withDescription
(
"socket host"
);
public
static
final
Option
<
Integer
>
PORT
=
Options
.
key
(
"port"
).
intType
().
noDefaultValue
().
withDescription
(
"socket port"
);
public
static
final
Option
<
String
>
SUFFIX
=
Options
.
key
(
"suffix"
).
stringType
().
noDefaultValue
().
withDescription
(
"suffix"
);
public
static
final
Option
<
Integer
>
NS
=
Options
.
key
(
"ns"
).
intType
().
noDefaultValue
().
withDescription
(
"ns"
);
public
static
final
Option
<
String
>
ID
=
Options
.
key
(
"id"
).
stringType
().
noDefaultValue
().
withDescription
(
"id"
);
public
static
final
Option
<
String
>
TYPE
=
Options
.
key
(
"type"
).
stringType
().
defaultValue
(
"int"
).
withDescription
(
"type"
);
public
static
final
Option
<
Integer
>
GS
=
Options
.
key
(
"gs"
).
intType
().
defaultValue
(
1
).
withDescription
(
"type"
);
public
static
OptionRule
optionRule
()
{
return
OptionRule
.
builder
().
required
(
HOST
,
PORT
,
SUFFIX
,
NS
,
ID
,
TYPE
).
optional
(
GS
).
build
();
}
public
static
OptionRule
metadataRule
()
{
return
OptionRule
.
builder
().
required
(
NS
,
ID
,
TYPE
).
build
();
}
}
seatunnel-datasource/seatunnel-datasource-plugins/datasource-opcua-kepserver/src/main/java/org/apache/seatunnel/datasource/plugin/opcua/OpcuaRequestParamsUtils.java
0 → 100644
浏览文件 @
390785bd
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
apache
.
seatunnel
.
datasource
.
plugin
.
opcua
;
import
org.apache.seatunnel.shade.com.typesafe.config.Config
;
import
org.apache.seatunnel.shade.com.typesafe.config.ConfigFactory
;
import
java.util.Map
;
import
java.util.Properties
;
import
static
com
.
google
.
common
.
base
.
Preconditions
.
checkArgument
;
public
class
OpcuaRequestParamsUtils
{
public
static
Properties
parsePropertiesFromRequestParams
(
Map
<
String
,
String
>
requestParams
)
{
checkArgument
(
requestParams
.
containsKey
(
OpcuaOptionRule
.
HOST
.
key
()),
String
.
format
(
"Missing %s in requestParams"
,
OpcuaOptionRule
.
HOST
.
key
()));
final
Properties
properties
=
new
Properties
();
properties
.
put
(
OpcuaOptionRule
.
HOST
.
key
(),
requestParams
.
get
(
OpcuaOptionRule
.
HOST
.
key
()));
if
(
requestParams
.
containsKey
(
OpcuaOptionRule
.
PORT
.
key
()))
{
Config
configObject
=
ConfigFactory
.
parseString
(
requestParams
.
get
(
OpcuaOptionRule
.
PORT
.
key
()));
configObject
.
entrySet
()
.
forEach
(
entry
->
{
properties
.
put
(
entry
.
getKey
(),
entry
.
getValue
().
unwrapped
().
toString
());
});
}
return
properties
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论