Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Groovy Scripting of Jazz API pauses after executing

 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?

0 votes


Accepted answer

Permanent link
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

0 votes

Comments

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

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

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,936
× 411
× 6

Question asked: Feb 09 '22, 9:37 a.m.

Question was seen: 1,129 times

Last updated: Feb 15 '22, 2:02 a.m.

Confirmation Cancel Confirm