diff options
author | Arne Juul <arnej@yahooinc.com> | 2022-11-10 14:45:56 +0000 |
---|---|---|
committer | Arne Juul <arnej@yahooinc.com> | 2022-11-14 13:03:30 +0000 |
commit | d308934d6d55c6661f881b30aa4ad3a850b66321 (patch) | |
tree | bf523ed5c1fcd377e55bd84aa43b32785f1e9c93 | |
parent | 60e0c807988226eba418e9c80da2fd0b8f5e9015 (diff) |
flesh out StandaloneContainer, mostly common code
-rw-r--r-- | client/go/jvm/application_container.go | 16 | ||||
-rw-r--r-- | client/go/jvm/container.go | 37 | ||||
-rw-r--r-- | client/go/jvm/env.go | 2 | ||||
-rw-r--r-- | client/go/jvm/options.go | 4 | ||||
-rw-r--r-- | client/go/jvm/run.go | 25 | ||||
-rw-r--r-- | client/go/jvm/standalone_container.go | 41 |
6 files changed, 81 insertions, 44 deletions
diff --git a/client/go/jvm/application_container.go b/client/go/jvm/application_container.go index 8470fbf2c13..44e4f64fd2f 100644 --- a/client/go/jvm/application_container.go +++ b/client/go/jvm/application_container.go @@ -19,9 +19,7 @@ const ( ) type ApplicationContainer struct { - configId string - serviceName string - jvmArgs *Options + containerBase } func (a *ApplicationContainer) ArgForMain() string { @@ -29,14 +27,6 @@ func (a *ApplicationContainer) ArgForMain() string { return fmt.Sprintf("file:%s/%s", dir, JAR_FOR_APPLICATION_CONTAINER) } -func (a *ApplicationContainer) ServiceName() string { - return a.serviceName -} - -func (a *ApplicationContainer) ConfigId() string { - return a.configId -} - func (a *ApplicationContainer) Discriminator() string { cfgId := a.ConfigId() if cfgId != "" { @@ -71,7 +61,6 @@ func (a *ApplicationContainer) addJdiscProperties() { opts.AddOption("-Djdisc.config.file=" + propsFile) opts.AddOption("-Djdisc.cache.path=" + bCacheDir) opts.AddOption("-Djdisc.logger.tag=" + cfgId) - } func validPercentage(val int) bool { @@ -171,6 +160,9 @@ func (a *ApplicationContainer) configureCPU(qc *QrStartConfig) { } func (a *ApplicationContainer) addJvmArgs(opts *Options) { + if a.jvmArgs != nil { + panic("can only set jvmArgs once") + } a.jvmArgs = opts opts.AddOption("-Dconfig.id=" + a.ConfigId()) if env := os.Getenv(VESPA_CONTAINER_JVMARGS); env != "" { diff --git a/client/go/jvm/container.go b/client/go/jvm/container.go index a07ba684a03..ac10f775859 100644 --- a/client/go/jvm/container.go +++ b/client/go/jvm/container.go @@ -3,9 +3,46 @@ package jvm +import ( + "github.com/vespa-engine/vespa/client/go/prog" + "github.com/vespa-engine/vespa/client/go/util" +) + type Container interface { ServiceName() string ConfigId() string ArgForMain() string + JvmOptions() *Options Exec() } + +type containerBase struct { + configId string + serviceName string + jvmArgs *Options +} + +func (cb *containerBase) ServiceName() string { + return cb.serviceName +} + +func (cb *containerBase) JvmOptions() *Options { + return cb.jvmArgs +} + +func (cb *containerBase) ConfigId() string { + return cb.configId +} + +func (cb *containerBase) Exec() { + argv := make([]string, 0, 100) + argv = append(argv, "java") + for _, x := range cb.JvmOptions().Args() { + argv = append(argv, x) + } + p := prog.NewSpec(argv) + p.ConfigureNumaCtl() + exportEnvSettings(cb, p) + err := p.Run() + util.JustExitWith(err) +} diff --git a/client/go/jvm/env.go b/client/go/jvm/env.go index 761c4ac5f9b..5157847fb86 100644 --- a/client/go/jvm/env.go +++ b/client/go/jvm/env.go @@ -26,7 +26,7 @@ const ( MALLOC_ARENA_MAX = util.ENV_MALLOC_ARENA_MAX ) -func exportEnvSettings(c Container, ps *prog.Spec) { +func exportEnvSettings(c *containerBase, ps *prog.Spec) { vespaHome := defaults.VespaHome() vlt := fmt.Sprintf("file:%s/logs/vespa/vespa.log", vespaHome) lcd := fmt.Sprintf("%s/var/db/vespa/logcontrol", vespaHome) diff --git a/client/go/jvm/options.go b/client/go/jvm/options.go index a6800150d84..cbaaa32cfc3 100644 --- a/client/go/jvm/options.go +++ b/client/go/jvm/options.go @@ -22,7 +22,7 @@ type Options struct { fixSpec util.FixSpec } -func NewOptions(c Container) Options { +func NewOptions(c Container) *Options { vespaUid, vespaGid := vespa.FindVespaUidAndGid() fixSpec := util.FixSpec{ UserId: vespaUid, @@ -30,7 +30,7 @@ func NewOptions(c Container) Options { DirMode: 0755, FileMode: 0644, } - return Options{ + return &Options{ container: c, classPath: make([]string, 0, 10), jvmArgs: make([]string, 0, 100), diff --git a/client/go/jvm/run.go b/client/go/jvm/run.go index fad72376d6a..44da3bbace0 100644 --- a/client/go/jvm/run.go +++ b/client/go/jvm/run.go @@ -6,7 +6,6 @@ package jvm import ( "os" - "github.com/vespa-engine/vespa/client/go/prog" "github.com/vespa-engine/vespa/client/go/trace" "github.com/vespa-engine/vespa/client/go/util" ) @@ -25,29 +24,13 @@ func RunApplicationContainer(extraArgs []string) int { } func NewApplicationContainer(extraArgs []string) Container { - configId := os.Getenv(util.ENV_CONFIG_ID) - serviceName := os.Getenv(util.ENV_SERVICE_NAME) - a := ApplicationContainer{ - configId: configId, - serviceName: serviceName, - } + var a ApplicationContainer + a.configId = os.Getenv(util.ENV_CONFIG_ID) + a.serviceName = os.Getenv(util.ENV_SERVICE_NAME) opts := NewOptions(&a) - a.addJvmArgs(&opts) + a.addJvmArgs(opts) for _, x := range extraArgs { opts.AddOption(x) } return &a } - -func (a *ApplicationContainer) Exec() { - argv := make([]string, 0, 100) - argv = append(argv, "java") - for _, x := range a.jvmArgs.Args() { - argv = append(argv, x) - } - p := prog.NewSpec(argv) - p.ConfigureNumaCtl() - exportEnvSettings(a, p) - err := p.Run() - util.JustExitWith(err) -} diff --git a/client/go/jvm/standalone_container.go b/client/go/jvm/standalone_container.go index 36c56c09b23..799e1f2eb02 100644 --- a/client/go/jvm/standalone_container.go +++ b/client/go/jvm/standalone_container.go @@ -5,8 +5,11 @@ package jvm import ( "fmt" + "os" "github.com/vespa-engine/vespa/client/go/defaults" + "github.com/vespa-engine/vespa/client/go/trace" + "github.com/vespa-engine/vespa/client/go/util" ) const ( @@ -14,7 +17,7 @@ const ( ) type StandaloneContainer struct { - serviceName string + containerBase } func (a *StandaloneContainer) ArgForMain() string { @@ -30,10 +33,15 @@ func (a *StandaloneContainer) ConfigId() string { } func (a *StandaloneContainer) addJvmArgs(opts *Options) { + if a.jvmArgs != nil { + panic("can only set jvmArgs once") + } + a.jvmArgs = opts opts.AddCommonXX() opts.AddOption("-XX:-OmitStackTraceInFastThrow") opts.AddCommonOpens() opts.AddCommonJdkProperties() + a.addJdiscProperties() svcName := a.ServiceName() if svcName == "configserver" { RemoveStaleZkLocks(a) @@ -41,16 +49,33 @@ func (a *StandaloneContainer) addJvmArgs(opts *Options) { zkLogFile := fmt.Sprintf("%s/zookeeper.%s", logsDir, svcName) opts.AddOption("-Dzookeeper_log_file_prefix=" + zkLogFile) } - panic("not finished yet") } -func (a *StandaloneContainer) Exec() { - panic("not implemented yet") +func NewStandaloneContainer(svcName string) Container { + var a StandaloneContainer + a.serviceName = svcName + a.addJvmArgs(NewOptions(&a)) + return &a } -func NewStandaloneContainer(svcName string) Container { - a := StandaloneContainer{ - serviceName: svcName, +func (a *StandaloneContainer) addJdiscProperties() { + opts := a.JvmOptions() + opts.AddCommonJdiscProperties() + containerParentDir := defaults.UnderVespaHome("var/jdisc_container") + bCacheParentDir := defaults.UnderVespaHome("var/vespa/bundlecache") + svcName := a.ServiceName() + bCacheDir := fmt.Sprintf("%s/%s", bCacheParentDir, svcName) + propsFile := fmt.Sprintf("%s/%s.properties", containerParentDir, svcName) + opts.fixSpec.FixDir(containerParentDir) + opts.fixSpec.FixDir(bCacheParentDir) + opts.fixSpec.FixDir(bCacheDir) + trace.Trace("write props file:", propsFile) + err := os.WriteFile(propsFile, selectedEnv(), 0600) + if err != nil { + util.JustExitWith(err) } - return &a + opts.AddOption("-Djdisc.export.packages=") + opts.AddOption("-Djdisc.config.file=" + propsFile) + opts.AddOption("-Djdisc.cache.path=" + bCacheDir) + opts.AddOption("-Djdisc.logger.tag=" + svcName) } |