Skip to content

OHFJIRA-27 - Add support for clustered jobs (quartz)#33

Merged
hanusto merged 1 commit intodevelopfrom
feature/OHFJIRA-27-Add-support-for-clustered-jobs
May 3, 2017
Merged

OHFJIRA-27 - Add support for clustered jobs (quartz)#33
hanusto merged 1 commit intodevelopfrom
feature/OHFJIRA-27-Add-support-for-clustered-jobs

Conversation

@openhubframework
Copy link
Collaborator

@openhubframework openhubframework commented Mar 12, 2017

In cluster we need two types of job:

  • jobs which can run on random node and can be executed parallel (it's not condition to start jobs in the same time)
  • jobs which can run only once in the cluster, doesn't matter on which node

Solution:

  • remove apache camel quartz component
  • jobs and triggers is defined with annotation QuartzJob (use only on method that will be invoked), QuartzSimpleTrigger and QuartzCronTrigger
  • in annotation QuartzJob we cen set enum JobExecuteTypeInCluster that has two options:
    • CONCURRENT - job will be executed parralel on nodes
    • NOT_CONCURRENT - job which can run only on one node
  • information about concurrent jobs is stored in memory
  • information about not concurrent jobs is stored in database

JIRA:
https://openhubframework.atlassian.net/browse/OHFJIRA-27

Copy link
Contributor

@pjuza pjuza left a comment

Choose a reason for hiding this comment

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

Quite big implementation :).

