转 Managing kettle job configuration

简介:

Over time I've grown a habit of making a configuration file for my kettle jobs. This is especially useful if you have a reusable job, where the same work has to be done but against different conditions. A simple example where I found this useful is when you have separate development, testing and production environments: when you're done developing your job, you transfer the .kjb file (and its dependencies) to the testing environment. This is the easy part. But the job still has to run within the new environment, against different database connections, webservice urls and file system paths.

Variables

In the past, much has been written about using kettle variables, parameters and arguments. Variables are the basic features that provide the mechanism to configure the transformation steps and job entries: instead of using literal configuration values, you use a variable reference. This way, you can initialize all variables to whatever values are appropriate at that time, and for that environment. Today, I don't want to discuss variables and variable references - instead I'm just focussing on how to manage the configuration once you already used variable references inside your your jobs and transformations.

Managing configuration

To manage the configuration, I typically start the main job with a set-variables.ktr transformation. This transformation reads configuration data from a config.properties file and assigns it to the variables so any subsequent jobs and transformations can access the configration data through variable references. The main job has one parameter called ${CONFIG_DIR} which has to be set by the caller so the set-variables.ktr transformation knows where to look for its config.properties file:


Reading configuration properties

The config.properties file is just a list of key/value pairs separated by an equals sign. Each key represents a variable name, and the value the appropriate value. The following snippet should give you an idea:

#staging database connection
STAGING_DATABASE=staging
STAGING_HOST=localhost
STAGING_PORT=3351
STAGING_USER=staging
STAGING_PASSWORD=$74g!n9

The set-variables.ktr transformation reads it using a "Property Input" step, and this yields a stream of key/value pairs:


Pivoting key/value pairs to use the "set variables" step

In the past, I used to set the variables using the "Set variables" step. This step works by creating a variable from selected fields in the incoming stream and assigning the field value to it. This means that you can't just feed the stream of key/value pairs from the property input step into the set variables step: the stream coming out of the property input step contains multiple rows with just two fields called "Key" and "value". Feeding it directly into the "Set variables" step would just lead to creating two variables called Key and Value, and they would be assigned values multiple times for all key/value pairs in the stream. So in order to meaningfully assign variable, I used to pivot the stream of key/value pairs into a single row having one field for each key in the stream using the "Row Denormaliser" step:

key field: the value of this field is scanned to determine in which output fields to put the corresponding value. There are no fields that make up a grouping: rather, we want all key/value pairs to end up in one big row. Or put another way, there is just one group comprising all key/value pairs. Finally, the grid below specifies for each distinct value of the "Key" field to which output field name it should be mapped, and in all cases, we want the value of the "Value" field to be stored in those fields. 


Drawbacks

There are two important drawbacks to this approach:

  • The "Row Normaliser" uses the value of the keys to map the value to a new field. This means that we have to type the name of each and every variable appearing in the config.properties file. So you manually need to keep he config.propeties and the "Denormaliser" synchronized, and in practice it's very easy to make mistakes here.

  • Due to the fact that the "Row Denormaliser" step literally needs to know all variables, the set-variables.ktr transformation becomes specific for just one particular project.

Given these drawbacks, I seriously started to question the usefulness of a separate configuration file: because the set-variables.ktrtransformation has to know all variables names anyway, I was tempted to store the configration values themselves also inside the transformation (using a "generate rows" or "data grid" step or something like that), and "simply" make a new set-variables.ktrtransformation for every environment. Of course, that didn't feel right either.


Solution: Javascript

As it turns out, there is in fact a very simple solution that solves all of these problems: don't use the "set variables" step for this kind of problem! We still need to set the variables of course, but we can conveniently do this using a JavaScript step. The new set-variables.ktr transformation now looks like this:

The actual variable assignemnt is done with Kettle's built-in setVariable(key, value, scope). The key and value from the incoming stream are passed as arguments to the key and value arguments of the setVariable() function. The third argument of thesetVariable() function is a string that identifies the scope of the variable, and must have one of the following values:

  • "s" - system-wide

  • "r" - up to the root

  • "p" - up to the parent job of this transormation

  • "g" - up to the grandparent job of this transormation

For my purpose, I settle for "r".

The bonus is that this set-variables.ktr is less complex than the previous one and is now even completely independent of the content of the configuration. It has become a reusable transformation that you can use over and over.

------------------------------------------------------------------------------------------------------

