Refactor and move event handling code into the cluster package#2752
Conversation
dbfd98b to
eb42260
Compare
9249e16 to
eeafb8d
Compare
3edec95 to
839ce5f
Compare
|
Ping @allencloud can you take a look? |
|
OK, I will today. @nishanttotla |
a3c9c7d to
2342a32
Compare
Signed-off-by: Nishant Totla <nishanttotla@gmail.com>
Signed-off-by: Nishant Totla <nishanttotla@gmail.com>
This is to eliminate some confusion around how events are handled in Swarm. Signed-off-by: Nishant Totla <nishanttotla@gmail.com>
function Signed-off-by: Nishant Totla <nishanttotla@gmail.com>
Signed-off-by: Nishant Totla <nishanttotla@gmail.com>
2342a32 to
9f062b6
Compare
alexmavr
left a comment
There was a problem hiding this comment.
Implementation looks good, just a couple comments on code structure. I ran a couple smoke-tests locally and this PR does not seem to be causing any behavioral changes on first glance.
|
|
||
| // EventHandler is exported | ||
| type EventHandler interface { | ||
| Handle(*Event) error |
There was a problem hiding this comment.
It looks like at this point all implementations of this method always return nil instead of an error. How about making this not return anything?
There was a problem hiding this comment.
Seems like you're right. I can't recall why it was this way in the past, because generally event related errors don't cause things to fail, but perhaps in the future we might want to log those errors. What do you think?
There was a problem hiding this comment.
Personally, I like to avoid returning an error when one is never expected to occur, but I don't have a strong preference here.
| // CloseWatchQueues unregisters all API event handlers (the ones with | ||
| // watch queues) and closes the respective queues. This should be | ||
| // called when the manager shuts down | ||
| func (eh *ClusterEventHandlers) CloseWatchQueues() { |
There was a problem hiding this comment.
This could also be structured as a generic Cleanup method. Then, we can switch on the type of the handler below and perform any sort of type-specific cleanup (such as closing the watch queue for APIEventHandlers).
This is probably a vain effort though, as the other handlers don't require any cleanup, and I don't think we expect any new types of event handlers with the current architecture
There was a problem hiding this comment.
I agree that this effort isn't very useful at this time, and we will not have more types of event handlers. Besides, it won't be hard to change it in the future if necessary.
cluster/event_map.go
Outdated
| } | ||
|
|
||
| // HandleAll callbacks for the events | ||
| func (eh *ClusterEventHandlers) HandleAll(e *Event) { |
There was a problem hiding this comment.
Why not name this Handle so that the ClusterEventHandlers also satisfies the EventHandler interface?
There was a problem hiding this comment.
I called it HandleAll for more clarity about what it does, and it didn't seem like we got anything by making it satisfy the interface.
There was a problem hiding this comment.
The benefit to the rename is that we don't have to implement a Cluster.Handle method at all, if we embed Cluster.ClusterEventHandlers
cluster/mesos/cluster.go
Outdated
| @@ -169,31 +167,31 @@ func NewCluster(scheduler *scheduler.Scheduler, TLSConfig *tls.Config, master st | |||
|
|
|||
| // Handle callbacks for the events | |||
| func (c *Cluster) Handle(e *cluster.Event) error { | |||
There was a problem hiding this comment.
If the Cluster struct were to embed a clusterEventHandlers, and the HandleAll method were renamed to Handle, this method wrapper could be removed entirely, as well as the Register/Unregister methods below.
This comment also applies for the swarm cluster object as well
There was a problem hiding this comment.
This sounds like a reasonable thing to do. I believe in addition to renaming HandleAll, we'll also need to change the interface to not have Handle return the error, as you said above.
cluster/mesos/cluster.go
Outdated
| // CloseWatchQueues unregisters all API event handlers (the ones with | ||
| // watch queues) and closes the respective queues. This should be | ||
| // called when the manager shuts down | ||
| func (c *Cluster) CloseWatchQueues() { |
There was a problem hiding this comment.
This method looks like a no-op, is there any reason why it can't be removed?
There was a problem hiding this comment.
Oh, this is a mistake I think. It was supposed to call the CloseWatchQueues function of ClusterEventHandlers.
Signed-off-by: Nishant Totla <nishanttotla@gmail.com>
9d05bfa to
4fcf4a1
Compare
|
@alexmavr Addressed your comments, and embedded I've kept the error returned by the handler as of now, because I want to investigate if it makes sense to error out in some places (this I plan to do as a follow-up) |
alexmavr
left a comment
There was a problem hiding this comment.
LGTM. Tests still pass with the new changes
cluster/mesos/cluster.go
Outdated
| refuseTimeout: defaultRefuseTimeout, | ||
| } | ||
|
|
||
| cluster.InitClusterEventHandlers() |
There was a problem hiding this comment.
That method change wasn't really required, you can still initialize an embedded struct, such as:
cluster := &Cluster{
ClusterEventHandlers: cluster.NewClusterEventHandlers(),
}
There was a problem hiding this comment.
Oh yeah, I had changed it earlier for some reason, but forgot to fix it later. I'll change it.
…side the Cluster object Signed-off-by: Nishant Totla <nishanttotla@gmail.com>
4fcf4a1 to
995e078
Compare
In this PR
watchQueueas a cluster object, and package it inside theAPIEventHandlerclusterpackageAddresses #2749
Follows up #2747