I don't have any critical comments, only many smallers. I'm not able to validate the whole model (because it's too big ...) but I believe it's ok ...

* @see QuartzSimpleTrigger
* @since 2.0
*/
public enum ClusterExecuteType {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't be better ScheduledJobType?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I dont know. This is not for job, but it is for trigger. And maybe this is not good. I will add this setting into job. And name can be JobExecuteTypeInCluster.

import org.quartz.SimpleTrigger;

/**
* Defined one {@link SimpleTrigger} in {@link QuartzJob}.
Copy link
Contributor

Choose a reason for hiding this comment

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

Better describe why use this annotation instead of QuartzCronTrigger

/**
* See documentation in {@link SimpleTrigger#MISFIRE_INSTRUCTION_SMART_POLICY}.
*
* @see SimpleTrigger
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't it needless to add more times "@see SimpleTrigger"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will remove it and add "@see SimpleTrigger" on class.

/**
* Factory for create new {@link Trigger}s instance.
* <p>
* Every trigger instance running concurrent in all nodes in cluster at the same time
Copy link
Contributor

Choose a reason for hiding this comment

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

language mistake - Every trigger instance is able to running in ...

Factory for create new => Factory class for creating new ...

*
* @return execute type in cluster mode
*/
ClusterExecuteType clusterExecuteType();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is there not default value? I would expect concurrent ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think that default value is not good idea. Set this attribute is important and when he has default value, many user not fill them.

* Job running concurrent in all nodes in cluster at the same time.
* </p>
*
* @author Petr Juza
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know why there are so many @see items in specific implementations, I would remove them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will remove it

*
* @return cron triggers
*/
QuartzCronTrigger[] cronTriggers() default {};
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to set cron and simple triggers at the same time?
If not then add description to JavaDoc + it's possible to define common parent class/annotation and then have only one trigger parameter?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes it is. One job can have one or more QuartzCronTrigger and one or more QuartzSimpleTrigger at the same time.


/**
* Defined one quartz {@link Job} with default group name {@value #OPEN_HUB_JOB_GROUP_NAME}.
* For base use see in {@link {@link QuartzJob}}.
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove once @link ...

*
* @return name
*/
String name() default StringUtils.EMPTY;
Copy link
Contributor

Choose a reason for hiding this comment

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

I see method in QuartzUtils for generating job's name. Wouldn't be better to define JobNameGenerator interface with default implementation from QuartzUtils?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In QuartzUtils is not method for generate job name, but for generate trigger name. Job name is defined in annotation attribute name. I will create TriggerNameGenerator interface.

*/
@Bean(name = "quartzProperties")
@Profile(Profiles.POSTGRES)
public Properties quartzPostgresProperties() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would define it in property file because when you add new DB then you should always add new method to the code.

Copy link
Contributor

@pjuza pjuza left a comment

Choose a reason for hiding this comment

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

I went through all your comments and it's OK for me.

Only one thing - how to solve when new database type will be used? At this moment you should add new code and it's not flexible ...

@openhubframework openhubframework added this to the v2.0 milestone Mar 20, 2017
@openhubframework
Copy link
Collaborator Author

openhubframework commented Mar 20, 2017

You have right, this is not good solution. I will change it and move properties into configuration file application-h2.cfg or application-postgres.cfg.

@openhubframework openhubframework force-pushed the feature/OHFJIRA-27-Add-support-for-clustered-jobs branch from 9103f7e to 3e2167b Compare March 25, 2017 20:45
@openhubframework
Copy link
Collaborator Author

openhubframework commented Mar 25, 2017

It is ready for review.

Changes:

  • Move quartz settgins from QuartzConfig into application properties

  • Add name() and group() into QuartzSimpleTrigger and QuartzCronTrigger - now user can direct specify trigger name and trigger group (generator is not necessary)

  • Edit javadoc (remove @see etc.)

  • rename ClusterExecuteType into JobExecuteTypeInCluster and add this attribute into QuartzJob (remove from triggers)

@coveralls
Copy link

Coverage Status

Coverage decreased (-6.7%) to 64.474% when pulling 3e2167b on feature/OHFJIRA-27-Add-support-for-clustered-jobs into 0237ab9 on develop.

Copy link
Contributor

@pjuza pjuza left a comment

Choose a reason for hiding this comment

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

Two common points:

  • test coverage descreased about 6% - it's too much, please add more unit tests
  • please add wiki pages with information about using your quartz API. It will be helpful to better understand your code

* @param env environment
* @param propertyNamePrefix prefix for property names
* @return {@link Properties} with properties that name start with propertyNamePrefix
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider to use Tools.getAllKnownPropertyNames in implementation ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will use it. One small disadvantage is, that list will be use twice (first for getting names and second for getting values for names).

Copy link
Contributor

@pjuza pjuza left a comment

Choose a reason for hiding this comment

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

Once again review ...

* {@link QuartzCronTrigger}.
* <p>
* Annotation can be added on method and this method will be called when trigger will be executed.
* </p>
Copy link
Contributor

Choose a reason for hiding this comment

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

if you have starting and ending element p then it will create two empty lines and you propably want to have one line, don't you?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I dont understand. Where is two empty lines? In HTML or in source code?

Copy link
Contributor

Choose a reason for hiding this comment

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

When you use ending p and starting p ...

* Annotation can be added on method and this method will be called when trigger will be executed.
* </p>
* <p>
* Every job must have at least one {@link QuartzCronTrigger} or {@link QuartzSimpleTrigger}. And one job can have
Copy link
Contributor

Choose a reason for hiding this comment

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

it's quite complicated sentence :)

//-------------------------------------------------- SET / GET -----------------------------------------------------

@Override
public void setApplicationContext(final ApplicationContext applicationContext) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We have already full AOP support thus you can use @configured ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I used Autowired for load ApplicationContext property

@openhubframework openhubframework force-pushed the feature/OHFJIRA-27-Add-support-for-clustered-jobs branch from 9bb7fd1 to 3397711 Compare April 7, 2017 18:52
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.6%) to 55.401% when pulling 3397711 on feature/OHFJIRA-27-Add-support-for-clustered-jobs into e2ddfad on develop.

@hanusto hanusto force-pushed the feature/OHFJIRA-27-Add-support-for-clustered-jobs branch from 3397711 to f2e129c Compare May 3, 2017 18:37
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.6%) to 55.295% when pulling f2e129c on feature/OHFJIRA-27-Add-support-for-clustered-jobs into a31eaee on develop.

@hanusto hanusto self-requested a review May 3, 2017 19:35
Copy link
Collaborator

@hanusto hanusto left a comment

Choose a reason for hiding this comment

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

For this moment these PR meets the requirements.

@hanusto hanusto requested a review from pjuza May 3, 2017 19:39
@hanusto hanusto merged commit f2ff63b into develop May 3, 2017
@hanusto hanusto deleted the feature/OHFJIRA-27-Add-support-for-clustered-jobs branch May 3, 2017 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants