Kettle Series-[kettleutil]kettle plug-ins, custom Java class controls like Kettle

Source: Internet
Author: User

The kettle plug-in function is similar to kettle existing definition Java class plug-in, custom Java class Plug-in is mainly to support writing Java code directly in kettle to implement custom special functions, and this control is mainly to transfer custom code to the jar package, This means that the implementation of the custom feature has been developed in the IDE such as Eclipse.

The reason for designing this plugin is that it is not easy to write Java code directly in kettle, the development experience is far from Eclipse, Java syntax is limited, debugging is troublesome. The implementation of simple logic is OK, a little more complex is troublesome, need to be familiar with Java and kettle related interfaces. While simple functions can be implemented in JavaScript scripts, it is often difficult for a complex feature to write Java implementations directly in a custom Java class control.

Some people say that each time you can directly develop a new plug-in, although the Java plug-in mechanism is still very good, but the development of a plug-in is not so easy, need to design metadata, plug-in function implementation, plug-in interface design, etc., where the adjustment of the operating interface is my least willing to spend time, Slowly, I can also pull up the configuration interface for common controls, but I don't think it's necessary, so there are a lot of things to do to achieve a perfect plugin.

And this plug-in synthesis of the above two mechanisms, both the simplicity of the custom Java class, directly write the core business code, the Operation interface Unified use a JSON object as a parameter setting path, so based on this development function, just inherit a base class and write a function implementation class can be, and directly develop the convenience of plug-ins , simply import the relevant jar package into the project as a user class library, create a class, inherit the base class, and you can write your business code in eclipse.

The plugin has been open source as a subproject of my other open source Project Kettle Management Platform (http://www.cnblogs.com/majinju/p/5739820.html), and the relevant code can be obtained from that project on GitHub, The following is a description of the plug-in developed to implement their own business.

    1. In eclipse, create the User class library ku, download the 0.1.0 deployment package to the blog post of the Kettle Management Platform project, and then add all the jars in the Lib directory of the deployment package.
    2. Create a Java project in Eclipse, add the user class library created in the previous step to the build path, and then create a new Java class, the following is the implementation code sample.
/*** Project name:kettleutil* date:2016 June 29 afternoon 4:58:19* Copyright (c), Jingma All rights reserved.*/packageNet.oschina.kettleutil.utilrun;importNet.oschina.kettleutil.kettleutilrunbase;importNet.oschina.mytuils.kettleutils;importOrg.pentaho.di.core.row.rowmetainterface;importOrg.pentaho.di.core.row.valuemeta;importOrg.pentaho.di.core.variables.variablespace;importOrg.pentaho.di.trans.step.stepmeta;importCom.alibaba.fastjson.json;importCom.alibaba.fastjson.jsonarray;importcom.alibaba.fastjson.jsonobject;/** * Kettle Util Run Example <br/> * date:2016 year June 29 <br/> * @author Jingma * @versi On */public class Kurdemo extendskettleutilrunbase{/** * Specific processing of each row of data * @see Net.oschina.kettleutil.kettleutilrunbase#disposerow (java.lang.object[]) */@Override protected voidDisposerow (object[] outputrow) {//Set JOB name Outputrow[getfieldindex ("Job_name")] =Kettleutils.getrootjobname (KU); }/** * * @see net.oschina.kettleutil.kettleutilrunbase#init () */@Override protected voidInit () {ku.logbasic ("Initialize plug-in"); }/** * * @see net.oschina.kettleutil.kettleutilrunbase#end () */ @Override protected void  End () {Ku.logbasic ("End of data Processing" );}/** * * @see Net.oschina.kettleutil.KettleUti Lrunbase#getdefaultconfiginfo () */ @Override public  String Getdefaultconfiginfo () {//Create a JSON object to build the configuration object , avoid building JSON strings directly with the jsonobject params = new  jsonobject ();//Set a parameter Key1 params.put ("Key1", "" ); Create a JSON array object to hold the array parameters jsonarray arr = new  Jsonarray (); Arr.add ("arr1" ); Arr.add ("arr2" ); Params.put ("array" , arr);//////"array": [///"arr1",//"ARR2"//],//"Key1": "//}//Returns the default JSON configuration parameters after formatting For easy and quick modification of the configuration return json.tojsonstring (params, true );} public void  GetFields (rowmetainterface R, String Origin, rowmetainterface[] info, Stepmeta nextStep, variablespace space) {//Add output to the next field AddField (R, "Job_name", Valuemeta.type_string,valuemeta.trim_type_both,origin, "job name" ); }}

3. After the development is complete, pack into the kettlelib and restart the kettle. The following is the plug-in configuration interface, you can modify the step name, fill in the class name of your implementation class's full classpath, and then you can click the "Get Default Configuration" button to get the configuration information of the implementation class you configured, as needed to complete the configuration.

The above is done based on the plug-in development and use of work, as can be seen from the implementation of writing a class, you can complete a plug-in development work.

Kettle Series-[kettleutil]kettle plug-ins, custom Java class controls like Kettle

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.