Eliminate duplicate mirrorProvider in Hooks

This commit is contained in:
WANG Ziqin 2019-07-31 16:11:56 +08:00
parent 8408236646
commit 06fce98c00
5 changed files with 27 additions and 22 deletions

View File

@ -17,7 +17,6 @@ import (
type cgroupHook struct { type cgroupHook struct {
emptyHook emptyHook
provider mirrorProvider
basePath string basePath string
baseGroup string baseGroup string
created bool created bool
@ -36,7 +35,9 @@ func newCgroupHook(p mirrorProvider, basePath, baseGroup, subsystem, memLimit st
subsystem = "cpu" subsystem = "cpu"
} }
return &cgroupHook{ return &cgroupHook{
provider: p, emptyHook: emptyHook{
provider: p,
},
basePath: basePath, basePath: basePath,
baseGroup: baseGroup, baseGroup: baseGroup,
subsystem: subsystem, subsystem: subsystem,

View File

@ -7,10 +7,9 @@ import (
type dockerHook struct { type dockerHook struct {
emptyHook emptyHook
provider mirrorProvider image string
image string volumes []string
volumes []string options []string
options []string
} }
func newDockerHook(p mirrorProvider, gCfg dockerConfig, mCfg mirrorConfig) *dockerHook { func newDockerHook(p mirrorProvider, gCfg dockerConfig, mCfg mirrorConfig) *dockerHook {
@ -23,10 +22,12 @@ func newDockerHook(p mirrorProvider, gCfg dockerConfig, mCfg mirrorConfig) *dock
options = append(options, mCfg.DockerOptions...) options = append(options, mCfg.DockerOptions...)
return &dockerHook{ return &dockerHook{
provider: p, emptyHook: emptyHook{
image: mCfg.DockerImage, provider: p,
volumes: volumes, },
options: options, image: mCfg.DockerImage,
volumes: volumes,
options: options,
} }
} }

View File

@ -18,7 +18,6 @@ const (
type execPostHook struct { type execPostHook struct {
emptyHook emptyHook
provider mirrorProvider
// exec on success or on failure // exec on success or on failure
execOn uint8 execOn uint8
@ -37,9 +36,11 @@ func newExecPostHook(provider mirrorProvider, execOn uint8, command string) (*ex
} }
return &execPostHook{ return &execPostHook{
provider: provider, emptyHook: emptyHook{
execOn: execOn, provider: provider,
command: cmd, },
execOn: execOn,
command: cmd,
}, nil }, nil
} }

View File

@ -14,12 +14,13 @@ import (
type logLimiter struct { type logLimiter struct {
emptyHook emptyHook
provider mirrorProvider
} }
func newLogLimiter(provider mirrorProvider) *logLimiter { func newLogLimiter(provider mirrorProvider) *logLimiter {
return &logLimiter{ return &logLimiter{
provider: provider, emptyHook: emptyHook{
provider: provider,
},
} }
} }

View File

@ -11,14 +11,15 @@ import (
type zfsHook struct { type zfsHook struct {
emptyHook emptyHook
provider mirrorProvider zpool string
zpool string
} }
func newZfsHook(provider mirrorProvider, zpool string) *zfsHook { func newZfsHook(provider mirrorProvider, zpool string) *zfsHook {
return &zfsHook{ return &zfsHook{
provider: provider, emptyHook: emptyHook{
zpool: zpool, provider: provider,
},
zpool: zpool,
} }
} }
@ -40,12 +41,12 @@ func (z *zfsHook) printHelpMessage() {
func (z *zfsHook) preJob() error { func (z *zfsHook) preJob() error {
workingDir := z.provider.WorkingDir() workingDir := z.provider.WorkingDir()
if _, err := os.Stat(workingDir); os.IsNotExist(err) { if _, err := os.Stat(workingDir); os.IsNotExist(err) {
logger.Errorf("Directory %s doesn't exist", workingDir); logger.Errorf("Directory %s doesn't exist", workingDir)
z.printHelpMessage() z.printHelpMessage()
return err return err
} }
if err := sh.Command("mountpoint", "-q", workingDir).Run(); err != nil { if err := sh.Command("mountpoint", "-q", workingDir).Run(); err != nil {
logger.Errorf("%s is not a mount point", workingDir); logger.Errorf("%s is not a mount point", workingDir)
z.printHelpMessage() z.printHelpMessage()
return err return err
} }