aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Marius Venstad <jonmv@users.noreply.github.com>2023-11-30 07:37:48 +0100
committerGitHub <noreply@github.com>2023-11-30 07:37:48 +0100
commitaa207732992038ae65d73a04832ac8a3753b73a9 (patch)
tree03f4348852097be2e56e678e0b8054ac266e203c
parentee2644acc1af50dafd85a1314bc37d3f936b51d9 (diff)
parentef223425a7c034ba129a5084b56a6fd11385449a (diff)
Merge pull request #29501 from vespa-engine/mpolden/cli-cleanup
CLI package cleanup
-rw-r--r--client/go/internal/admin/clusterstate/cluster_state.go4
-rw-r--r--client/go/internal/admin/clusterstate/detect_model.go14
-rw-r--r--client/go/internal/admin/clusterstate/set_node_state.go6
-rw-r--r--client/go/internal/admin/deploy/cmd.go4
-rw-r--r--client/go/internal/admin/deploy/curl.go8
-rw-r--r--client/go/internal/admin/deploy/fetch.go4
-rw-r--r--client/go/internal/admin/deploy/persist.go8
-rw-r--r--client/go/internal/admin/deploy/urls.go4
-rw-r--r--client/go/internal/admin/jvm/application_container.go17
-rw-r--r--client/go/internal/admin/jvm/application_container_test.go (renamed from client/go/internal/util/md5_test.go)8
-rw-r--r--client/go/internal/admin/jvm/container.go7
-rw-r--r--client/go/internal/admin/jvm/env.go7
-rw-r--r--client/go/internal/admin/jvm/mem_avail.go4
-rw-r--r--client/go/internal/admin/jvm/options.go11
-rw-r--r--client/go/internal/admin/jvm/properties.go4
-rw-r--r--client/go/internal/admin/jvm/qr_start_cfg.go6
-rw-r--r--client/go/internal/admin/jvm/standalone_container.go7
-rw-r--r--client/go/internal/admin/jvm/zk_locks.go6
-rw-r--r--client/go/internal/admin/prog/numactl.go4
-rw-r--r--client/go/internal/admin/prog/run.go4
-rw-r--r--client/go/internal/admin/prog/valgrind.go4
-rw-r--r--client/go/internal/admin/prog/valgrind_test.go4
-rw-r--r--client/go/internal/admin/vespa-wrapper/configserver/check.go4
-rw-r--r--client/go/internal/admin/vespa-wrapper/configserver/env.go4
-rw-r--r--client/go/internal/admin/vespa-wrapper/configserver/fix_dirs_and_files.go8
-rw-r--r--client/go/internal/admin/vespa-wrapper/configserver/logd.go4
-rw-r--r--client/go/internal/admin/vespa-wrapper/configserver/runserver.go16
-rw-r--r--client/go/internal/admin/vespa-wrapper/configserver/start.go10
-rw-r--r--client/go/internal/admin/vespa-wrapper/configserver/zk.go4
-rw-r--r--client/go/internal/admin/vespa-wrapper/main.go4
-rw-r--r--client/go/internal/admin/vespa-wrapper/services/configproxy.go10
-rw-r--r--client/go/internal/admin/vespa-wrapper/services/env.go4
-rw-r--r--client/go/internal/admin/vespa-wrapper/services/prechecks.go4
-rw-r--r--client/go/internal/admin/vespa-wrapper/services/sentinel.go6
-rw-r--r--client/go/internal/admin/vespa-wrapper/services/start.go12
-rw-r--r--client/go/internal/admin/vespa-wrapper/services/stop.go6
-rw-r--r--client/go/internal/admin/vespa-wrapper/standalone/start.go10
-rw-r--r--client/go/internal/admin/vespa-wrapper/startcbinary/cmd.go9
-rw-r--r--client/go/internal/admin/vespa-wrapper/startcbinary/tuning.go6
-rw-r--r--client/go/internal/cli/auth/auth0/auth0.go6
-rw-r--r--client/go/internal/cli/auth/zts/zts.go6
-rw-r--r--client/go/internal/cli/cmd/api_key.go4
-rw-r--r--client/go/internal/cli/cmd/cert.go8
-rw-r--r--client/go/internal/cli/cmd/clone_list.go8
-rw-r--r--client/go/internal/cli/cmd/clone_test.go8
-rw-r--r--client/go/internal/cli/cmd/document.go19
-rw-r--r--client/go/internal/cli/cmd/document_test.go4
-rw-r--r--client/go/internal/cli/cmd/feed.go8
-rw-r--r--client/go/internal/cli/cmd/man_test.go4
-rw-r--r--client/go/internal/cli/cmd/prod.go6
-rw-r--r--client/go/internal/cli/cmd/prod_test.go6
-rw-r--r--client/go/internal/cli/cmd/query.go8
-rw-r--r--client/go/internal/cli/cmd/result.go (renamed from client/go/internal/util/operation_result.go)6
-rw-r--r--client/go/internal/cli/cmd/root.go43
-rw-r--r--client/go/internal/cli/cmd/test.go7
-rw-r--r--client/go/internal/cli/cmd/test_test.go4
-rw-r--r--client/go/internal/cli/cmd/testutil_test.go8
-rw-r--r--client/go/internal/cli/cmd/visit.go50
-rw-r--r--client/go/internal/httputil/httputil.go (renamed from client/go/internal/util/http.go)26
-rw-r--r--client/go/internal/ioutil/ioutil.go (renamed from client/go/internal/util/io.go)24
-rw-r--r--client/go/internal/ioutil/ioutil_test.go (renamed from client/go/internal/util/io_test.go)26
-rw-r--r--client/go/internal/list/array_list.go (renamed from client/go/internal/util/array_list.go)3
-rw-r--r--client/go/internal/list/array_list_test.go (renamed from client/go/internal/util/array_list_test.go)3
-rw-r--r--client/go/internal/mock/http.go4
-rw-r--r--client/go/internal/osutil/execvp.go (renamed from client/go/internal/util/execvp.go)5
-rw-r--r--client/go/internal/osutil/execvp_windows.go (renamed from client/go/internal/util/execvp_windows.go)2
-rw-r--r--client/go/internal/osutil/fix_fs.go (renamed from client/go/internal/util/fix_fs.go)4
-rw-r--r--client/go/internal/osutil/fix_fs_test.go (renamed from client/go/internal/util/fix_fs_test.go)23
-rw-r--r--client/go/internal/osutil/just_exit.go (renamed from client/go/internal/util/just_exit.go)16
-rw-r--r--client/go/internal/osutil/run_cmd.go (renamed from client/go/internal/util/run_cmd.go)2
-rw-r--r--client/go/internal/osutil/setrlimit.go (renamed from client/go/internal/util/setrlimit.go)2
-rw-r--r--client/go/internal/osutil/setrlimit_windows.go (renamed from client/go/internal/util/setrlimit_windows.go)2
-rw-r--r--client/go/internal/osutil/tune_logctl.go (renamed from client/go/internal/util/tune_logctl.go)2
-rw-r--r--client/go/internal/osutil/tuning.go (renamed from client/go/internal/util/tuning.go)2
-rw-r--r--client/go/internal/util/md5.go17
-rw-r--r--client/go/internal/util/spinner.go35
-rw-r--r--client/go/internal/version/version.go4
-rw-r--r--client/go/internal/vespa/application.go22
-rw-r--r--client/go/internal/vespa/crypto.go10
-rw-r--r--client/go/internal/vespa/deploy.go8
-rw-r--r--client/go/internal/vespa/deploy_test.go6
-rw-r--r--client/go/internal/vespa/detect_hostname.go4
-rw-r--r--client/go/internal/vespa/document/http.go6
-rw-r--r--client/go/internal/vespa/document/http_test.go14
-rw-r--r--client/go/internal/vespa/find_home.go11
-rw-r--r--client/go/internal/vespa/load_env.go7
-rw-r--r--client/go/internal/vespa/prestart.go6
-rw-r--r--client/go/internal/vespa/switch_user.go6
-rw-r--r--client/go/internal/vespa/target.go8
-rw-r--r--client/go/internal/vespa/target_cloud.go6
-rw-r--r--client/go/internal/vespa/target_custom.go8
-rw-r--r--client/go/internal/vespa/xml/config.go3
92 files changed, 401 insertions, 405 deletions
diff --git a/client/go/internal/admin/clusterstate/cluster_state.go b/client/go/internal/admin/clusterstate/cluster_state.go
index 52f7c2181b4..fe6c6c1a4d2 100644
--- a/client/go/internal/admin/clusterstate/cluster_state.go
+++ b/client/go/internal/admin/clusterstate/cluster_state.go
@@ -11,7 +11,7 @@ import (
"strings"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
)
// common struct used various places in the clustercontroller REST api:
@@ -117,6 +117,6 @@ func (model *VespaModelConfig) getClusterState(cluster string) (*ClusterState, *
return &parsedJson, &cc
}
// no success:
- util.JustExitMsg(fmt.Sprint(errs))
+ osutil.ExitMsg(fmt.Sprint(errs))
panic("unreachable")
}
diff --git a/client/go/internal/admin/clusterstate/detect_model.go b/client/go/internal/admin/clusterstate/detect_model.go
index 0f261526145..db2e167ea6a 100644
--- a/client/go/internal/admin/clusterstate/detect_model.go
+++ b/client/go/internal/admin/clusterstate/detect_model.go
@@ -9,7 +9,7 @@ import (
"strings"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
)
@@ -17,11 +17,11 @@ func getConfigServerHosts(s string) []string {
if s != "" {
return []string{s}
}
- backticks := util.BackTicksForwardStderr
+ backticks := osutil.BackTicksForwardStderr
got, err := backticks.Run(vespa.FindHome()+"/bin/vespa-print-default", "configservers")
res := strings.Fields(got)
if err != nil || len(res) < 1 {
- util.JustExitMsg("bad configservers: " + got)
+ osutil.ExitMsg("bad configservers: " + got)
}
trace.Debug("found", len(res), "configservers:", res)
return res
@@ -31,13 +31,13 @@ func getConfigServerPort(i int) int {
if i > 0 {
return i
}
- backticks := util.BackTicksForwardStderr
+ backticks := osutil.BackTicksForwardStderr
got, err := backticks.Run(vespa.FindHome()+"/bin/vespa-print-default", "configserver_rpc_port")
if err == nil {
i, err = strconv.Atoi(strings.TrimSpace(got))
}
if err != nil || i < 1 {
- util.JustExitMsg("bad configserver_rpc_port: " + got)
+ osutil.ExitMsg("bad configserver_rpc_port: " + got)
}
trace.Debug("found configservers rpc port:", i)
return i
@@ -55,13 +55,13 @@ func detectModel(opts *Options) *VespaModelConfig {
"-p", strconv.Itoa(cfgPort),
"-s", cfgHost,
}
- backticks := util.BackTicksForwardStderr
+ backticks := osutil.BackTicksForwardStderr
data, err := backticks.Run(vespa.FindHome()+"/bin/vespa-get-config", args...)
parsed := parseModelConfig(data)
if err == nil && parsed != nil {
return parsed
}
}
- util.JustExitMsg("could not get model config")
+ osutil.ExitMsg("could not get model config")
panic("unreachable")
}
diff --git a/client/go/internal/admin/clusterstate/set_node_state.go b/client/go/internal/admin/clusterstate/set_node_state.go
index a838b43503f..023d3ed71c8 100644
--- a/client/go/internal/admin/clusterstate/set_node_state.go
+++ b/client/go/internal/admin/clusterstate/set_node_state.go
@@ -16,7 +16,7 @@ import (
"github.com/vespa-engine/vespa/client/go/internal/admin/envvars"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
"github.com/vespa-engine/vespa/client/go/internal/build"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
)
const (
@@ -80,7 +80,7 @@ func runSetNodeState(opts *Options, args []string) {
}
wanted, err := knownState(args[0])
if err != nil {
- util.JustExitWith(err)
+ osutil.ExitErr(err)
}
reason := ""
if len(args) > 1 {
@@ -138,7 +138,7 @@ func (cc *ClusterControllerSpec) setNodeUserState(s serviceSpec, wanted KnownSta
}
jsonBytes, err := json.Marshal(request)
if err != nil {
- util.JustExitWith(err)
+ osutil.ExitErr(err)
}
url := fmt.Sprintf("http://%s:%d/cluster/v2/%s/%s/%d",
cc.host, cc.port,
diff --git a/client/go/internal/admin/deploy/cmd.go b/client/go/internal/admin/deploy/cmd.go
index 955ae93f859..f2edf3c7450 100644
--- a/client/go/internal/admin/deploy/cmd.go
+++ b/client/go/internal/admin/deploy/cmd.go
@@ -11,7 +11,7 @@ import (
"github.com/spf13/cobra"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
"github.com/vespa-engine/vespa/client/go/internal/build"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
)
@@ -24,7 +24,7 @@ func NewDeployCmd() *cobra.Command {
curOptions Options
)
if err := vespa.LoadDefaultEnv(); err != nil {
- util.JustExitWith(err)
+ osutil.ExitErr(err)
}
cobra.EnableCommandSorting = false
cmd := &cobra.Command{
diff --git a/client/go/internal/admin/deploy/curl.go b/client/go/internal/admin/deploy/curl.go
index 0ce1305226f..accd16b06f5 100644
--- a/client/go/internal/admin/deploy/curl.go
+++ b/client/go/internal/admin/deploy/curl.go
@@ -14,7 +14,7 @@ import (
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
"github.com/vespa-engine/vespa/client/go/internal/curl"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
)
@@ -60,20 +60,20 @@ func urlWithoutQuery(url string) string {
func newCurlCommand(url string, args []string) *curl.Command {
tls, err := vespa.LoadTlsConfig()
if err != nil {
- util.JustExitWith(err)
+ osutil.ExitErr(err)
}
if tls != nil && strings.HasPrefix(url, "http:") {
url = "https:" + url[5:]
}
cmd, err := curl.RawArgs(url, args...)
if err != nil {
- util.JustExitWith(err)
+ osutil.ExitErr(err)
}
if tls != nil {
if tls.DisableHostnameValidation {
cmd, err = curl.RawArgs(url, append(args, "--insecure")...)
if err != nil {
- util.JustExitWith(err)
+ osutil.ExitErr(err)
}
}
cmd.PrivateKey = tls.Files.PrivateKey
diff --git a/client/go/internal/admin/deploy/fetch.go b/client/go/internal/admin/deploy/fetch.go
index 9b4a927882d..010c0b1f324 100644
--- a/client/go/internal/admin/deploy/fetch.go
+++ b/client/go/internal/admin/deploy/fetch.go
@@ -12,7 +12,7 @@ import (
"strconv"
"strings"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
)
// main entry point for vespa-deploy fetch
@@ -90,7 +90,7 @@ func getPartAfterSlash(path string) string {
return parts[idx-1]
}
if idx == 0 {
- util.JustExitMsg("cannot find part after slash: " + path)
+ osutil.ExitMsg("cannot find part after slash: " + path)
}
return parts[idx]
}
diff --git a/client/go/internal/admin/deploy/persist.go b/client/go/internal/admin/deploy/persist.go
index 2c40606e1ab..781fc64106a 100644
--- a/client/go/internal/admin/deploy/persist.go
+++ b/client/go/internal/admin/deploy/persist.go
@@ -10,7 +10,7 @@ import (
"path/filepath"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
)
const (
@@ -43,11 +43,11 @@ func configsourceUrlUsedFile() string {
func createTenantDir(tenant string) string {
vespaDeployTempDir, err := createVespaDeployDir()
if err != nil {
- util.JustExitWith(err)
+ osutil.ExitErr(err)
}
tdir := filepath.Join(vespaDeployTempDir, tenant)
if err := os.MkdirAll(tdir, 0700); err != nil {
- util.JustExitWith(err)
+ osutil.ExitErr(err)
}
return tdir
}
@@ -80,7 +80,7 @@ func getSessionIdFromFile(tenant string) string {
fn := filepath.Join(dir, sessionIdFileName)
bytes, err := os.ReadFile(fn)
if err != nil {
- util.JustExitMsg("Could not read session id from file, and no session id supplied as argument. Exiting.")
+ osutil.ExitMsg("Could not read session id from file, and no session id supplied as argument. Exiting.")
}
trace.Trace("Session-id", string(bytes), "found from file", fn)
return string(bytes)
diff --git a/client/go/internal/admin/deploy/urls.go b/client/go/internal/admin/deploy/urls.go
index e9110bd9463..e840f4de29c 100644
--- a/client/go/internal/admin/deploy/urls.go
+++ b/client/go/internal/admin/deploy/urls.go
@@ -9,7 +9,7 @@ import (
"strings"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
)
@@ -28,7 +28,7 @@ func makeConfigsourceUrls(opts *Options) []string {
var results = make([]string, 0, 3)
if opts.ServerHost == "" {
home := vespa.FindHome()
- backticks := util.BackTicksForwardStderr
+ backticks := osutil.BackTicksForwardStderr
configsources, _ := backticks.Run(home+"/bin/vespa-print-default", "configservers_http")
for _, src := range strings.Split(configsources, "\n") {
colonParts := strings.Split(src, ":")
diff --git a/client/go/internal/admin/jvm/application_container.go b/client/go/internal/admin/jvm/application_container.go
index c525ea77949..3806dfea302 100644
--- a/client/go/internal/admin/jvm/application_container.go
+++ b/client/go/internal/admin/jvm/application_container.go
@@ -4,14 +4,16 @@
package jvm
import (
+ "crypto/md5"
"fmt"
+ "io"
"os"
"github.com/vespa-engine/vespa/client/go/internal/admin/defaults"
"github.com/vespa-engine/vespa/client/go/internal/admin/envvars"
"github.com/vespa-engine/vespa/client/go/internal/admin/prog"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
)
const (
@@ -22,6 +24,13 @@ type ApplicationContainer struct {
containerBase
}
+func md5Hex(text string) string {
+ hasher := md5.New()
+ io.WriteString(hasher, text)
+ hash := hasher.Sum(nil)
+ return fmt.Sprintf("%x", hash)
+}
+
func (a *ApplicationContainer) ArgForMain() string {
dir := defaults.UnderVespaHome("lib/jars")
return fmt.Sprintf("file:%s/%s", dir, JAR_FOR_APPLICATION_CONTAINER)
@@ -31,7 +40,7 @@ func (a *ApplicationContainer) Discriminator() string {
cfgId := a.ConfigId()
if cfgId != "" {
trace.Trace("Discriminator: using md5 of", cfgId)
- return util.Md5Hex(cfgId + "\n")
+ return md5Hex(cfgId + "\n")
}
svcName := a.ServiceName()
if svcName != "" {
@@ -40,7 +49,7 @@ func (a *ApplicationContainer) Discriminator() string {
}
pid := os.Getpid()
trace.Trace("Discriminator: using md5 of", pid)
- return util.Md5Hex(fmt.Sprintf("%d", pid))
+ return md5Hex(fmt.Sprintf("%d", pid))
}
func (a *ApplicationContainer) addJdiscProperties() {
@@ -168,6 +177,6 @@ func (c *ApplicationContainer) exportExtraEnv(ps *prog.Spec) {
if c.ConfigId() != "" {
ps.Setenv(envvars.VESPA_CONFIG_ID, c.ConfigId())
} else {
- util.JustExitMsg("application container requires a config id")
+ osutil.ExitMsg("application container requires a config id")
}
}
diff --git a/client/go/internal/util/md5_test.go b/client/go/internal/admin/jvm/application_container_test.go
index ac3bc6a9546..3a062edee16 100644
--- a/client/go/internal/util/md5_test.go
+++ b/client/go/internal/admin/jvm/application_container_test.go
@@ -1,5 +1,7 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package util
+// Author: arnej
+
+package jvm
import (
"testing"
@@ -8,6 +10,6 @@ import (
)
func TestMD5SimpleInputs(t *testing.T) {
- assert.Equal(t, "d41d8cd98f00b204e9800998ecf8427e", Md5Hex(""))
- assert.Equal(t, "4044e8209f286312a68bbb54f8714922", Md5Hex("admin/cluster-controllers/0\n"))
+ assert.Equal(t, "d41d8cd98f00b204e9800998ecf8427e", md5Hex(""))
+ assert.Equal(t, "4044e8209f286312a68bbb54f8714922", md5Hex("admin/cluster-controllers/0\n"))
}
diff --git a/client/go/internal/admin/jvm/container.go b/client/go/internal/admin/jvm/container.go
index 086ca8dde25..852bdb2464b 100644
--- a/client/go/internal/admin/jvm/container.go
+++ b/client/go/internal/admin/jvm/container.go
@@ -10,7 +10,8 @@ import (
"github.com/vespa-engine/vespa/client/go/internal/admin/prog"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/list"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
)
type Container interface {
@@ -60,7 +61,7 @@ func readableEnv(env map[string]string) string {
}
func (cb *containerBase) Exec() {
- argv := util.ArrayListOf(cb.JvmOptions().Args())
+ argv := list.ArrayListOf(cb.JvmOptions().Args())
argv.Insert(0, "java")
p := prog.NewSpec(argv)
p.ConfigureNumaCtl()
@@ -71,5 +72,5 @@ func (cb *containerBase) Exec() {
trace.Info("JVM env:", readableEnv(p.Env))
trace.Info("JVM exec:", argv)
err := p.Run()
- util.JustExitWith(err)
+ osutil.ExitErr(err)
}
diff --git a/client/go/internal/admin/jvm/env.go b/client/go/internal/admin/jvm/env.go
index 5c1e938d46b..ab7b005668b 100644
--- a/client/go/internal/admin/jvm/env.go
+++ b/client/go/internal/admin/jvm/env.go
@@ -11,7 +11,8 @@ import (
"github.com/vespa-engine/vespa/client/go/internal/admin/envvars"
"github.com/vespa-engine/vespa/client/go/internal/admin/prog"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/ioutil"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
)
func (opts *Options) exportEnvSettings(ps *prog.Spec) {
@@ -33,7 +34,7 @@ func (opts *Options) exportEnvSettings(ps *prog.Spec) {
if preload := ps.Getenv(envvars.PRELOAD); preload != "" {
checked := []string{}
for _, fileName := range strings.Split(preload, ":") {
- if util.PathExists(fileName) {
+ if ioutil.Exists(fileName) {
checked = append(checked, fileName)
} else {
trace.Info("File in PRELOAD missing, skipped:", fileName)
@@ -45,6 +46,6 @@ func (opts *Options) exportEnvSettings(ps *prog.Spec) {
ps.Setenv(envvars.LD_PRELOAD, preload)
}
}
- util.OptionallyReduceTimerFrequency()
+ osutil.OptionallyReduceTimerFrequency()
c.exportExtraEnv(ps)
}
diff --git a/client/go/internal/admin/jvm/mem_avail.go b/client/go/internal/admin/jvm/mem_avail.go
index bcc475e8ba8..df5acf79043 100644
--- a/client/go/internal/admin/jvm/mem_avail.go
+++ b/client/go/internal/admin/jvm/mem_avail.go
@@ -10,7 +10,7 @@ import (
"strings"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
)
func parseFree(txt string) AmountOfMemory {
@@ -91,7 +91,7 @@ func vespa_cg2get_impl(rootdir, limitname string) (output string, err error) {
func getAvailableMemory() AmountOfMemory {
result := BytesOfMemory(0)
- backticks := util.BackTicksWithStderr
+ backticks := osutil.BackTicksWithStderr
freeOutput, err := backticks.Run("free", "-m")
if err == nil {
result = parseFree(freeOutput)
diff --git a/client/go/internal/admin/jvm/options.go b/client/go/internal/admin/jvm/options.go
index a788fb0cca9..30c07526a40 100644
--- a/client/go/internal/admin/jvm/options.go
+++ b/client/go/internal/admin/jvm/options.go
@@ -10,22 +10,23 @@ import (
"github.com/vespa-engine/vespa/client/go/internal/admin/defaults"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/list"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
)
type Options struct {
container Container
classPath []string
- jvmArgs util.ArrayList[string]
+ jvmArgs list.ArrayList[string]
mainClass string
jarWithDeps string
- fixSpec util.FixSpec
+ fixSpec osutil.FixSpec
}
func NewOptions(c Container) *Options {
vespaUid, vespaGid := vespa.FindVespaUidAndGid()
- fixSpec := util.FixSpec{
+ fixSpec := osutil.FixSpec{
UserId: vespaUid,
GroupId: vespaGid,
DirMode: 0755,
@@ -79,7 +80,7 @@ func (opts *Options) AddJvmArgsFromString(args string) {
func (opts *Options) ConfigureCpuCount(cnt int) {
if cnt <= 0 {
- out, err := util.BackTicksForwardStderr.Run("nproc", "--all")
+ out, err := osutil.BackTicksForwardStderr.Run("nproc", "--all")
if err != nil {
trace.Trace("failed nproc:", err)
} else {
diff --git a/client/go/internal/admin/jvm/properties.go b/client/go/internal/admin/jvm/properties.go
index 446f218a2ad..d0016e03b51 100644
--- a/client/go/internal/admin/jvm/properties.go
+++ b/client/go/internal/admin/jvm/properties.go
@@ -11,7 +11,7 @@ import (
"strings"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
)
// quote as specified in JDK source file java.base/share/classes/java/util/Properties.java
@@ -101,6 +101,6 @@ func writeEnvAsProperties(envv []string, propsFile string) {
trace.Trace("write props file:", propsFile)
err := os.WriteFile(propsFile, envAsProperties(envv), 0600)
if err != nil {
- util.JustExitWith(err)
+ osutil.ExitErr(err)
}
}
diff --git a/client/go/internal/admin/jvm/qr_start_cfg.go b/client/go/internal/admin/jvm/qr_start_cfg.go
index 4edb02b2a84..a14ab0d1946 100644
--- a/client/go/internal/admin/jvm/qr_start_cfg.go
+++ b/client/go/internal/admin/jvm/qr_start_cfg.go
@@ -8,7 +8,7 @@ import (
"strings"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
)
type QrStartConfig struct {
@@ -42,10 +42,10 @@ func (a *ApplicationContainer) getQrStartCfg() *QrStartConfig {
"-n", "search.config.qr-start",
"-i", a.ConfigId(),
}
- backticks := util.BackTicksForwardStderr
+ backticks := osutil.BackTicksForwardStderr
data, err := backticks.Run("vespa-get-config", args...)
if err != nil {
- util.JustExitMsg("could not get qr-start config: " + err.Error())
+ osutil.ExitMsg("could not get qr-start config: " + err.Error())
} else {
codec := json.NewDecoder(strings.NewReader(data))
err = codec.Decode(&parsedJson)
diff --git a/client/go/internal/admin/jvm/standalone_container.go b/client/go/internal/admin/jvm/standalone_container.go
index 859aea9157d..20031bc7725 100644
--- a/client/go/internal/admin/jvm/standalone_container.go
+++ b/client/go/internal/admin/jvm/standalone_container.go
@@ -9,7 +9,8 @@ import (
"github.com/vespa-engine/vespa/client/go/internal/admin/defaults"
"github.com/vespa-engine/vespa/client/go/internal/admin/envvars"
"github.com/vespa-engine/vespa/client/go/internal/admin/prog"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/ioutil"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
)
const (
@@ -78,9 +79,9 @@ func (a *StandaloneContainer) addJdiscProperties() {
func (c *StandaloneContainer) exportExtraEnv(ps *prog.Spec) {
vespaHome := defaults.VespaHome()
app := fmt.Sprintf("%s/conf/%s-app", vespaHome, c.ServiceName())
- if util.IsDirectory(app) {
+ if ioutil.IsDir(app) {
ps.Setenv(envvars.STANDALONE_JDISC_APP_LOCATION, app)
} else {
- util.JustExitMsg("standalone container requires an application directory, missing: " + app)
+ osutil.ExitMsg("standalone container requires an application directory, missing: " + app)
}
}
diff --git a/client/go/internal/admin/jvm/zk_locks.go b/client/go/internal/admin/jvm/zk_locks.go
index 90a05f94905..3f0c8ea3301 100644
--- a/client/go/internal/admin/jvm/zk_locks.go
+++ b/client/go/internal/admin/jvm/zk_locks.go
@@ -8,7 +8,7 @@ import (
"github.com/vespa-engine/vespa/client/go/internal/admin/defaults"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
)
const (
@@ -16,12 +16,12 @@ const (
)
func RemoveStaleZkLocks(c Container) {
- backticks := util.BackTicksWithStderr
+ backticks := osutil.BackTicksWithStderr
cmd := fmt.Sprintf("rm -f '%s/%s.%s'*lck", defaults.VespaHome(), ZOOKEEPER_LOG_FILE_PREFIX, c.ServiceName())
trace.Trace("cleaning locks:", cmd)
out, err := backticks.Run("/bin/sh", "-c", cmd)
if err != nil {
trace.Warning("Failure [", out, "] when running command:", cmd)
- util.JustExitWith(err)
+ osutil.ExitErr(err)
}
}
diff --git a/client/go/internal/admin/prog/numactl.go b/client/go/internal/admin/prog/numactl.go
index da159529ec0..58bec66e986 100644
--- a/client/go/internal/admin/prog/numactl.go
+++ b/client/go/internal/admin/prog/numactl.go
@@ -10,7 +10,7 @@ import (
"github.com/vespa-engine/vespa/client/go/internal/admin/envvars"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
)
const (
@@ -23,7 +23,7 @@ func (p *Spec) ConfigureNumaCtl() {
if p.Getenv(envvars.VESPA_NO_NUMACTL) != "" {
return
}
- backticks := util.BackTicksIgnoreStderr
+ backticks := osutil.BackTicksIgnoreStderr
out, err := backticks.Run(NUMACTL_PROG, "--hardware")
trace.Debug("numactl --hardware says:", out)
if err != nil {
diff --git a/client/go/internal/admin/prog/run.go b/client/go/internal/admin/prog/run.go
index 7dafbad1446..31a88610697 100644
--- a/client/go/internal/admin/prog/run.go
+++ b/client/go/internal/admin/prog/run.go
@@ -5,7 +5,7 @@ package prog
import (
"github.com/vespa-engine/vespa/client/go/internal/admin/envvars"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
)
func (spec *Spec) Run() error {
@@ -22,5 +22,5 @@ func (spec *Spec) Run() error {
spec.Setenv(envvars.LD_PRELOAD, spec.vespaMallocPreload)
}
envv := spec.EffectiveEnv()
- return util.Execvpe(prog, args, envv)
+ return osutil.Execvpe(prog, args, envv)
}
diff --git a/client/go/internal/admin/prog/valgrind.go b/client/go/internal/admin/prog/valgrind.go
index 301146bd444..a8a41b95245 100644
--- a/client/go/internal/admin/prog/valgrind.go
+++ b/client/go/internal/admin/prog/valgrind.go
@@ -10,7 +10,7 @@ import (
"github.com/vespa-engine/vespa/client/go/internal/admin/envvars"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
)
@@ -23,7 +23,7 @@ func (p *Spec) ConfigureValgrind() {
p.shouldUseCallgrind = false
if p.MatchesListEnv(envvars.VESPA_USE_VALGRIND) {
trace.Trace("using valgrind as", p.Program, "has basename in", envvars.VESPA_USE_VALGRIND)
- backticks := util.BackTicksWithStderr
+ backticks := osutil.BackTicksWithStderr
out, err := backticks.Run(VALGRIND_PROG, "--help")
if err != nil {
trace.Trace("trial run of valgrind fails:", err, "=>", out)
diff --git a/client/go/internal/admin/prog/valgrind_test.go b/client/go/internal/admin/prog/valgrind_test.go
index 5bc9c1625fe..30dcca0c724 100644
--- a/client/go/internal/admin/prog/valgrind_test.go
+++ b/client/go/internal/admin/prog/valgrind_test.go
@@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
)
var tmpBin string
@@ -22,7 +22,7 @@ func useMock(prog, target string) {
os.Remove(symlink)
err := os.Symlink(mock, symlink)
if err != nil {
- util.JustExitWith(err)
+ osutil.ExitErr(err)
}
}
diff --git a/client/go/internal/admin/vespa-wrapper/configserver/check.go b/client/go/internal/admin/vespa-wrapper/configserver/check.go
index 73270271051..a9c1c09348e 100644
--- a/client/go/internal/admin/vespa-wrapper/configserver/check.go
+++ b/client/go/internal/admin/vespa-wrapper/configserver/check.go
@@ -8,7 +8,7 @@ import (
"github.com/vespa-engine/vespa/client/go/internal/admin/defaults"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
)
func checkIsConfigserver(myname string) {
@@ -20,5 +20,5 @@ func checkIsConfigserver(myname string) {
}
}
trace.Warning("only these hosts should run a config server:", onlyHosts)
- util.JustExitMsg(fmt.Sprintf("this host [%s] should not run a config server", myname))
+ osutil.ExitMsg(fmt.Sprintf("this host [%s] should not run a config server", myname))
}
diff --git a/client/go/internal/admin/vespa-wrapper/configserver/env.go b/client/go/internal/admin/vespa-wrapper/configserver/env.go
index 3b43fc269f8..b4dac91d275 100644
--- a/client/go/internal/admin/vespa-wrapper/configserver/env.go
+++ b/client/go/internal/admin/vespa-wrapper/configserver/env.go
@@ -8,7 +8,7 @@ import (
"os"
"github.com/vespa-engine/vespa/client/go/internal/admin/envvars"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
)
func exportSettings(vespaHome string) {
@@ -27,5 +27,5 @@ func exportSettings(vespaHome string) {
os.Setenv(envvars.STANDALONE_JDISC_APP_LOCATION, app)
os.Setenv(envvars.STANDALONE_JDISC_DEPLOYMENT_PROFILE, "configserver")
os.Setenv(envvars.MALLOC_ARENA_MAX, "1")
- util.OptionallyReduceTimerFrequency()
+ osutil.OptionallyReduceTimerFrequency()
}
diff --git a/client/go/internal/admin/vespa-wrapper/configserver/fix_dirs_and_files.go b/client/go/internal/admin/vespa-wrapper/configserver/fix_dirs_and_files.go
index 87f5f13d9d0..349366cb928 100644
--- a/client/go/internal/admin/vespa-wrapper/configserver/fix_dirs_and_files.go
+++ b/client/go/internal/admin/vespa-wrapper/configserver/fix_dirs_and_files.go
@@ -4,13 +4,13 @@
package configserver
import (
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
)
-func makeFixSpec() util.FixSpec {
+func makeFixSpec() osutil.FixSpec {
vespaUid, vespaGid := vespa.FindVespaUidAndGid()
- return util.FixSpec{
+ return osutil.FixSpec{
UserId: vespaUid,
GroupId: vespaGid,
DirMode: 0755,
@@ -18,7 +18,7 @@ func makeFixSpec() util.FixSpec {
}
}
-func fixDirsAndFiles(fixSpec util.FixSpec) {
+func fixDirsAndFiles(fixSpec osutil.FixSpec) {
fixSpec.FixDir("var/zookeeper")
fixSpec.FixDir("var/zookeeper/conf")
fixSpec.FixDir("var/zookeeper/version-2")
diff --git a/client/go/internal/admin/vespa-wrapper/configserver/logd.go b/client/go/internal/admin/vespa-wrapper/configserver/logd.go
index 99fc9aa622a..3d51ce317a2 100644
--- a/client/go/internal/admin/vespa-wrapper/configserver/logd.go
+++ b/client/go/internal/admin/vespa-wrapper/configserver/logd.go
@@ -8,12 +8,12 @@ import (
"github.com/vespa-engine/vespa/client/go/internal/admin/envvars"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
)
func maybeStartLogd() {
if os.Getenv(envvars.VESPA_CONFIGSERVER_MULTITENANT) == "true" {
- backticks := util.BackTicksForwardStderr
+ backticks := osutil.BackTicksForwardStderr
out, err := backticks.Run("libexec/vespa/start-logd")
if err != nil {
panic(err)
diff --git a/client/go/internal/admin/vespa-wrapper/configserver/runserver.go b/client/go/internal/admin/vespa-wrapper/configserver/runserver.go
index 25935c814e7..5fdaa5fa9b8 100644
--- a/client/go/internal/admin/vespa-wrapper/configserver/runserver.go
+++ b/client/go/internal/admin/vespa-wrapper/configserver/runserver.go
@@ -8,7 +8,9 @@ import (
"github.com/vespa-engine/vespa/client/go/internal/admin/defaults"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/ioutil"
+ "github.com/vespa-engine/vespa/client/go/internal/list"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
)
const (
@@ -27,25 +29,25 @@ func (rs *RunServer) PidFile() string {
func (rs *RunServer) ProgPath() string {
p := fmt.Sprintf("%s/bin64/%s", defaults.VespaHome(), PROG_NAME)
- if util.IsExecutableFile(p) {
+ if ioutil.IsExecutable(p) {
return p
}
p = fmt.Sprintf("%s/bin/%s", defaults.VespaHome(), PROG_NAME)
- if util.IsExecutableFile(p) {
+ if ioutil.IsExecutable(p) {
return p
}
panic(fmt.Errorf("not an executable file: %s", p))
}
func (rs *RunServer) WouldRun() bool {
- backticks := util.BackTicksForwardStderr
+ backticks := osutil.BackTicksForwardStderr
out, err := backticks.Run(rs.ProgPath(), "-s", rs.ServiceName, "-p", rs.PidFile(), "-W")
trace.Trace("output from -W:", out, "error:", err)
return err == nil
}
func (rs *RunServer) Exec(prog string) {
- argv := util.ArrayList[string]{
+ argv := list.ArrayList[string]{
PROG_NAME,
"-s", rs.ServiceName,
"-r", "30",
@@ -54,6 +56,6 @@ func (rs *RunServer) Exec(prog string) {
prog,
}
argv.AppendAll(rs.Args...)
- err := util.Execvp(rs.ProgPath(), argv)
- util.JustExitWith(err)
+ err := osutil.Execvp(rs.ProgPath(), argv)
+ osutil.ExitErr(err)
}
diff --git a/client/go/internal/admin/vespa-wrapper/configserver/start.go b/client/go/internal/admin/vespa-wrapper/configserver/start.go
index 91064b21849..452ea714100 100644
--- a/client/go/internal/admin/vespa-wrapper/configserver/start.go
+++ b/client/go/internal/admin/vespa-wrapper/configserver/start.go
@@ -9,7 +9,7 @@ import (
"github.com/vespa-engine/vespa/client/go/internal/admin/envvars"
"github.com/vespa-engine/vespa/client/go/internal/admin/jvm"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
)
@@ -37,7 +37,7 @@ func commonPreChecks() (veHome string) {
checkIsConfigserver(veHost)
e = os.Chdir(veHome)
if e != nil {
- util.JustExitWith(e)
+ osutil.ExitErr(e)
}
return
}
@@ -45,8 +45,8 @@ func commonPreChecks() (veHome string) {
func JustStartConfigserver() int {
vespaHome := commonPreChecks()
vespa.CheckCorrectUser()
- util.TuneResourceLimits()
- util.TuneLogging(SERVICE_NAME, "com.google.api.client.http.HttpTransport", "config=off")
+ osutil.TuneResourceLimits()
+ osutil.TuneLogging(SERVICE_NAME, "com.google.api.client.http.HttpTransport", "config=off")
exportSettings(vespaHome)
removeStaleZkLocks(vespaHome)
c := jvm.NewStandaloneContainer(SERVICE_NAME)
@@ -76,7 +76,7 @@ func runConfigserverWithRunserver() int {
func StartConfigserverEtc() int {
vespaHome := commonPreChecks()
vespa.RunPreStart()
- util.TuneResourceLimits()
+ osutil.TuneResourceLimits()
fixSpec := makeFixSpec()
fixDirsAndFiles(fixSpec)
exportSettings(vespaHome)
diff --git a/client/go/internal/admin/vespa-wrapper/configserver/zk.go b/client/go/internal/admin/vespa-wrapper/configserver/zk.go
index 2fee37f0662..c14c8fe8e29 100644
--- a/client/go/internal/admin/vespa-wrapper/configserver/zk.go
+++ b/client/go/internal/admin/vespa-wrapper/configserver/zk.go
@@ -7,7 +7,7 @@ import (
"fmt"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
)
const (
@@ -15,7 +15,7 @@ const (
)
func removeStaleZkLocks(vespaHome string) {
- backticks := util.BackTicksIgnoreStderr
+ backticks := osutil.BackTicksIgnoreStderr
cmd := fmt.Sprintf("rm -f '%s/%s'*lck", vespaHome, ZOOKEEPER_LOG_FILE_PREFIX)
trace.Trace("cleaning locks:", cmd)
backticks.Run("/bin/sh", "-c", cmd)
diff --git a/client/go/internal/admin/vespa-wrapper/main.go b/client/go/internal/admin/vespa-wrapper/main.go
index ad1eee52b63..32c5f909491 100644
--- a/client/go/internal/admin/vespa-wrapper/main.go
+++ b/client/go/internal/admin/vespa-wrapper/main.go
@@ -17,7 +17,7 @@ import (
"github.com/vespa-engine/vespa/client/go/internal/admin/vespa-wrapper/services"
"github.com/vespa-engine/vespa/client/go/internal/admin/vespa-wrapper/standalone"
"github.com/vespa-engine/vespa/client/go/internal/admin/vespa-wrapper/startcbinary"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
)
@@ -99,7 +99,7 @@ func main() {
func handleSimplePanic() {
if r := recover(); r != nil {
- if jee, ok := r.(*util.JustExitError); ok {
+ if jee, ok := r.(*osutil.ExitError); ok {
fmt.Fprintln(os.Stderr, jee)
os.Exit(1)
} else {
diff --git a/client/go/internal/admin/vespa-wrapper/services/configproxy.go b/client/go/internal/admin/vespa-wrapper/services/configproxy.go
index e92b05ccc1e..bed6e980cf4 100644
--- a/client/go/internal/admin/vespa-wrapper/services/configproxy.go
+++ b/client/go/internal/admin/vespa-wrapper/services/configproxy.go
@@ -15,7 +15,7 @@ import (
"github.com/vespa-engine/vespa/client/go/internal/admin/envvars"
"github.com/vespa-engine/vespa/client/go/internal/admin/jvm"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
)
@@ -30,9 +30,9 @@ func JustRunConfigproxy() int {
vespa.CheckCorrectUser()
configsources := defaults.VespaConfigserverRpcAddrs()
if len(configsources) < 1 {
- util.JustExitMsg("could not find any configservers")
+ osutil.ExitMsg("could not find any configservers")
}
- util.TuneResourceLimits()
+ osutil.TuneResourceLimits()
c := jvm.NewConfigProxyJvm(PROXY_SERVICE_NAME)
userargs := os.Getenv(envvars.VESPA_CONFIGPROXY_JVMARGS)
c.ConfigureOptions(configsources, userargs)
@@ -68,7 +68,7 @@ func startProxyWithRunserver() {
func waitForProxyResponse() bool {
hname, _ := vespa.FindOurHostname()
- backtick := util.BackTicksWithStderr
+ backtick := osutil.BackTicksWithStderr
start := time.Now()
fmt.Printf("Waiting for config proxy to start\n")
for sleepcount := 0; sleepcount < 1800; sleepcount++ {
@@ -135,7 +135,7 @@ func StartConfigproxy() int {
}
func stopProxyWithRunserver() {
- _, err := util.SystemCommand.Run("vespa-runserver",
+ _, err := osutil.SystemCommand.Run("vespa-runserver",
"-s", PROXY_SERVICE_NAME,
"-p", CONFIGPROXY_PIDFILE, "-S")
if err != nil {
diff --git a/client/go/internal/admin/vespa-wrapper/services/env.go b/client/go/internal/admin/vespa-wrapper/services/env.go
index 9a7ba40c73e..23cf80213d5 100644
--- a/client/go/internal/admin/vespa-wrapper/services/env.go
+++ b/client/go/internal/admin/vespa-wrapper/services/env.go
@@ -8,7 +8,7 @@ import (
"os"
"github.com/vespa-engine/vespa/client/go/internal/admin/envvars"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
)
func exportSettings(vespaHome string) {
@@ -21,5 +21,5 @@ func exportSettings(vespaHome string) {
os.Setenv(envvars.JAVAVM_LD_PRELOAD, "")
os.Setenv(envvars.LD_PRELOAD, "")
os.Setenv(envvars.MALLOC_ARENA_MAX, "1")
- util.OptionallyReduceTimerFrequency()
+ osutil.OptionallyReduceTimerFrequency()
}
diff --git a/client/go/internal/admin/vespa-wrapper/services/prechecks.go b/client/go/internal/admin/vespa-wrapper/services/prechecks.go
index bb6bf55e06b..93a53707ba2 100644
--- a/client/go/internal/admin/vespa-wrapper/services/prechecks.go
+++ b/client/go/internal/admin/vespa-wrapper/services/prechecks.go
@@ -8,7 +8,7 @@ import (
"github.com/vespa-engine/vespa/client/go/internal/admin/envvars"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
)
@@ -31,7 +31,7 @@ func commonPreChecks() (veHome, veHost string) {
}
err = os.Chdir(veHome)
if err != nil {
- util.JustExitWith(err)
+ osutil.ExitErr(err)
}
return
}
diff --git a/client/go/internal/admin/vespa-wrapper/services/sentinel.go b/client/go/internal/admin/vespa-wrapper/services/sentinel.go
index 7694c930731..e489bf70ded 100644
--- a/client/go/internal/admin/vespa-wrapper/services/sentinel.go
+++ b/client/go/internal/admin/vespa-wrapper/services/sentinel.go
@@ -13,7 +13,7 @@ import (
"github.com/vespa-engine/vespa/client/go/internal/admin/envvars"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
)
@@ -48,7 +48,7 @@ func startSentinelWithRunserver() {
}
func waitForSentinelPid() bool {
- backtick := util.BackTicksWithStderr
+ backtick := osutil.BackTicksWithStderr
start := time.Now()
for sleepcount := 0; sleepcount < 1000; sleepcount++ {
time.Sleep(10 * time.Millisecond)
@@ -84,7 +84,7 @@ func StartConfigSentinel() int {
}
func stopSentinelWithRunserver() {
- _, err := util.SystemCommand.Run("vespa-runserver",
+ _, err := osutil.SystemCommand.Run("vespa-runserver",
"-s", SENTINEL_SERVICE_NAME,
"-p", SENTINEL_PIDFILE, "-S")
if err != nil {
diff --git a/client/go/internal/admin/vespa-wrapper/services/start.go b/client/go/internal/admin/vespa-wrapper/services/start.go
index d2c2fb6f5ba..de658264669 100644
--- a/client/go/internal/admin/vespa-wrapper/services/start.go
+++ b/client/go/internal/admin/vespa-wrapper/services/start.go
@@ -10,7 +10,7 @@ import (
"github.com/vespa-engine/vespa/client/go/internal/admin/envvars"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
)
@@ -33,14 +33,14 @@ func StartServices() int {
}
func checkjava() {
- backticks := util.BackTicksWithStderr
+ backticks := osutil.BackTicksWithStderr
out, err := backticks.Run("java", "-version")
if err != nil {
trace.Warning("cannot run 'java -version'")
- util.JustExitWith(err)
+ osutil.ExitErr(err)
}
if !strings.Contains(out, "64-Bit Server VM") {
- util.JustExitWith(fmt.Errorf("java must invoke the 64-bit Java VM, but -version says:\n%s\n", out))
+ osutil.ExitErr(fmt.Errorf("java must invoke the 64-bit Java VM, but -version says:\n%s\n", out))
}
}
@@ -53,7 +53,7 @@ func VespaStartServices() int {
trace.Debug("common prechecks ok, running in", home, "on", host)
vespa.RunPreStart()
trace.Debug("prestart ok")
- util.TuneResourceLimits()
+ osutil.TuneResourceLimits()
increase_vm_max_map_count()
trace.Debug("resource limits ok")
checkjava()
@@ -64,7 +64,7 @@ func VespaStartServices() int {
drop_caches()
err := vespa.MaybeSwitchUser("start-services")
if err != nil {
- util.JustExitWith(err)
+ osutil.ExitErr(err)
}
return StartServices()
}
diff --git a/client/go/internal/admin/vespa-wrapper/services/stop.go b/client/go/internal/admin/vespa-wrapper/services/stop.go
index 54d557847ce..c4c4787c83a 100644
--- a/client/go/internal/admin/vespa-wrapper/services/stop.go
+++ b/client/go/internal/admin/vespa-wrapper/services/stop.go
@@ -8,7 +8,7 @@ import (
"github.com/vespa-engine/vespa/client/go/internal/admin/envvars"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
)
@@ -21,11 +21,11 @@ func VespaStopServices() int {
}
err := vespa.LoadDefaultEnv()
if err != nil {
- util.JustExitWith(err)
+ osutil.ExitErr(err)
}
err = vespa.MaybeSwitchUser("vespa-stop-services")
if err != nil {
- util.JustExitWith(err)
+ osutil.ExitErr(err)
}
vespa.CheckCorrectUser()
trace.Debug("running as correct user")
diff --git a/client/go/internal/admin/vespa-wrapper/standalone/start.go b/client/go/internal/admin/vespa-wrapper/standalone/start.go
index add29d37671..a3703ce930c 100644
--- a/client/go/internal/admin/vespa-wrapper/standalone/start.go
+++ b/client/go/internal/admin/vespa-wrapper/standalone/start.go
@@ -9,7 +9,7 @@ import (
"github.com/vespa-engine/vespa/client/go/internal/admin/jvm"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
)
@@ -23,20 +23,20 @@ func commonPreChecks() {
veHome := vespa.FindAndVerifyVespaHome()
err := os.Chdir(veHome)
if err != nil {
- util.JustExitWith(err)
+ osutil.ExitErr(err)
}
err = vespa.LoadDefaultEnv()
if err != nil {
- util.JustExitWith(err)
+ osutil.ExitErr(err)
}
}
func StartStandaloneContainer(extraArgs []string) int {
commonPreChecks()
- util.TuneResourceLimits()
+ osutil.TuneResourceLimits()
serviceName := os.Getenv("VESPA_SERVICE_NAME")
if serviceName == "" {
- util.JustExitMsg("Missing service name, ensure VESPA_SERVICE_NAME is set in the environment")
+ osutil.ExitMsg("Missing service name, ensure VESPA_SERVICE_NAME is set in the environment")
}
c := jvm.NewStandaloneContainer(serviceName)
jvmOpts := c.JvmOptions()
diff --git a/client/go/internal/admin/vespa-wrapper/startcbinary/cmd.go b/client/go/internal/admin/vespa-wrapper/startcbinary/cmd.go
index 8902aef80df..a35f0c5b820 100644
--- a/client/go/internal/admin/vespa-wrapper/startcbinary/cmd.go
+++ b/client/go/internal/admin/vespa-wrapper/startcbinary/cmd.go
@@ -9,7 +9,8 @@ import (
"github.com/vespa-engine/vespa/client/go/internal/admin/envvars"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/ioutil"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
)
@@ -22,7 +23,7 @@ func Run(args []string) int {
spec := NewProgSpec(args)
err := vespa.LoadDefaultEnv()
if err != nil {
- util.JustExitWith(err)
+ osutil.ExitErr(err)
}
hostname, err := vespa.FindOurHostname()
if err != nil {
@@ -34,12 +35,12 @@ func Run(args []string) int {
func IsCandidate(program string) bool {
binary := program + "-bin"
if strings.Contains(binary, "/") {
- return util.IsRegularFile(binary)
+ return ioutil.IsFile(binary)
} else {
path := strings.Split(os.Getenv(envvars.PATH), ":")
for _, dir := range path {
fn := dir + "/" + binary
- if util.IsRegularFile(fn) {
+ if ioutil.IsFile(fn) {
return true
}
}
diff --git a/client/go/internal/admin/vespa-wrapper/startcbinary/tuning.go b/client/go/internal/admin/vespa-wrapper/startcbinary/tuning.go
index 898e4558152..06c20021ff6 100644
--- a/client/go/internal/admin/vespa-wrapper/startcbinary/tuning.go
+++ b/client/go/internal/admin/vespa-wrapper/startcbinary/tuning.go
@@ -4,10 +4,10 @@
package startcbinary
import (
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
)
func configureTuning() {
- util.OptionallyReduceTimerFrequency()
- util.TuneResourceLimits()
+ osutil.OptionallyReduceTimerFrequency()
+ osutil.TuneResourceLimits()
}
diff --git a/client/go/internal/cli/auth/auth0/auth0.go b/client/go/internal/cli/auth/auth0/auth0.go
index 7fae6e78b61..9466e9865b5 100644
--- a/client/go/internal/cli/auth/auth0/auth0.go
+++ b/client/go/internal/cli/auth/auth0/auth0.go
@@ -14,7 +14,7 @@ import (
"time"
"github.com/vespa-engine/vespa/client/go/internal/cli/auth"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/httputil"
)
const (
@@ -31,7 +31,7 @@ type Credentials struct {
// Client is a client for the Auth0 service.
type Client struct {
- httpClient util.HTTPClient
+ httpClient httputil.Client
Authenticator *auth.Authenticator // TODO: Make this private
options Options
provider auth0Provider
@@ -80,7 +80,7 @@ func cancelOnInterrupt() context.Context {
// NewClient constructs a new Auth0 client, storing configuration in the given configPath. The client will be configured for
// use in the given Vespa system.
-func NewClient(httpClient util.HTTPClient, options Options) (*Client, error) {
+func NewClient(httpClient httputil.Client, options Options) (*Client, error) {
a := Client{}
a.httpClient = httpClient
a.options = options
diff --git a/client/go/internal/cli/auth/zts/zts.go b/client/go/internal/cli/auth/zts/zts.go
index b60aa363e70..1c31ba05dd3 100644
--- a/client/go/internal/cli/auth/zts/zts.go
+++ b/client/go/internal/cli/auth/zts/zts.go
@@ -11,7 +11,7 @@ import (
"sync"
"time"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/httputil"
)
const (
@@ -21,7 +21,7 @@ const (
// Client is a client for Athenz ZTS, an authentication token service.
type Client struct {
- client util.HTTPClient
+ client httputil.Client
tokenURL *url.URL
domain string
now func() time.Time
@@ -38,7 +38,7 @@ type Token struct {
func (t *Token) isExpired(now time.Time) bool { return t.ExpiresAt.Sub(now) < expirySlack }
// NewClient creates a new client for an Athenz ZTS service located at serviceURL.
-func NewClient(client util.HTTPClient, domain, serviceURL string) (*Client, error) {
+func NewClient(client httputil.Client, domain, serviceURL string) (*Client, error) {
tokenURL, err := url.Parse(serviceURL)
if err != nil {
return nil, err
diff --git a/client/go/internal/cli/cmd/api_key.go b/client/go/internal/cli/cmd/api_key.go
index 133c9db0d3b..d882c527516 100644
--- a/client/go/internal/cli/cmd/api_key.go
+++ b/client/go/internal/cli/cmd/api_key.go
@@ -10,7 +10,7 @@ import (
"github.com/fatih/color"
"github.com/spf13/cobra"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/ioutil"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
)
@@ -71,7 +71,7 @@ func doApiKey(cli *CLI, overwriteKey bool, args []string) error {
return err
}
apiKeyFile := cli.config.apiKeyPath(app.Tenant)
- if util.PathExists(apiKeyFile) && !overwriteKey {
+ if ioutil.Exists(apiKeyFile) && !overwriteKey {
err := fmt.Errorf("refusing to overwrite %s", apiKeyFile)
cli.printErr(err, "Use -f to overwrite it")
printPublicKey(system, apiKeyFile, app.Tenant)
diff --git a/client/go/internal/cli/cmd/cert.go b/client/go/internal/cli/cmd/cert.go
index 6aa99a01902..3e18fafb815 100644
--- a/client/go/internal/cli/cmd/cert.go
+++ b/client/go/internal/cli/cmd/cert.go
@@ -10,7 +10,7 @@ import (
"github.com/fatih/color"
"github.com/spf13/cobra"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/ioutil"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
)
@@ -122,10 +122,10 @@ func doCert(cli *CLI, overwriteCertificate, skipApplicationPackage bool, args []
if !overwriteCertificate {
hint := "Use -f flag to force overwriting"
- if util.PathExists(privateKeyFile.path) {
+ if ioutil.Exists(privateKeyFile.path) {
return errHint(fmt.Errorf("private key %s already exists", color.CyanString(privateKeyFile.path)), hint)
}
- if util.PathExists(certificateFile.path) {
+ if ioutil.Exists(certificateFile.path) {
return errHint(fmt.Errorf("certificate %s already exists", color.CyanString(certificateFile.path)), hint)
}
}
@@ -213,7 +213,7 @@ func copyCertificate(cli *CLI, target vespa.Target, pkg vespa.ApplicationPackage
if err := os.MkdirAll(filepath.Dir(dstPath), 0755); err != nil {
return fmt.Errorf("could not create security directory: %w", err)
}
- err = util.AtomicWriteFile(dstPath, data)
+ err = ioutil.AtomicWriteFile(dstPath, data)
if err == nil {
cli.printSuccess("Copied certificate from ", tlsOptions.CertificateFile, " to ", dstPath)
}
diff --git a/client/go/internal/cli/cmd/clone_list.go b/client/go/internal/cli/cmd/clone_list.go
index 40656841276..c6a99533c03 100644
--- a/client/go/internal/cli/cmd/clone_list.go
+++ b/client/go/internal/cli/cmd/clone_list.go
@@ -7,14 +7,14 @@ import (
"sort"
"time"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/httputil"
)
-func listSampleApps(client util.HTTPClient) ([]string, error) {
+func listSampleApps(client httputil.Client) ([]string, error) {
return listSampleAppsAt("https://api.github.com/repos/vespa-engine/sample-apps/contents/", client)
}
-func listSampleAppsAt(url string, client util.HTTPClient) ([]string, error) {
+func listSampleAppsAt(url string, client httputil.Client) ([]string, error) {
rfs, err := getRepositoryFiles(url, client)
if err != nil {
return nil, err
@@ -36,7 +36,7 @@ func listSampleAppsAt(url string, client util.HTTPClient) ([]string, error) {
return apps, nil
}
-func getRepositoryFiles(url string, client util.HTTPClient) ([]repositoryFile, error) {
+func getRepositoryFiles(url string, client httputil.Client) ([]repositoryFile, error) {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
diff --git a/client/go/internal/cli/cmd/clone_test.go b/client/go/internal/cli/cmd/clone_test.go
index 331845b3883..e783f75d9d4 100644
--- a/client/go/internal/cli/cmd/clone_test.go
+++ b/client/go/internal/cli/cmd/clone_test.go
@@ -13,8 +13,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
+ "github.com/vespa-engine/vespa/client/go/internal/ioutil"
"github.com/vespa-engine/vespa/client/go/internal/mock"
- "github.com/vespa-engine/vespa/client/go/internal/util"
)
func TestClone(t *testing.T) {
@@ -101,9 +101,9 @@ func TestClone(t *testing.T) {
func assertFiles(t *testing.T, app string) {
t.Helper()
- assert.True(t, util.PathExists(filepath.Join(app, "README.md")))
- assert.True(t, util.PathExists(filepath.Join(app, "src", "main", "application")))
- assert.True(t, util.IsDirectory(filepath.Join(app, "src", "main", "application")))
+ assert.True(t, ioutil.Exists(filepath.Join(app, "README.md")))
+ assert.True(t, ioutil.Exists(filepath.Join(app, "src", "main", "application")))
+ assert.True(t, ioutil.IsDir(filepath.Join(app, "src", "main", "application")))
servicesStat, err := os.Stat(filepath.Join(app, "src", "main", "application", "services.xml"))
require.Nil(t, err)
diff --git a/client/go/internal/cli/cmd/document.go b/client/go/internal/cli/cmd/document.go
index 6892956880b..0393a9b2595 100644
--- a/client/go/internal/cli/cmd/document.go
+++ b/client/go/internal/cli/cmd/document.go
@@ -15,7 +15,8 @@ import (
"github.com/fatih/color"
"github.com/spf13/cobra"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/httputil"
+ "github.com/vespa-engine/vespa/client/go/internal/ioutil"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
"github.com/vespa-engine/vespa/client/go/internal/vespa/document"
)
@@ -39,7 +40,7 @@ func documentClient(cli *CLI, timeoutSecs, waitSecs int, printCurl bool) (*docum
Timeout: time.Duration(timeoutSecs) * time.Second,
BaseURL: docService.BaseURL,
NowFunc: time.Now,
- }, []util.HTTPClient{docService})
+ }, []httputil.Client{docService})
if err != nil {
return nil, nil, err
}
@@ -103,22 +104,22 @@ func readDocument(id string, timeoutSecs, waitSecs int, printCurl bool, cli *CLI
return printResult(cli, operationResult(true, document.Document{Id: docId}, service, result), true)
}
-func operationResult(read bool, doc document.Document, service *vespa.Service, result document.Result) util.OperationResult {
+func operationResult(read bool, doc document.Document, service *vespa.Service, result document.Result) OperationResult {
if result.Err != nil {
- return util.Failure(result.Err.Error())
+ return Failure(result.Err.Error())
}
bodyReader := bytes.NewReader(result.Body)
if result.HTTPStatus == 200 {
if read {
- return util.SuccessWithPayload("Read "+doc.Id.String(), util.ReaderToJSON(bodyReader))
+ return SuccessWithPayload("Read "+doc.Id.String(), ioutil.ReaderToJSON(bodyReader))
} else {
- return util.Success(doc.Operation.String() + " " + doc.Id.String())
+ return Success(doc.Operation.String() + " " + doc.Id.String())
}
}
if result.HTTPStatus/100 == 4 {
- return util.FailureWithPayload("Invalid document operation: Status "+strconv.Itoa(result.HTTPStatus), util.ReaderToJSON(bodyReader))
+ return FailureWithPayload("Invalid document operation: Status "+strconv.Itoa(result.HTTPStatus), ioutil.ReaderToJSON(bodyReader))
}
- return util.FailureWithPayload(service.Description()+" at "+service.BaseURL+": Status "+strconv.Itoa(result.HTTPStatus), util.ReaderToJSON(bodyReader))
+ return FailureWithPayload(service.Description()+" at "+service.BaseURL+": Status "+strconv.Itoa(result.HTTPStatus), ioutil.ReaderToJSON(bodyReader))
}
func newDocumentCmd(cli *CLI) *cobra.Command {
@@ -269,7 +270,7 @@ func documentService(cli *CLI, waitSecs int) (*vespa.Service, error) {
return waiter.Service(target, cli.config.cluster())
}
-func printResult(cli *CLI, result util.OperationResult, payloadOnlyOnSuccess bool) error {
+func printResult(cli *CLI, result OperationResult, payloadOnlyOnSuccess bool) error {
out := cli.Stdout
if !result.Success {
out = cli.Stderr
diff --git a/client/go/internal/cli/cmd/document_test.go b/client/go/internal/cli/cmd/document_test.go
index 0b8d5a50615..3cfc66fdad4 100644
--- a/client/go/internal/cli/cmd/document_test.go
+++ b/client/go/internal/cli/cmd/document_test.go
@@ -12,8 +12,8 @@ import (
"testing"
"github.com/stretchr/testify/assert"
+ "github.com/vespa-engine/vespa/client/go/internal/ioutil"
"github.com/vespa-engine/vespa/client/go/internal/mock"
- "github.com/vespa-engine/vespa/client/go/internal/util"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
)
@@ -148,7 +148,7 @@ func assertDocumentSend(args []string, expectedOperation string, expectedMethod
Fields json.RawMessage `json:"fields"`
}
assert.Nil(t, json.Unmarshal(data, &expectedPayload))
- assert.Equal(t, `{"fields":`+string(expectedPayload.Fields)+"}", util.ReaderToString(client.LastRequest.Body))
+ assert.Equal(t, `{"fields":`+string(expectedPayload.Fields)+"}", ioutil.ReaderToString(client.LastRequest.Body))
} else {
assert.Nil(t, client.LastRequest.Body)
}
diff --git a/client/go/internal/cli/cmd/feed.go b/client/go/internal/cli/cmd/feed.go
index 89e13a4673c..69b847547a9 100644
--- a/client/go/internal/cli/cmd/feed.go
+++ b/client/go/internal/cli/cmd/feed.go
@@ -12,7 +12,7 @@ import (
"time"
"github.com/spf13/cobra"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/httputil"
"github.com/vespa-engine/vespa/client/go/internal/vespa/document"
)
@@ -124,7 +124,7 @@ $ cat docs.jsonl | vespa feed -`,
return cmd
}
-func createServices(n int, timeout time.Duration, waitSecs int, cli *CLI) ([]util.HTTPClient, string, error) {
+func createServices(n int, timeout time.Duration, waitSecs int, cli *CLI) ([]httputil.Client, string, error) {
if n < 1 {
return nil, "", fmt.Errorf("need at least one client")
}
@@ -132,7 +132,7 @@ func createServices(n int, timeout time.Duration, waitSecs int, cli *CLI) ([]uti
if err != nil {
return nil, "", err
}
- services := make([]util.HTTPClient, 0, n)
+ services := make([]httputil.Client, 0, n)
baseURL := ""
waiter := cli.waiter(time.Duration(waitSecs) * time.Second)
for i := 0; i < n; i++ {
@@ -144,7 +144,7 @@ func createServices(n int, timeout time.Duration, waitSecs int, cli *CLI) ([]uti
// Create a separate HTTP client for each service
client := cli.httpClientFactory(timeout)
// Feeding should always use HTTP/2
- util.ForceHTTP2(client, service.TLSOptions.KeyPair, service.TLSOptions.CACertificate, service.TLSOptions.TrustAll)
+ httputil.ForceHTTP2(client, service.TLSOptions.KeyPair, service.TLSOptions.CACertificate, service.TLSOptions.TrustAll)
service.SetClient(client)
services = append(services, service)
}
diff --git a/client/go/internal/cli/cmd/man_test.go b/client/go/internal/cli/cmd/man_test.go
index ad05efcb2a3..ae434624ac7 100644
--- a/client/go/internal/cli/cmd/man_test.go
+++ b/client/go/internal/cli/cmd/man_test.go
@@ -7,7 +7,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/ioutil"
)
func TestMan(t *testing.T) {
@@ -15,5 +15,5 @@ func TestMan(t *testing.T) {
cli, stdout, _ := newTestCLI(t)
assert.Nil(t, cli.Run("man", tmpDir))
assert.Equal(t, fmt.Sprintf("Success: Man pages written to %s\n", tmpDir), stdout.String())
- assert.True(t, util.PathExists(filepath.Join(tmpDir, "vespa.1")))
+ assert.True(t, ioutil.Exists(filepath.Join(tmpDir, "vespa.1")))
}
diff --git a/client/go/internal/cli/cmd/prod.go b/client/go/internal/cli/cmd/prod.go
index ddf2995126a..0912ca31e25 100644
--- a/client/go/internal/cli/cmd/prod.go
+++ b/client/go/internal/cli/cmd/prod.go
@@ -15,7 +15,7 @@ import (
"github.com/fatih/color"
"github.com/spf13/cobra"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/ioutil"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
"github.com/vespa-engine/vespa/client/go/internal/vespa/xml"
)
@@ -187,7 +187,7 @@ $ vespa prod deploy`,
func writeWithBackup(stdout io.Writer, pkg vespa.ApplicationPackage, filename, contents string) error {
dst := filepath.Join(pkg.Path, filename)
- if util.PathExists(dst) {
+ if ioutil.Exists(dst) {
data, err := os.ReadFile(dst)
if err != nil {
return err
@@ -199,7 +199,7 @@ func writeWithBackup(stdout io.Writer, pkg vespa.ApplicationPackage, filename, c
renamed := false
for i := 1; i <= 1000; i++ {
bak := fmt.Sprintf("%s.%d.bak", dst, i)
- if !util.PathExists(bak) {
+ if !ioutil.Exists(bak) {
fmt.Fprintf(stdout, "Backing up existing %s to %s\n", color.YellowString(filename), color.YellowString(bak))
if err := os.Rename(dst, bak); err != nil {
return err
diff --git a/client/go/internal/cli/cmd/prod_test.go b/client/go/internal/cli/cmd/prod_test.go
index 7f2836125d8..6d8a50124ac 100644
--- a/client/go/internal/cli/cmd/prod_test.go
+++ b/client/go/internal/cli/cmd/prod_test.go
@@ -10,8 +10,8 @@ import (
"testing"
"github.com/stretchr/testify/assert"
+ "github.com/vespa-engine/vespa/client/go/internal/ioutil"
"github.com/vespa-engine/vespa/client/go/internal/mock"
- "github.com/vespa-engine/vespa/client/go/internal/util"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
)
@@ -76,8 +76,8 @@ func TestProdInit(t *testing.T) {
assert.Contains(t, servicesXML, contentFragment)
// Backups are created
- assert.True(t, util.PathExists(deploymentPath+".1.bak"))
- assert.True(t, util.PathExists(servicesPath+".1.bak"))
+ assert.True(t, ioutil.Exists(deploymentPath+".1.bak"))
+ assert.True(t, ioutil.Exists(servicesPath+".1.bak"))
}
func readFileString(t *testing.T, filename string) string {
diff --git a/client/go/internal/cli/cmd/query.go b/client/go/internal/cli/cmd/query.go
index bf2272ca981..3e5a60a15df 100644
--- a/client/go/internal/cli/cmd/query.go
+++ b/client/go/internal/cli/cmd/query.go
@@ -16,7 +16,7 @@ import (
"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/vespa-engine/vespa/client/go/internal/curl"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/ioutil"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
)
@@ -98,11 +98,11 @@ func query(cli *CLI, arguments []string, timeoutSecs, waitSecs int, curl bool) e
defer response.Body.Close()
if response.StatusCode == 200 {
- log.Print(util.ReaderToJSON(response.Body))
+ log.Print(ioutil.ReaderToJSON(response.Body))
} else if response.StatusCode/100 == 4 {
- return fmt.Errorf("invalid query: %s\n%s", response.Status, util.ReaderToJSON(response.Body))
+ return fmt.Errorf("invalid query: %s\n%s", response.Status, ioutil.ReaderToJSON(response.Body))
} else {
- return fmt.Errorf("%s from container at %s\n%s", response.Status, color.CyanString(url.Host), util.ReaderToJSON(response.Body))
+ return fmt.Errorf("%s from container at %s\n%s", response.Status, color.CyanString(url.Host), ioutil.ReaderToJSON(response.Body))
}
return nil
}
diff --git a/client/go/internal/util/operation_result.go b/client/go/internal/cli/cmd/result.go
index 7dc60f92e1d..65b7ec4ca63 100644
--- a/client/go/internal/util/operation_result.go
+++ b/client/go/internal/cli/cmd/result.go
@@ -1,8 +1,4 @@
-// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-// A struct containing the result of an operation
-// Author: bratseth
-
-package util
+package cmd
type OperationResult struct {
Success bool
diff --git a/client/go/internal/cli/cmd/root.go b/client/go/internal/cli/cmd/root.go
index 1f324658b69..383ce7dd28d 100644
--- a/client/go/internal/cli/cmd/root.go
+++ b/client/go/internal/cli/cmd/root.go
@@ -12,6 +12,7 @@ import (
"strings"
"time"
+ "github.com/briandowns/spinner"
"github.com/fatih/color"
"github.com/mattn/go-colorable"
"github.com/mattn/go-isatty"
@@ -20,7 +21,7 @@ import (
"github.com/vespa-engine/vespa/client/go/internal/build"
"github.com/vespa-engine/vespa/client/go/internal/cli/auth/auth0"
"github.com/vespa-engine/vespa/client/go/internal/cli/auth/zts"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/httputil"
"github.com/vespa-engine/vespa/client/go/internal/version"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
)
@@ -58,8 +59,8 @@ type CLI struct {
config *Config
version version.Version
- httpClient util.HTTPClient
- httpClientFactory func(timeout time.Duration) util.HTTPClient
+ httpClient httputil.Client
+ httpClientFactory func(timeout time.Duration) httputil.Client
auth0Factory auth0Factory
ztsFactory ztsFactory
}
@@ -102,9 +103,33 @@ func (c *execSubprocess) Run(name string, args ...string) ([]byte, error) {
return exec.Command(name, args...).Output()
}
-type auth0Factory func(httpClient util.HTTPClient, options auth0.Options) (vespa.Authenticator, error)
+type auth0Factory func(httpClient httputil.Client, options auth0.Options) (vespa.Authenticator, error)
-type ztsFactory func(httpClient util.HTTPClient, domain, url string) (vespa.Authenticator, error)
+type ztsFactory func(httpClient httputil.Client, domain, url string) (vespa.Authenticator, error)
+
+// newSpinner writes message to writer w and executes function fn. While fn is running a spinning animation will be
+// displayed after message.
+func newSpinner(w io.Writer, message string, fn func() error) error {
+ s := spinner.New(spinner.CharSets[11], 100*time.Millisecond, spinner.WithWriter(w))
+ // Cursor is hidden by default. Hiding cursor requires Stop() to be called to restore cursor (i.e. if the process is
+ // interrupted), however we don't want to bother with a signal handler just for this
+ s.HideCursor = false
+ if err := s.Color("blue", "bold"); err != nil {
+ return err
+ }
+ if !strings.HasSuffix(message, " ") {
+ message += " "
+ }
+ s.Prefix = message
+ s.FinalMSG = "\r" + message + "done\n"
+ s.Start()
+ err := fn()
+ if err != nil {
+ s.FinalMSG = "\r" + message + "failed\n"
+ }
+ s.Stop()
+ return err
+}
// New creates the Vespa CLI, writing output to stdout and stderr, and reading environment variables from environment.
func New(stdout, stderr io.Writer, environment []string) (*CLI, error) {
@@ -136,7 +161,7 @@ For detailed description of flags and configuration, see 'vespa help config'.
if err != nil {
return nil, err
}
- httpClientFactory := util.CreateClient
+ httpClientFactory := httputil.NewClient
cli := CLI{
Environment: env,
Stdin: os.Stdin,
@@ -152,10 +177,10 @@ For detailed description of flags and configuration, see 'vespa help config'.
httpClient: httpClientFactory(time.Second * 10),
httpClientFactory: httpClientFactory,
- auth0Factory: func(httpClient util.HTTPClient, options auth0.Options) (vespa.Authenticator, error) {
+ auth0Factory: func(httpClient httputil.Client, options auth0.Options) (vespa.Authenticator, error) {
return auth0.NewClient(httpClient, options)
},
- ztsFactory: func(httpClient util.HTTPClient, domain, url string) (vespa.Authenticator, error) {
+ ztsFactory: func(httpClient httputil.Client, domain, url string) (vespa.Authenticator, error) {
return zts.NewClient(httpClient, domain, url)
},
}
@@ -239,7 +264,7 @@ func (c *CLI) configureSpinner() {
return fn()
}
} else {
- c.spinner = util.Spinner
+ c.spinner = newSpinner
}
}
diff --git a/client/go/internal/cli/cmd/test.go b/client/go/internal/cli/cmd/test.go
index 376611767d9..3bc78fc91c8 100644
--- a/client/go/internal/cli/cmd/test.go
+++ b/client/go/internal/cli/cmd/test.go
@@ -21,7 +21,8 @@ import (
"github.com/fatih/color"
"github.com/spf13/cobra"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/httputil"
+ "github.com/vespa-engine/vespa/client/go/internal/ioutil"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
)
@@ -277,7 +278,7 @@ func verify(step step, defaultCluster string, defaultParameters map[string]strin
var response *http.Response
if externalEndpoint {
- util.ConfigureTLS(context.cli.httpClient, []tls.Certificate{}, nil, false)
+ httputil.ConfigureTLS(context.cli.httpClient, []tls.Certificate{}, nil, false)
response, err = context.cli.httpClient.Do(request, 60*time.Second)
} else {
response, err = service.Do(request, 600*time.Second) // Vespa should provide a response within the given request timeout
@@ -294,7 +295,7 @@ func verify(step step, defaultCluster string, defaultParameters map[string]strin
color.RedString(strconv.Itoa(response.StatusCode)),
color.CyanString(method),
color.CyanString(requestUrl.String()),
- util.ReaderToJSON(response.Body)), nil
+ ioutil.ReaderToJSON(response.Body)), nil
}
if responseBodySpec == nil {
diff --git a/client/go/internal/cli/cmd/test_test.go b/client/go/internal/cli/cmd/test_test.go
index 1888db017d4..728e8c29691 100644
--- a/client/go/internal/cli/cmd/test_test.go
+++ b/client/go/internal/cli/cmd/test_test.go
@@ -15,8 +15,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
+ "github.com/vespa-engine/vespa/client/go/internal/ioutil"
"github.com/vespa-engine/vespa/client/go/internal/mock"
- "github.com/vespa-engine/vespa/client/go/internal/util"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
)
@@ -205,6 +205,6 @@ func assertRequests(requests []*http.Request, client *mock.HTTPClient, t *testin
if actualBody == nil {
actualBody = io.NopCloser(strings.NewReader(""))
}
- assert.Equal(t, util.ReaderToJSON(want.Body), util.ReaderToJSON(actualBody))
+ assert.Equal(t, ioutil.ReaderToJSON(want.Body), ioutil.ReaderToJSON(actualBody))
}
}
diff --git a/client/go/internal/cli/cmd/testutil_test.go b/client/go/internal/cli/cmd/testutil_test.go
index 89f40035f6a..dbeb281a4a8 100644
--- a/client/go/internal/cli/cmd/testutil_test.go
+++ b/client/go/internal/cli/cmd/testutil_test.go
@@ -11,8 +11,8 @@ import (
"time"
"github.com/vespa-engine/vespa/client/go/internal/cli/auth/auth0"
+ "github.com/vespa-engine/vespa/client/go/internal/httputil"
"github.com/vespa-engine/vespa/client/go/internal/mock"
- "github.com/vespa-engine/vespa/client/go/internal/util"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
)
@@ -31,13 +31,13 @@ func newTestCLI(t *testing.T, envVars ...string) (*CLI, *bytes.Buffer, *bytes.Bu
t.Fatal(err)
}
httpClient := &mock.HTTPClient{}
- cli.httpClientFactory = func(timeout time.Duration) util.HTTPClient { return httpClient }
+ cli.httpClientFactory = func(timeout time.Duration) httputil.Client { return httpClient }
cli.httpClient = httpClient
cli.exec = &mock.Exec{}
- cli.auth0Factory = func(httpClient util.HTTPClient, options auth0.Options) (vespa.Authenticator, error) {
+ cli.auth0Factory = func(httpClient httputil.Client, options auth0.Options) (vespa.Authenticator, error) {
return &mockAuthenticator{}, nil
}
- cli.ztsFactory = func(httpClient util.HTTPClient, domain, url string) (vespa.Authenticator, error) {
+ cli.ztsFactory = func(httpClient httputil.Client, domain, url string) (vespa.Authenticator, error) {
return &mockAuthenticator{}, nil
}
return cli, &stdout, &stderr
diff --git a/client/go/internal/cli/cmd/visit.go b/client/go/internal/cli/cmd/visit.go
index f6e2f64e534..963833337c2 100644
--- a/client/go/internal/cli/cmd/visit.go
+++ b/client/go/internal/cli/cmd/visit.go
@@ -16,7 +16,7 @@ import (
"time"
"github.com/spf13/cobra"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/ioutil"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
)
@@ -157,26 +157,26 @@ func getEpoch(timeStamp string) (int64, error) {
return t, nil
}
-func checkArguments(vArgs visitArgs) (res util.OperationResult) {
+func checkArguments(vArgs visitArgs) (res OperationResult) {
if vArgs.slices > 0 || vArgs.sliceId > -1 {
if !(vArgs.slices > 0 && vArgs.sliceId > -1) {
- return util.Failure("Both 'slices' and 'slice-id' must be set")
+ return Failure("Both 'slices' and 'slice-id' must be set")
}
if vArgs.sliceId >= vArgs.slices {
- return util.Failure("The 'slice-id' must be in range [0, slices)")
+ return Failure("The 'slice-id' must be in range [0, slices)")
}
}
// to and from will support RFC3339 format soon, add more validation then
if vArgs.from != "" {
_, err := getEpoch(vArgs.from)
if err != nil {
- return util.Failure("Invalid 'from' argument: '" + vArgs.from + "': " + err.Error())
+ return Failure("Invalid 'from' argument: '" + vArgs.from + "': " + err.Error())
}
}
if vArgs.to != "" {
_, err := getEpoch(vArgs.to)
if err != nil {
- return util.Failure("Invalid 'to' argument: '" + vArgs.to + "': " + err.Error())
+ return Failure("Invalid 'to' argument: '" + vArgs.to + "': " + err.Error())
}
}
for _, b := range vArgs.bucketSpaces {
@@ -186,10 +186,10 @@ func checkArguments(vArgs visitArgs) (res util.OperationResult) {
"global":
// Do nothing
default:
- return util.Failure("Invalid 'bucket-space' argument '" + b + "', must be 'default' or 'global'")
+ return Failure("Invalid 'bucket-space' argument '" + b + "', must be 'default' or 'global'")
}
}
- return util.Success("")
+ return Success("")
}
type HandlersInfo struct {
@@ -208,11 +208,11 @@ func parseHandlersOutput(r io.Reader) (*HandlersInfo, error) {
return &handlersInfo, err
}
-func probeHandler(service *vespa.Service, cli *CLI) (res util.OperationResult) {
+func probeHandler(service *vespa.Service, cli *CLI) (res OperationResult) {
urlPath := service.BaseURL + "/"
url, urlParseError := url.Parse(urlPath)
if urlParseError != nil {
- return util.Failure("Invalid request path: '" + urlPath + "': " + urlParseError.Error())
+ return Failure("Invalid request path: '" + urlPath + "': " + urlParseError.Error())
}
request := &http.Request{
URL: url,
@@ -221,20 +221,20 @@ func probeHandler(service *vespa.Service, cli *CLI) (res util.OperationResult) {
timeout := time.Duration(90) * time.Second
response, err := service.Do(request, timeout)
if err != nil {
- return util.Failure("Request failed: " + err.Error())
+ return Failure("Request failed: " + err.Error())
}
defer response.Body.Close()
if response.StatusCode == 200 {
handlersInfo, err := parseHandlersOutput(response.Body)
if err != nil || len(handlersInfo.Handlers) == 0 {
cli.printWarning("Could not parse JSON response from"+urlPath, err.Error())
- return util.Failure("Bad endpoint")
+ return Failure("Bad endpoint")
}
for _, h := range handlersInfo.Handlers {
if strings.HasSuffix(h.HandlerClass, "DocumentV1ApiHandler") {
for _, binding := range h.ServerBindings {
if strings.Contains(binding, "/document/v1/") {
- return util.Success("handler OK")
+ return Success("handler OK")
}
}
w := fmt.Sprintf("expected /document/v1/ binding, but got: %v", h.ServerBindings)
@@ -242,13 +242,13 @@ func probeHandler(service *vespa.Service, cli *CLI) (res util.OperationResult) {
}
}
cli.printWarning("Missing /document/v1/ API; add <document-api /> to the container cluster declaration in services.xml")
- return util.Failure("Missing /document/v1 API")
+ return Failure("Missing /document/v1 API")
} else {
- return util.FailureWithPayload(service.Description()+" at "+request.URL.Host+": "+response.Status, util.ReaderToJSON(response.Body))
+ return FailureWithPayload(service.Description()+" at "+request.URL.Host+": "+response.Status, ioutil.ReaderToJSON(response.Body))
}
}
-func visitClusters(vArgs *visitArgs, service *vespa.Service) (res util.OperationResult) {
+func visitClusters(vArgs *visitArgs, service *vespa.Service) (res OperationResult) {
clusters := []string{
vArgs.contentCluster,
}
@@ -294,7 +294,7 @@ func probeVisit(vArgs *visitArgs, service *vespa.Service) []string {
return clusters
}
-func runVisit(vArgs *visitArgs, service *vespa.Service) (res util.OperationResult) {
+func runVisit(vArgs *visitArgs, service *vespa.Service) (res OperationResult) {
vArgs.debugPrint(fmt.Sprintf("trying to visit: '%s'", vArgs.contentCluster))
var totalDocuments int = 0
var continuationToken string
@@ -340,7 +340,7 @@ func quoteArgForUrl(arg string) string {
return buf.String()
}
-func runOneVisit(vArgs *visitArgs, service *vespa.Service, contToken string) (*VespaVisitOutput, util.OperationResult) {
+func runOneVisit(vArgs *visitArgs, service *vespa.Service, contToken string) (*VespaVisitOutput, OperationResult) {
urlPath := service.BaseURL + "/document/v1/?cluster=" + quoteArgForUrl(vArgs.contentCluster)
if vArgs.fieldSet != "" {
urlPath = urlPath + "&fieldSet=" + quoteArgForUrl(vArgs.fieldSet)
@@ -370,7 +370,7 @@ func runOneVisit(vArgs *visitArgs, service *vespa.Service, contToken string) (*V
}
url, urlParseError := url.Parse(urlPath)
if urlParseError != nil {
- return nil, util.Failure("Invalid request path: '" + urlPath + "': " + urlParseError.Error())
+ return nil, Failure("Invalid request path: '" + urlPath + "': " + urlParseError.Error())
}
request := &http.Request{
URL: url,
@@ -379,7 +379,7 @@ func runOneVisit(vArgs *visitArgs, service *vespa.Service, contToken string) (*V
timeout := time.Duration(900) * time.Second
response, err := service.Do(request, timeout)
if err != nil {
- return nil, util.Failure("Request failed: " + err.Error())
+ return nil, Failure("Request failed: " + err.Error())
}
defer response.Body.Close()
vvo, err := parseVisitOutput(response.Body)
@@ -390,16 +390,16 @@ func runOneVisit(vArgs *visitArgs, service *vespa.Service, contToken string) (*V
vArgs.cli.printWarning(fmt.Sprintf("Inconsistent contents from: %v", url))
vArgs.cli.printWarning(fmt.Sprintf("claimed count: %d", vvo.DocumentCount))
vArgs.cli.printWarning(fmt.Sprintf("document blobs: %d", len(vvo.Documents)))
- return nil, util.Failure("Inconsistent contents from document API")
+ return nil, Failure("Inconsistent contents from document API")
}
- return vvo, util.Success("visited " + vArgs.contentCluster)
+ return vvo, Success("visited " + vArgs.contentCluster)
} else {
- return nil, util.Failure("error reading response: " + err.Error())
+ return nil, Failure("error reading response: " + err.Error())
}
} else if response.StatusCode/100 == 4 {
- return vvo, util.FailureWithPayload("Invalid document operation: "+response.Status, util.ReaderToJSON(response.Body))
+ return vvo, FailureWithPayload("Invalid document operation: "+response.Status, ioutil.ReaderToJSON(response.Body))
} else {
- return vvo, util.FailureWithPayload(service.Description()+" at "+request.URL.Host+": "+response.Status, util.ReaderToJSON(response.Body))
+ return vvo, FailureWithPayload(service.Description()+" at "+request.URL.Host+": "+response.Status, ioutil.ReaderToJSON(response.Body))
}
}
diff --git a/client/go/internal/util/http.go b/client/go/internal/httputil/httputil.go
index a7a9de5b8e4..e1e27de5523 100644
--- a/client/go/internal/util/http.go
+++ b/client/go/internal/httputil/httputil.go
@@ -1,5 +1,5 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package util
+package httputil
import (
"context"
@@ -14,15 +14,16 @@ import (
"golang.org/x/net/http2"
)
-type HTTPClient interface {
+// Client represents a HTTP client usable by the Vespa CLI.
+type Client interface {
Do(request *http.Request, timeout time.Duration) (response *http.Response, error error)
}
-type defaultHTTPClient struct {
+type defaultClient struct {
client *http.Client
}
-func (c *defaultHTTPClient) Do(request *http.Request, timeout time.Duration) (response *http.Response, error error) {
+func (c *defaultClient) Do(request *http.Request, timeout time.Duration) (response *http.Response, error error) {
if c.client.Timeout != timeout { // Set wanted timeout
c.client.Timeout = timeout
}
@@ -33,8 +34,10 @@ func (c *defaultHTTPClient) Do(request *http.Request, timeout time.Duration) (re
return c.client.Do(request)
}
-func ConfigureTLS(client HTTPClient, certificates []tls.Certificate, caCertificate []byte, trustAll bool) {
- c, ok := client.(*defaultHTTPClient)
+// ConfigureTLS configures the given client with given certificates and caCertificate. If trustAll is true, the client
+// will skip verification of the certificate chain.
+func ConfigureTLS(client Client, certificates []tls.Certificate, caCertificate []byte, trustAll bool) {
+ c, ok := client.(*defaultClient)
if !ok {
return
}
@@ -60,8 +63,10 @@ func ConfigureTLS(client HTTPClient, certificates []tls.Certificate, caCertifica
}
}
-func ForceHTTP2(client HTTPClient, certificates []tls.Certificate, caCertificate []byte, trustAll bool) {
- c, ok := client.(*defaultHTTPClient)
+// ForceHTTP2 configures the given client exclusively with a HTTP/2 transport. The other options are passed to
+// ConfigureTLS. If certificates is nil, the client will be configured with H2C (HTTP/2 over clear-text).
+func ForceHTTP2(client Client, certificates []tls.Certificate, caCertificate []byte, trustAll bool) {
+ c, ok := client.(*defaultClient)
if !ok {
return
}
@@ -85,8 +90,9 @@ func ForceHTTP2(client HTTPClient, certificates []tls.Certificate, caCertificate
ConfigureTLS(client, certificates, caCertificate, trustAll)
}
-func CreateClient(timeout time.Duration) HTTPClient {
- return &defaultHTTPClient{
+// NewClients creates a new HTTP client the given default timeout.
+func NewClient(timeout time.Duration) Client {
+ return &defaultClient{
client: &http.Client{
Timeout: timeout,
Transport: http.DefaultTransport,
diff --git a/client/go/internal/util/io.go b/client/go/internal/ioutil/ioutil.go
index 9e755737035..d3a33698d13 100644
--- a/client/go/internal/util/io.go
+++ b/client/go/internal/ioutil/ioutil.go
@@ -2,7 +2,7 @@
// File utilities.
// Author: bratseth
-package util
+package ioutil
import (
"bytes"
@@ -14,26 +14,26 @@ import (
"strings"
)
-// Returns true if the given path exists
-func PathExists(path string) bool {
+// Exists returns true if the given path exists.
+func Exists(path string) bool {
info, err := os.Stat(path)
return !errors.Is(err, os.ErrNotExist) && info != nil
}
-// Returns true if the given path points to an existing directory
-func IsDirectory(path string) bool {
+// IsDir returns true if the given path points to an existing directory.
+func IsDir(path string) bool {
info, err := os.Stat(path)
return !errors.Is(err, os.ErrNotExist) && info != nil && info.IsDir()
}
-// Returns true if the given path points to an existing file
-func IsRegularFile(path string) bool {
+// IsFile returns true if the given path points to an existing regular file.
+func IsFile(path string) bool {
info, err := os.Stat(path)
return !errors.Is(err, os.ErrNotExist) && info != nil && info.Mode().IsRegular()
}
-// Returns true if the given path points to an executable
-func IsExecutableFile(path string) bool {
+// IsExecutable returns true if the given path points to an executable file.
+func IsExecutable(path string) bool {
info, err := os.Stat(path)
return !errors.Is(err, os.ErrNotExist) &&
info != nil &&
@@ -41,21 +41,21 @@ func IsExecutableFile(path string) bool {
((int(info.Mode()) & 0111) == 0111)
}
-// Returns the content of a reader as a string
+// ReaderToString Returns the content of reader as a string. Read errors are ignored.
func ReaderToString(reader io.Reader) string {
var buffer strings.Builder
io.Copy(&buffer, reader)
return buffer.String()
}
-// Returns the content of a reader as a byte array
+// ReaderToBytes returns the content of a reader as a byte array. Read errors are ignored.
func ReaderToBytes(reader io.Reader) []byte {
var buffer bytes.Buffer
buffer.ReadFrom(reader)
return buffer.Bytes()
}
-// Returns the contents of reader as indented JSON
+// ReaderToJSON returns the contents of reader as indented JSON. Read errors are ignored.
func ReaderToJSON(reader io.Reader) string {
bodyBytes, _ := io.ReadAll(reader)
var prettyJSON bytes.Buffer
diff --git a/client/go/internal/util/io_test.go b/client/go/internal/ioutil/ioutil_test.go
index 0b2ad0f081b..907132c9eaa 100644
--- a/client/go/internal/util/io_test.go
+++ b/client/go/internal/ioutil/ioutil_test.go
@@ -1,5 +1,5 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package util
+package ioutil
import (
"os"
@@ -9,46 +9,46 @@ import (
)
func TestPathExists(t *testing.T) {
- assert.Equal(t, true, PathExists("io.go"))
- assert.Equal(t, false, PathExists("nosuchthing.go"))
+ assert.Equal(t, true, Exists("ioutil.go"))
+ assert.Equal(t, false, Exists("nosuchthing.go"))
tmpDir := t.TempDir()
err := os.MkdirAll(tmpDir+"/no", 0755)
assert.Nil(t, err)
err = os.MkdirAll(tmpDir+"/no/such", 0)
assert.Nil(t, err)
- assert.Equal(t, false, PathExists(tmpDir+"/no/such/thing.go"))
+ assert.Equal(t, false, Exists(tmpDir+"/no/such/thing.go"))
}
func TestIsDir(t *testing.T) {
tmpDir := t.TempDir()
err := os.MkdirAll(tmpDir+"/no", 0755)
assert.Nil(t, err)
- assert.Equal(t, true, IsDirectory(tmpDir+"/no"))
+ assert.Equal(t, true, IsDir(tmpDir+"/no"))
err = os.MkdirAll(tmpDir+"/no/such", 0)
assert.Nil(t, err)
- assert.Equal(t, true, IsDirectory(tmpDir+"/no/such"))
- assert.Equal(t, false, IsDirectory(tmpDir+"/no/such/thing.go"))
+ assert.Equal(t, true, IsDir(tmpDir+"/no/such"))
+ assert.Equal(t, false, IsDir(tmpDir+"/no/such/thing.go"))
}
func TestIsRegularFile(t *testing.T) {
- assert.Equal(t, true, IsRegularFile("io.go"))
- assert.Equal(t, false, IsRegularFile("."))
+ assert.Equal(t, true, IsFile("ioutil.go"))
+ assert.Equal(t, false, IsFile("."))
tmpDir := t.TempDir()
err := os.MkdirAll(tmpDir+"/no", 0755)
assert.Nil(t, err)
err = os.MkdirAll(tmpDir+"/no/such", 0)
assert.Nil(t, err)
- assert.Equal(t, false, IsRegularFile(tmpDir+"/no/such/thing.go"))
+ assert.Equal(t, false, IsFile(tmpDir+"/no/such/thing.go"))
}
func TestIsExecutableFile(t *testing.T) {
- assert.Equal(t, false, IsExecutableFile("io.go"))
- assert.Equal(t, false, IsExecutableFile("nosuchthing.go"))
+ assert.Equal(t, false, IsExecutable("io.go"))
+ assert.Equal(t, false, IsExecutable("nosuchthing.go"))
tmpDir := t.TempDir()
err := os.WriteFile(tmpDir+"/run.sh", []byte("#!/bin/sh\necho foo\n"), 0755)
assert.Nil(t, err)
- assert.Equal(t, true, IsExecutableFile(tmpDir+"/run.sh"))
+ assert.Equal(t, true, IsExecutable(tmpDir+"/run.sh"))
/* unix only:
out, err := BackTicksWithStderr.Run(tmpDir + "/run.sh")
assert.Nil(t, err)
diff --git a/client/go/internal/util/array_list.go b/client/go/internal/list/array_list.go
index 0e768b5617f..07427074089 100644
--- a/client/go/internal/util/array_list.go
+++ b/client/go/internal/list/array_list.go
@@ -1,8 +1,7 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
// Author: arnej
-// generic utilities
-package util
+package list
type ArrayList[E comparable] []E
diff --git a/client/go/internal/util/array_list_test.go b/client/go/internal/list/array_list_test.go
index d8a3fa88b5c..f31a94966c5 100644
--- a/client/go/internal/util/array_list_test.go
+++ b/client/go/internal/list/array_list_test.go
@@ -1,5 +1,6 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package util
+
+package list
import (
"testing"
diff --git a/client/go/internal/mock/http.go b/client/go/internal/mock/http.go
index c01811c4630..06e143ab80d 100644
--- a/client/go/internal/mock/http.go
+++ b/client/go/internal/mock/http.go
@@ -9,7 +9,7 @@ import (
"strconv"
"time"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/httputil"
)
type HTTPClient struct {
@@ -95,4 +95,4 @@ func (c *HTTPClient) Do(request *http.Request, timeout time.Duration) (*http.Res
nil
}
-func (c *HTTPClient) Clone() util.HTTPClient { return c }
+func (c *HTTPClient) Clone() httputil.Client { return c }
diff --git a/client/go/internal/util/execvp.go b/client/go/internal/osutil/execvp.go
index 38514696365..331b8166428 100644
--- a/client/go/internal/util/execvp.go
+++ b/client/go/internal/osutil/execvp.go
@@ -3,7 +3,7 @@
//go:build !windows
-package util
+package osutil
import (
"fmt"
@@ -12,6 +12,7 @@ import (
"github.com/vespa-engine/vespa/client/go/internal/admin/envvars"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
+ "github.com/vespa-engine/vespa/client/go/internal/ioutil"
"golang.org/x/sys/unix"
)
@@ -22,7 +23,7 @@ func findInPath(prog string) string {
path := strings.Split(os.Getenv(envvars.PATH), ":")
for _, dir := range path {
fn := dir + "/" + prog
- if IsExecutableFile(fn) {
+ if ioutil.IsExecutable(fn) {
return fn
}
}
diff --git a/client/go/internal/util/execvp_windows.go b/client/go/internal/osutil/execvp_windows.go
index d01eda589ff..0e8e7a4a673 100644
--- a/client/go/internal/util/execvp_windows.go
+++ b/client/go/internal/osutil/execvp_windows.go
@@ -3,7 +3,7 @@
//go:build windows
-package util
+package osutil
import (
"fmt"
diff --git a/client/go/internal/util/fix_fs.go b/client/go/internal/osutil/fix_fs.go
index 12d49462e07..837624cc05b 100644
--- a/client/go/internal/util/fix_fs.go
+++ b/client/go/internal/osutil/fix_fs.go
@@ -1,7 +1,7 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
// Author: arnej
-package util
+package osutil
import (
"errors"
@@ -149,5 +149,5 @@ func (spec *FixSpec) complainAndExit(got error, fn string, wanted os.FileMode) {
out, _ := BackTicksWithStderr.Run("stat", "--", fn)
trace.Warning(out)
trace.Warning("this is a fatal error!")
- JustExitWith(got)
+ ExitErr(got)
}
diff --git a/client/go/internal/util/fix_fs_test.go b/client/go/internal/osutil/fix_fs_test.go
index 0ecf2e06535..792986d7996 100644
--- a/client/go/internal/util/fix_fs_test.go
+++ b/client/go/internal/osutil/fix_fs_test.go
@@ -1,5 +1,5 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package util
+package osutil
import (
"os"
@@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
+ "github.com/vespa-engine/vespa/client/go/internal/ioutil"
)
func setup(t *testing.T) string {
@@ -36,15 +37,15 @@ func testFixSpec(t *testing.T, spec FixSpec) {
spec.FixFile(tmpDir + "/a/f3")
spec.FixFile(tmpDir + "/b/f4")
spec.FixFile(tmpDir + "/a/bad/f5")
- assert.Equal(t, true, IsDirectory(tmpDir+"/a"))
- assert.Equal(t, true, IsDirectory(tmpDir+"/b"))
- assert.Equal(t, true, IsDirectory(tmpDir+"/a/bad"))
- assert.Equal(t, true, IsDirectory(tmpDir+"/a/bad/ok"))
- assert.Equal(t, true, IsRegularFile(tmpDir+"/a/f1"))
- assert.Equal(t, true, IsRegularFile(tmpDir+"/a/f2"))
- assert.Equal(t, false, IsRegularFile(tmpDir+"/a/f3"))
- assert.Equal(t, false, IsRegularFile(tmpDir+"/b/f4"))
- assert.Equal(t, false, IsRegularFile(tmpDir+"/a/bad/f5"))
+ assert.Equal(t, true, ioutil.IsDir(tmpDir+"/a"))
+ assert.Equal(t, true, ioutil.IsDir(tmpDir+"/b"))
+ assert.Equal(t, true, ioutil.IsDir(tmpDir+"/a/bad"))
+ assert.Equal(t, true, ioutil.IsDir(tmpDir+"/a/bad/ok"))
+ assert.Equal(t, true, ioutil.IsFile(tmpDir+"/a/f1"))
+ assert.Equal(t, true, ioutil.IsFile(tmpDir+"/a/f2"))
+ assert.Equal(t, false, ioutil.IsFile(tmpDir+"/a/f3"))
+ assert.Equal(t, false, ioutil.IsFile(tmpDir+"/b/f4"))
+ assert.Equal(t, false, ioutil.IsFile(tmpDir+"/a/bad/f5"))
info, err := os.Stat(tmpDir + "/a")
assert.Nil(t, err)
@@ -118,7 +119,7 @@ func TestSuperUserOnly(t *testing.T) {
func expectSimplePanic() {
if r := recover(); r != nil {
- if jee, ok := r.(*JustExitError); ok {
+ if jee, ok := r.(*ExitError); ok {
trace.Trace("got as expected:", jee)
return
}
diff --git a/client/go/internal/util/just_exit.go b/client/go/internal/osutil/just_exit.go
index ad07f451c9c..5ad85ec9ceb 100644
--- a/client/go/internal/util/just_exit.go
+++ b/client/go/internal/osutil/just_exit.go
@@ -1,7 +1,7 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
// Author: arnej
-package util
+package osutil
import (
"fmt"
@@ -9,12 +9,12 @@ import (
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
)
-type JustExitError struct {
+type ExitError struct {
err error
msg string
}
-func (j *JustExitError) String() string {
+func (j *ExitError) String() string {
if j.err != nil {
if j.msg == "" {
return j.err.Error()
@@ -27,22 +27,22 @@ func (j *JustExitError) String() string {
return j.msg
}
-func (j *JustExitError) Error() string {
+func (j *ExitError) Error() string {
return j.String()
}
-func JustExitMsg(message string) {
+func ExitMsg(message string) {
trace.Trace("just exit with message")
- j := JustExitError{
+ j := ExitError{
err: nil,
msg: message,
}
panic(&j)
}
-func JustExitWith(e error) {
+func ExitErr(e error) {
trace.Trace("just exit with error")
- j := JustExitError{
+ j := ExitError{
err: e,
msg: "",
}
diff --git a/client/go/internal/util/run_cmd.go b/client/go/internal/osutil/run_cmd.go
index cc40f86154c..ca0d621f9f9 100644
--- a/client/go/internal/util/run_cmd.go
+++ b/client/go/internal/osutil/run_cmd.go
@@ -1,7 +1,7 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
// Author: arnej
-package util
+package osutil
import (
"bytes"
diff --git a/client/go/internal/util/setrlimit.go b/client/go/internal/osutil/setrlimit.go
index 1a96d260fcb..6bc6d68af3e 100644
--- a/client/go/internal/util/setrlimit.go
+++ b/client/go/internal/osutil/setrlimit.go
@@ -2,7 +2,7 @@
//go:build !windows
-package util
+package osutil
import (
"os"
diff --git a/client/go/internal/util/setrlimit_windows.go b/client/go/internal/osutil/setrlimit_windows.go
index f2993c7af13..e61233ba9e6 100644
--- a/client/go/internal/util/setrlimit_windows.go
+++ b/client/go/internal/osutil/setrlimit_windows.go
@@ -2,7 +2,7 @@
//go:build windows
-package util
+package osutil
type ResourceId int
diff --git a/client/go/internal/util/tune_logctl.go b/client/go/internal/osutil/tune_logctl.go
index b66c14c2d65..f68259170c7 100644
--- a/client/go/internal/util/tune_logctl.go
+++ b/client/go/internal/osutil/tune_logctl.go
@@ -1,7 +1,7 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
// Author: arnej
-package util
+package osutil
func TuneLogging(serviceName, component, settings string) bool {
arg := serviceName
diff --git a/client/go/internal/util/tuning.go b/client/go/internal/osutil/tuning.go
index cca314247ab..8e9b894e8ae 100644
--- a/client/go/internal/util/tuning.go
+++ b/client/go/internal/osutil/tuning.go
@@ -1,7 +1,7 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
// Author: arnej
-package util
+package osutil
import (
"os"
diff --git a/client/go/internal/util/md5.go b/client/go/internal/util/md5.go
deleted file mode 100644
index 6a98b49c472..00000000000
--- a/client/go/internal/util/md5.go
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-// Author: arnej
-
-package util
-
-import (
- "crypto/md5"
- "fmt"
- "io"
-)
-
-func Md5Hex(text string) string {
- hasher := md5.New()
- io.WriteString(hasher, text)
- hash := hasher.Sum(nil)
- return fmt.Sprintf("%x", hash)
-}
diff --git a/client/go/internal/util/spinner.go b/client/go/internal/util/spinner.go
deleted file mode 100644
index 323a5fffe12..00000000000
--- a/client/go/internal/util/spinner.go
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-package util
-
-import (
- "io"
- "strings"
- "time"
-
- "github.com/briandowns/spinner"
-)
-
-// Spinner writes message to writer w and executes function fn. While fn is running a spinning animation will be
-// displayed after message.
-func Spinner(w io.Writer, message string, fn func() error) error {
- s := spinner.New(spinner.CharSets[11], 100*time.Millisecond, spinner.WithWriter(w))
- // Cursor is hidden by default. Hiding cursor requires Stop() to be called to restore cursor (i.e. if the process is
- // interrupted), however we don't want to bother with a signal handler just for this
- s.HideCursor = false
- if err := s.Color("blue", "bold"); err != nil {
- return err
- }
- if !strings.HasSuffix(message, " ") {
- message += " "
- }
- s.Prefix = message
- s.FinalMSG = "\r" + message + "done\n"
- s.Start()
- err := fn()
- if err != nil {
- s.FinalMSG = "\r" + message + "failed\n"
- }
- s.Stop()
- return err
-}
diff --git a/client/go/internal/version/version.go b/client/go/internal/version/version.go
index 1b27d01ea83..513c808a582 100644
--- a/client/go/internal/version/version.go
+++ b/client/go/internal/version/version.go
@@ -5,8 +5,6 @@ import (
"fmt"
"strconv"
"strings"
-
- "github.com/vespa-engine/vespa/client/go/internal/util"
)
// Version represents a semantic version number.
@@ -74,7 +72,7 @@ func (v1 Version) Less(v2 Version) bool { return v1.Compare(v2) < 0 }
func MustParse(s string) Version {
v, err := Parse(s)
if err != nil {
- util.JustExitWith(err)
+ panic(err)
}
return v
}
diff --git a/client/go/internal/vespa/application.go b/client/go/internal/vespa/application.go
index 6d28b24100f..5d1ab610e38 100644
--- a/client/go/internal/vespa/application.go
+++ b/client/go/internal/vespa/application.go
@@ -10,7 +10,7 @@ import (
"path/filepath"
"strings"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/ioutil"
)
type ApplicationPackage struct {
@@ -24,7 +24,7 @@ func (ap *ApplicationPackage) HasDeploymentSpec() bool { return ap.hasFile("depl
func (ap *ApplicationPackage) hasFile(pathSegment ...string) bool {
if !ap.IsZip() {
- return util.PathExists(filepath.Join(append([]string{ap.Path}, pathSegment...)...))
+ return ioutil.Exists(filepath.Join(append([]string{ap.Path}, pathSegment...)...))
}
zipName := filepath.Join(pathSegment...)
return ap.hasZipEntry(func(name string) bool { return zipName == name })
@@ -50,7 +50,7 @@ func (ap *ApplicationPackage) IsJava() bool {
if ap.IsZip() {
return ap.hasZipEntry(func(name string) bool { return filepath.Ext(name) == ".jar" })
}
- return util.PathExists(filepath.Join(ap.Path, "pom.xml"))
+ return ioutil.Exists(filepath.Join(ap.Path, "pom.xml"))
}
func (ap *ApplicationPackage) Validate() error {
@@ -74,11 +74,11 @@ func (ap *ApplicationPackage) Validate() error {
func isZip(filename string) bool { return filepath.Ext(filename) == ".zip" }
func zipDir(dir string, destination string) error {
- if !util.PathExists(dir) {
+ if !ioutil.Exists(dir) {
message := "'" + dir + "' should be an application package zip or dir, but does not exist"
return errors.New(message)
}
- if !util.IsDirectory(dir) {
+ if !ioutil.IsDir(dir) {
message := "'" + dir + "' should be an application package dir, but is a (non-zip) file"
return errors.New(message)
}
@@ -267,10 +267,10 @@ func findApplicationPackage(zipOrDir string, options PackageOptions) (Applicatio
}
// Pre-packaged application. We prefer the uncompressed application because this allows us to add
// security/clients.pem to the package on-demand
- hasPOM := util.PathExists(filepath.Join(zipOrDir, "pom.xml"))
+ hasPOM := ioutil.Exists(filepath.Join(zipOrDir, "pom.xml"))
if hasPOM && !options.SourceOnly {
path := filepath.Join(zipOrDir, "target", "application")
- if util.PathExists(path) {
+ if ioutil.Exists(path) {
testPath := existingPath(filepath.Join(zipOrDir, "target", "application-test"))
return ApplicationPackage{Path: path, TestPath: testPath}, nil
}
@@ -279,14 +279,14 @@ func findApplicationPackage(zipOrDir string, options PackageOptions) (Applicatio
}
}
// Application with Maven directory structure, but with no POM or no hard requirement on packaging
- if path := filepath.Join(zipOrDir, "src", "main", "application"); util.PathExists(path) {
+ if path := filepath.Join(zipOrDir, "src", "main", "application"); ioutil.Exists(path) {
testPath := existingPath(filepath.Join(zipOrDir, "src", "test", "application"))
return ApplicationPackage{Path: path, TestPath: testPath}, nil
}
// Application without Java components
- if util.PathExists(filepath.Join(zipOrDir, "services.xml")) {
+ if ioutil.Exists(filepath.Join(zipOrDir, "services.xml")) {
testPath := ""
- if util.PathExists(filepath.Join(zipOrDir, "tests")) {
+ if ioutil.Exists(filepath.Join(zipOrDir, "tests")) {
testPath = zipOrDir
}
return ApplicationPackage{Path: zipOrDir, TestPath: testPath}, nil
@@ -295,7 +295,7 @@ func findApplicationPackage(zipOrDir string, options PackageOptions) (Applicatio
}
func existingPath(path string) string {
- if util.PathExists(path) {
+ if ioutil.Exists(path) {
return path
}
return ""
diff --git a/client/go/internal/vespa/crypto.go b/client/go/internal/vespa/crypto.go
index 13d3ac570cc..9b4d776d97d 100644
--- a/client/go/internal/vespa/crypto.go
+++ b/client/go/internal/vespa/crypto.go
@@ -20,7 +20,7 @@ import (
"strings"
"time"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/ioutil"
)
const (
@@ -36,18 +36,18 @@ type PemKeyPair struct {
// WriteCertificateFile writes the certificate contained in this key pair to certificateFile.
func (kp *PemKeyPair) WriteCertificateFile(certificateFile string, overwrite bool) error {
- if util.PathExists(certificateFile) && !overwrite {
+ if ioutil.Exists(certificateFile) && !overwrite {
return fmt.Errorf("cannot overwrite existing file: %s", certificateFile)
}
- return util.AtomicWriteFile(certificateFile, kp.Certificate)
+ return ioutil.AtomicWriteFile(certificateFile, kp.Certificate)
}
// WritePrivateKeyFile writes the private key contained in this key pair to privateKeyFile.
func (kp *PemKeyPair) WritePrivateKeyFile(privateKeyFile string, overwrite bool) error {
- if util.PathExists(privateKeyFile) && !overwrite {
+ if ioutil.Exists(privateKeyFile) && !overwrite {
return fmt.Errorf("cannot overwrite existing file: %s", privateKeyFile)
}
- return util.AtomicWriteFile(privateKeyFile, kp.PrivateKey)
+ return ioutil.AtomicWriteFile(privateKeyFile, kp.PrivateKey)
}
// CreateKeyPair creates a key pair containing a private key and self-signed X509 certificate.
diff --git a/client/go/internal/vespa/deploy.go b/client/go/internal/vespa/deploy.go
index 35fd523f15a..10ddb321e19 100644
--- a/client/go/internal/vespa/deploy.go
+++ b/client/go/internal/vespa/deploy.go
@@ -18,7 +18,7 @@ import (
"strings"
"time"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/ioutil"
"github.com/vespa-engine/vespa/client/go/internal/version"
)
@@ -120,10 +120,10 @@ func ZoneFromString(s string) (ZoneID, error) {
}
func Fetch(deployment DeploymentOptions, path string) (string, error) {
- if util.IsDirectory(path) {
+ if ioutil.IsDir(path) {
path = filepath.Join(path, "application.zip")
}
- if util.PathExists(path) {
+ if ioutil.Exists(path) {
return "", fmt.Errorf("%s already exists", path)
}
if deployment.Target.IsCloud() {
@@ -540,7 +540,7 @@ func checkResponse(req *http.Request, response *http.Response) error {
if response.StatusCode/100 == 4 {
return fmt.Errorf("invalid application package (%s)\n%s", response.Status, extractError(response.Body))
} else if response.StatusCode != 200 {
- return fmt.Errorf("error from deploy API at %s (%s):\n%s", req.URL.Host, response.Status, util.ReaderToJSON(response.Body))
+ return fmt.Errorf("error from deploy API at %s (%s):\n%s", req.URL.Host, response.Status, ioutil.ReaderToJSON(response.Body))
}
return nil
}
diff --git a/client/go/internal/vespa/deploy_test.go b/client/go/internal/vespa/deploy_test.go
index 516a21e7786..4c2fb912224 100644
--- a/client/go/internal/vespa/deploy_test.go
+++ b/client/go/internal/vespa/deploy_test.go
@@ -14,8 +14,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
+ "github.com/vespa-engine/vespa/client/go/internal/ioutil"
"github.com/vespa-engine/vespa/client/go/internal/mock"
- "github.com/vespa-engine/vespa/client/go/internal/util"
"github.com/vespa-engine/vespa/client/go/internal/version"
)
@@ -235,7 +235,7 @@ func TestFetch(t *testing.T) {
dir := t.TempDir()
dst, err := Fetch(opts, dir)
require.Nil(t, err)
- assert.True(t, util.PathExists(dst))
+ assert.True(t, ioutil.Exists(dst))
f, err := os.Open(dst)
require.Nil(t, err)
@@ -264,7 +264,7 @@ func TestFetchCloud(t *testing.T) {
dir := t.TempDir()
dst, err := Fetch(opts, dir)
require.Nil(t, err)
- assert.True(t, util.PathExists(dst))
+ assert.True(t, ioutil.Exists(dst))
}
type pkgFixture struct {
diff --git a/client/go/internal/vespa/detect_hostname.go b/client/go/internal/vespa/detect_hostname.go
index e6b2d113ec1..062d83d66a4 100644
--- a/client/go/internal/vespa/detect_hostname.go
+++ b/client/go/internal/vespa/detect_hostname.go
@@ -11,7 +11,7 @@ import (
"github.com/vespa-engine/vespa/client/go/internal/admin/envvars"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
)
// detect if this host is IPv6-only, in which case we want to pass
@@ -109,7 +109,7 @@ func findOurHostnameFrom(name string) (string, error) {
if good {
return trimmed, nil
}
- backticks := util.BackTicksIgnoreStderr
+ backticks := osutil.BackTicksIgnoreStderr
out, err := backticks.Run("vespa-detect-hostname")
if err != nil {
out, err = backticks.Run("hostname", "-f")
diff --git a/client/go/internal/vespa/document/http.go b/client/go/internal/vespa/document/http.go
index f878938d6fc..3871ab19edd 100644
--- a/client/go/internal/vespa/document/http.go
+++ b/client/go/internal/vespa/document/http.go
@@ -18,7 +18,7 @@ import (
"github.com/go-json-experiment/json"
"github.com/klauspost/compress/gzip"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/httputil"
)
type Compression int
@@ -52,7 +52,7 @@ type ClientOptions struct {
}
type countingHTTPClient struct {
- client util.HTTPClient
+ client httputil.Client
inflight atomic.Int64
}
@@ -70,7 +70,7 @@ type pendingDocument struct {
err error
}
-func NewClient(options ClientOptions, httpClients []util.HTTPClient) (*Client, error) {
+func NewClient(options ClientOptions, httpClients []httputil.Client) (*Client, error) {
if len(httpClients) < 1 {
return nil, fmt.Errorf("need at least one HTTP client")
}
diff --git a/client/go/internal/vespa/document/http_test.go b/client/go/internal/vespa/document/http_test.go
index b2c1139f95f..89e9e96064b 100644
--- a/client/go/internal/vespa/document/http_test.go
+++ b/client/go/internal/vespa/document/http_test.go
@@ -10,8 +10,8 @@ import (
"testing"
"time"
+ "github.com/vespa-engine/vespa/client/go/internal/httputil"
"github.com/vespa-engine/vespa/client/go/internal/mock"
- "github.com/vespa-engine/vespa/client/go/internal/util"
)
type manualClock struct {
@@ -33,7 +33,7 @@ type mockHTTPClient struct {
func TestLeastBusyClient(t *testing.T) {
httpClient := mock.HTTPClient{}
- var httpClients []util.HTTPClient
+ var httpClients []httputil.Client
for i := 0; i < 4; i++ {
httpClients = append(httpClients, &mockHTTPClient{i, &httpClient})
}
@@ -83,7 +83,7 @@ func TestClientSend(t *testing.T) {
client, _ := NewClient(ClientOptions{
BaseURL: "https://example.com:1337",
Timeout: time.Duration(5 * time.Second),
- }, []util.HTTPClient{&httpClient})
+ }, []httputil.Client{&httpClient})
clock := manualClock{t: time.Now(), tick: time.Second}
client.now = clock.now
var stats Stats
@@ -164,7 +164,7 @@ func TestClientGet(t *testing.T) {
client, _ := NewClient(ClientOptions{
BaseURL: "https://example.com:1337",
Timeout: time.Duration(5 * time.Second),
- }, []util.HTTPClient{&httpClient})
+ }, []httputil.Client{&httpClient})
clock := manualClock{t: time.Now(), tick: time.Second}
client.now = clock.now
doc := `{
@@ -196,7 +196,7 @@ func TestClientSendCompressed(t *testing.T) {
client, _ := NewClient(ClientOptions{
BaseURL: "https://example.com:1337",
Timeout: time.Duration(5 * time.Second),
- }, []util.HTTPClient{httpClient})
+ }, []httputil.Client{httpClient})
bigBody := fmt.Sprintf(`{"fields": {"foo": "%s"}}`, strings.Repeat("s", 512+1))
bigDoc := Document{Create: true, Id: mustParseId("id:ns:type::doc1"), Operation: OperationUpdate, Body: []byte(bigBody)}
@@ -313,7 +313,7 @@ func TestClientMethodAndURL(t *testing.T) {
httpClient := mock.HTTPClient{}
client, _ := NewClient(ClientOptions{
BaseURL: "https://example.com/",
- }, []util.HTTPClient{&httpClient})
+ }, []httputil.Client{&httpClient})
for i, tt := range tests {
client.options.Timeout = tt.options.Timeout
client.options.Route = tt.options.Route
@@ -333,7 +333,7 @@ func benchmarkClientSend(b *testing.B, compression Compression, document Documen
Compression: compression,
BaseURL: "https://example.com:1337",
Timeout: time.Duration(5 * time.Second),
- }, []util.HTTPClient{&httpClient})
+ }, []httputil.Client{&httpClient})
b.ResetTimer() // ignore setup
for n := 0; n < b.N; n++ {
client.Send(document)
diff --git a/client/go/internal/vespa/find_home.go b/client/go/internal/vespa/find_home.go
index 46dcdedd71c..3545ce6a8c7 100644
--- a/client/go/internal/vespa/find_home.go
+++ b/client/go/internal/vespa/find_home.go
@@ -11,7 +11,8 @@ import (
"github.com/vespa-engine/vespa/client/go/internal/admin/envvars"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/ioutil"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
)
const (
@@ -46,7 +47,7 @@ func FindHome() string {
}
for _, dir := range strings.Split(os.Getenv(envvars.PATH), ":") {
fn := fmt.Sprintf("%s/%s", dir, myProgName)
- if util.IsRegularFile(fn) {
+ if ioutil.IsFile(fn) {
trace.Debug("findPath", myProgName, "=>", dir)
return dir
}
@@ -56,7 +57,7 @@ func FindHome() string {
// detect path from argv[0]
for path := findPath(); path != ""; path = dirName(path) {
mySelf := fmt.Sprintf("%s/%s", path, scriptUtilsFilename)
- if util.IsRegularFile(mySelf) {
+ if ioutil.IsFile(mySelf) {
trace.Debug("found", mySelf, "VH =>", path)
os.Setenv(envvars.VESPA_HOME, path)
return path
@@ -82,9 +83,9 @@ func HasFileUnderVespaHome(fn string) (bool, string) {
func FindAndVerifyVespaHome() string {
vespaHome := FindHome()
myself := fmt.Sprintf("%s/%s", vespaHome, scriptUtilsFilename)
- if !util.IsExecutableFile(myself) {
+ if !ioutil.IsExecutable(myself) {
trace.Warning("missing or bad file:", myself)
- util.JustExitMsg("Not a valid VESPA_HOME: " + vespaHome)
+ osutil.ExitMsg("Not a valid VESPA_HOME: " + vespaHome)
}
return vespaHome
}
diff --git a/client/go/internal/vespa/load_env.go b/client/go/internal/vespa/load_env.go
index 24e1b1cdefa..a799cbf4f9a 100644
--- a/client/go/internal/vespa/load_env.go
+++ b/client/go/internal/vespa/load_env.go
@@ -14,7 +14,8 @@ import (
"github.com/vespa-engine/vespa/client/go/internal/admin/envvars"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/ioutil"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
)
const (
@@ -248,7 +249,7 @@ func shellQuote(s string) string {
}
if i != l {
err := fmt.Errorf("expected length %d but was %d", l, i)
- util.JustExitWith(err)
+ osutil.ExitErr(err)
}
return string(res)
}
@@ -276,7 +277,7 @@ func (builder *pathBuilder) applyTo(receiver loadEnvReceiver) {
}
func (builder *pathBuilder) appendPath(p string) {
- if !util.IsDirectory(p) {
+ if !ioutil.IsDir(p) {
return
}
for _, elem := range builder.curPath {
diff --git a/client/go/internal/vespa/prestart.go b/client/go/internal/vespa/prestart.go
index 5b29915bcb2..e6932e951ad 100644
--- a/client/go/internal/vespa/prestart.go
+++ b/client/go/internal/vespa/prestart.go
@@ -8,7 +8,7 @@ import (
"os"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
)
func RunPreStart() error {
@@ -23,7 +23,7 @@ func RunPreStart() error {
return err
}
vespaUid, vespaGid := FindVespaUidAndGid()
- fixSpec := util.FixSpec{
+ fixSpec := osutil.FixSpec{
UserId: vespaUid,
GroupId: vespaGid,
DirMode: 0755,
@@ -57,7 +57,7 @@ func RunPreStart() error {
// fix wrong ownerships within directories:
var fixer fs.WalkDirFunc = func(path string, d fs.DirEntry, err error) error {
if err != nil {
- util.JustExitWith(err)
+ osutil.ExitErr(err)
}
if d.IsDir() {
fixSpec.FixDir(path)
diff --git a/client/go/internal/vespa/switch_user.go b/client/go/internal/vespa/switch_user.go
index c84da567224..bce59b96f32 100644
--- a/client/go/internal/vespa/switch_user.go
+++ b/client/go/internal/vespa/switch_user.go
@@ -11,7 +11,7 @@ import (
"github.com/vespa-engine/vespa/client/go/internal/admin/envvars"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/osutil"
)
const ENV_CHECK = envvars.VESPA_ALREADY_SWITCHED_USER_TO
@@ -55,7 +55,7 @@ func CheckCorrectUser() {
if err2 != nil {
trace.Warning("note: user.Lookup(", vespaUser, ") failed:", err2)
}
- util.JustExitMsg("running as wrong user. Check your VESPA_USER setting")
+ osutil.ExitMsg("running as wrong user. Check your VESPA_USER setting")
}
// re-execute a vespa-wrapper action after switching to the vespa user
@@ -87,7 +87,7 @@ func MaybeSwitchUser(action string) error {
mySelf := fmt.Sprintf("%s/%s", vespaHome, scriptUtilsFilename)
os.Setenv(ENV_CHECK, wantUser.Username)
args := []string{SU_PROG, mySelf, action}
- return util.Execvp(SU_PROG, args)
+ return osutil.Execvp(SU_PROG, args)
}
return nil
}
diff --git a/client/go/internal/vespa/target.go b/client/go/internal/vespa/target.go
index 3a76eac0292..543ce2f4a29 100644
--- a/client/go/internal/vespa/target.go
+++ b/client/go/internal/vespa/target.go
@@ -12,7 +12,7 @@ import (
"time"
"github.com/vespa-engine/vespa/client/go/internal/curl"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/httputil"
"github.com/vespa-engine/vespa/client/go/internal/version"
)
@@ -84,7 +84,7 @@ type Service struct {
deployAPI bool
auth Authenticator
- httpClient util.HTTPClient
+ httpClient httputil.Client
customClient bool
retryInterval time.Duration
}
@@ -143,7 +143,7 @@ type LogOptions struct {
func (s *Service) Do(request *http.Request, timeout time.Duration) (*http.Response, error) {
if !s.customClient {
// Do not override TLS config if a custom client has been configured
- util.ConfigureTLS(s.httpClient, s.TLSOptions.KeyPair, s.TLSOptions.CACertificate, s.TLSOptions.TrustAll)
+ httputil.ConfigureTLS(s.httpClient, s.TLSOptions.KeyPair, s.TLSOptions.CACertificate, s.TLSOptions.TrustAll)
}
if s.auth != nil {
if err := s.auth.Authenticate(request); err != nil {
@@ -157,7 +157,7 @@ func (s *Service) Do(request *http.Request, timeout time.Duration) (*http.Respon
}
// SetClient sets a custom HTTP client that this service should use.
-func (s *Service) SetClient(client util.HTTPClient) {
+func (s *Service) SetClient(client httputil.Client) {
s.httpClient = client
s.customClient = true
}
diff --git a/client/go/internal/vespa/target_cloud.go b/client/go/internal/vespa/target_cloud.go
index 708810061d2..c063b99edef 100644
--- a/client/go/internal/vespa/target_cloud.go
+++ b/client/go/internal/vespa/target_cloud.go
@@ -12,7 +12,7 @@ import (
"strconv"
"time"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/httputil"
"github.com/vespa-engine/vespa/client/go/internal/version"
)
@@ -35,7 +35,7 @@ type cloudTarget struct {
apiOptions APIOptions
deploymentOptions CloudDeploymentOptions
logOptions LogOptions
- httpClient util.HTTPClient
+ httpClient httputil.Client
apiAuth Authenticator
deploymentAuth Authenticator
retryInterval time.Duration
@@ -74,7 +74,7 @@ type logMessage struct {
}
// CloudTarget creates a Target for the Vespa Cloud or hosted Vespa platform.
-func CloudTarget(httpClient util.HTTPClient, apiAuth Authenticator, deploymentAuth Authenticator,
+func CloudTarget(httpClient httputil.Client, apiAuth Authenticator, deploymentAuth Authenticator,
apiOptions APIOptions, deploymentOptions CloudDeploymentOptions,
logOptions LogOptions, retryInterval time.Duration) (Target, error) {
return &cloudTarget{
diff --git a/client/go/internal/vespa/target_custom.go b/client/go/internal/vespa/target_custom.go
index 0f3817e8c13..9d62f7dc297 100644
--- a/client/go/internal/vespa/target_custom.go
+++ b/client/go/internal/vespa/target_custom.go
@@ -11,14 +11,14 @@ import (
"strconv"
"time"
- "github.com/vespa-engine/vespa/client/go/internal/util"
+ "github.com/vespa-engine/vespa/client/go/internal/httputil"
"github.com/vespa-engine/vespa/client/go/internal/version"
)
type customTarget struct {
targetType string
baseURL string
- httpClient util.HTTPClient
+ httpClient httputil.Client
tlsOptions TLSOptions
retryInterval time.Duration
}
@@ -36,7 +36,7 @@ type serviceInfo struct {
}
// LocalTarget creates a target for a Vespa platform running locally.
-func LocalTarget(httpClient util.HTTPClient, tlsOptions TLSOptions, retryInterval time.Duration) Target {
+func LocalTarget(httpClient httputil.Client, tlsOptions TLSOptions, retryInterval time.Duration) Target {
return &customTarget{
targetType: TargetLocal,
baseURL: "http://127.0.0.1",
@@ -47,7 +47,7 @@ func LocalTarget(httpClient util.HTTPClient, tlsOptions TLSOptions, retryInterva
}
// CustomTarget creates a Target for a Vespa platform running at baseURL.
-func CustomTarget(httpClient util.HTTPClient, baseURL string, tlsOptions TLSOptions, retryInterval time.Duration) Target {
+func CustomTarget(httpClient httputil.Client, baseURL string, tlsOptions TLSOptions, retryInterval time.Duration) Target {
return &customTarget{
targetType: TargetCustom,
baseURL: baseURL,
diff --git a/client/go/internal/vespa/xml/config.go b/client/go/internal/vespa/xml/config.go
index 05d73474ffc..d1c16b01652 100644
--- a/client/go/internal/vespa/xml/config.go
+++ b/client/go/internal/vespa/xml/config.go
@@ -11,7 +11,6 @@ import (
"strconv"
"strings"
- "github.com/vespa-engine/vespa/client/go/internal/util"
"github.com/vespa-engine/vespa/client/go/internal/vespa"
)
@@ -25,7 +24,7 @@ func init() {
</deployment>`
d, err := ReadDeployment(strings.NewReader(defaultDeploymentRaw))
if err != nil {
- util.JustExitWith(err)
+ panic(err)
}
DefaultDeployment = d
}