In this tutorial will see:
I've used Talend Integration Suite 2.3.3 with a Java project.
We are going to create one of the simpliest job you can do with Talend. This job is based on the TouchFile's component and create on the Desktop an empty file. This simple job allows us to verify fastly that our job as been executed via the webservice. Here is the job:
The file address in this case is:
"C:/Users/nfrancisco/Desktop/"+TalendDate.getDate("MM-DD-hh-mm-ss")+".txt"
This allows me to launch the job several times and to store the date in the name of the file, at the moment the job has ended.
The next step consists on creating a new task in order to run on an execution server the job we implemented:
You need to connect to your webapplication in order to create a task:
When connected to your administration page click on the Job Conductor tab and create a new task by clicking on the Add Button:
You need there to specify for the task:
You need to have defined at least one execution server by clicking on the server tab.
After this configuration, you will see your task by clicking another time on the tab Job Conductor:
In this case the status of the task is : “Ready to run” that means that the job code has been generated (here java code has been generated) and has been deployed on the execution server. You generate the code by clicking on the first button at the right of the name of the task:
Then to deploy it on the server chosen you can click on this button:
Finally, to run your job you can click on:
The first step before executing the following java class is to recover the id of the job you want to execute via the webapp. To do this, you need to read the Id number of the job deployed. If the id column is not appearing in your webapp page then you can click on Id above your columns. Then you can copy paste the following code into an eclipse interface, add the needed libraries to your path and launch the java class with your own parameters. This class has to constructors, one generic inwhich you can parameters all the characteristics of your object JobConductor, the second can create an object with your defaults parameters but you need to modify this second constructor.
Here is the java code:
import java.rmi.RemoteException;
import org.talend.administrator.webservices.*;
public class JobConductor {
int TaskId;
String IP;
String port;
String AdministratorWAR;
String login;
String pass;
public static void LaunchTask(JobConductor jobconductor) {
String sessionId;
String IPWebService="http://localhost:8080/org.talend.administrator/services/AdministratorWebService?wsdl";
AdministratorWebServiceProxy awsp = new AdministratorWebServiceProxy(IPWebService);
try {
sessionId = awsp.initSession(jobconductor.login, jobconductor.pass);
System.out.println(sessionId);
String[][] contextParams = null;
awsp.scheduleTaskForInstantRun(sessionId,jobconductor.TaskId , true, contextParams);
awsp.closeSession(sessionId);
System.out.println("Task n°" + jobconductor.TaskId + " succesfull");
}
catch (RemoteException e) {
// TODO Auto-generated catch block
System.out.println("Error with the task n°"
+ jobconductor.TaskId);
e.printStackTrace();
}
}
public static void main(String args[]){
JobConductor jobconductor = new JobConductor(3);
LaunchTask(jobconductor);
}
public JobConductor(String administratorWAR, String ip, int taskId,
String login, String pass, String port) {
this.AdministratorWAR = administratorWAR;
this.IP = ip;
this.TaskId = taskId;
this.login = login;
this.pass = pass;
this.port = port;
}
public JobConductor(int taskId) {
this.AdministratorWAR = "org.talend.administrator";
this.IP = "localhost";
this.TaskId = taskId;
this.login = "nfrancisco@talend.com";
this.pass = "*************";
this.port = "3306";
}
}
To execute this class, you will have to add some libraries that you can download by clicking here: