Featured Post

Applying Email Validation to a JavaFX TextField Using Binding

This example uses the same controller as in a previous post but adds a use case to support email validation.  A Commons Validator object is ...

Friday, December 14, 2012

DYNAMIC_SETTINGS in Talend Open Studio Custom Components

The "Dynamic settings" tab is present on all Talend Open Studio components, but few components actually use it.  That's because most components can be parameterized through text boxes in which a user can insert a context variable statement (ex, "context.RUN_ALL").  However, this technique does not permit the configuration of checkbox values and any components that offer a setting on the Component View ought to be fully configurable.

tContextLoad is a Talend Open Studio component that uses Dynamic Settings.  The checkbox "Print operations" will specify that each key/value pair be printed out as the context is loaded.  This is a troubleshooting function that you might turn off in a production environment to reduce the clutter of a log file.  If a problem arises, say caused by a system change, retaining the ability to turn it on without changing code is indispensable.

Dynamic Settings

Within Talend Open Studio, the setting "Print operations" can be toggled during development.  However, once the job is exported, the last setting (checked or unchecked) will be saved.  Without Dynamic Settings, this setting will remain until a new job is deployed.

The Print Operations Parameter
Dynamic Settings gives you the ability to associate a parameter -- such as "Print operations" -- with an expression.  Generally, the expression will be a context variable like "context.RUN_ALL".  This is the same type of expression that you might put in a text box like a filename, but you need Dynamic Settings because there's nowhere in a checkbox to put a line of code.

Select the Dynamic Settings tab and press the green plus icon.  In the Code box, you can put a constant or a line of code.  In this case, 'false' is used as a default value.

Dynamic Settings Tab of tContextLoad
Development

To use Dynamic Settings in a custom component, define a PARAMETER element in the component's XML file.  The PARAMETER can be placed in the PARAMETERS or ADVANCED_PARAMETERS sections.  The parameter should have the DYNAMIC_SETTINGS attribute set to "true". A default value is provided in the DEFAULT subelement.


This is a parameter definition from a soon-to-be-realeased (Dec 2012) version of tScriptRules.

<PARAMETER FIELD="CHECK" NAME="RUN_ALL" NUM_ROW="2" DYNAMIC_SETTINGS="true">
  <DEFAULT>false</DEFAULT>
</PARAMETER>


Working with the Dynamic Setting in the Talend Javajet code is a little different than the usual 'getValue()' call you might make on a text box.  You'll need to check if you're operating context mode and if you are not,  you'll need to treat the variable as a String.  Otherwise, make the getValue() call.

Boolean runAll_<%= cid %> = false;

<%
  if( node.getElementParameter("RUN_ALL").isContextMode() ) {
%>
   runAll_<%= cid %> = <%= ElementParameterParser.getValue(node, "__RUN_ALL__") %>;
<%
   } else {
    if ( ElementParameterParser.getValue(node, "__RUN_ALL__").equals("true") ) {
%>
     runAll_<%= cid %> = true; // not from context
<%
   }
}
%>


Note the RUN_ALL used in the isContextMode() call and the __RUN_ALL__ used in the getValue() calls.

The result of this block of JET code is a variable 'runAll_<%= cid %>' that I use later in the program to initialize an object.

Usage

This job shows a simple usage of tScriptRules.  There is a context variable 'RUN_ALL' that is defined as a Boolean with a default value of 'false'.

A tScriptRules Job with a Context Variable
This is the Dynamic Settings tab of the tScriptRules_1 component.  The plus icon was pressed and the "Run all rules" parameter was displayed with its default value "false".  I selected the Code text box and entered "context.RUN_ALL".

Dynamic Settings of a tScriptRules Component
This will affect the "Advanced settings" tab by disabling and highlighting the parameter.  Prior to the Dynamic Settings modification, this checkbox could be selected and deselected.  If you want this control returned while you work on the job, return to the Dynamic Settings tab and remove the Run all rules parameter using the red X icon.

Parameter Referenced on Dynamic Settings is Disabled
The context variable is the mechanism by which a command line argument is passed to the Talend job.  See this post for more information about command line arguments.

When you write a custom component for Talend Open Studio, you ought to make all available parameters configurable from the command line.  That's because you may not know the exact use case for a component user.  Give them the most flexibility with a little extra effort on the Javajet side

3 comments:

  1. Thank you for the tip Carl, very useful!

    Xavier

    ReplyDelete
  2. Hi Carl, I am looking for some help on running Python script (which is on remote server) from Talend. tSystem Component works if on the same. Any help is appreciated.

    ReplyDelete
    Replies
    1. Hi,

      I work exclusively with TOS and deploy my Talend code with some type of scheduler. Schedulers like Automate 10 and Control-M will ship with an agent that can run on a remote server. The controlling scheduler can then talk to the remote server and execute your .py. I've also built JavaEE services that do this (I don't have the source unfortunately).

      If you can wrap your .py up in a RESTful service call that can securely be invoked from your Talend server, then just use a tREST.

      Good luck

      Delete