A Simple Talend Job - Exporting a Context

Preliminary notes

This use case can be reproduced with both Talend Open Studio and Talend Integration Suite.
This use case relies on the use case "A Simple Talend Job".

Rationale

Execute a Talend job into Petals and passing it a context as a parameter described in the service's WSDL interface..
The job is exposed as a service into Petals. When this service is called, the parameter is passed to the job, which is then executed.

Unlike the native way of passing options, exporting a context as a parameter is one of the recommended ways to pass information to a job from Petals ESB.

The input message provides the value of of the context which is exposed as a parameter in the service's interface.
Only the job's result is expected in the response.

Creating and exporting the job

The job to be executed performs the following actions:

  1. The job is passed the value of the context variable.
  2. The job connects to a database.
  3. It retrieves the content of a table.
  4. It serializes part of the extracted data as a CSV file on the disk.

This job has one context variable, which indicates the location of the CSV file.


In the scope of this use case, it is assumed there is a database formationtalend on the localhost, having a table named customers.
The schema of the customers table includes two columns named CustomerName and CustomerAddress, both being of type varchar(255).

Creating the job

The job export is detailed in the use case "A Simple Talend Job".
There is no difference.

Exporting the job

Select the job and right-click it. Select Export Job Scripts.
In the Export type combo, select Petals ESB.
Update the target destination and let the job be exposed as a singleton.

Click Edit the exposed contexts.
A dialog shows up. Export the outputLocation context as a Parameter.

You should have the following dialog:

Click the Export mode column, and select Parameter in the combo box. Click OK.
The link label should be updated and indicate the number of exported contexts.

Click Finish.

Deploying and testing in Petals

Looking at the generated WSDL

In the created Petals service assembly, the most interesting thing to look at is the WSDL.
Indeed, the WSDL will determine the way the exported service will be called.


The input message's description expects a value for the exported context.

<xs:element name="executeJob" type="tns:executeJob" />
<xs:complexType name="executeJob">
	<xs:sequence>
		<xs:element minOccurs="0" name="contexts" type="tns:talendContexts" />
		<xs:element minOccurs="0" name="in-attachments" type="tns:inAttachments" />
		<xs:element maxOccurs="unbounded" minOccurs="0" name="in-data-bean" type="tns:inRow" />
		<xs:element maxOccurs="unbounded" minOccurs="0" name="talend-option" type="xs:string" />
	</xs:sequence>
</xs:complexType>

<xs:complexType name="talendContexts">
	<xs:sequence>
		<xs:element name="outputLocation" type="xs:string" minOccurs="0"
			default="C:/Documents and Settings/vzurczak/Bureau/output.csv" />
	</xs:sequence>
</xs:complexType>

<xs:complexType name="inAttachments">
	<xs:sequence>
	</xs:sequence>
</xs:complexType>

<xs:complexType name="inRow">
	<xs:sequence>
	</xs:sequence>
</xs:complexType>


As you can see, the context name, type and default value have been exported in the generated WSDL.
In any case, the default value is more useful to document the service than for the execution.

Obviously, the file path example to illustrate a context may not be the best one (for portability reasons).
Anyway, it serves its purpose, which is being an example of interactions between Petals ESB and a Talend job.


And the output message only includes the job's result.

<xs:element name="executeJobResponse" type="tns:executeJobResponse" />
<xs:complexType name="executeJobResponse">
	<xs:sequence>
		<xs:element minOccurs="0" name="talend-job-output" type="tns:talendJobOutput" />
	</xs:sequence>
</xs:complexType>

<xs:complexType name="talendJobOutput">
	<xs:sequence>
		<xs:element maxOccurs="unbounded" minOccurs="0" name="executionResult" nillable="true" type="ns1:stringArray" />
		<xs:element minOccurs="0" name="outAttachment" type="tns:outAttachments" />
		<xs:element maxOccurs="unbounded" minOccurs="0" name="outDataBean" nillable="true" type="tns:outRow" />
	</xs:sequence>
</xs:complexType>

<xs:complexType name="outAttachments">
	<xs:sequence>
	</xs:sequence>
</xs:complexType>

<xs:complexType name="outRow">
	<xs:sequence>
	</xs:sequence>
</xs:complexType>

Deploying and testing this new service

To test this service, you can use a tool like SoapUI.
This way, you can see what the XML messages look like.

The first thing to do is to create a service-unit for the Petals-BC-SOAP component, that exposes (consumes) our Talend job as a service outside the bus.
This step is not described here. You can take a look at the Petals-BC-SOAP documentation and the Petals Studio documentation.
Just make sure the SOAP configuration uses the InOut MEP.


Now, your input message (in SoapUI) should look like this:

<soapenv:Envelope
            xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
            xmlns:tal="http://petals.ow2.org/talend/">

   <soapenv:Header/>
   <soapenv:Body>
      <tal:executeJob>
         <!--Optional:-->
         <tal:contexts>
            <!--Optional:-->
            <tal:outputLocation>C:/Documents and Settings/vzurczak/Bureau/output.csv</tal:outputLocation>
         </tal:contexts>
         <!--Optional:-->
         <tal:in-attachments/>
         <!--Zero or more repetitions:-->
         <tal:in-data-bean/>
         <!--Zero or more repetitions:-->
         <tal:talend-option>?</tal:talend-option>
      </tal:executeJob>
   </soapenv:Body>
</soapenv:Envelope>


By default, SoapUI (as well as any generated Java client) puts the default value as the initial value.
However, the interest is that it can be changed.

Exposing a context as a parameter allows anyone to specify a context value.
While using the native Talend parameters requires the user to know both how the job works and how it was designed.


The returned message, when everything works, is:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <tns:executeJobResponse
            xmlns:tns="http://petals.ow2.org/talend/"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

         <tns:talend-job-output>
            <tns:executionResult>
               <jaxb:item xmlns:jaxb="http://jaxb.dev.java.net/array">0</jaxb:item>
            </tns:executionResult>
            <tns:outAttachment/>
         </tns:talend-job-output>
      </tns:executeJobResponse>
   </soapenv:Body>
</soapenv:Envelope>


If the job execution fails, the 0 is replaced by another integer, e.g. 1.
One failure reason can be, as an example, that the database is not started.


Another way to check the job's successful completion, is to check the existence of the output file.
Here are the first lines in this file (the database was populated with random values from another Talend job - do not be shocked by the values).

Griffith Paving and Sealcoatin;talend@apres91
Bill's Dive Shop;511 Maple Ave.&nbsp; Apt. 1B
Childress Child Day Care;662 Lyons Circle
Facelift Kitchen and Bath;220 Vine Ave.
Terrinni & Son Auto and Truck;770 Exmoor Rd.
Kermit the Pet Shop;1860 Parkside Ln.
Tub's Furniture Store;807 Old Trail Rd.
Toggle & Myerson Ltd;618 Sheriden rd.
Childress Child Day Care;788 Tennyson Ave.
Elle Hypnosis and Therapy Cent;2032 Northbrook Ct.
Lennox Air Pollution Control;4522 N. Greenview Apt. 1B
...

Labels

petals petals Delete
tutorial tutorial Delete
talend talend Delete
se se Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.