It's all about the answers!

Ask a question

Groovy Scripting of Jazz API pauses after executing


Peter Carenza (136) | asked Feb 09 '22, 9:37 a.m.

 We have implemented a way to run Jazz API methods through groovy using the hints shown at this link: https://jazz.net/forum/questions/150675/how-can-i-script-jazzrtc-using-groovy


So the groovy scripts do exactly what they're supposed to - we have scripts to do things like change build label, set RTC work item actions, add attachments, etc. However, there's a really big problem that comes with the groovy scripting - after the script finishes, the execution pauses for anywhere from 30 to 90 seconds after execution completes. We've verified this by putting trace printlns at the beginning and end of the script. We have a calling script and an "RTC" master class where all the methods that operate directly on RTC are located.
For instance, one calling script:
import com.ibm.team.repository.client.TeamPlatform
import das.*
def REPO_URL = System.getenv("RTC_REPO_URL") ?: "https://rtcccm.bcbst.com/ccm"
def USER_ID = args[0]
def PASSWORD = args[1]
def RESULTUUID = args[2]
def LABELVALUE = args[3]
def LINKVALUE = args[4]

def p(obj) {
    println "${obj}"
}
println "Start"
TeamPlatform.startup()
def rtc = new RTC(REPO_URL, USER_ID, PASSWORD)
rtc.login()
rtc.addBuildResultLink(RESULTUUID, LABELVALUE, LINKVALUE)
rtc.logout()
TeamPlatform.shutdown()
println "Stop"
        
Will show "Start" and "Stop" rather quickly, but the script won't actually complete for a noticeable amount of time.
Could anyone fill me in on why this extended pause happens after API execution, and if there's any way to resolve it?

Accepted answer


permanent link
Ralph Schoon (63.1k33645) | answered Feb 09 '22, 10:53 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Feb 09 '22, 10:58 a.m.
I have no idea about using Groovy...... But the Wiki refers to the build system toolkit as the container for the plain java client libraries. Do you use the build system toolkit? This bundle might have some differences to the other packaging of the plain java client libraries.

I am not sure if this is relevant, but I have written an application that uses the TeamPlatform but can be run as a RMI server (to avoid repeatedly have to login which cost up to 8 seconds).  I had to explicitly add some code to shut down the team platform, otherwise the whole thing would hang and never terminate. The team platform would keep the Java VM/runtime alive. What you describe kind of smells like something like that. 

The code I had to use was:

    /**
     * Hook to terminate gracefully
     * 
     */
    private static class TerminateRuntimeHook extends Thread {
        @Override
        public void run() {
            if (TeamPlatform.isStarted()) {
                // System.out.println("Shutting down Team Platform ...");
                TeamPlatform.shutdown();
            }
        }
    }

    // Add the hook
    private static final TerminateRuntimeHook hook;
    static {
        hook = new TerminateRuntimeHook();
        Runtime.getRuntime().addShutdownHook(hook);
    }



    

Peter Carenza selected this answer as the correct answer

Comments
Peter Carenza commented Feb 14 '22, 1:21 p.m.

 Thanks for this! I issued a TeamPlatform.shutdown() on each of the functions and it worked. 


Ralph Schoon commented Feb 15 '22, 2:02 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Yes, you should always run the shutdown to free the resources and threads. 

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.