puppetlabs/puppet — pull request #1800 by trlinkin (2013-07-24 01:35:45+00:00)
Title: (#3946) Add support for finalize method to providers

Without this commit, providers are not given the opportunity to perform
final actions, such as release resources, in the event no changes on the
resource have occurred. Currently, only the flush method is called after
a resource has been fully evaluated, and only when the resource has
changes.

This is useful in cases where pre-fetching may have initialized some
resources, or there is a common resource with open references against
it. For instance, a socket used by all providers of a type, or perhaps a
mapped file that will be flushed in one bulk operation once all open
references are closed.

This commit adds a path for execution of a finalize method on the
provider. It starts at the evaluate method in the transaction resource
harness. On each resource, regardless of returned events, an "applied"
method is called on the resource. This is to signal the resource it has
been fully applied. Default behavior of the applied method is to call
the finalize method on the provider if supported. This operation
closely mimics the operation of the flush method in resources..

The finalize method has certain implications on the operation of a
provider. First, if defined, it will be called regardless of the outcome
of resource application. This means if there is anything flush handels
that overlaps with finalize, care must be taken. If it is to not operate
when the provider is in a failure mode, the provider must be aware of
its internal state and act accordingly. If a shared resource is being
used, care must be taken to not clear it until after it is no longer
needed.