kettle环境初始化

本文详细介绍了Kettle启动时的初始化流程,包括创建.kettle目录、读取kettle.properties文件、初始化日志配置、注册插件类型等内容。

背景

程序启动时会初始化kettle的运行环境,例如,spoon启动时main方法就会调用KettleEnvironment.init()来为spoon的运行环境作初始化。通过KettleEnvironment.init()来初始化环境时,会读取属性文件、注册插件等,以init()方法为切入点,调试了一下源码,大概整理了一下脉络,并简单记录下来:

步骤

  1. 调用KettleClientEnvironment.init()方法初始化客户端环境,具体的子流程以下:
  2. 创建.kettle目录,并在该目录下创建一个默认的kttle.properties文件—createKettleHome()
  3. 读取kettle.properties文件,把内容设置到系统变量中—EnvUtil.environmentInit()
  4. 初始化一些日志配置
  5. 注册插件类型(5种类型)并进行初始化—PluginRegistry.init( true )
  6. 如果运行在一个standalone model(例如spoon,kitche,carte),则会初始化JNDI,具体细节查看JndiUtil.initJNDI()
  7. 把本地插件类型RowDistributionPluginType,StepPluginType,PartitionerPluginType,JobEntryPluginType,LogTablePluginType, RepositoryPluginType,LifecyclePluginTypeKettleLifecyclePluginType,ImportRulePluginType,CartePluginType,CompressionPluginType, AuthenticationProviderPluginType,AuthenticationConsumerPluginType添加到PluginRestry类的**pluginTypes:List**中
  8. 调用PluginRegistry.init()进行初始化插件
  9. 初始化kettle变量,其实是解析kettle-variables.xml并保存里面的配置到List里—KettleVariablesList.init()
  10. 初始化生命周期监听器—initLifecycleListeners()
  11. 初始化日志插件—initLoggingPlugins()

流程图

