|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | +// |
| 3 | +// Copyright (C) 2024 Renesas Electronics Corporation. |
| 4 | +// Copyright (C) 2024 EPAM Systems, Inc. |
| 5 | +// |
| 6 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +// you may not use this file except in compliance with the License. |
| 8 | +// You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, software |
| 13 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +// See the License for the specific language governing permissions and |
| 16 | +// limitations under the License. |
| 17 | + |
| 18 | +package alertutils |
| 19 | + |
| 20 | +import ( |
| 21 | + "reflect" |
| 22 | + |
| 23 | + "github.com/aosedge/aos_common/api/cloudprotocol" |
| 24 | +) |
| 25 | + |
| 26 | +// AlertsPayloadEqual compares alerts ignoring timestamp. |
| 27 | +// |
| 28 | +//nolint:funlen |
| 29 | +func AlertsPayloadEqual(alert1, alert2 interface{}) bool { |
| 30 | + switch alert1casted := alert1.(type) { |
| 31 | + case cloudprotocol.SystemAlert: |
| 32 | + alert2casted, ok := alert2.(cloudprotocol.SystemAlert) |
| 33 | + if !ok { |
| 34 | + return false |
| 35 | + } |
| 36 | + |
| 37 | + newAlert1 := alert1casted |
| 38 | + newAlert1.Timestamp = alert2casted.Timestamp |
| 39 | + |
| 40 | + return reflect.DeepEqual(newAlert1, alert2casted) |
| 41 | + |
| 42 | + case cloudprotocol.CoreAlert: |
| 43 | + alert2casted, ok := alert2.(cloudprotocol.CoreAlert) |
| 44 | + if !ok { |
| 45 | + return false |
| 46 | + } |
| 47 | + |
| 48 | + newAlert1 := alert1casted |
| 49 | + newAlert1.Timestamp = alert2casted.Timestamp |
| 50 | + |
| 51 | + return reflect.DeepEqual(newAlert1, alert2casted) |
| 52 | + |
| 53 | + case cloudprotocol.DownloadAlert: |
| 54 | + alert2casted, ok := alert2.(cloudprotocol.DownloadAlert) |
| 55 | + if !ok { |
| 56 | + return false |
| 57 | + } |
| 58 | + |
| 59 | + newAlert1 := alert1casted |
| 60 | + newAlert1.Timestamp = alert2casted.Timestamp |
| 61 | + |
| 62 | + return reflect.DeepEqual(newAlert1, alert2casted) |
| 63 | + |
| 64 | + case cloudprotocol.SystemQuotaAlert: |
| 65 | + alert2casted, ok := alert2.(cloudprotocol.SystemQuotaAlert) |
| 66 | + if !ok { |
| 67 | + return false |
| 68 | + } |
| 69 | + |
| 70 | + newAlert1 := alert1casted |
| 71 | + newAlert1.Timestamp = alert2casted.Timestamp |
| 72 | + |
| 73 | + return reflect.DeepEqual(newAlert1, alert2casted) |
| 74 | + |
| 75 | + case cloudprotocol.InstanceQuotaAlert: |
| 76 | + alert2casted, ok := alert2.(cloudprotocol.InstanceQuotaAlert) |
| 77 | + if !ok { |
| 78 | + return false |
| 79 | + } |
| 80 | + |
| 81 | + newAlert1 := alert1casted |
| 82 | + newAlert1.Timestamp = alert2casted.Timestamp |
| 83 | + |
| 84 | + return reflect.DeepEqual(newAlert1, alert2casted) |
| 85 | + |
| 86 | + case cloudprotocol.DeviceAllocateAlert: |
| 87 | + alert2casted, ok := alert2.(cloudprotocol.DeviceAllocateAlert) |
| 88 | + if !ok { |
| 89 | + return false |
| 90 | + } |
| 91 | + |
| 92 | + newAlert1 := alert1casted |
| 93 | + newAlert1.Timestamp = alert2casted.Timestamp |
| 94 | + |
| 95 | + return reflect.DeepEqual(newAlert1, alert2casted) |
| 96 | + |
| 97 | + case cloudprotocol.ResourceValidateAlert: |
| 98 | + alert2casted, ok := alert2.(cloudprotocol.ResourceValidateAlert) |
| 99 | + if !ok { |
| 100 | + return false |
| 101 | + } |
| 102 | + |
| 103 | + newAlert1 := alert1casted |
| 104 | + newAlert1.Timestamp = alert2casted.Timestamp |
| 105 | + |
| 106 | + return reflect.DeepEqual(newAlert1, alert2casted) |
| 107 | + |
| 108 | + case cloudprotocol.ServiceInstanceAlert: |
| 109 | + alert2casted, ok := alert2.(cloudprotocol.ServiceInstanceAlert) |
| 110 | + if !ok { |
| 111 | + return false |
| 112 | + } |
| 113 | + |
| 114 | + newAlert1 := alert1casted |
| 115 | + newAlert1.Timestamp = alert2casted.Timestamp |
| 116 | + |
| 117 | + return reflect.DeepEqual(newAlert1, alert2casted) |
| 118 | + } |
| 119 | + |
| 120 | + return false |
| 121 | +} |
0 commit comments