Call a job deployed in the web application via a webservice

In this tutorial will see:

  • how to create a simple job without contexts and deploy it on an execution server
  • how to launch this job via a JAVA application using the internal TIS webservice

I've used Talend Integration Suite 2.3.3 with a Java project.

First glimpse

Create the simplest job

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:

:doc:launchtisws_jobtouchfile.png

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:

Create a task in the job scheduler

You need to connect to your webapplication in order to create a task:

:doc:launchtisws_webappadministrationpage.png

When connected to your administration page click on the Job Conductor tab and create a new task by clicking on the Add Button:

:doc:launchtisws_jobconductor_task_creation.jpg

You need there to specify for the task:

  • His name
  • his description
  • the project that contains the job we want to execute
  • the name of the job
  • the version of the job
  • the execution context
  • finally, the execution server in which the job will be deployed

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:

:doc:launchtisws_jobconductor.png

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:

:doc:launchtisws_jobconductor_generate_code.jpg

Then to deploy it on the server chosen you can click on this button:

:doc:launchtisws_jobconductor_deploy_job.jpg.jpg

Finally, to run your job you can click on:

:doc:launchtisws_jobconductor_run_job.jpg

Create the java class to launch the webservice

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:

:doc:launchtisws_java_libraries.zip

 
doc/launch_job_via_jobconductor_webservice.txt · Last modified: 2011/12/17 03:52 (external edit)
 
 
Recent changes RSS feed Driven by DokuWiki