aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/internal/cli
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/cli
parent8fbbe2b40cd7e4e00d9694e31534ea51dd47f264 (diff)
Wait for deploy service
Diffstat (limited to 'client/go/internal/cli')
-rw-r--r--client/go/internal/cli/cmd/deploy.go21
-rw-r--r--client/go/internal/cli/cmd/deploy_test.go32
-rw-r--r--client/go/internal/cli/cmd/root.go30
3 files changed, 68 insertions, 15 deletions
diff --git a/client/go/internal/cli/cmd/deploy.go b/client/go/internal/cli/cmd/deploy.go
index 09ad06da627..b037a953b53 100644
--- a/client/go/internal/cli/cmd/deploy.go
+++ b/client/go/internal/cli/cmd/deploy.go
@@ -73,6 +73,9 @@ $ vespa deploy -t cloud -z perf.aws-us-east-1c`,
return err
}
}
+ if err := waitForDeployService(cli, target, timeout); err != nil {
+ return err
+ }
var result vespa.PrepareResult
if err := cli.spinner(cli.Stderr, "Uploading application package ...", func() error {
result, err = vespa.Deploy(opts)
@@ -84,7 +87,7 @@ $ vespa deploy -t cloud -z perf.aws-us-east-1c`,
if opts.Target.IsCloud() {
cli.printSuccess("Triggered deployment of ", color.CyanString(pkg.Path), " with run ID ", color.CyanString(strconv.FormatInt(result.ID, 10)))
} else {
- cli.printSuccess("Deployed ", color.CyanString(pkg.Path))
+ cli.printSuccess("Deployed ", color.CyanString(pkg.Path), " with session ID ", color.CyanString(strconv.FormatInt(result.ID, 10)))
printPrepareLog(cli.Stderr, result)
}
if opts.Target.IsCloud() {
@@ -158,6 +161,9 @@ func newActivateCmd(cli *CLI) *cobra.Command {
return err
}
timeout := time.Duration(waitSecs) * time.Second
+ if err := waitForDeployService(cli, target, timeout); err != nil {
+ return err
+ }
opts := vespa.DeploymentOptions{Target: target, Timeout: timeout}
err = vespa.Activate(sessionID, opts)
if err != nil {
@@ -171,10 +177,23 @@ func newActivateCmd(cli *CLI) *cobra.Command {
return cmd
}
+func waitForDeployService(cli *CLI, target vespa.Target, timeout time.Duration) error {
+ if timeout == 0 {
+ return nil
+ }
+ s, err := target.DeployService(0)
+ if err != nil {
+ return err
+ }
+ cli.printInfo("Waiting up to ", color.CyanString(timeout.String()), " for ", s.Description(), " to become ready ...")
+ return s.Wait(timeout)
+}
+
func waitForContainerServices(cli *CLI, target vespa.Target, sessionOrRunID int64, timeout time.Duration) error {
if timeout == 0 {
return nil
}
+ cli.printInfo("Waiting up to ", color.CyanString(timeout.String()), " for deployment to converge ...")
if _, err := target.AwaitDeployment(sessionOrRunID, timeout); err != nil {
return err
}
diff --git a/client/go/internal/cli/cmd/deploy_test.go b/client/go/internal/cli/cmd/deploy_test.go
index b72cf7bc714..35c9b05050c 100644
--- a/client/go/internal/cli/cmd/deploy_test.go
+++ b/client/go/internal/cli/cmd/deploy_test.go
@@ -6,6 +6,7 @@ package cmd
import (
"bytes"
+ "io"
"path/filepath"
"strconv"
"strings"
@@ -61,6 +62,33 @@ Hint: Pass --add-cert to use the certificate of the current application
assert.Contains(t, stdout.String(), "Success: Triggered deployment")
}
+func TestDeployWait(t *testing.T) {
+ cli, stdout, _ := newTestCLI(t)
+ client := &mock.HTTPClient{}
+ cli.httpClient = client
+ cli.retryInterval = 0
+ pkg := "testdata/applications/withSource/src/main/application"
+ // Deploy service is initially unavailable
+ client.NextResponseError(io.EOF)
+ client.NextStatus(500)
+ client.NextStatus(500)
+ // ... then becomes healthy
+ client.NextStatus(200)
+ client.NextStatus(200)
+ // Deployment succeeds
+ client.NextResponse(mock.HTTPResponse{
+ URI: "/application/v2/tenant/default/prepareandactivate",
+ Status: 200,
+ Body: []byte(`{"session-id": "1"}`),
+ })
+ mockServiceStatus(client, "foo") // Wait for deployment
+ mockServiceStatus(client, "foo") // Look up services
+ assert.Nil(t, cli.Run("deploy", "--wait=3", pkg))
+ assert.Equal(t,
+ "\nSuccess: Deployed "+pkg+" with session ID 1\n",
+ stdout.String())
+}
+
func TestPrepareZip(t *testing.T) {
assertPrepare("testdata/applications/withTarget/target/application.zip",
[]string{"prepare", "testdata/applications/withTarget/target/application.zip"}, t)
@@ -85,7 +113,7 @@ func TestDeployZipWithURLTargetArgument(t *testing.T) {
cli.httpClient = client
assert.Nil(t, cli.Run(arguments...))
assert.Equal(t,
- "\nSuccess: Deployed "+applicationPackage+"\n",
+ "\nSuccess: Deployed "+applicationPackage+" with session ID 0\n",
stdout.String())
assertDeployRequestMade("http://target:19071", client, t)
}
@@ -161,7 +189,7 @@ func assertDeploy(applicationPackage string, arguments []string, t *testing.T) {
cli.httpClient = client
assert.Nil(t, cli.Run(arguments...))
assert.Equal(t,
- "\nSuccess: Deployed "+applicationPackage+"\n",
+ "\nSuccess: Deployed "+applicationPackage+" with session ID 0\n",
stdout.String())
assertDeployRequestMade("http://127.0.0.1:19071", client, t)
}
diff --git a/client/go/internal/cli/cmd/root.go b/client/go/internal/cli/cmd/root.go
index 2829dce2b21..b88d86ce453 100644
--- a/client/go/internal/cli/cmd/root.go
+++ b/client/go/internal/cli/cmd/root.go
@@ -43,6 +43,13 @@ type CLI struct {
Stdout io.Writer
Stderr io.Writer
+ exec executor
+ isTerminal func() bool
+ spinner func(w io.Writer, message string, fn func() error) error
+
+ now func() time.Time
+ retryInterval time.Duration
+
cmd *cobra.Command
config *Config
version version.Version
@@ -51,10 +58,6 @@ type CLI struct {
httpClientFactory func(timeout time.Duration) util.HTTPClient
auth0Factory auth0Factory
ztsFactory ztsFactory
- exec executor
- isTerminal func() bool
- spinner func(w io.Writer, message string, fn func() error) error
- now func() time.Time
}
// ErrCLI is an error returned to the user. It wraps an exit status, a regular error and optional hints for resolving
@@ -134,12 +137,15 @@ For detailed description of flags and configuration, see 'vespa help config'.
Stdout: stdout,
Stderr: stderr,
- version: version,
- cmd: cmd,
+ exec: &execSubprocess{},
+ now: time.Now,
+ retryInterval: 2 * time.Second,
+
+ version: version,
+ cmd: cmd,
+
httpClient: httpClientFactory(time.Second * 10),
httpClientFactory: httpClientFactory,
- exec: &execSubprocess{},
- now: time.Now,
auth0Factory: func(httpClient util.HTTPClient, options auth0.Options) (vespa.Authenticator, error) {
return auth0.NewClient(httpClient, options)
},
@@ -296,7 +302,7 @@ func (c *CLI) printSuccess(msg ...interface{}) {
}
func (c *CLI) printInfo(msg ...interface{}) {
- fmt.Fprintln(c.Stderr, "Info:", fmt.Sprint(msg...))
+ fmt.Fprintln(c.Stderr, fmt.Sprint(msg...))
}
func (c *CLI) printDebug(msg ...interface{}) {
@@ -405,9 +411,9 @@ func (c *CLI) createCustomTarget(targetType, customURL string) (vespa.Target, er
}
switch targetType {
case vespa.TargetLocal:
- return vespa.LocalTarget(c.httpClient, tlsOptions), nil
+ return vespa.LocalTarget(c.httpClient, tlsOptions, c.retryInterval), nil
case vespa.TargetCustom:
- return vespa.CustomTarget(c.httpClient, customURL, tlsOptions), nil
+ return vespa.CustomTarget(c.httpClient, customURL, tlsOptions, c.retryInterval), nil
default:
return nil, fmt.Errorf("invalid custom target: %s", targetType)
}
@@ -489,7 +495,7 @@ func (c *CLI) createCloudTarget(targetType string, opts targetOptions, customURL
Writer: c.Stdout,
Level: vespa.LogLevel(logLevel),
}
- return vespa.CloudTarget(c.httpClient, apiAuth, deploymentAuth, apiOptions, deploymentOptions, logOptions)
+ return vespa.CloudTarget(c.httpClient, apiAuth, deploymentAuth, apiOptions, deploymentOptions, logOptions, c.retryInterval)
}
// system returns the appropiate system for the target configured in this CLI.