aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/internal/vespa
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2023-08-18 10:25:21 +0200
committerMartin Polden <mpolden@mpolden.no>2023-08-21 14:27:17 +0200
commit7b4f133606eebb8d10100bb72de8df1e2a98dd17 (patch)
treeddb54e9f6aca62fd4ed16b2b08de3d660178f914 /client/go/internal/vespa
parent8fbbe2b40cd7e4e00d9694e31534ea51dd47f264 (diff)
Wait for deploy service
Diffstat (limited to 'client/go/internal/vespa')
-rw-r--r--client/go/internal/vespa/deploy.go4
-rw-r--r--client/go/internal/vespa/deploy_test.go4
-rw-r--r--client/go/internal/vespa/target.go2
-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/target_test.go25
6 files changed, 18 insertions, 31 deletions
diff --git a/client/go/internal/vespa/deploy.go b/client/go/internal/vespa/deploy.go
index 6577ac0d38b..8fd35e4a933 100644
--- a/client/go/internal/vespa/deploy.go
+++ b/client/go/internal/vespa/deploy.go
@@ -149,7 +149,7 @@ func Prepare(deployment DeploymentOptions) (PrepareResult, error) {
return PrepareResult{}, err
}
var jsonResponse struct {
- SessionID string `json:"session-id"`
+ SessionID string `json:"session-id"` // API returns ID as string
Log []LogLinePrepareResponse `json:"log"`
}
jsonDec := json.NewDecoder(response.Body)
@@ -384,7 +384,7 @@ func uploadApplicationPackage(url *url.URL, opts DeploymentOptions) (PrepareResu
defer response.Body.Close()
var jsonResponse struct {
- SessionID string `json:"session-id"` // Config server
+ SessionID string `json:"session-id"` // Config server. API returns ID as string
RunID int64 `json:"run"` // Controller
Log []LogLinePrepareResponse `json:"log"`
diff --git a/client/go/internal/vespa/deploy_test.go b/client/go/internal/vespa/deploy_test.go
index 276e0f958d9..9addf81138a 100644
--- a/client/go/internal/vespa/deploy_test.go
+++ b/client/go/internal/vespa/deploy_test.go
@@ -19,7 +19,7 @@ import (
func TestDeploy(t *testing.T) {
httpClient := mock.HTTPClient{}
- target := LocalTarget(&httpClient, TLSOptions{})
+ target := LocalTarget(&httpClient, TLSOptions{}, 0)
appDir, _ := mock.ApplicationPackageDir(t, false, false)
opts := DeploymentOptions{
Target: target,
@@ -170,7 +170,7 @@ func TestFindApplicationPackage(t *testing.T) {
func TestDeactivate(t *testing.T) {
httpClient := mock.HTTPClient{}
- target := LocalTarget(&httpClient, TLSOptions{})
+ target := LocalTarget(&httpClient, TLSOptions{}, 0)
opts := DeploymentOptions{Target: target}
require.Nil(t, Deactivate(opts))
assert.Equal(t, 1, len(httpClient.Requests))
diff --git a/client/go/internal/vespa/target.go b/client/go/internal/vespa/target.go
index df82cc435b2..bbee85217df 100644
--- a/client/go/internal/vespa/target.go
+++ b/client/go/internal/vespa/target.go
@@ -34,8 +34,6 @@ const (
// AnyDeployment waits for a deployment to converge on any generation
AnyDeployment int64 = -2
-
- defaultRetryInterval = 2 * time.Second
)
var errWaitTimeout = errors.New("wait timed out")
diff --git a/client/go/internal/vespa/target_cloud.go b/client/go/internal/vespa/target_cloud.go
index 9b53180b7bb..14b7f1f4c52 100644
--- a/client/go/internal/vespa/target_cloud.go
+++ b/client/go/internal/vespa/target_cloud.go
@@ -72,7 +72,9 @@ type logMessage struct {
}
// CloudTarget creates a Target for the Vespa Cloud or hosted Vespa platform.
-func CloudTarget(httpClient util.HTTPClient, apiAuth Authenticator, deploymentAuth Authenticator, apiOptions APIOptions, deploymentOptions CloudDeploymentOptions, logOptions LogOptions) (Target, error) {
+func CloudTarget(httpClient util.HTTPClient, apiAuth Authenticator, deploymentAuth Authenticator,
+ apiOptions APIOptions, deploymentOptions CloudDeploymentOptions,
+ logOptions LogOptions, retryInterval time.Duration) (Target, error) {
return &cloudTarget{
httpClient: httpClient,
apiOptions: apiOptions,
@@ -80,7 +82,7 @@ func CloudTarget(httpClient util.HTTPClient, apiAuth Authenticator, deploymentAu
logOptions: logOptions,
apiAuth: apiAuth,
deploymentAuth: deploymentAuth,
- retryInterval: defaultRetryInterval,
+ retryInterval: retryInterval,
}, nil
}
diff --git a/client/go/internal/vespa/target_custom.go b/client/go/internal/vespa/target_custom.go
index e6c13502430..a49654e3dff 100644
--- a/client/go/internal/vespa/target_custom.go
+++ b/client/go/internal/vespa/target_custom.go
@@ -35,24 +35,24 @@ type serviceInfo struct {
}
// LocalTarget creates a target for a Vespa platform running locally.
-func LocalTarget(httpClient util.HTTPClient, tlsOptions TLSOptions) Target {
+func LocalTarget(httpClient util.HTTPClient, tlsOptions TLSOptions, retryInterval time.Duration) Target {
return &customTarget{
targetType: TargetLocal,
baseURL: "http://127.0.0.1",
httpClient: httpClient,
tlsOptions: tlsOptions,
- retryInterval: defaultRetryInterval,
+ retryInterval: retryInterval,
}
}
// CustomTarget creates a Target for a Vespa platform running at baseURL.
-func CustomTarget(httpClient util.HTTPClient, baseURL string, tlsOptions TLSOptions) Target {
+func CustomTarget(httpClient util.HTTPClient, baseURL string, tlsOptions TLSOptions, retryInterval time.Duration) Target {
return &customTarget{
targetType: TargetCustom,
baseURL: baseURL,
httpClient: httpClient,
tlsOptions: tlsOptions,
- retryInterval: defaultRetryInterval,
+ retryInterval: retryInterval,
}
}
diff --git a/client/go/internal/vespa/target_test.go b/client/go/internal/vespa/target_test.go
index 8fe424e897c..c9a5fc74de9 100644
--- a/client/go/internal/vespa/target_test.go
+++ b/client/go/internal/vespa/target_test.go
@@ -3,7 +3,6 @@ package vespa
import (
"bytes"
- "fmt"
"io"
"net/http"
"strings"
@@ -19,7 +18,7 @@ import (
func TestLocalTarget(t *testing.T) {
// Local target uses discovery
client := &mock.HTTPClient{}
- lt := LocalTarget(client, TLSOptions{})
+ lt := LocalTarget(client, TLSOptions{}, 0)
assertServiceURL(t, "http://127.0.0.1:19071", lt, "deploy")
for i := 0; i < 2; i++ {
response := `
@@ -67,31 +66,19 @@ func TestLocalTarget(t *testing.T) {
assertServiceURL(t, "http://127.0.0.1:8081", lt, "feed")
}
-func setRetryInterval(target Target, interval time.Duration) {
- switch t := target.(type) {
- case *cloudTarget:
- t.retryInterval = interval
- case *customTarget:
- t.retryInterval = interval
- default:
- panic(fmt.Sprintf("unexpected type %T", t))
- }
-}
-
func TestCustomTarget(t *testing.T) {
// Custom target always uses URL directly, without discovery
- ct := CustomTarget(&mock.HTTPClient{}, "http://192.0.2.42", TLSOptions{})
+ ct := CustomTarget(&mock.HTTPClient{}, "http://192.0.2.42", TLSOptions{}, 0)
assertServiceURL(t, "http://192.0.2.42", ct, "deploy")
assertServiceURL(t, "http://192.0.2.42", ct, "")
- ct2 := CustomTarget(&mock.HTTPClient{}, "http://192.0.2.42:60000", TLSOptions{})
+ ct2 := CustomTarget(&mock.HTTPClient{}, "http://192.0.2.42:60000", TLSOptions{}, 0)
assertServiceURL(t, "http://192.0.2.42:60000", ct2, "deploy")
assertServiceURL(t, "http://192.0.2.42:60000", ct2, "")
}
func TestCustomTargetWait(t *testing.T) {
client := &mock.HTTPClient{}
- target := CustomTarget(client, "http://192.0.2.42", TLSOptions{})
- setRetryInterval(target, 0)
+ target := CustomTarget(client, "http://192.0.2.42", TLSOptions{}, 0)
// Fails once
client.NextStatus(500)
assertService(t, true, target, "", 0)
@@ -107,7 +94,7 @@ func TestCustomTargetWait(t *testing.T) {
func TestCustomTargetAwaitDeployment(t *testing.T) {
client := &mock.HTTPClient{}
- target := CustomTarget(client, "http://192.0.2.42", TLSOptions{})
+ target := CustomTarget(client, "http://192.0.2.42", TLSOptions{}, 0)
// Not converged initially
_, err := target.AwaitDeployment(42, 0)
@@ -269,9 +256,9 @@ func createCloudTarget(t *testing.T, logWriter io.Writer) (Target, *mock.HTTPCli
},
},
LogOptions{Writer: logWriter},
+ 0,
)
require.Nil(t, err)
- setRetryInterval(target, 0)
return target, client
}