Created with Raphaël 2.3.0 KettleEnvironment.init()方法 调用KettleClientEnvironment.init()方法初始化客户端环境 JndiUtil.initJNDI():初始化JNDI,当运行在一个standalone model(spoon,kitche,carte) 注册本地插件类型(13种,如StepPluginType等),并进行初始化PluginRegistry.init() KettleVariablesList.init():初始化kettle变量,其实是解析kettle-variables.xml并保存里面的配置到List里 initLifecycleListeners():初始化生命周期监听器;initLoggingPlugins():初始化日志插件 结束
Created with Raphaël 2.3.0 调用KettleClientEnvironment.init()方法初始化客户端环境 createKettleHome:创建.kettle目录,并在该目录下创建一个默认的kttle.properties文件 EnvUtil.environmentInit():读取kettle.properties文件,把内容设置到系统变量中 初始化一些日志配置 注册插件类型(5种类型)并进行初始化:PluginRegistry.init( true ); 结束
java.nio.file.FileSystemNotFoundException at com.sun.nio.zipfs.ZipFileSystemProvider.getFileSystem(ZipFileSystemProvider.java:171) at com.sun.nio.zipfs.ZipFileSystemProvider.getPath(ZipFileSystemProvider.java:157) at java.nio.file.Paths.get(Paths.java:143) at com.ruoyi.kettle.tools.KettleUtil$KettleEnv.init(KettleUtil.java:448) at com.ruoyi.kettle.tools.KettleUtil.runKettleJob(KettleUtil.java:238) at com.ruoyi.kettle.service.impl.KettleJobServiceImpl.runJobRightNow(KettleJobServiceImpl.java:259) at com.ruoyi.kettle.tools.RedisStreamUtil.readGroup(RedisStreamUtil.java:251) at com.ruoyi.kettle.tools.CommandLineRunnerImpl$1.run(CommandLineRunnerImpl.java:26) 16:51:35.413 [Thread-3] ERROR c.r.k.t.KettleUtil - [init,461] - Kettle环境初始化失败 java.nio.file.FileSystemNotFoundException public static class KettleEnv { public static void init() { try { //增加自定义的插件库 int lengths = StepPluginType.getInstance().getPluginFolders().size(); URL resourceUrl = KettleUtil.class.getClassLoader().getResource(""); if (resourceUrl == null) { throw new FileNotFoundException("无法定位资源目录"); } Path homePath = Paths.get(resourceUrl.toURI()); Path kettleRoot = homePath.resolve("kettlePlugins").normalize(); String pluginPath = String.valueOf(kettleRoot); log.info("kettle插件路径,{}",pluginPath); if (!StepPluginType.getInstance().getPluginFolders().stream().anyMatch(a -> a.getFolder().equals(pluginPath))) { StepPluginType.getInstance().getPluginFolders().add(new PluginFolder(pluginPath, false, true)); } KettleEnvironment.init(); EnvUtil.environmentInit(); log.info("Kettle环境初始化成功"); } catch (Exception e) { e.printStackTrace(); log.error("Kettle环境初始化失败"); } } } kettle插件在D:\IDEA\java_kettle\smart-kettle\RuoYi-master\ruoyi-admin\src\main\resources\kettlePlugins,我希望执行kettle作业时候直接用本地程序的插件,ruoyi框架打jar包部署,提示上面的情况,怎么调整。
06-06
//执行本地文件作业 public boolean runKettleJob(Map<String, String> initKettleParam, String jobName) throws URISyntaxException, FileNotFoundException { KettleEnv.init(); String uuid = UUID.randomUUID().toString(); String pluginBasePath = KettleEnv.getPluginBasePath(); if (pluginBasePath == null) { throw new IllegalStateException("Kettle插件基础路径未初始化"); } // 设置JNDI路径(基于插件路径) Path jndiPath = Paths.get(pluginBasePath, "simple-jndi"); Const.JNDI_DIRECTORY = jndiPath.toString(); // 设置系统属性 System.setProperty("KETTLE_HOME", pluginBasePath); System.setProperty("org.osjava.sj.root", jndiPath.toString()); log.info("Kettle插件基础路径: {}", pluginBasePath); log.info("JNDI路径: {}", jndiPath); Path jobPath = Paths.get(jobName); log.info("JjobPath: {}", jobPath.toString()); DataSource ds = null; try { ds = (DataSource) new InitialContext().lookup("ORA_BIM"); } catch (NamingException e) { throw new RuntimeException(e); } try (Connection conn = ds.getConnection()) { log.info("JNDI Connection Successful!"); } catch (SQLException e) { throw new RuntimeException(e); } 09:49:35.706 [Thread-19] INFO c.r.k.t.KettleUtil - [init,543] - Kettle环境初始化成功 09:49:35.707 [Thread-19] INFO c.r.k.t.KettleUtil - [runKettleJob,266] - Kettle插件基础路径: D:\IDEA\java_kettle\smart-kettle\RuoYi-master\ruoyi-admin\target\classes\kettlePlugins 09:49:35.707 [Thread-19] INFO c.r.k.t.KettleUtil - [runKettleJob,267] - JNDI路径: D:\IDEA\java_kettle\smart-kettle\RuoYi-master\ruoyi-admin\target\classes\kettlePlugins\simple-jndi 09:49:35.707 [Thread-19] INFO c.r.k.t.KettleUtil - [runKettleJob,270] - JjobPath: D:\kettle\pims_etl_jndi\pims_job_jndi.kjb java.lang.NullPointerException at com.ruoyi.kettle.tools.KettleUtil.runKettleJob(KettleUtil.java:279) at com.ruoyi.kettle.service.impl.KettleJobServiceImpl.runJobRightNow(KettleJobServiceImpl.java:259) at com.ruoyi.kettle.tools.RedisStreamUtil.readGroup(RedisStreamUtil.java:251) at com.ruoyi.kettle.tools.CommandLineRunnerImpl$1.run(CommandLineRunnerImpl.java:26) D:\IDEA\java_kettle\smart-kettle\RuoYi-master\ruoyi-admin\target\classes\kettlePlugins\simple-jndi目录下jdbc.properties配置如下: SampleData/type=javax.sql.DataSource SampleData/driver=org.h2.Driver SampleData/url=jdbc:h2:file:samples/db/sampledb;IFEXISTS=TRUE SampleData/user=PENTAHO_USER SampleData/password=PASSWORD Quartz/type=javax.sql.DataSource Quartz/driver=org.hsqldb.jdbcDriver Quartz/url=jdbc:hsqldb:hsql://localhost/quartz Quartz/user=pentaho_user Quartz/password=password Hibernate/type=javax.sql.DataSource Hibernate/driver=org.hsqldb.jdbcDriver Hibernate/url=jdbc:hsqldb:hsql://localhost/hibernate Hibernate/user=hibuser Hibernate/password=password Shark/type=javax.sql.DataSource Shark/driver=org.hsqldb.jdbcDriver Shark/url=jdbc:hsqldb:hsql://localhost/shark Shark/user=sa Shark/password= PDI_Operations_Mart/type=javax.sql.DataSource PDI_Operations_Mart/driver=org.postgresql.Driver PDI_Operations_Mart/url=jdbc:postgresql://localhost:5432/hibernate?searchpath=pentaho_operations_mart PDI_Operations_Mart/user=hibuser PDI_Operations_Mart/password=password live_logging_info/type=javax.sql.DataSource live_logging_info/driver=org.postgresql.Driver live_logging_info/url=jdbc:postgresql://localhost:5432/hibernate?searchpath=pentaho_dilogs live_logging_info/user=hibuser live_logging_info/password=password ORA_BIMS/type=javax.sql.DataSource ORA_BIMS/driver=com.mysql.cj.jdbc.Driver ORA_BIMS/url=jdbc:mysql://192.168.168.217:3306/plasma_kb?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8 ORA_BIMS/user=plasma ORA_BIMS/password=szrouting2004plasma ORA_BIM/type=javax.sql.DataSource ORA_BIM/driver=oracle.jdbc.driver.OracleDriver ORA_BIM/url=jdbc:oracle:thin:@192.168.168.218:1521:orcl ORA_BIM/user=BIM ORA_BIM/password=szrouting2015bip 经过验证配置没有问题,是哪里出错了
06-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值