github.com/interconnectedcloud/qdr-operator@v0.0.0-20210826174505-576d2b33dac7/test/e2e/framework/qdrmanagement/entities/connector.go (about) 1 package entities 2 3 import ( 4 "encoding/json" 5 "github.com/interconnectedcloud/qdr-operator/test/e2e/framework/qdrmanagement/entities/common" 6 "strconv" 7 "strings" 8 ) 9 10 type ConnectionStatusType int 11 12 const ( 13 ConnectionStatusConnecting ConnectionStatusType = iota 14 ConnectionStatusSuccess 15 ConnectionStatusFailed 16 ) 17 18 type Connector struct { 19 EntityCommon 20 Host string `json:"host"` 21 Port string `json:"port"` 22 ProtocolFamily common.SocketAddressFamilyType `json:"protocolFamily,string"` 23 Role common.RoleType `json:"role,string"` 24 Cost int `json:"cost"` 25 SslProfile string `json:"sslProfile"` 26 SaslMechanisms string `json:"saslMechanisms"` 27 AllowRedirect bool `json:"allowRedirect"` 28 MaxFrameSize int `json:"maxFrameSize"` 29 MaxSessionFrames int `json:"maxSessionFrames"` 30 IdleSecondsTimeout int `json:"idleSecondsTimeout"` 31 StripAnnotations StripAnnotationsType `json:"stripAnnotations,string"` 32 LinkCapacity int `json:"linkCapacity"` 33 VerifyHostname bool `json:"verifyHostname"` 34 SaslUsername string `json:"saslUsername"` 35 SaslPassword string `json:"saslPassword"` 36 MessageLoggingComponents string `json:"messageLoggingComponents"` 37 FailoverUrls string `json:"failoverUrls"` 38 ConnectionStatus ConnectionStatusType `json:"connectionStatus,string"` 39 ConnectionMsg string `json:"connectionMsg"` 40 PolicyVhost string `json:"policyVhost"` 41 } 42 43 func (Connector) GetEntityId() string { 44 return "connector" 45 } 46 47 // UnmarshalJSON returns the appropriate ConnectionStatusType for parsed string 48 func (a *ConnectionStatusType) UnmarshalJSON(b []byte) error { 49 var s string 50 51 if len(b) == 0 { 52 return nil 53 } 54 if b[0] != '"' { 55 b = []byte(strconv.Quote(string(b))) 56 } 57 if err := json.Unmarshal(b, &s); err != nil { 58 return err 59 } 60 switch strings.ToLower(s) { 61 case "connecting": 62 *a = ConnectionStatusConnecting 63 case "success": 64 *a = ConnectionStatusSuccess 65 case "failed": 66 *a = ConnectionStatusFailed 67 } 68 return nil 69 } 70 71 // MarshalJSON returns the string representation of ConnectionStatusType 72 func (a ConnectionStatusType) MarshalJSON() ([]byte, error) { 73 var s string 74 switch a { 75 case ConnectionStatusConnecting: 76 s = "CONNECTING" 77 case ConnectionStatusSuccess: 78 s = "SUCCESS" 79 case ConnectionStatusFailed: 80 s = "FAILED" 81 } 82 return json.Marshal(s) 83 }