-
Notifications
You must be signed in to change notification settings - Fork 0
/
dequeue_instance.go
83 lines (71 loc) · 2.6 KB
/
dequeue_instance.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
package handlers
import (
"database/sql"
"fmt"
"net/http"
"github.com/gorilla/mux"
"github.com/pkg/errors"
"github.com/replicatedhq/kurl-testgrid/tgapi/pkg/testinstance"
)
type DequeueInstanceResponse struct {
ID string `json:"id"`
NumPrimaryNodes int `json:"numPrimaryNodes"`
NumSecondaryNodes int `json:"numSecondaryNodes"`
Memory string `json:"memory"`
CPU string `json:"cpu"`
OperatingSystemName string `json:"operatingSystemName"`
OperatingSystemVersion string `json:"operatingSystemVersion"`
OperatingSystemImage string `json:"operatingSystemImage"`
OperatingSystemPreInit string `json:"operatingSystemPreInit"`
KurlYAML string `json:"kurlYaml"`
KurlURL string `json:"kurlUrl"`
KurlFlags string `json:"kurlFlags"`
UpgradeURL string `json:"upgradeUrl"`
SupportbundleYAML string `json:"supportbundleYaml"`
PreInstallScript string `json:"preInstallScript"`
PostInstallScript string `json:"postInstallScript"`
PostUpgradeScript string `json:"postUpgradeScript"`
KurlRef string `json:"kurlRef"`
}
func DequeueInstance(w http.ResponseWriter, r *http.Request) {
dequeueInstance(w, "")
}
func DequeueInstanceWithRef(w http.ResponseWriter, r *http.Request) {
refID := mux.Vars(r)["refId"]
dequeueInstance(w, refID)
}
func dequeueInstance(w http.ResponseWriter, refID string) {
testInstance, err := testinstance.GetNextEnqueued(refID)
if err != nil {
if errors.Cause(err) != sql.ErrNoRows {
w.WriteHeader(500)
fmt.Printf("error dequeing instance: %s\n", err.Error())
return
}
JSON(w, 200, []DequeueInstanceResponse{})
return
}
dequeueInstanceResponse := DequeueInstanceResponse{
ID: testInstance.ID,
NumPrimaryNodes: testInstance.NumPrimaryNodes,
NumSecondaryNodes: testInstance.NumSecondaryNodes,
Memory: testInstance.Memory,
CPU: testInstance.CPU,
OperatingSystemName: testInstance.OSName,
OperatingSystemVersion: testInstance.OSVersion,
OperatingSystemImage: testInstance.OSImage,
OperatingSystemPreInit: testInstance.OSPreInit,
KurlYAML: testInstance.KurlYAML,
KurlURL: testInstance.KurlURL,
KurlFlags: testInstance.KurlFlags,
UpgradeURL: testInstance.UpgradeURL,
SupportbundleYAML: testInstance.SupportbundleYAML,
PreInstallScript: testInstance.PreInstallScript,
PostInstallScript: testInstance.PostInstallScript,
PostUpgradeScript: testInstance.PostUpgradeScript,
KurlRef: testInstance.RefID,
}
JSON(w, 200, []DequeueInstanceResponse{
dequeueInstanceResponse,
})
}