New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1709723: last check-in date is not updated for hypervisors reported by virt-who (candlepin changes) [ENT-1049] #2314
Conversation
Januson
commented
Apr 30, 2019
- Create a new endpoint POST /hypervisors/heartbeat/{owner}
- The new endpoint updates last checkin date of all consumers for the given reporter_id
| " SET lastcheckin = :checkin" + | ||
| " WHERE id IN (SELECT consumer_id" + | ||
| " FROM cp_consumer_hypervisor" + | ||
| " WHERE reporter_id = :reporter)"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be scoped to the current organization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need a subselect:
"UPDATE cp_consumer a, cp_consumer_hypervisor b, cp_owner c" +
" SET a.lastcheckin = :checkin" +
" WHERE a.id = b.consumer_id" +
" AND b.reporter_id = :reporter" +
" AND a.owner_id = c.id" +
" AND c.account = :orgKey;"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few changes required that shouldn't be a problem, before we can merge.
server/src/main/java/org/candlepin/pinsetter/tasks/HypervisorHeartbeatUpdateJob.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/candlepin/resource/HypervisorResource.java
Outdated
Show resolved
Hide resolved
| /** | ||
| * Asynchronous job for refreshing the lastCheckin for specific reporter_id. | ||
| * A job will wait for a running job of the same Owner to finish before | ||
| * beginning execution |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably remove the second sentence of the comment, since this job is not marked for uniqueness (it would have to either extend the UniqueByEntityJob class, or alternatively provide the isSchedulable & scheduleJob methods). Alternatively, you can make it unique for Owners & class (so that only one job of this type is running for this owner at a time), but I believe it is not necessary for this job.
@wottop Can you verify that we don't need this job to be unique-by-entity? ^
server/src/main/java/org/candlepin/pinsetter/tasks/HypervisorHeartbeatUpdateJob.java
Show resolved
Hide resolved
| " SET lastcheckin = :checkin" + | ||
| " WHERE id IN (SELECT consumer_id" + | ||
| " FROM cp_consumer_hypervisor" + | ||
| " WHERE reporter_id = :reporter)"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need a subselect:
"UPDATE cp_consumer a, cp_consumer_hypervisor b, cp_owner c" +
" SET a.lastcheckin = :checkin" +
" WHERE a.id = b.consumer_id" +
" AND b.reporter_id = :reporter" +
" AND a.owner_id = c.id" +
" AND c.account = :orgKey;"
51b0c6f
to
cab60be
Compare
b219d0c
to
84be24e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-reviewing: the changes noted before are now fixed, and the code in general is good, but I missed looking at the API design itself before.
| @POST | ||
| @Produces(MediaType.APPLICATION_JSON) | ||
| @Transactional | ||
| @Path("/heartbeat/{owner}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something I did not think about before is the design of the API itself.
-
For the verb: I would say that this should be either a PATCH or a PUT instead of a POST (technically, it fits much more to use a PATCH, since we don't accept an entire entity, like a
ConsumerDTOor aHypervisorDTOto be updated, but we only want to update a specific field of the entity, the last check in date). -
For the url: I think the
{owner}should be at the start, since it is the top-level entity, which is consistent with all other endpoints we have. Also, maybe thereporter_idshould also be in the URL, since this is what identifies the entity/ies being PATCHed. So the url should be one of:/{owner}/heartbeat,/{owner}/{reporter_id}/heartbeator/{owner}/heartbeat/{reporter_id}.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/{owner}/heartbeat and leave the reporter_id as a parameter like the hypervisor check in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
40b0f06
to
7691541
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK by me.
…y virt-who
- Create a new endpoint POST /hypervisors/{owner}/heartbeat
- The new endpoint updates last checkin date of all consumers for the given reporter_id
7691541
to
2f310f2
Compare