FOR BI PROS LEARN Tableau
Trigger Tableau Schedule from Java
September 9, 2014
1
, , , , , , ,

java_trigger

One of our customers asked me to help trigger Tableau Server extracts/schedules from their ETL application. The most easier way is to invoke tabcmd and call the runschedule command.  Well, I am not huge fan of the command line invocation from tools and applications, it’s fragile and platform dependent (our ETL is running on Linux and Solaris). One option could be the Tableau Server 8.2 REST API, but unfortunately it is more user/workbook management than publishing or triggering – it misses the necessary API call for triggering schedules. For me the cleanest solution is to build an ETL component and invoke Tableau Server directly. In this post I will explain how to design and implement the code which invoke a particular Tableau Server feature (like running schedule), while in Part 2 I will show how you can encapsulate it to an ETL component.

 

Talend_anyscale_700

This client uses Talend which relies on java components and plugins, thus I should build the wire frame in java as well. I am using the WebAuth class from “Undocumented Tableau Server Authentication in Java” as starter. This class simply logs in to the tableau server (without the need of trusted authentication, so you can test it on your own PC instead of trusted locations) and let you execute your own code on the authenticated channel.

To build this template code first download the java sources from GitHub and open with one of your favorite java editor (intelliJ, eclipse,  or netbeans). This sample project is maven based, so you should build the sources with maven which will download the necessary dependencies from the maven sources:

Server Auth

 

You can test if everything works properly with the bundled tests. First you should change the server address, username and password in the AppTest.java file, then call the JUnit test.

This looks cool so far, so lets add the schedule refresh logic. Okay, but how? The easy way is always cheating, lets see how tabcmd does this. You should look into the tabcmd.jar file (copy it to tabcmd.zip, then you can simply unzip it and look into the command folder).

Server Auth 4

As you see, there is one .rb file per one tabcmd command in the tabcmd.zip\tabcmd\lib\commands folder.

If you open the runschedule.rb, you will see the magic – how tabcmd executes the web request:

What we can see here?

  • The URL what we should invoke is “/run/schedules” with POST method
  • We need two parameters: format which is xml and the name of the schedule
  • We should pass the authenticity token (as always).

Hurry up, add this to our java code. First, extend the function with this additional schedule name parameter:

To add the HTTP call which passes the schedule name to runschedule, you should use something like this:

What happens here:

  1. Get the authenticity token from the previous web call
  2. Set up the POST server URL
  3. Add the parameters to the request

We can go to the server and check results, the schedule was triggered and the extracts are refreshed. Pretty cool, isn’t it? With few lines of code, without the hassle of the tabcmd porting or executable invocation.

In the next round we will see how can you add this java code into your Talend ETL workflows and call them directly after data warehouse data refresh.

 


 

If you like this solution, don’t forget to share it!

 

Tamás Földi

Tamás Földi

Director of IT Development at Starschema
Decades of experience with data processing and state of the art programming. From nuclear bomb explosion simulation to distributed file systems. ethical hacking, real time stream processing practically I always had a great fun with those geeky ones and zeros.
Tamás Földi
  • Jibin

    Hi Tamas,
    This is a great post. Does your solution work with ‘https’ protocol also or does it only work with http protocol? If not, could you let me know how I could configure it to work for https as well?

Related items

/ You may check this items as well

Scaling Tableau Image

Scaling out Tableau Extracts – Building a distributed, multi-node MPP Hyper Cluster

One of our customers asked me to help trigger Tabl...

Read more
Pasted image at 2018_01_09 04_59 PM

Python Experiments in Tableau 1. – Add live currency conversion to Tableau Dashboards using TabPy

One of our customers asked me to help trigger Tabl...

Read more
Tableau Docker

HOWTO: Tableau Server Linux in Docker Container

One of our customers asked me to help trigger Tabl...

Read more