• Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » Using context file with compiled PERL

#1 2008-05-25 07:29:20

psm2000
Member
Registered: 2008-02-25
Posts: 108

Using context file with compiled PERL

Hello,

I am using TOS 2.4.0 M1 in a PERL project. I've already deployed some TOS jobs in a compiled format on multiple machines which do not have PERL installations due to corporate policies etc. This is the only method feasible for me to deploy TOS. I use PERLAPP (PDK 7.x by ActiveState) to create the exe files. This works nicely.

All the jobs so far did not use any context files. Now I am developing a job that uses Context file to feed some information such as DB names, output file names and locations etc. Because of this, the *_Default.pl file has entries that it never used to have before. Please note that I am not interested in switching contexts from dev to prod etc. I am only interested in passing the parameters that can be changed from outside as I am deploying win32 exe files.

The problem is that PERLAPP uses the main .pl file to create the compiled file. It cannot use both job.pl as well as job_Default.pl that holds some information as to the parameters. Since it never reads the Default file, of course the job fails due to empty pointers. Following will make it clear as to what is showing up in the Default file.
------------
$_context{ODBC_CONNECTION} = $_context{ODBC_CONNECTION};
$_context{OUTPUT1} = $_context{OUTPUT1};
$_context{OUTPUT2} = $_context{OUTPUT2};
$_context{OUTPUT3} = $_context{OUTPUT3};
$_context{DBNAME} = $_context{DBNAME};

1;
---------------
The Context file looks like following:
ODBC_CONNECTION=connectiontodb
DBNAME=mydb
OUTPUT1=c:\Output\out1.txt
OUTPUT2=c:\Output\out2.txt
OUTPUT3=c:\Output\out3.txt
----------------

Q. I want to be able to fold in the Default.pl file information in my main PERL script so that PERLAPP will compile the main perl script properly. I do not mind doing this manually every time as long as I know where to put this. Again, I will not be changing contexts (dev to prod etc.) so if there is another way I can do this, I would love to know (such as global parameters etc.) as long as this information can be changed by user in a simple text file.

I've attached some images so if I am doing something totally wrong, one of you might be able to correct me.

Please help!! I need to deliver a demo with this functionality very soon.

Thank you in advance.
Regards,
Sean


Uploaded Images

Offline

#2 2008-05-25 08:13:58

psm2000
Member
Registered: 2008-02-25
Posts: 108

Re: Using context file with compiled PERL

Hello,
I was able to solve this problem by editing the main PERL script. This is the change I made
-----------------------------------------------
<snip>
if (defined $opt{context}) {
    my $context_filename =
        $_globals{project_name}
        .'.job_'.$_globals{job_name}
        .'_'.$_globals{job_version}
        .'_'.$opt{context}
        .'.pl'
    ;

    use FindBin;
    use lib $FindBin::Bin;
    require $context_filename;
}

if (defined $opt{context_param}) {
    foreach my $key (keys %{ $opt{context_param} }) {
        $_context{$key} = $opt{context_param}{$key};
    }
}

##start my change
$_context{ODBC_CONNECTION} = $_context{ODBC_CONNECTION};
$_context{OUTPUT1} = $_context{OUTPUT1};
$_context{OUTPUT2} = $_context{OUTPUT2};
$_context{OUTPUT3} = $_context{OUTPUT3};
$_context{DBNAME} = $_context{DBNAME};
##end change
<snip>
--------------------------------------------

This compiled and ran file in exe format. I am still interested in knowing if there is a better way (or I have a wrong approach to begin with) even though I found this to be fairly easy. I can each time look for this code and add the Default file here.

Regards,
Sean

Offline

  • Index
  •  » Talend Open Studio for Data Integration » Usage, Operation
  •  » Using context file with compiled PERL

Board footer

Powered by FluxBB