summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2021-09-06 10:29:46 +0200
committerMartin Polden <mpolden@mpolden.no>2021-09-06 11:03:21 +0200
commit96af4ea308f253cc14280ced3b1e566062070a1b (patch)
tree80157e36f55b807ac207c3fe552d1b37a2818741 /client
parent7c784391589e9ebc3d03531c99a32b2bd13b1971 (diff)
Implement basic deploy --wait
Diffstat (limited to 'client')
-rw-r--r--client/go/cmd/deploy.go9
-rw-r--r--client/go/cmd/helpers.go19
-rw-r--r--client/go/cmd/status.go31
-rw-r--r--client/go/cmd/status_test.go8
-rw-r--r--client/go/vespa/target.go2
5 files changed, 37 insertions, 32 deletions
diff --git a/client/go/cmd/deploy.go b/client/go/cmd/deploy.go
index 7d180775e24..1b9883bf1e8 100644
--- a/client/go/cmd/deploy.go
+++ b/client/go/cmd/deploy.go
@@ -63,6 +63,7 @@ has started but may not have completed.`,
log.Printf("\nUse %s for deployment status, or see", color.Cyan("vespa status"))
log.Print(color.Cyan(fmt.Sprintf("https://console.vespa.oath.cloud/tenant/%s/application/%s/dev/instance/%s", opts.Deployment.Application.Tenant, opts.Deployment.Application.Application, opts.Deployment.Application.Instance)))
}
+ waitForQueryService()
} else {
printErr(nil, err.Error())
}
@@ -116,12 +117,20 @@ var activateCmd = &cobra.Command{
})
if err == nil {
printSuccess("Activated ", color.Cyan(pkg.Path), " with session ", sessionID)
+ waitForQueryService()
} else {
printErr(nil, err.Error())
}
},
}
+func waitForQueryService() {
+ if waitSecsArg > 0 {
+ log.Println()
+ waitForService("query")
+ }
+}
+
func writeSessionID(appConfigDir string, sessionID int64) {
if err := os.MkdirAll(appConfigDir, 0755); err != nil {
printErr(err, "Could not create directory for session ID")
diff --git a/client/go/cmd/helpers.go b/client/go/cmd/helpers.go
index 915ae5290d7..108115e1076 100644
--- a/client/go/cmd/helpers.go
+++ b/client/go/cmd/helpers.go
@@ -124,3 +124,22 @@ func getTarget() vespa.Target {
printErrHint(fmt.Errorf("Invalid target: %s", targetType), "Valid targets are 'local', 'cloud' or an URL")
return nil
}
+
+func waitForService(service string) {
+ s := getService(service)
+ timeout := time.Duration(waitSecsArg) * time.Second
+ if timeout > 0 {
+ log.Printf("Waiting %d %s for service to become ready ...", color.Cyan(waitSecsArg), color.Cyan("seconds"))
+ }
+ status, err := s.Wait(timeout)
+ if status/100 == 2 {
+ log.Print(s.Description(), " at ", color.Cyan(s.BaseURL), " is ", color.Green("ready"))
+ } else {
+ log.Print(s.Description(), " at ", color.Cyan(s.BaseURL), " is ", color.Red("not ready"))
+ if err == nil {
+ log.Print(color.Yellow(fmt.Sprintf("Status %d", status)))
+ } else {
+ log.Print(color.Yellow(err))
+ }
+ }
+}
diff --git a/client/go/cmd/status.go b/client/go/cmd/status.go
index b0d299ecfac..8764cddbb91 100644
--- a/client/go/cmd/status.go
+++ b/client/go/cmd/status.go
@@ -5,10 +5,6 @@
package cmd
import (
- "fmt"
- "log"
- "time"
-
"github.com/spf13/cobra"
)
@@ -25,7 +21,7 @@ var statusCmd = &cobra.Command{
Example: `$ vespa status query`,
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
- status("query", "Query API")
+ waitForService("query")
},
}
@@ -35,7 +31,7 @@ var statusQueryCmd = &cobra.Command{
Example: `$ vespa status query`,
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
- status("query", "Query API")
+ waitForService("query")
},
}
@@ -45,7 +41,7 @@ var statusDocumentCmd = &cobra.Command{
Example: `$ vespa status document`,
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
- status("document", "Document API")
+ waitForService("document")
},
}
@@ -55,25 +51,6 @@ var statusDeployCmd = &cobra.Command{
Example: `$ vespa status deploy`,
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
- status("deploy", "Deploy API")
+ waitForService("deploy")
},
}
-
-func status(service string, description string) {
- s := getService(service)
- timeout := time.Duration(waitSecsArg) * time.Second
- if timeout > 0 {
- log.Printf("Waiting %d %s for service to become ready ...", color.Cyan(waitSecsArg), color.Cyan("seconds"))
- }
- status, err := s.Wait(timeout)
- if status/100 == 2 {
- log.Print(description, " at ", color.Cyan(s.BaseURL), " is ", color.Green("ready"))
- } else {
- log.Print(description, " at ", color.Cyan(s.BaseURL), " is ", color.Red("not ready"))
- if err == nil {
- log.Print(color.Yellow(fmt.Sprintf("Status %d", status)))
- } else {
- log.Print(color.Yellow(err))
- }
- }
-}
diff --git a/client/go/cmd/status_test.go b/client/go/cmd/status_test.go
index 10b1950d5d1..488f979008c 100644
--- a/client/go/cmd/status_test.go
+++ b/client/go/cmd/status_test.go
@@ -54,13 +54,13 @@ func assertDeployStatus(target string, args []string, t *testing.T) {
func assertQueryStatus(target string, args []string, t *testing.T) {
client := &mockHttpClient{}
assert.Equal(t,
- "Query API at "+target+" is ready\n",
+ "Container (query API) at "+target+" is ready\n",
executeCommand(t, client, []string{"status", "query"}, args),
"vespa status container")
assert.Equal(t, target+"/ApplicationStatus", client.lastRequest.URL.String())
assert.Equal(t,
- "Query API at "+target+" is ready\n",
+ "Container (query API) at "+target+" is ready\n",
executeCommand(t, client, []string{"status"}, args),
"vespa status (the default)")
assert.Equal(t, target+"/ApplicationStatus", client.lastRequest.URL.String())
@@ -69,7 +69,7 @@ func assertQueryStatus(target string, args []string, t *testing.T) {
func assertDocumentStatus(target string, args []string, t *testing.T) {
client := &mockHttpClient{}
assert.Equal(t,
- "Document API at "+target+" is ready\n",
+ "Container (document API) at "+target+" is ready\n",
executeCommand(t, client, []string{"status", "document"}, args),
"vespa status container")
assert.Equal(t, target+"/ApplicationStatus", client.lastRequest.URL.String())
@@ -78,7 +78,7 @@ func assertDocumentStatus(target string, args []string, t *testing.T) {
func assertQueryStatusError(target string, args []string, t *testing.T) {
client := &mockHttpClient{nextStatus: 500}
assert.Equal(t,
- "Query API at "+target+" is not ready\nStatus 500\n",
+ "Container (query API) at "+target+" is not ready\nStatus 500\n",
executeCommand(t, client, []string{"status", "container"}, args),
"vespa status container")
}
diff --git a/client/go/vespa/target.go b/client/go/vespa/target.go
index 61bfbe603a0..ae3d82429d6 100644
--- a/client/go/vespa/target.go
+++ b/client/go/vespa/target.go
@@ -83,7 +83,7 @@ func (s *Service) Wait(timeout time.Duration) (int, error) {
func (s *Service) Description() string {
switch s.Name {
case queryService:
- return "Container (search API)"
+ return "Container (query API)"
case documentService:
return "Container (document API)"
case deployService: