Skip to content

Work towards automated cleaning of JcrJobRepository#107

Merged
sagarsane merged 1 commit intomasterfrom
6-clean-jcr-job-repository
Jun 29, 2016
Merged

Work towards automated cleaning of JcrJobRepository#107
sagarsane merged 1 commit intomasterfrom
6-clean-jcr-job-repository

Conversation

@sagarsane
Copy link
Contributor

No description provided.

@sagarsane sagarsane changed the title [WIP] Initial work towards cleaning jobrepository [WIP] Initial work towards automated cleaning of JcrJobRepository Apr 5, 2016
@sagarsane
Copy link
Contributor Author

@jazeren1 @jbornemann @jdigger just WIP. Need to still properly test this and implement unit tests

@sagarsane sagarsane force-pushed the 6-clean-jcr-job-repository branch 4 times, most recently from 8d2cb53 to 7d855e2 Compare April 7, 2016 15:58
@sagarsane sagarsane changed the title [WIP] Initial work towards automated cleaning of JcrJobRepository Work towards automated cleaning of JcrJobRepository Apr 7, 2016
@sagarsane
Copy link
Contributor Author

Opening this up for some initial "approach" review.

Currently I have a servlet that's triggering the cleaning. I'll be updating this to have a Cron like we discussed. Wanted to get some feedback on the approach I have taken.

After I almost finished the job repp cleanup functionality .. But then I realized that there are way too many private methods in the service I have for cleanup. (this commit : 1e51ff8)

Because of that, I thought it'd be better "host" the functionality on the DAO objects themselves.. Felt like that looked and organized better. ( this commit: 7d855e2)

Does the latter approach look better? In order to make that happen, I had to extend Spring Batch's DAO interfaces to add the additional APIs we need for clean-up.

@jdigger @jazeren1 @jbornemann @masroormohammed can you please take a look?

@sagarsane
Copy link
Contributor Author

Ugh hold on. Tests are failing. Taking a look.

@sagarsane
Copy link
Contributor Author

sagarsane commented Apr 7, 2016

I'll change the logging to debug, etc. when this is good to go. I figured the logging will help right now during testing.

Also made the change in grabbit version right now for easier installation for testing.

To test,

gw clean build install -x uninstallBundles -x uninstall -x remove

I've had to ignore uninstall. Seems to be having issues with other bundles in AEM :(

Run some content syncs for any number of paths .. or if you already have some data under

/var/grabbit/job/repository/jobExecutions then you probably have some data you can use to test the clean up.

Current testing is to do a POST to http://localhost:4502/grabbit/jobrepository/clean and add a hours parameter that should be an integer.

This number can be any "integer" .. I have tested that it works fine for > 24 hours as well. More-over, I am also logging everything that's going on .. along with the Date its using to compare and everything. So your logs will look something like this :

07.04.2016 16:20:01.267 *INFO* [10.0.2.2 [1460046001202] GET /bin/cleanRepository HTTP/1.1] com.twcable.grabbit.spring.batch.repository.JcrJobExecutionDao JobExecutions: [/var/grabbit/job/repository/jobExecutions/1628554003093086836, /var/grabbit/job/repository/jobExecutions/5944394638596509927], size: 2
07.04.2016 16:20:01.269 *INFO* [10.0.2.2 [1460046001202] GET /bin/cleanRepository HTTP/1.1] com.twcable.grabbit.spring.batch.repository.JcrJobExecutionDao Current time: Thu Apr 07 16:20:01 UTC 2016
07.04.2016 16:20:01.269 *INFO* [10.0.2.2 [1460046001202] GET /bin/cleanRepository HTTP/1.1] com.twcable.grabbit.spring.batch.repository.JcrJobExecutionDao Hours 24 .. OlderThanHours Time: Wed Apr 06 16:20:01 UTC 2016
07.04.2016 16:20:01.271 *INFO* [10.0.2.2 [1460046001202] GET /bin/cleanRepository HTTP/1.1] com.twcable.grabbit.spring.batch.repository.JcrJobExecutionDao JobExecutionsOlder than 24 hours: [] , length: 0
07.04.2016 16:20:01.277 *INFO* [10.0.2.2 [1460046001202] GET /bin/cleanRepository HTTP/1.1] com.twcable.grabbit.spring.batch.repository.services.impl.DefaultCleanJobRepository jobInstancesToRemove: [], size: 0
07.04.2016 16:20:01.278 *INFO* [10.0.2.2 [1460046001202] GET /bin/cleanRepository HTTP/1.1] com.twcable.grabbit.spring.batch.repository.services.impl.DefaultCleanJobRepository stepExecutionsToRemove: [], size: 0
07.04.2016 16:20:01.278 *INFO* [10.0.2.2 [1460046001202] GET /bin/cleanRepository HTTP/1.1] com.twcable.grabbit.spring.batch.repository.services.impl.DefaultCleanJobRepository jobExecutionContextsToRemove: [], size: 0
07.04.2016 16:20:01.278 *INFO* [10.0.2.2 [1460046001202] GET /bin/cleanRepository HTTP/1.1] com.twcable.grabbit.spring.batch.repository.services.impl.DefaultCleanJobRepository stepExecutionContextsToResource: [], size: 0
07.04.2016 16:20:01.278 *INFO* [10.0.2.2 [1460046001202] GET /bin/cleanRepository HTTP/1.1] com.twcable.grabbit.spring.batch.repository.services.impl.DefaultCleanJobRepository Removing 0 JobInstances
07.04.2016 16:20:01.278 *INFO* [10.0.2.2 [1460046001202] GET /bin/cleanRepository HTTP/1.1] com.twcable.grabbit.spring.batch.repository.services.impl.DefaultCleanJobRepository Removing 0 JobExecutions
07.04.2016 16:20:01.278 *INFO* [10.0.2.2 [1460046001202] GET /bin/cleanRepository HTTP/1.1] com.twcable.grabbit.spring.batch.repository.services.impl.DefaultCleanJobRepository Removing 0 StepExecutions
07.04.2016 16:20:01.278 *INFO* [10.0.2.2 [1460046001202] GET /bin/cleanRepository HTTP/1.1] com.twcable.grabbit.spring.batch.repository.services.impl.DefaultCleanJobRepository Removing 0 JobExecutionContexts
07.04.2016 16:20:01.278 *INFO* [10.0.2.2 [1460046001202] GET /bin/cleanRepository HTTP/1.1] com.twcable.grabbit.spring.batch.repository.services.impl.DefaultCleanJobRepository Removing 0 StepExecutionContexts