There are some people argue that why not config these variables in <Kettle Installation Folder>\.kettle\kettle.properties, of course this way can achieve this goal, but this solution is not good, because when the Kettle Job(.kjb) or Kettle Transformation(.ktr) files are moved to another environment(dev, test, alpha, beta, prod..), you need to update this file, this is also need to be done when one or more properties are updated.

See also: http://wiki.pentaho.com/display/EAI/Expose+key-value+pairs+from+a+.properties+file+as+variables

目录
相关文章
|
4月前
|
存储 监控 API
二手 ERP 系统对接闲鱼 API:落地方案、接口边界与业务踩坑
二手ERP对接闲鱼需分清两大接口:闲管家开放平台(仅管理自有店铺,支持商品/订单/物流双向操作)与第三方数据接口(仅读取全网商品,用于选品估价)。二者职责分明,混用将导致业务故障。务必通过正规渠道接入,避免逆向抓包。
706 0
|
5月前
|
数据采集 安全 API
IP风控网站是做什么的?5大核心场景+工具选型指南
IP风控网站是基于IP多维画像的实时风险识别系统,毫秒级判断请求可信度:识别网络类型(数据中心/住宅/移动)、代理特征(VPN/住宅代理)及历史恶意行为,输出0-100风险评分。支持API与私有离线库部署,广泛应用于金融反欺诈、电商防刷单、广告反作弊、账号安全与反爬虫等场景,兼顾安全、性能与合规。(239字)
429 0
|
6月前
|
人工智能 API 网络安全
零基础上手!阿里云Hermes Agent与OpenClaw对接Token Plan全流程部署指南
部署Hermes Agent与OpenClaw的前提是拥有阿里云账号并完成实名认证,个人用户可通过身份证刷脸或支付宝授权快速完成,企业用户需上传营业执照及法人信息,审核周期1-3个工作日。未实名认证账号无法购买云服务器、开通百炼大模型服务,这是部署的基础门槛。
394 0
|
6月前
|
人工智能 搜索推荐 数据挖掘
AI时代创业成本重构
本文深度解析AI时代创业范式革命,提出“OPC一人公司”新模式:依托大模型(MaaS)、智能体(AaaS)与内容IP生态,实现零团队、低至千元启动、全流程自主闭环的轻量化创业。适用于大学生、自由职业者、职场人及实体经营者,重塑低成本、低风险、可持续的个体商业新路径。
运营必看!1688大变天,您的流量为啥跑了?
近期,有1688商友反映,1688店铺流量下滑明显,以往稳定的流量格局似已一去不返。这背后的核心原因,是1688平台业务模式的全面升级。为助力1688商友破局,今天将深度解析1688变革后的核心要点,助您寻回失落的流量。
|
10月前
|
编解码 资源调度 算法
深度图与点云去噪实战:双边滤波+统计/半径滤波原理与Open3D全实现
本文系统讲解3D视觉中深度图与点云的工业级去噪方案:详解统计滤波(剔孤立点)、半径滤波(除稀疏噪点簇)及双边滤波(边缘保留平滑),提供Open3D+OpenCV全流程代码,支持深度图预处理→点云生成→联合去噪,兼顾精度、效率与鲁棒性。(239字)
1430 6
|
缓存 安全 Java
《深入理解Spring》过滤器(Filter)——Web请求的第一道防线
Servlet过滤器是Java Web核心组件,可在请求进入容器时进行预处理与响应后处理,适用于日志、认证、安全、跨域等全局性功能,具有比Spring拦截器更早的执行时机和更广的覆盖范围。
【Vue2从入门到精通】一分钟让你学会vue2搜索关键词高亮
本文主要介绍了vue2实现搜索关键词高亮的方法,有需要的朋友可以借鉴参考,祝大家多多进步,早日升职加薪。
909 0
【Vue2从入门到精通】一分钟让你学会vue2搜索关键词高亮
|
前端开发 JavaScript 搜索推荐
响应式企业网站模板推荐 | 适配PC/手机/平板| 1对1打造专属企业官网CMS源码
在移动互联网时代,响应式企业网站成为标配,可适配PC、平板、手机等多端设备,提升用户体验与SEO效果。本文详解响应式设计的技术原理(媒体查询、流式布局等)、主流模板推荐(WordPress、Bootstrap、Vue等)及CMS定制开发流程,助力企业高效构建专业官网。
|
存储 前端开发 中间件
『软件工程10』结构化系统分析:数据流图和字典案例分析
该文章通过具体案例分析了在软件工程中如何运用数据流图和数据字典来进行结构化系统分析,帮助明确系统的信息流程和数据定义。
『软件工程10』结构化系统分析:数据流图和字典案例分析