Talend Administration Center API
The TAC API or MetaServlet is a RESTFul service. The MetaServlet allows you to start jobs, create a new user and a whole lot of other good stuff. This post will explain you how to use this useful service!
To reach the MetaServlet you need to use an URL that looks something like: <TAC_URL>/metaServlet?<Base64EncodedAction>
For example:
The base64 encodes is actually an encoded JSON string. This string contains an action which tells TAC what to do. The e2FjdGlvbk5hbWUgOiBoZWxwfQ== string represents the action:
The servlet will return a JSON string when the action is completed. For example the help function will return a JSON string with all the available actions with some descriptions.
Everything clear? Ready to apply the MetaServlet in your project? Maybe not well let’s head into the example!
Run a deployed job with MetaServlet
In this example we’re going to start a job called MetaServletDemo. The job expects a context parameter message.
We’re going to start this job using the MetaServlet.
Solution
We’re going to use two actions: getTaskIdByName and runTask. The runTask needs a taskId. Therefore we need to get the taskId by using the task name.
Retrieving the taskId
So, the first step is using the action getTaskIdByName. You may be thinking: “I can find the taskId in the TAC! Why should I use this action?“
Well, you’re right you can indeed find the taskId in the job conductor. BUT! A job receives a taskId when it’s deployed on the server. This means that the job can have a different taskId in your production environment than in the development environment. You would need to change the code of your application when you would release in production. Big nono!
So now that’s out of the way, let look into the getTaskIdByName action:
We’ve configured the JSON string but we need to encode it to Base64 before we can use it in the URL to call the MetaServlet. You can use a website like https://www.base64encode.org.
We’ve got the complete URL now that the string is encoded:
http://localhost:8080/org.talend.administrator/metaServlet?ew0KYWN0aW9uTmFtZTogZ2V0VGFza0lkQnlOYW1lLA0KICAJYXV0aFBhc3M6IGRlbW8sDQogIAlhdXRoVXNlcjogZHJpZXNAZGVtby5jb20sDQoJdGFza05hbWU6IE1ldGFTZXJ2bGV0RGVtbw0KfQ0K
The URL results in the following reponse:
As you can see the taskId of getTaskIdByName is 1. The id can be used to start the task. Let’s take a look at the run action!
Run the task
Now that we’ve got the taskId, we can run the runTask action. We can run the task now that we’ve got the taskId. The JSON string for this action looks the like:
Encode this string and run the URL. The job will start and the MetaServlet will respond as soon as the job is finished running. Let’s hope that the job ran successfully!
Great the job ran perfectly!
Help! I don’t know the parameters of an action
We already discussed the help action in the beginning of this post. You can use this action and add an extra parameter with the name of the action.
The MetaServlet returns useful information like: action description, a sample JSON string and possible return codes.