Skip to content

Commit 2742250

Browse files
committed
SUMO-216512: Add support for uninstall and upgrade in tf provider
1 parent 563a40c commit 2742250

File tree

1 file changed

+31
-180
lines changed

1 file changed

+31
-180
lines changed

sumologic/sumologic_app.go

Lines changed: 31 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"time"
88
)
99

10-
func (s *Client) GetDashboard(id string) (*Dashboard, error) {
11-
url := fmt.Sprintf("v2/dashboards/%s", id)
10+
func (s *Client) GetAppInstance(id string) (*AppInstance, error) {
11+
url := fmt.Sprintf("v2/apps/instances/%s", id)
1212
data, _, err := s.Get(url)
1313
if err != nil {
1414
return nil, err
@@ -17,58 +17,61 @@ func (s *Client) GetDashboard(id string) (*Dashboard, error) {
1717
return nil, nil
1818
}
1919

20-
var dashboard Dashboard
21-
err = json.Unmarshal(data, &dashboard)
20+
var appInstance AppInstance
21+
err = json.Unmarshal(data, &appInstance)
2222
if err != nil {
2323
return nil, err
2424
}
25-
log.Printf("[GetDashboard] response: %+v\n", dashboard)
26-
return &dashboard, nil
25+
log.Printf("[GetAppInstance] response: %+v\n", appInstance)
26+
return &appInstance, nil
2727
}
2828

29-
func (s *Client) GetAppInstance(id string) (*Dashboard, error) {
30-
url := fmt.Sprintf("v2/apps/instances/%s", id)
31-
data, _, err := s.Get(url)
29+
func (s *Client) CreateAppInstance(uuid string, appInstallPayload AppInstallPayload) (*AppInstallResponse, error) {
30+
url := fmt.Sprintf("v2/apps/%s/install", uuid)
31+
jobId, err := s.Post(url, appInstallPayload)
3232
if err != nil {
3333
return nil, err
3434
}
35-
if data == nil {
36-
return nil, nil
37-
}
3835

39-
var dashboard Dashboard
40-
err = json.Unmarshal(data, &dashboard)
36+
// Wait for install job to finish
37+
url = fmt.Sprintf("v2/apps/install/%s/status", jobId)
38+
_, err = waitForJob(url, time.Minute, s)
4139
if err != nil {
4240
return nil, err
4341
}
44-
log.Printf("[GetDashboard] response: %+v\n", dashboard)
45-
return &dashboard, nil
46-
}
4742

48-
func (s *Client) CreateDashboard(dashboardReq Dashboard) (*Dashboard, error) {
49-
responseBody, err := s.Post("v2/dashboards", dashboardReq)
43+
var appInstallResponse AppInstallResponse
44+
b, _, _ := s.Get(url)
45+
err = json.Unmarshal(b, &appInstallResponse)
5046
if err != nil {
5147
return nil, err
5248
}
49+
log.Printf("[CreateAppInstance] response: %+v\n", appInstallResponse)
50+
return &appInstallResponse, nil
51+
}
5352

54-
var dashboard Dashboard
55-
err = json.Unmarshal(responseBody, &dashboard)
53+
func (s *Client) DeleteAppInstance(uuid string) error {
54+
url := fmt.Sprintf("v2/apps/%s/uninstall", uuid)
55+
jobId, err := s.Post(url, nil)
5656
if err != nil {
57-
return nil, err
57+
return err
5858
}
59-
log.Printf("[CreateDashboard] response: %+v\n", dashboard)
60-
return &dashboard, nil
59+
60+
// Wait for install job to finish
61+
url = fmt.Sprintf("v2/apps/uninstall/%s/status", jobId)
62+
_, err = waitForJob(url, time.Minute, s)
63+
return err
6164
}
6265

63-
func (s *Client) CreateAppInstance(uuid string, appInstallPayload AppInstallPayload) (*AppInstallResponse, error) {
64-
url := fmt.Sprintf("v2/apps/%s/install", uuid)
66+
func (s *Client) UpdateAppInstance(uuid string, appInstallPayload AppInstallPayload) (*AppInstallResponse, error) {
67+
url := fmt.Sprintf("v2/apps/%s/upgrade", uuid)
6568
jobId, err := s.Post(url, appInstallPayload)
6669
if err != nil {
6770
return nil, err
6871
}
6972

7073
// Wait for install job to finish
71-
url = fmt.Sprintf("v2/apps/install/%s/status", jobId)
74+
url = fmt.Sprintf("v2/apps/upgrade/%s/status", jobId)
7275
_, err = waitForJob(url, time.Minute, s)
7376
if err != nil {
7477
return nil, err
@@ -80,22 +83,10 @@ func (s *Client) CreateAppInstance(uuid string, appInstallPayload AppInstallPayl
8083
if err != nil {
8184
return nil, err
8285
}
83-
log.Printf("[CreateApp] response: %+v\n", appInstallResponse)
86+
log.Printf("[UpdateAppInstance] response: %+v\n", appInstallResponse)
8487
return &appInstallResponse, nil
8588
}
8689

87-
func (s *Client) DeleteDashboard(id string) error {
88-
url := fmt.Sprintf("v2/dashboards/%s", id)
89-
_, err := s.Delete(url)
90-
return err
91-
}
92-
93-
func (s *Client) UpdateDashboard(dashboard Dashboard) error {
94-
url := fmt.Sprintf("v2/dashboards/%s", dashboard.ID)
95-
_, err := s.Put(url, dashboard)
96-
return err
97-
}
98-
9990
type AppInstallPayload struct {
10091
VERSION string `json:"version"`
10192
PARAMETERS map[string]string `json:"parameters"`
@@ -131,143 +122,3 @@ type ManagedObject struct {
131122
TYPE string `json:"type"`
132123
DESCRIPTION string `json:"description"`
133124
}
134-
135-
type Dashboard struct {
136-
ID string `json:"id,omitempty"`
137-
Title string `json:"title"`
138-
Description string `json:"description"`
139-
FolderId string `json:"folderId"`
140-
TopologyLabelMap *TopologyLabel `json:"topologyLabelMap"`
141-
Domain string `json:"domain"`
142-
RefreshInterval int `json:"refreshInterval"`
143-
TimeRange interface{} `json:"timeRange"`
144-
Panels []interface{} `json:"panels"`
145-
Layout interface{} `json:"layout"`
146-
Variables []Variable `json:"variables"`
147-
Theme string `json:"theme"`
148-
ColoringRules []ColoringRule `json:"coloringRules"`
149-
}
150-
151-
type TopologyLabel struct {
152-
Data map[string][]string `json:"data"`
153-
}
154-
155-
// Panel related structs
156-
type TextPanel struct {
157-
Id string `json:"id,omitempty"`
158-
Key string `json:"key"`
159-
Title string `json:"title"`
160-
VisualSettings string `json:"visualSettings"`
161-
KeepVisualSettingsConsistentWithParent bool `json:"keepVisualSettingsConsistentWithParent"`
162-
PanelType string `json:"panelType"`
163-
// Text panel related properties
164-
Text string `json:"text"`
165-
}
166-
167-
type SumoSearchPanel struct {
168-
Id string `json:"id,omitempty"`
169-
Key string `json:"key"`
170-
Title string `json:"title"`
171-
VisualSettings string `json:"visualSettings"`
172-
KeepVisualSettingsConsistentWithParent bool `json:"keepVisualSettingsConsistentWithParent"`
173-
PanelType string `json:"panelType"`
174-
// Search panel related properties
175-
Queries []SearchPanelQuery `json:"queries"`
176-
Description string `json:"description"`
177-
TimeRange interface{} `json:"timeRange"`
178-
ColoringRules []ColoringRule `json:"coloringRules"`
179-
LinkedDashboards []LinkedDashboard `json:"linkedDashboards"`
180-
}
181-
182-
type SearchPanelQuery struct {
183-
QueryString string `json:"queryString"`
184-
QueryType string `json:"queryType"`
185-
QueryKey string `json:"queryKey"`
186-
MetricsQueryMode string `json:"metricsQueryMode,omitempty"`
187-
MetricsQueryData *MetricsQueryData `json:"metricsQueryData,omitempty"`
188-
}
189-
190-
type MetricsQueryData struct {
191-
Metric string `json:"metric"`
192-
AggregationType string `json:"aggregationType"`
193-
GroupBy string `json:"groupBy,omitempty"`
194-
Filters []MetricsQueryFilter `json:"filters"`
195-
Operators []MetricsQueryOperator `json:"operators"`
196-
}
197-
198-
type MetricsQueryFilter struct {
199-
Key string `json:"key"`
200-
Value string `json:"value"`
201-
Negation bool `json:"negation,omitempty"`
202-
}
203-
204-
type MetricsQueryOperator struct {
205-
Name string `json:"operatorName"`
206-
Parameters []MetricsQueryOperatorParameter `json:"parameters"`
207-
}
208-
209-
type MetricsQueryOperatorParameter struct {
210-
Key string `json:"key"`
211-
Value string `json:"value"`
212-
}
213-
214-
// Layout related structs
215-
type GridLayout struct {
216-
LayoutType string `json:"layoutType"`
217-
LayoutStructures []LayoutStructure `json:"layoutStructures"`
218-
}
219-
220-
type LayoutStructure struct {
221-
Key string `json:"key"`
222-
Structure string `json:"structure"`
223-
}
224-
225-
// Variable related structs
226-
type Variable struct {
227-
Id string `json:"id,omitempty"`
228-
Name string `json:"name"`
229-
DisplayName string `json:"displayName,omitempty"`
230-
DefaultValue string `json:"defaultValue,omitempty"`
231-
SourceDefinition interface{} `json:"sourceDefinition"`
232-
AllowMultiSelect bool `json:"allowMultiSelect,omitempty"`
233-
IncludeAllOption bool `json:"includeAllOption"`
234-
HideFromUI bool `json:"hideFromUI,omitempty"`
235-
}
236-
237-
type MetadataVariableSourceDefinition struct {
238-
VariableSourceType string `json:"variableSourceType"`
239-
Filter string `json:"filter"`
240-
Key string `json:"key"`
241-
}
242-
243-
type CsvVariableSourceDefinition struct {
244-
VariableSourceType string `json:"variableSourceType"`
245-
Values string `json:"values"`
246-
}
247-
248-
type LogQueryVariableSourceDefinition struct {
249-
VariableSourceType string `json:"variableSourceType"`
250-
Query string `json:"query"`
251-
Field string `json:"field"`
252-
}
253-
254-
// Coloring Rule related structs
255-
type ColoringRule struct {
256-
Scope string `json:"scope"`
257-
SingleSeriesAggregateFunction string `json:"singleSeriesAggregateFunction"`
258-
MultipleSeriesAggregateFunction string `json:"multipleSeriesAggregateFunction"`
259-
ColorThresholds []ColorThreshold `json:"colorThresholds"`
260-
}
261-
262-
type ColorThreshold struct {
263-
Color string `json:"color"`
264-
Min float64 `json:"min,omitempty"`
265-
Max float64 `json:"max,omitempty"`
266-
}
267-
268-
type LinkedDashboard struct {
269-
Id string `json:"id"`
270-
RelativePath string `json:"relativePath,omitempty"`
271-
IncludeTimeRange bool `json:"includeTimeRange"`
272-
IncludeVariables bool `json:"includeVariables"`
273-
}

0 commit comments

Comments
 (0)