aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/src/cmd/status.go
blob: 809b63623aef51c8abfe858a4807a014bcd5e55e (plain) (blame)
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
// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
// vespa status command
// author: bratseth

package cmd

import (
    "github.com/spf13/cobra"
    "github.com/vespa-engine/vespa/utils"
)

func init() {
    rootCmd.AddCommand(statusCmd)
    statusCmd.AddCommand(statusContainerCmd)
    statusCmd.AddCommand(statusConfigServerCmd)
}

var statusCmd = &cobra.Command{
    Use:   "status",
    Short: "Verifies that a vespa target is ready to use (container by default)",
    Long:  `TODO`,
    Run: func(cmd *cobra.Command, args []string) {
        status(getTarget(queryContext).query, "Container")
    },
}

var statusContainerCmd = &cobra.Command{
    Use:   "container",
    Short: "Verifies that your Vespa container endpoint is ready [Default]",
    Long:  `TODO`,
    Run: func(cmd *cobra.Command, args []string) {
        status(getTarget(queryContext).query, "Container")
    },
}

var statusConfigServerCmd = &cobra.Command{
    Use:   "config-server",
    Short: "Verifies that your Vespa config server endpoint is ready",
    Long:  `TODO`,
    Run: func(cmd *cobra.Command, args []string) {
        status(getTarget(deployContext).deploy, "Config server")
    },
}

func status(target string, description string) {
    path := "/ApplicationStatus"
    response := utils.HttpGet(target, path, description)
    if (response == nil) {
        return
    }
    defer response.Body.Close()

    if response.StatusCode != 200 {
        utils.Error(description, "at", target, "is not ready")
        utils.Detail("Response status:", response.Status)
    } else {
        utils.Success(description, "at", target, "is ready")
    }
}