You can play around with the "hours" param for the servlet and see how it performs .. deletions will be made based on Comparison between "Date.now() - hours" and "All COMPLETED and FAILED JobExecutions" ... it will also delete all the corresponding "StepExecutions", "JobInstances" and "ExecutionContexts" ...


JcrJobRepositoryFactoryBean jobRepositoryFactoryBean = configurableApplicationContext.getBean(JcrJobRepositoryFactoryBean)

List<String> jobExecutionPaths = jobRepositoryFactoryBean.jobExecutionDao.getJobExecutions([BatchStatus.FAILED, BatchStatus.COMPLETED])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other "BatchStatus" options are

STARTING, STARTED, STOPPING, STOPPED, ABANDONED, UNKNOWN;

So, should we query for everything except "STARTING" and "STARTED" and "STOPPING" ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sagarsane whats the difference between STARTING and STARTED?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I understand .. its similar to OSGi's STARTING and ACTIVE bundle states (not 1-1 comparison tho :) )

https://blog.codecentric.de/en/2014/04/spring-batch-batchstatus-state-transitions/ has a bit more info.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!fixed

@sagarsane
Copy link
Contributor Author

Done with some main CR comments. Still not done anything to suggestions like #107 (comment) .. I like that idea but wanted to discuss that first.

@jazeren1 @jbornemann @jdigger @masroormohammed please take a look .

@Dnjoroge
Copy link

👍 Testing

Resource jobExecutionResource = resolver.getResource(jobExecutionResourcePath)
ValueMap props = jobExecutionResource.adaptTo(ValueMap)
Long jobExecutionId = props[JcrGrabbitJobExecutionDao.EXECUTION_ID] as Long
String query = "select * from [nt:unstructured] as s " +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/s/resource/ ?

@sagarsane sagarsane force-pushed the 6-clean-jcr-job-repository branch from cf69e36 to cf354ce Compare April 18, 2016 19:06
@Slf4j
@CompileStatic
@SlingServlet(methods = ['POST'], resourceTypes = ['twcable:grabbit/jobrepository/clean'])
class GrabbitCleanJobRepositoryServlet extends SlingAllMethodsServlet {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbornemann @jazeren1 @jdigger @masroormohammed added this.

POST /grabbit/jobrepository/clean with param 'hours'

I like using a POST API to clean the jobrepository .. that acts as a "resource" .. and that resource manifests with the help of given "hours" param. This servlet returns JobExecutionIds that were removed (if successful)

@sagarsane sagarsane force-pushed the 6-clean-jcr-job-repository branch from cf354ce to 90eabe8 Compare April 18, 2016 19:12
@sagarsane
Copy link
Contributor Author

Updated testing instructions to have the new API to clean the jobrepository

@masroormohammed
Copy link
Contributor

+1 Testing

@sagarsane
Copy link
Contributor Author

CR changes have been made @jdigger @jbornemann

@viveksachdeva
Copy link

viveksachdeva commented Jun 27, 2016

@sagarsane : +1 Testing

…y that is older than X hours from "now"

* New API added : POST /grabbit/jobrepository/clean --data hours=X
* All JobInstances, JobExecutions, StepExecutions and ExecutionContexts that either FAILED or COMPLETED X hours from "now", i.e., when the API was called -- will be deleted
@sagarsane sagarsane force-pushed the 6-clean-jcr-job-repository branch from 3e5670c to b39f3b7 Compare June 29, 2016 05:15
@sagarsane sagarsane merged commit b39f3b7 into master Jun 29, 2016
@sagarsane sagarsane deleted the 6-clean-jcr-job-repository branch June 29, 2016 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants