Version

    Execute Groovy Code

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

    The basic attribute of this task is a source code of written in Groovy.

    If the 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 is 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.

    CloverDX Server contains Groovy version 2.0.0

    Table 44. List of variables available in Groovy code
    Variable Class Description Availability

    event

    com.cloveretl.server.events.AbstractServerEvent

    every time

    task

    com.cloveretl.server.persistent.Task

    every time

    now

    java.util.Date

    current time

    every time

    parameters

    java.util.Properties

    Properties of a task

    every time

    user

    com.cloveretl.server. persistent.User

    Same as event.getUser()

    every time

    run

    com.cloveretl.server. persistent.RunRecord

    When the event is an instance of GraphServerEvent

    tracking

    com.cloveretl.server. worker.commons.persistent.TrackingGraph

    same as run.getTrackingGraph()

    When the event is an instance of GraphServerEvent

    sandbox

    com.cloveretl.server. persistent.Sandbox

    same as run.getSandbox()

    When the event is an instance of GraphServerEvent

    schedule

    com.cloveretl.server. persistent.Schedule

    same as ((ScheduleServerEvent)event). getSchedule()

    When the event is an instance of ScheduleServerEvent

    servletContext

    javax.servlet.ServletContext

    every time

    cloverConfiguration

    com.cloveretl.server.spring.CloverConfiguration

    Configuration values for CloverDX Server

    every time

    serverFacade

    com.cloveretl.server.facade. api.ServerFacade

    The reference to the facade interface. Useful for calling CloverDX Server core.

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

    every time

    sessionToken

    String

    A valid session token of the user who owns the event. It is useful for authorization to the facade interface.

    every time

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

    Example of use Groovy script

    This example shows a script which writes a text file describing the finished graph. It shows use of the '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();