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 |
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 |
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 |
Dynamic Settings of a tScriptRules Component |
Parameter Referenced on Dynamic Settings is Disabled |
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
Thank you for the tip Carl, very useful!
ReplyDeleteXavier
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.
ReplyDeleteHi,
DeleteI 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