- 1 概述:
- 2 准备环境(我这里用的是1.5.0):
- 2.1 idea环境OK,下载一套所需要版本的openlookeng源码:gitee: https://gitee.com/openlookeng/hetu-core github:https://github.com/openlookeng/hetu-core
- 2.2 自己部署一套对应版本的openlookeng集群用来调试:部署方法:转载:https://blog.csdn.net/openLooKeng/article/details/120088344
- 3 connector 开发
- 3.1 在openLooKeng源码根目录创建与Connector名对应的模块
- 3.2 将当前模块加入io.hetu.core组中,版本需要和当前openLooKeng工程版本一致:
- 3.3 定义当前工程信息,添加packaging选项为hetu-plugin在打包编译时会将当前工程打包到heto-core的plugin目录下。
- 3.4 引入 SPI 依赖,每个Plugin工程都会依赖 presto-spi 模块:
- 3.5 在hetu core根目录下的pom.xml中,将我们新增的Connector 加入到 modules 中
- 3.6 在hetu-server的src/main/provisio/hetu.xml配置文件中,注册新增的Connector
- 3.7 hetu-dm模块代码实现
- 3.7.1 需要实现的类
- 3.7.2 主要代码示例
- 3.8 编译整个openLooKeng工程时,我们需要将自定义添加的connector也编译打包到plugin目录下,或者package hetu-dm 模块,将插件包放入环境中
- 4 测试环境调试
- 4.1 配置dm.properties
- 4.2 启动openlookeng集群
- 4.2.1 执行启动脚本:start.sh
- 4.2.2 查看日志
- 4.2.3 登录openlookeng webUI界面进行SQL查询测试
- 5 金仓connector的实现步骤同达梦相同,并且同属于jdbc数据源,代码大多数可以复用
openlookeng架构以及执行逻辑,connector的原理等概念性问题,请自行百度,这里不再阐述
2 准备环境(我这里用的是1.5.0): 2.1 idea环境OK,下载一套所需要版本的openlookeng源码:gitee: https://gitee.com/openlookeng/hetu-core github:https://github.com/openlookeng/hetu-core 2.2 自己部署一套对应版本的openlookeng集群用来调试:部署方法:转载:https://blog.csdn.net/openLooKeng/article/details/120088344 3 connector 开发 3.1 在openLooKeng源码根目录创建与Connector名对应的模块如:[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-HCDPYEud-1652084173587)(C:UsersadminAppDataRoamingTyporatypora-user-imagesimage-20220507143249304.png)]
3.2 将当前模块加入io.hetu.core组中,版本需要和当前openLooKeng工程版本一致:3.3 定义当前工程信息,添加packaging选项为hetu-plugin在打包编译时会将当前工程打包到heto-core的plugin目录下。presto-root io.hetu.core 1.5.0
3.4 引入 SPI 依赖,每个Plugin工程都会依赖 presto-spi 模块:hetu-dm Hetu - DM Connector hetu-plugin
io.hetu.core
presto-spi
provided
3.5 在hetu core根目录下的pom.xml中,将我们新增的Connector 加入到 modules 中
3.6 在hetu-server的src/main/provisio/hetu.xml配置文件中,注册新增的Connector...... hetu-dm ......
经过以上步骤,新增Connector的准备工作就已经完成。在开发过程中根据具体实现使用到的类来添加依赖。Plugin使用了独立的类加载器,和其他的类是隔离的,因此Plugin可以使用不同版本的类库,区别于hetu core内部使用的版本。
3.7 hetu-dm模块代码实现 3.7.1 需要实现的类[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-4N08lnt4-1652084173591)(C:UsersadminAppDataRoamingTyporatypora-user-imagesimage-20220507152446994.png)]
3.7.2 主要代码示例DMPlugin:
@ConnectorConfig(connectorLabel = "DM : Query and create tables on an external DM database",
propertiesEnabled = true)
public class DMPlugin extends JdbcPlugin {
public DMPlugin() {
super("dm", new DMClientModule());
}
@Override
public Optional getConnectorWithProperties()
{
ConnectorConfig connectorConfig = DMPlugin.class.getAnnotation(ConnectorConfig.class);
Optional connectorWithProperties = ConnectorUtil.assembleConnectorProperties(connectorConfig,
Arrays.asList(BaseJdbcConfig.class.getDeclaredMethods()));
ConnectorUtil.addConnUrlProperty(connectorWithProperties, "jdbc:dm://host:port");
return connectorWithProperties;
}
}
DMClientModule:
public class DMClientModule implements Module {
@Override
public void configure(Binder binder) {
binder.bind(JdbcClient.class).to(DMClient.class).in(Scopes.SINGLETON);
configBinder(binder).bindConfig(BaseJdbcConfig.class);
configBinder(binder).bindConfig(DMConfig.class);
}
@Provides
@Singleton
public static ConnectionFactory getConnectionFactory(BaseJdbcConfig config, DMConfig dmConfig)
{
Properties connectionProperties = basicConnectionProperties(config);
Driver driver;
try {
driver = (Driver) Class.forName(Constants.DM_JDBC_DRIVER_CLASS_NAME).getConstructor(((Class>[]) null)).newInstance();
}
catch (InstantiationException | ClassNotFoundException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
throw new PrestoException(JDBC_ERROR, e);
}
return new DriverConnectionFactory(driver, config.getConnectionUrl(),
Optional.ofNullable(config.getUserCredentialName()),
Optional.ofNullable(config.getPasswordCredentialName()), connectionProperties);
}
}
3.8 编译整个openLooKeng工程时,我们需要将自定义添加的connector也编译打包到plugin目录下,或者package hetu-dm 模块,将插件包放入环境中
如[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-CPC9YLrR-1652084173593)(C:UsersadminAppDataRoamingTyporatypora-user-imagesimage-20220507153436330.png)]
将此目录放到$openlookeng_home/hetu-server-1.5.0/plugin/ 下,重命名为dm,并将DM连接jdbc的驱动拷贝至此目录下
如:[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-SCkiJDu2-1652084173593)(C:UsersadminAppDataRoamingTyporatypora-user-imagesimage-20220507153732202.png)]
4 测试环境调试 4.1 配置dm.properties进入/hetu-server-1.5.0/etc/catalog 目录:
vim dm.properties
配置以下配置项:
connector.name=dm --此名字与自定义connector的名字保持一致
connection-url=jdbc:dm://ip:5236/DMTEST
connection-user=SYSDBA
connection-password=SYSDBA123
配置完成后分发至其他服务器
4.2 启动openlookeng集群
4.2.1 执行启动脚本:start.sh
4.2.2 查看日志
tailf -300 /hetu-server-1.5.0/data/var/log/server.log
如图所示dmplugin加载成功
如图所示配置文件加载成功
测试结果如图所示:



