Run the indexing service in JIRA in an isolated thread

Deleted user May 31, 2018

Hello everyone,

We have developed a script that we use as a Reindex Service that runs every minute.

How can we run it in an isolated thread, so Jira does not go down, in case of any problem with reindexing. Can you help me, please?

Thanks in advance.
Regards,

Almu

 

 

2 answers

2 accepted

1 vote
Answer accepted
Nic Brough -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.
May 31, 2018

Ok, while the principle of "index in another thread" is a good abstract idea, your question scares me.

Why are you doing this?

Indexing is not something you should ever have to think about in Jira.  Questions starting with "I want to index" are almost always posted by people who are trying to do really bad things in Jira (inadvertently, as they don't understand the internals, and are trying to do something in a way they haven't realised is totally wrong)

Deleted user May 31, 2018

Hi Nic,

I have inherited this Jira Server, and someone created a groovy script that runs as a Service in Jira, every minute. I do not know why this was done. In your opinion, do I have to delete this service because Jira does reindexing automatically when needed?

Thx & BR,

Almu

Nic Brough -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.
May 31, 2018

Before you delete it, you really should find out why they did this. 

My best guess is they were hiding a massive problem that they've created elsewhere.

You may only be able to identify that by stopping it running, and seeing what goes wrong!

But in the long run, yes, absolutely, you need rid of this completely, it's a very poor practice and totally unneccessary.

bibin.koshy October 29, 2019

Hi @Moses Thomas and @Nic Brough -Adaptavist- 

I would like to use this API call specified on this doc to re-index jira server through linux terminal.

https://confluence.atlassian.com/jirakb/reindex-jira-server-using-rest-api-via-curl-command-663617587.html?_ga=2.225356698.1460643556.1572270390-554649307.1572270390

Just one question, i am getting "authentication failure" when i try and get this working. I just use root without any password, so how would i run this?

curl -u root:password -X POST $JIRAURL/rest/api/2/reindex?type=FOREGROUND

Kind regards,

--Bibin

Moses Thomas
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 29, 2019

@bibin.koshy  You cannot not use linux user to authenticate  login  to  Jira, user must  be admin user in  Jira.  use a  dedicated user with  admin  rights  in Jira.

 

Best regards,

Mo

Like bibin.koshy likes this
Nic Brough -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.
October 29, 2019

Is "root" a valid admin user in Jira?

(Standard advice here though - do NOT do this automatically, you should not need to do it)

Like bibin.koshy likes this
bibin.koshy October 29, 2019

Thank you so much for both replies! @Nic Brough -Adaptavist- @Moses Thomas 

1 vote
Answer accepted
Moses Thomas
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 31, 2018

@[deleted]In my opinion it is not  a  good idea to  run indexing every minute, why  because in case you have a large JIRA  instance , this will  drastically  reduce JIRA performance. my advice to you is to perform indexing like once  a day in your  production ( lets say  at  night when less user are accessing Jira)

Even better run a background indexing  see  REST API documentation https://confluence.atlassian.com/jirakb/how-to-trigger-re-indexing-using-rest-request-via-curl-command-663617587.html, you  can add  it in your  script in the case where you use linux/unixlike server and use cron tab in linux/Unixlike servers to  define when  reindexing should be triggered automatically.

 

Best!

Deleted user May 31, 2018

Hi Moses Thomas,

I have inherited this Jira Server, and someone created a groovy script that runs as a Service in Jira. Look:

Reindex Service com.onresolve.jira.groovy.GroovyService

input-file: /mnt/nas/jira/ReindexService.groovy

Schedule 0 0/1 * 1/1 * ? *

I am not sure whether the best option is to delete this service or schedule it in this way

0 59 23 * * *

What is your opinion, please?

Thx & BR,

ALmu

Moses Thomas
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 31, 2018

@[deleted] I will  suggest  you  schedule is daily.

Deleted user June 4, 2018

Thanks

Rajat Sethi October 15, 2018

Hi @[deleted],

 

Will it be possible for you to share the groovy script with me? We have a similar need to write a re-index service that we plan to run every week. I will be much obliged. 

 

Thanks,

Rajat 

Deleted user October 22, 2018

Hi Rajat

Here you are

cat ReindexService.groovy


def usuario = "adminuser"
def filter_id = "10327"

import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.bc.JiraServiceContextImpl
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.issue.search.*
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.index.IndexException
import com.atlassian.jira.ManagerFactory
import com.atlassian.jira.user.ApplicationUser
import org.apache.log4j.Category
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.util.ImportUtils
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.user.ApplicationUsers
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.ManagerFactory
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.ComponentManager

import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.issue.index.*;

WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );

 
String jqlSearch = " filter="+ filter_id;
SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class)
ComponentManager componentManager = ComponentManager.getInstance()
CommentManager commentManager = ComponentAccessor.getCommentManager()
IssueManager issueManager = ComponentAccessor.getIssueManager();
UserUtil userUtil = ComponentAccessor.getUserUtil()
def searchProvider = ComponentAccessor.getComponent(SearchProvider.class)
def userManager = ComponentAccessor.getUserManager()
def user2 = userManager.getUserByName(usuario)


Category log = Category.getInstance("com.onresolve.jira.groovy")
log.setLevel(org.apache.log4j.Level.DEBUG)
log.debug "START Reindex filter Service"

def String adminUserName = usuario
def String nagComment = ""

SearchService.ParseResult parseResult = searchService.parseQuery(user2, jqlSearch)

if (parseResult.isValid()) {
def searchResult = searchService.search(user2, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
def issues = searchResult.issues.collect {issueManager.getIssueObject(it.id)}
log.debug "Entro... size:" + issues.size();

for ( issue in issues ){

def issueobtained = issueManager.getIssueObject(issue.getKey());
def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)
issueIndexingService.reIndex(issueobtained);

}
log.debug "FINISH Reindex filter Service"

} else {
log.debug("Invalid JQL: " + jqlSearch);
}

 

Cheers,

Almu

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events