-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
handler.go
104 lines (84 loc) · 2.62 KB
/
handler.go
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package probe
import (
"fmt"
log "github.com/sirupsen/logrus"
"github.com/mintoolkit/mint/pkg/app"
"github.com/mintoolkit/mint/pkg/app/master/command"
"github.com/mintoolkit/mint/pkg/app/master/config"
"github.com/mintoolkit/mint/pkg/app/master/probe/http"
"github.com/mintoolkit/mint/pkg/app/master/version"
cmd "github.com/mintoolkit/mint/pkg/command"
"github.com/mintoolkit/mint/pkg/docker/dockerclient"
"github.com/mintoolkit/mint/pkg/report"
"github.com/mintoolkit/mint/pkg/util/errutil"
"github.com/mintoolkit/mint/pkg/util/fsutil"
v "github.com/mintoolkit/mint/pkg/version"
)
const appName = command.AppName
type ovars = app.OutVars
// OnCommand implements the 'probe' command
func OnCommand(
xc *app.ExecutionContext,
gparams *command.GenericParams,
targetEndpoint string,
targetPorts []uint,
httpProbeOpts config.HTTPProbeOptions) {
printState := true
logger := log.WithFields(log.Fields{"app": appName, "cmd": Name})
cmdName := fmt.Sprintf("cmd=%s", Name)
viChan := version.CheckAsync(gparams.CheckVersion, gparams.InContainer, gparams.IsDSImage)
cmdReport := report.NewProbeCommand(gparams.ReportLocation, gparams.InContainer)
cmdReport.State = cmd.StateStarted
xc.Out.State(cmd.StateStarted)
xc.Out.Info("params",
ovars{
"target": targetEndpoint,
})
client, err := dockerclient.New(gparams.ClientConfig)
if err == dockerclient.ErrNoDockerInfo {
exitMsg := "missing Docker connection info"
if gparams.InContainer && gparams.IsDSImage {
exitMsg = "make sure to pass the Docker connect parameters to the slim app container"
}
xc.Out.Info("docker.connect.error",
ovars{
"message": exitMsg,
})
exitCode := -222
xc.Out.State("exited",
ovars{
"exit.code": exitCode,
"version": v.Current(),
"location": fsutil.ExeDir(),
})
xc.Exit(exitCode)
}
errutil.FailOn(err)
if gparams.Debug {
version.Print(xc, cmdName, logger, client, false, gparams.InContainer, gparams.IsDSImage)
}
probe, err := http.NewEndpointProbe(xc, targetEndpoint, targetPorts, httpProbeOpts, printState)
xc.FailOn(err)
probe.Start()
xc.Out.Prompt("waiting for the HTTP probe to finish")
<-probe.DoneChan()
xc.Out.Info("event",
ovars{
"message": "HTTP probe is done",
})
if probe != nil && probe.CallCount > 0 && probe.OkCount == 0 {
xc.Out.Error("probe.error", "no.successful.calls")
}
xc.Out.State(cmd.StateCompleted)
cmdReport.State = cmd.StateCompleted
xc.Out.State(cmd.StateDone)
vinfo := <-viChan
version.PrintCheckVersion(xc, "", vinfo)
cmdReport.State = cmd.StateDone
if cmdReport.Save() {
xc.Out.Info("report",
ovars{
"file": cmdReport.ReportLocation(),
})
}
}