Subjob with dynamic context for datasource initialization

Subjob with dynamic context for datasource initialization

Hello there,

How can I dynamically set context in subjob of route to initialize datasource ? (Talend 5.3.1)

I'm facing a problem : I have a route that calls a subjob. This subjob is a set of insert in database. I need a datasource (because of transaction) which parameters should be specified by the calling route (depending on input, it could be different databases, but same output tables in job).

Here is route, filling job context as follow


My cTalendJob_1 configuration
 

And my subjob here :

with my datasource configuration



I'm logging some stuff :
[list=*]
  • In route, in cProcessor_1, I can see all my headers filled : Headers: {breadcrumbId=IDSmiley SurprisedCTO-ARA-52349-1409749882218-1:1:1:1:1, logidriveSchema=udd, logidriveUser=udd, logidriveHost=localhost, logidrivePwd=udd, logidrivePort=1521, logidriveDatabase=xe}

  • But in job, just before initializing datasource (third component), I log the following line : "DB connection openned: " + context.LOGIDRIVE_Server+":"+context.LOGIDRIVE_Port+"/"+context.LOGIDRIVE_Schema         and result is "15:11:23,854 INFO  [commandeLogidrive] DB connection openned: ${in.header.logidriveHost}:1521/${in.header.logidriveSchema}"



  • As I can see, only value hardcoded in ma cTalendJob is read, others that should be set from headers are not.
    What is wrong ? Any idea ?


    Thx you for help,
    Aurélien
    Seventeen Stars

    Re: Subjob with dynamic context for datasource initialization

    It is not possible. But you can always set the context variables of the called job or you could configure the child job for Implicit context load and provide for every run via a context variable a different path for this context file (to be loaded in the implicit context load). 

    Re: Subjob with dynamic context for datasource initialization

    Thx for your reply.

    I don't understand how can I load an implicit context with parameters that come from calling route.
    1) But you can always set the context variables of the called job => Ok to set context in subjob itself, but in this case, context cannot be changed between 2 runs of subjob
    2) you could configure the child job for Implicit context load => that sounds good: but where to load context ? In prejob ? I can't access any parameter from calling route in this block. I can propagate header of course, but these are available from tRouteInput only, too late to initialise tOracleConnection

    I'm still stuck :-(


    [EDIT] My first reply is wrong and was :
    I've found another way to set subjob context parameters from a route :
    [list=1]
  • create a parameter context in subjob, for example "myParam1"

  • set header in route with exactly the same name ("myParam1") with value you want to send to subjob

  • in cTalendJob component, do not map any context param and select "Use selected context"

  • => "myParam1" in subjob will be valuated with value of "myParam1" header of calling route.

    Aurélien 

    2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

    Talend named a Leader.

    Get your copy

    OPEN STUDIO FOR DATA INTEGRATION

    Kickstart your first data integration and ETL projects.

    Download now

    An API-First Approach to Modernizing Applications

    Learn how to use an API-First Approach to Modernize your Applications

    Watch Now

    Talend API Designer – Technical Overview

    Take a look at this technical overview video of Talend API Designer

    Watch Now

    Getting Started with APIs

    Find out how to get started with APIs

    Read