Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scriptrunner userSearchService doesn´t deliver all records and throws exception

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 31, 2023

Hi Community,

I´m executing a user search via Scriptrunner´s userSearchService for all active users according to  a specific directory (ad directory). This is my call:

 

def allUserParams = new UserSearchParams(allowEmptyQuery, includeActive, includeInactive, canMatchEmail, userFilter as UserFilter, projectIds as Set<Long>)

def allAdUsers = userSearchService.findUsers('', allUserParams).findAll { it.directoryId == ad.id }

 

Unfortunately I only get 880 records (knowing that there should be more users). So I checked the log file and found the following:

ipd-worker:thread-1 ERROR      [c.a.d.internal.ipd.DefaultIpdJobRunner] Error during executing com.atlassian.jira.ipd.http.HttpConnectionPoolInProductDiagnosticJob job
com.atlassian.jira.ipd.exception.UnableReadAttributeException: Unable to read attributes [currentThreadCount, currentThreadsBusy, maxThreads] from Mbean : [Catalina:type=ThreadPool]
	at com.atlassian.jira.ipd.http.HttpConnectionPoolInProductDiagnosticJob.getHttpPoolSizeValue(HttpConnectionPoolInProductDiagnosticJob.java:60)
	at com.atlassian.jira.ipd.http.HttpConnectionPoolInProductDiagnosticJob.measure(HttpConnectionPoolInProductDiagnosticJob.java:36)
	at com.atlassian.diagnostics.internal.ipd.DefaultIpdJobRunner.runJobs(DefaultIpdJobRunner.java:50)
	at com.atlassian.jira.ipd.JiraIpdScheduler.ipdEmitterIteration(JiraIpdScheduler.java:105)
	at com.atlassian.jira.util.thread.JiraThreadLocalUtils.lambda$wrap$1(JiraThreadLocalUtils.java:156)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: com.atlassian.jira.ipd.exception.UnableReadAttributeException: Unable to find Object name : [Catalina:name="http-nio-*",type=ThreadPool] ThreadPool type under Catalina domain
	at com.atlassian.jira.ipd.http.HttpConnectionPoolInProductDiagnosticJob.lambda$findSourceName$0(HttpConnectionPoolInProductDiagnosticJob.java:72)
	at java.base/java.util.Optional.orElseThrow(Optional.java:408)
	at com.atlassian.jira.ipd.http.HttpConnectionPoolInProductDiagnosticJob.findSourceName(HttpConnectionPoolInProductDiagnosticJob.java:72)
	at com.atlassian.jira.ipd.http.HttpConnectionPoolInProductDiagnosticJob.getHttpPoolSizeValue(HttpConnectionPoolInProductDiagnosticJob.java:55)
	... 10 more

 

Any help appreciated.

Best
Stefan

2 answers

2 accepted

0 votes
Answer accepted
Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 5, 2023

Hi @Ram Kumar Aravindakshan _Adaptavist_ 

I could resolve the missing results with adding another searchParam:
either adding "limitResults" or "maxResults" (maxResults is depricated) provided us all the records.

The problem with the exception is still ongoing but as mentioned before this seems to be a configuration problem in the tomcat server as this appears in other actions too.

Thanks for your hints.

Best
Stefan

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.
September 5, 2023

Hi @Stefan Salzl

Thanks for the update and great to hear you were able to resolve this issue.

Thank you and Kind regards,

Ram

Like Stefan Salzl likes this
Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 7, 2023

Hi @Ram Kumar Aravindakshan _Adaptavist_ 

one question from one of my comments is still open:

Another question came up when I read through the answer:
I´ve seen the jiraServiceContext now in many examples but I´m not really understanding what it is for or what it does. Could you describe the jiraServiceContext in some words to me? Or share any resource that might bring some light into the dark? ;)

Would it be possible to give me some hints regarding this?

Thanks in advance.

Best
Stefan

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.
September 7, 2023

Hi @Stefan Salzl

In this case, when invoking the UserSearchService one of the options is to use the JiraServiceContext which stores the current logged-in user object and passes it to the UserSearchService's findUsers method.

def jiraServiceContext = new JiraServiceContextImpl(Users.loggedInUser)

def allActiveUsers = ComponentAccessor.getComponent(UserSearchService).findUsers(jiraServiceContext, '', paramBuilder.build())

There are other alternatives, e.g. using a String for the named query or a query. The simpler approach is to user the JiraServiceContext.

More information on this is available at the Jira Api Docs.

Thank you and Kind regards,

Ram

0 votes
Answer accepted
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.
August 31, 2023 edited

Hi @Stefan Salzl

Could you please clarify which version of Jira and ScriptRunner you currently use when testing the code?

Also, from the log extract you have shared, I do not see any errors returned by ScriptRunner. It looks more like a Thread-related issue.

To proceed, could you please change the approach you are taking to invoke the  UserSearchParams class, i.e. from:-

def allUserParams = new UserSearchParams(allowEmptyQuery, includeActive, includeInactive, canMatchEmail, userFilter as UserFilter, projectIds as Set<Long>)

to using the UserSerachParams Builder as shown below:-

import com.adaptavist.hapi.jira.users.Users
....
....
import com.atlassian.jira.bc.user.search.UserSearchParams
import com.atlassian.jira.bc.user.search.UserSearchService
....
....

UserSearchParams.Builder paramBuilder = UserSearchParams.builder()
.allowEmptyQuery(true)
.includeActive(true)
.includeInactive(false)

def jiraServiceContext = new JiraServiceContextImpl(Users.loggedInUser)

def allActiveUsers = ComponentAccessor.getComponent(UserSearchService).findUsers(jiraServiceContext, '', paramBuilder.build())

Please refer to the sample code in the AdaptavistLibrary for a complete example of how to use the UserSearchParams.Builder class.

I am looking forward to your feedback and clarification.

Thank you and Kind regards,

Ram

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 1, 2023 edited

Hi @Ram Kumar Aravindakshan _Adaptavist_ 

Thanks for your reply.

Versions are:

  • Scriptrunner: 8.9.0
  • Jira (DC): 9.6.0

Unfortunately changing to userSearchParams builder didn´t change the behaviour:
Still only get 880 records --> is there any limitation of users/pagination I´m not aware of? The exception in the log still occurs (which I also would refer to a thread-related issue in the tomcat config --> already contacted the responsible person).

Another question came up when I read through the answer:
I´ve seen the jiraServiceContext now in many examples but I´m not really understanding what it is for or what it does. Could you describe the jiraServiceContext in some words to me? Or share any resource that might bring some light into the dark? ;)

Best
Stefan

Richard Cross
Contributor
May 15, 2024

Important to remember that this code does not show licensed users, i.e. those with authorization to use Jira and who count towards the license limit.

I'd like to know if there's a way of getting just those users.

 

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Atlassian Community Events