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 29.12. 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 an instance of GraphServerEvent
    trackingcom.cloveretl.server. worker.commons.persistent.TrackingGraphsame as run.getTrackingGraph()When the event is an instance of GraphServerEvent
    sandboxcom.cloveretl.server. persistent.Sandboxsame as run.getSandbox()When the event is an instance of GraphServerEvent
    schedulecom.cloveretl.server. persistent.Schedulesame as ((ScheduleServerEvent)event). getSchedule()When the event is an instance of ScheduleServerEvent
    servletContextjavax.servlet.ServletContext every time
    cloverConfigurationcom.cloveretl.server.spring.CloverConfigurationConfiguration values for CloverDX Serverevery time
    serverFacadecom.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
    sessionTokenString

    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();