/
deployment.go
123 lines (98 loc) · 2.68 KB
/
deployment.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package deployment
import (
"fmt"
"github.com/astronomer/astro-cli/config"
"github.com/astronomer/astro-cli/houston"
"github.com/astronomer/astro-cli/pkg/printutil"
)
var (
tab = printutil.Table{
Padding: []int{30, 30, 10, 50},
DynamicPadding: true,
Header: []string{"NAME", "DEPLOYMENT NAME", "ASTRO", "DEPLOYMENT ID"},
}
)
func Create(label, ws string) error {
req := houston.Request{
Query: houston.DeploymentCreateRequest,
Variables: map[string]interface{}{"label": label, "workspaceUuid": ws},
}
r, err := req.Do()
if err != nil {
return err
}
d := r.Data.CreateDeployment
c, err := config.GetCurrentContext()
if err != nil {
return err
}
tab.AddRow([]string{d.Label, d.ReleaseName, d.Version, d.Id}, false)
tab.SuccessMsg = "\n Successfully created deployment. Deployment can be accessed at the following URLs \n" +
fmt.Sprintf("\n Airflow Dashboard: https://%s-airflow.%s", d.ReleaseName, c.Domain) +
fmt.Sprintf("\n Flower Dashboard: https://%s-flower.%s", d.ReleaseName, c.Domain)
tab.Print()
return nil
}
func Delete(uuid string) error {
req := houston.Request{
Query: houston.DeploymentDeleteRequest,
Variables: map[string]interface{}{"deploymentUuid": uuid},
}
_, err := req.Do()
if err != nil {
return err
}
// TODO - add back in tab print once houston returns all relevant information
// tab.AddRow([]string{d.Label, d.ReleaseName, d.Id, d.Workspace.Uuid}, false)
// tab.SuccessMsg = "\n Successfully deleted deployment"
// tab.Print()
fmt.Println("\n Successfully deleted deployment")
return nil
}
// List all airflow deployments
func List(ws string, all bool) error {
var deployments []houston.Deployment
var r *houston.HoustonResponse
var err error
req := houston.Request{
Query: houston.DeploymentsGetRequest,
}
if all {
r, err = req.Do()
if err != nil {
return err
}
} else {
req.Variables = map[string]interface{}{"workspaceUuid": ws}
r, err = req.Do()
if err != nil {
return err
}
}
deployments = r.Data.GetDeployments
// Build rows
for _, d := range deployments {
if all {
ws = d.Workspace.Uuid
}
tab.AddRow([]string{d.Label, d.ReleaseName, "v" + d.Version, d.Id}, false)
}
tab.Print()
return nil
}
// Update an airflow deployment
func Update(uuid string, args map[string]string) error {
req := houston.Request{
Query: houston.DeploymentUpdateRequest,
Variables: map[string]interface{}{"deploymentUuid": uuid, "payload": args},
}
r, err := req.Do()
if err != nil {
return err
}
d := r.Data.UpdateDeployment
tab.AddRow([]string{d.Label, d.ReleaseName, d.Version, d.Id}, false)
tab.SuccessMsg = "\n Successfully updated deployment"
tab.Print()
return nil
}