Execute Groovy Code

This type of task allows execute code written in script language Groovy. The script can be defined in place or using a path to external .groovy file. It is possible to use some variables.

Basic attribute of this task is source code of written in Groovy.

If source codes are provided from both a file and through the input form only the code from the input form will be executed.

In cluster environment there is also one additional attribute "Node IDs to process the task". If it's empty, it may be any node, if there are nodes specified, the task will be processed on the first node which is online and ready.

CloverETL Server contains Groovy version 2.0.0

Table 20.15. List of variables available in Groovy code

variableclassdescriptionavailability
event com.cloveretl.server.events.AbstractServerEvent every time
taskcom.cloveretl.server. persistent.Task every time
nowjava.util.Datecurrent timeevery time
parametersjava.util.PropertiesProperties of a taskevery time
usercom.cloveretl.server. persistent.UserSame as event.getUser()every time
runcom.cloveretl.server. persistent.RunRecord When the event is instance of GraphServerEvent
trackingcom.cloveretl.server. persistent.TrackingGraphsame as run.getTrackingGraph()When the event is instance of GraphServerEvent
sandboxcom.cloveretl.server. persistent.Sandboxsame as run.getSandbox()When the event is instance of GraphServerEvent
schedulecom.cloveretl.server. persistent.Schedulesame as ((ScheduleServerEvent)event). getSchedule()When the event is instance of ScheduleServerEvent
servletContextjavax.servlet.ServletContext every time
cloverConfigurationcom.cloveretl.server.spring. CloverConfigurationConfiguration values for CloverETL Serverevery time
serverFacadecom.cloveretl.server.facade. api.ServerFacadeReference to the facade interface. Useful for calling CloverETL Server core.

WAR file contains JavaDoc of facade API and it is accessible on URL: http://host:port/clover/javadoc/index.html

every time
sessionTokenStringValid session token of the user who owns the event. It is useful for authorisation to the facade interface.every time

Variables run, tracking and sandbox are available only if event is instance of GraphServerEvent class. Variable schedule is only available for ScheduleServerEvent as event variable class.

Example of use Groovy script

This example shows a script which writes text file describing the finished graph. It shows use of 'run' variable.

import com.cloveretl.server.persistent.RunRecord;
String dir = "/tmp/";
RunRecord rr = (RunRecord)run;	

String fileName = "report"+rr.getId()+"_finished.txt";

FileWriter fw = new FileWriter(new File(dir+fileName));
fw.write("Run ID       :"+rr.getId()+"\n");
fw.write("Graph ID     :"+rr.getGraphId()+"\n");
fw.write("Sandbox      :"+rr.getSandbox().getName()+"\n");
fw.write("\n");
fw.write("Start time   :"+rr.getStartTime()+"\n");
fw.write("Stop time    :"+rr.getStopTime()+"\n");
fw.write("Duration     :"+rr.getDurationString()+"\n");
fw.write("Status 	   :"+rr.getStatus()+"\n");
fw.close();