Call rest api on post function and get 502 error

aas March 27, 2023

Hi all,

I have two instances of Jira Server and need integrate them. I've made a groovy script and add it to post function on issue creation step. This script sends rest requests to another Jira to make issue there. But sometimes another Jira has performance issues and answers with 502 error. Problems can last for several minutes (sometimes more). How can I handle this case? Is it a good idea to add a loop to send a request until I get a 200 response? I'm afraid that in this case issue won't be created in first Jira instance for a long time if another instance having problems for a long time

Or may be I can make not a post function script but Listener which listens issue created event and add a loop to send a request until I get a 200 response there? 

 

2 answers

1 vote
aas March 28, 2023

Hi @Ram Kumar Aravindakshan _Adaptavist_ 

It's a custom post-function on transition.  Script just create new issue in another instance of Jira if some conditions true 

I need to add code only in one instance

And on issue transition fires my script which send request from instance 1 to instance 2 and if in this time instance 2 slows down issue in instance 2 not created. Is it good idea to loop sending request in instance 1 while instance 2 not stops slowing down 

String jkIssueKey = createIssueInJiraJK()

if (jkIssueKey != null){

    commentIssues(jkIssueKey)        

} else{

   log.warn("Issue not created, comment not added")

}

log.info("End of script")
def createIssueInJiraJK(){    

    def jkIssueKey = null

    def currentIssue = issue.key

    def createdIssueKey

    def addressJira = "https://jira.anotherinstance.net"

    def user = ''

    def password = ''

    def authString = "${user}:${password}".bytes.encodeBase64().toString()

    def timeout = 120000

    def defaultRequestConfig = RequestConfig.custom()

                            .setConnectionRequestTimeout(timeout)

                            .setConnectTimeout(timeout)

                            .setSocketTimeout(timeout)

                            .build()                

    def http = new HTTPBuilder("${addressJira}/rest/api/2/issue")

    http.ignoreSSLIssues();

    http.setClient(HttpClients.custom().setDefaultRequestConfig(defaultRequestConfig).build())

    try {

        http.request(POST, ContentType.JSON) {

            headers.'Authorization' = "Basic ${authString}"

            body = ["fields":[

                    "project":[

                            "id":"100"

                 ],

                "summary":"${value_currentSummary}.toString(),

                "issuetype":[

                            "id":"11"

                ],

                "priority": [

                            "id": "2"

                ],           

                "description":"Description".toString()

                ]

            ]

            requestContentType = ContentType.JSON

                response.success = { resp, json ->  

                    jkIssueKey = json.key

                    log.info("Issue ${jkIssueKey} was created")

                    return jkIssueKey

                }

                response.failure = { resp ->

                    log.warn("response code is: " + resp.status.toString())        

                }

       }

} catch (Exception e) {

    log.warn("Exception : " + e)

}

}
0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 28, 2023

Hi @aas

In your description, you mentioned:-

I have two instances of Jira Server and need integrate them. I've made a groovy script and add it to post function on issue creation step.

Are you adding the code in both instances with the required modifications?

Please share your Post-Function code so I can review it and suggest a better solution.

Also, please clarify what Post-Function you use to make the REST request. Is it the ScriptRunner Custom post-function?

I am looking forward to your feedback.

Thank you and Kind regards,
Ram

aas March 28, 2023

Hi @Ram Kumar Aravindakshan _Adaptavist_ 

I accidentally answered in the wrong place. Look my answer above please

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events