open-nomad/client/allocrunnerv2/allocdir_hook.go
Michael Schurter 5c5c6dc41b refactor ar hooks into their own files
minimize passed dependencies to ease testing
2018-10-16 16:53:30 -07:00

36 lines
713 B
Go

package allocrunnerv2
import (
"context"
log "github.com/hashicorp/go-hclog"
"github.com/hashicorp/nomad/client/allocdir"
)
// allocDirHook creates and destroys the root directory and shared directories
// for an allocation.
type allocDirHook struct {
allocDir *allocdir.AllocDir
logger log.Logger
}
func newAllocDirHook(logger log.Logger, allocDir *allocdir.AllocDir) *allocDirHook {
ad := &allocDirHook{
allocDir: allocDir,
}
ad.logger = logger.Named(ad.Name())
return ad
}
func (h *allocDirHook) Name() string {
return "alloc_dir"
}
func (h *allocDirHook) Prerun(context.Context) error {
return h.allocDir.Build()
}
func (h *allocDirHook) Destroy() error {
return h.allocDir.Destroy()
}