1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
// vespa-deploy command
// Author: arnej
package deploy
import (
"fmt"
"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/vespa"
)
func makeConfigsourceUrl(opts *Options) string {
src := makeConfigsourceUrls(opts)[0]
if opts.Command == CmdPrepare || opts.Command == CmdActivate {
if lastUsed := getConfigsourceUrlUsed(); lastUsed != "" {
return lastUsed
}
fmt.Printf("Could not read config server URL used for previous upload of an application package, trying to use %s\n", src)
}
return src
}
func makeConfigsourceUrls(opts *Options) []string {
var results = make([]string, 0, 3)
if opts.ServerHost == "" {
home := vespa.FindHome()
backticks := util.BackTicksForwardStderr
configsources, _ := backticks.Run(home+"/bin/vespa-print-default", "configservers_http")
for _, src := range strings.Split(configsources, "\n") {
colonParts := strings.Split(src, ":")
if len(colonParts) > 1 {
// XXX overwrites port number from above - is this sensible?
src = fmt.Sprintf("%s:%s:%d", colonParts[0], colonParts[1], opts.PortNumber)
trace.Trace("can use config server at", src)
results = append(results, src)
}
}
if len(results) == 0 {
trace.Warning("Could not get url to config server, make sure that VESPA_CONFIGSERVERS is set")
results = append(results, fmt.Sprintf("http://localhost:%d", opts.PortNumber))
}
} else {
results = append(results, fmt.Sprintf("http://%s:%d", opts.ServerHost, opts.PortNumber))
}
return results
}
func pathPrefix(opts *Options) string {
return "/application/v2/tenant/" + opts.Tenant + "/session"
}
func addUrlPropertyFromFlag(url string, flag bool, propName string) string {
if !flag {
return url
} else {
return addUrlPropertyFromOption(url, "true", propName)
}
}
func addUrlPropertyFromOption(url, flag, propName string) string {
if flag == "" {
return url
}
if strings.Contains(url, "?") {
return url + "&" + propName + "=" + flag
} else {
return url + "?" + propName + "=" + flag
}
}
|