-
Notifications
You must be signed in to change notification settings - Fork 38
/
model_custommonitoringsignal.go
101 lines (83 loc) · 3.28 KB
/
model_custommonitoringsignal.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
package schedule
import (
"encoding/json"
"fmt"
)
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See NOTICE.txt in the project root for license information.
var _ MonitoringSignalBase = CustomMonitoringSignal{}
type CustomMonitoringSignal struct {
ComponentId string `json:"componentId"`
InputAssets *map[string]MonitoringInputDataBase `json:"inputAssets,omitempty"`
Inputs *map[string]JobInput `json:"inputs,omitempty"`
MetricThresholds []CustomMetricThreshold `json:"metricThresholds"`
// Fields inherited from MonitoringSignalBase
NotificationTypes *[]MonitoringNotificationType `json:"notificationTypes,omitempty"`
Properties *map[string]string `json:"properties,omitempty"`
}
var _ json.Marshaler = CustomMonitoringSignal{}
func (s CustomMonitoringSignal) MarshalJSON() ([]byte, error) {
type wrapper CustomMonitoringSignal
wrapped := wrapper(s)
encoded, err := json.Marshal(wrapped)
if err != nil {
return nil, fmt.Errorf("marshaling CustomMonitoringSignal: %+v", err)
}
var decoded map[string]interface{}
if err := json.Unmarshal(encoded, &decoded); err != nil {
return nil, fmt.Errorf("unmarshaling CustomMonitoringSignal: %+v", err)
}
decoded["signalType"] = "Custom"
encoded, err = json.Marshal(decoded)
if err != nil {
return nil, fmt.Errorf("re-marshaling CustomMonitoringSignal: %+v", err)
}
return encoded, nil
}
var _ json.Unmarshaler = &CustomMonitoringSignal{}
func (s *CustomMonitoringSignal) UnmarshalJSON(bytes []byte) error {
type alias CustomMonitoringSignal
var decoded alias
if err := json.Unmarshal(bytes, &decoded); err != nil {
return fmt.Errorf("unmarshaling into CustomMonitoringSignal: %+v", err)
}
s.ComponentId = decoded.ComponentId
s.MetricThresholds = decoded.MetricThresholds
s.NotificationTypes = decoded.NotificationTypes
s.Properties = decoded.Properties
var temp map[string]json.RawMessage
if err := json.Unmarshal(bytes, &temp); err != nil {
return fmt.Errorf("unmarshaling CustomMonitoringSignal into map[string]json.RawMessage: %+v", err)
}
if v, ok := temp["inputAssets"]; ok {
var dictionaryTemp map[string]json.RawMessage
if err := json.Unmarshal(v, &dictionaryTemp); err != nil {
return fmt.Errorf("unmarshaling InputAssets into dictionary map[string]json.RawMessage: %+v", err)
}
output := make(map[string]MonitoringInputDataBase)
for key, val := range dictionaryTemp {
impl, err := unmarshalMonitoringInputDataBaseImplementation(val)
if err != nil {
return fmt.Errorf("unmarshaling key %q field 'InputAssets' for 'CustomMonitoringSignal': %+v", key, err)
}
output[key] = impl
}
s.InputAssets = &output
}
if v, ok := temp["inputs"]; ok {
var dictionaryTemp map[string]json.RawMessage
if err := json.Unmarshal(v, &dictionaryTemp); err != nil {
return fmt.Errorf("unmarshaling Inputs into dictionary map[string]json.RawMessage: %+v", err)
}
output := make(map[string]JobInput)
for key, val := range dictionaryTemp {
impl, err := unmarshalJobInputImplementation(val)
if err != nil {
return fmt.Errorf("unmarshaling key %q field 'Inputs' for 'CustomMonitoringSignal': %+v", key, err)
}
output[key] = impl
}
s.Inputs = &output
}
return nil
}