ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2019 AT&T Intellectual Property |
| 3 | // Copyright 2019 Nokia |
| 4 | // |
| 5 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | // you may not use this file except in compliance with the License. |
| 7 | // You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, software |
| 12 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | // See the License for the specific language governing permissions and |
| 15 | // limitations under the License. |
nm755n | 15d3982 | 2019-11-28 16:56:00 +0000 | [diff] [blame] | 16 | |
| 17 | // This source code is part of the near-RT RIC (RAN Intelligent Controller) |
| 18 | // platform project (RICP). |
| 19 | |
Amichai | e3623cf | 2019-09-11 16:59:16 +0300 | [diff] [blame] | 20 | package services |
| 21 | |
| 22 | import ( |
| 23 | "e2mgr/configuration" |
| 24 | "e2mgr/logger" |
| 25 | "e2mgr/rNibWriter" |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 26 | "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common" |
Amichai | e3623cf | 2019-09-11 16:59:16 +0300 | [diff] [blame] | 27 | "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" |
| 28 | "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader" |
| 29 | "net" |
| 30 | "time" |
| 31 | ) |
| 32 | |
| 33 | type RNibDataService interface { |
idanshal | dc8932a | 2020-07-14 07:31:02 +0000 | [diff] [blame] | 34 | SaveNodeb(nodebInfo *entities.NodebInfo) error |
Amichai | e3623cf | 2019-09-11 16:59:16 +0300 | [diff] [blame] | 35 | UpdateNodebInfo(nodebInfo *entities.NodebInfo) error |
| 36 | SaveRanLoadInformation(inventoryName string, ranLoadInformation *entities.RanLoadInformation) error |
| 37 | GetNodeb(ranName string) (*entities.NodebInfo, error) |
| 38 | GetListNodebIds() ([]*entities.NbIdentity, error) |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 39 | PingRnib() bool |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 40 | GetE2TInstance(address string) (*entities.E2TInstance, error) |
| 41 | GetE2TInstances(addresses []string) ([]*entities.E2TInstance, error) |
| 42 | GetE2TAddresses() ([]string, error) |
| 43 | SaveE2TInstance(e2tInstance *entities.E2TInstance) error |
| 44 | SaveE2TAddresses(addresses []string) error |
| 45 | GetE2TInstanceNoLogs(address string) (*entities.E2TInstance, error) |
| 46 | GetE2TInstancesNoLogs(addresses []string) ([]*entities.E2TInstance, error) |
| 47 | SaveE2TInstanceNoLogs(e2tInstance *entities.E2TInstance) error |
| 48 | GetE2TAddressesNoLogs() ([]string, error) |
Amichai | f846c59 | 2020-01-08 16:45:07 +0200 | [diff] [blame] | 49 | RemoveE2TInstance(e2tAddress string) error |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 50 | UpdateGnbCells(nodebInfo *entities.NodebInfo, servedNrCells []*entities.ServedNRCell) error |
idanshal | d916e2a | 2020-04-22 15:56:43 +0300 | [diff] [blame] | 51 | RemoveServedNrCells(inventoryName string, servedNrCells []*entities.ServedNRCell) error |
ss412g | a07b859 | 2020-06-16 21:51:33 +0300 | [diff] [blame] | 52 | GetGeneralConfiguration() (*entities.GeneralConfiguration, error) |
| 53 | UpdateNodebInfoOnConnectionStatusInversion(nodebInfo *entities.NodebInfo, event string) error |
| 54 | SaveGeneralConfiguration(config *entities.GeneralConfiguration) error |
Amichai | 7e2e493 | 2020-07-07 15:49:07 +0000 | [diff] [blame] | 55 | RemoveEnb(nodebInfo *entities.NodebInfo) error |
Irina | 5830d4d | 2020-07-08 18:11:04 +0000 | [diff] [blame] | 56 | RemoveServedCells(inventoryName string, servedCells []*entities.ServedCellInfo) error |
| 57 | UpdateEnb(nodebInfo *entities.NodebInfo, servedCells []*entities.ServedCellInfo) error |
idanshal | dc8932a | 2020-07-14 07:31:02 +0000 | [diff] [blame] | 58 | AddNbIdentity(nodeType entities.Node_Type, nbIdentity *entities.NbIdentity) error |
Amichai | 1bf79dd | 2020-07-16 21:15:32 +0000 | [diff] [blame] | 59 | RemoveNbIdentity(nodeType entities.Node_Type, nbIdentity *entities.NbIdentity) error |
Amichai | 7ec48b2 | 2020-07-23 11:28:40 +0000 | [diff] [blame] | 60 | AddEnb(nodebInfo *entities.NodebInfo) error |
Amichai | e3623cf | 2019-09-11 16:59:16 +0300 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | type rNibDataService struct { |
idanshal | dc8932a | 2020-07-14 07:31:02 +0000 | [diff] [blame] | 64 | logger *logger.Logger |
| 65 | rnibReader reader.RNibReader |
| 66 | rnibWriter rNibWriter.RNibWriter |
| 67 | maxAttempts int |
| 68 | retryInterval time.Duration |
Amichai | e3623cf | 2019-09-11 16:59:16 +0300 | [diff] [blame] | 69 | } |
| 70 | |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 71 | func NewRnibDataService(logger *logger.Logger, config *configuration.Configuration, rnibReader reader.RNibReader, rnibWriter rNibWriter.RNibWriter) *rNibDataService { |
Amichai | e3623cf | 2019-09-11 16:59:16 +0300 | [diff] [blame] | 72 | return &rNibDataService{ |
idanshal | dc8932a | 2020-07-14 07:31:02 +0000 | [diff] [blame] | 73 | logger: logger, |
| 74 | rnibReader: rnibReader, |
| 75 | rnibWriter: rnibWriter, |
| 76 | maxAttempts: config.MaxRnibConnectionAttempts, |
| 77 | retryInterval: time.Duration(config.RnibRetryIntervalMs) * time.Millisecond, |
Amichai | e3623cf | 2019-09-11 16:59:16 +0300 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | |
idanshal | dc8932a | 2020-07-14 07:31:02 +0000 | [diff] [blame] | 81 | func (w *rNibDataService) AddNbIdentity(nodeType entities.Node_Type, nbIdentity *entities.NbIdentity) error { |
| 82 | w.logger.Infof("#RnibDataService.AddNbIdentity - nbIdentity: %s", nbIdentity) |
| 83 | |
| 84 | err := w.retry("AddNbIdentity", func() (err error) { |
| 85 | err = w.rnibWriter.AddNbIdentity(nodeType, nbIdentity) |
| 86 | return |
| 87 | }) |
| 88 | |
| 89 | return err |
| 90 | } |
| 91 | |
Amichai | 1bf79dd | 2020-07-16 21:15:32 +0000 | [diff] [blame] | 92 | func (w *rNibDataService) RemoveNbIdentity(nodeType entities.Node_Type, nbIdentity *entities.NbIdentity) error{ |
| 93 | w.logger.Infof("#RnibDataService.RemoveNbIdentity - nbIdentity: %s", nbIdentity) |
| 94 | |
| 95 | err := w.retry("RemoveNbIdentity", func() (err error) { |
| 96 | err = w.rnibWriter.RemoveNbIdentity(nodeType, nbIdentity) |
| 97 | return |
| 98 | }) |
| 99 | |
| 100 | return err |
| 101 | } |
| 102 | |
idanshal | d916e2a | 2020-04-22 15:56:43 +0300 | [diff] [blame] | 103 | func (w *rNibDataService) RemoveServedNrCells(inventoryName string, servedNrCells []*entities.ServedNRCell) error { |
| 104 | err := w.retry("RemoveServedNrCells", func() (err error) { |
| 105 | err = w.rnibWriter.RemoveServedNrCells(inventoryName, servedNrCells) |
| 106 | return |
| 107 | }) |
| 108 | |
| 109 | return err |
| 110 | } |
| 111 | |
Amichai | 7e2e493 | 2020-07-07 15:49:07 +0000 | [diff] [blame] | 112 | func (w *rNibDataService) RemoveEnb(nodebInfo *entities.NodebInfo) error { |
Amichai | c7018fe | 2020-07-09 10:18:52 +0000 | [diff] [blame] | 113 | w.logger.Infof("#RnibDataService.RemoveEnb - nodebInfo: %s", nodebInfo) |
| 114 | |
Amichai | 7e2e493 | 2020-07-07 15:49:07 +0000 | [diff] [blame] | 115 | err := w.retry("RemoveEnb", func() (err error) { |
| 116 | err = w.rnibWriter.RemoveEnb(nodebInfo) |
| 117 | return |
| 118 | }) |
| 119 | |
| 120 | return err |
| 121 | } |
| 122 | |
idanshal | 08bbf91 | 2020-04-20 17:11:33 +0300 | [diff] [blame] | 123 | func (w *rNibDataService) UpdateGnbCells(nodebInfo *entities.NodebInfo, servedNrCells []*entities.ServedNRCell) error { |
| 124 | w.logger.Infof("#RnibDataService.UpdateGnbCells - nodebInfo: %s, servedNrCells: %s", nodebInfo, servedNrCells) |
| 125 | |
| 126 | err := w.retry("UpdateGnbCells", func() (err error) { |
| 127 | err = w.rnibWriter.UpdateGnbCells(nodebInfo, servedNrCells) |
| 128 | return |
| 129 | }) |
| 130 | |
| 131 | return err |
| 132 | } |
| 133 | |
Amichai | e3623cf | 2019-09-11 16:59:16 +0300 | [diff] [blame] | 134 | func (w *rNibDataService) UpdateNodebInfo(nodebInfo *entities.NodebInfo) error { |
| 135 | w.logger.Infof("#RnibDataService.UpdateNodebInfo - nodebInfo: %s", nodebInfo) |
| 136 | |
| 137 | err := w.retry("UpdateNodebInfo", func() (err error) { |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 138 | err = w.rnibWriter.UpdateNodebInfo(nodebInfo) |
Amichai | e3623cf | 2019-09-11 16:59:16 +0300 | [diff] [blame] | 139 | return |
| 140 | }) |
| 141 | |
| 142 | return err |
| 143 | } |
| 144 | |
idanshal | dc8932a | 2020-07-14 07:31:02 +0000 | [diff] [blame] | 145 | func (w *rNibDataService) SaveNodeb(nodebInfo *entities.NodebInfo) error { |
| 146 | w.logger.Infof("#RnibDataService.SaveNodeb - nodebInfo: %s", nodebInfo) |
Amichai | e3623cf | 2019-09-11 16:59:16 +0300 | [diff] [blame] | 147 | |
| 148 | err := w.retry("SaveNodeb", func() (err error) { |
idanshal | dc8932a | 2020-07-14 07:31:02 +0000 | [diff] [blame] | 149 | err = w.rnibWriter.SaveNodeb(nodebInfo) |
Amichai | e3623cf | 2019-09-11 16:59:16 +0300 | [diff] [blame] | 150 | return |
| 151 | }) |
| 152 | |
| 153 | return err |
| 154 | } |
| 155 | |
| 156 | func (w *rNibDataService) SaveRanLoadInformation(inventoryName string, ranLoadInformation *entities.RanLoadInformation) error { |
| 157 | w.logger.Infof("#RnibDataService.SaveRanLoadInformation - inventoryName: %s, ranLoadInformation: %s", inventoryName, ranLoadInformation) |
| 158 | |
| 159 | err := w.retry("SaveRanLoadInformation", func() (err error) { |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 160 | err = w.rnibWriter.SaveRanLoadInformation(inventoryName, ranLoadInformation) |
Amichai | e3623cf | 2019-09-11 16:59:16 +0300 | [diff] [blame] | 161 | return |
| 162 | }) |
| 163 | |
| 164 | return err |
| 165 | } |
| 166 | |
| 167 | func (w *rNibDataService) GetNodeb(ranName string) (*entities.NodebInfo, error) { |
Amichai | e3623cf | 2019-09-11 16:59:16 +0300 | [diff] [blame] | 168 | |
| 169 | var nodeb *entities.NodebInfo = nil |
| 170 | |
| 171 | err := w.retry("GetNodeb", func() (err error) { |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 172 | nodeb, err = w.rnibReader.GetNodeb(ranName) |
Amichai | e3623cf | 2019-09-11 16:59:16 +0300 | [diff] [blame] | 173 | return |
| 174 | }) |
| 175 | |
is005q | 5c95332 | 2020-01-05 16:22:47 +0200 | [diff] [blame] | 176 | if err == nil { |
Amichai | 380b7a2 | 2020-01-14 16:38:06 +0200 | [diff] [blame] | 177 | w.logger.Infof("#RnibDataService.GetNodeb - RAN name: %s, connection status: %s, associated E2T: %s", nodeb.RanName, nodeb.ConnectionStatus, nodeb.AssociatedE2TInstanceAddress) |
is005q | 5c95332 | 2020-01-05 16:22:47 +0200 | [diff] [blame] | 178 | } |
| 179 | |
Amichai | e3623cf | 2019-09-11 16:59:16 +0300 | [diff] [blame] | 180 | return nodeb, err |
| 181 | } |
| 182 | |
| 183 | func (w *rNibDataService) GetListNodebIds() ([]*entities.NbIdentity, error) { |
Amichai | e3623cf | 2019-09-11 16:59:16 +0300 | [diff] [blame] | 184 | var nodeIds []*entities.NbIdentity = nil |
| 185 | |
| 186 | err := w.retry("GetListNodebIds", func() (err error) { |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 187 | nodeIds, err = w.rnibReader.GetListNodebIds() |
Amichai | e3623cf | 2019-09-11 16:59:16 +0300 | [diff] [blame] | 188 | return |
| 189 | }) |
| 190 | |
is005q | 5c95332 | 2020-01-05 16:22:47 +0200 | [diff] [blame] | 191 | if err == nil { |
| 192 | w.logger.Infof("#RnibDataService.GetListNodebIds - RANs count: %d", len(nodeIds)) |
| 193 | } |
| 194 | |
Amichai | e3623cf | 2019-09-11 16:59:16 +0300 | [diff] [blame] | 195 | return nodeIds, err |
| 196 | } |
| 197 | |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 198 | func (w *rNibDataService) GetE2TInstance(address string) (*entities.E2TInstance, error) { |
| 199 | var e2tInstance *entities.E2TInstance = nil |
| 200 | |
| 201 | err := w.retry("GetE2TInstance", func() (err error) { |
| 202 | e2tInstance, err = w.rnibReader.GetE2TInstance(address) |
| 203 | return |
| 204 | }) |
| 205 | |
| 206 | if err == nil { |
| 207 | w.logger.Infof("#RnibDataService.GetE2TInstance - E2T instance address: %s, state: %s, associated RANs count: %d, keep Alive ts: %d", e2tInstance.Address, e2tInstance.State, len(e2tInstance.AssociatedRanList), e2tInstance.KeepAliveTimestamp) |
| 208 | } |
| 209 | |
| 210 | return e2tInstance, err |
| 211 | } |
| 212 | |
| 213 | func (w *rNibDataService) GetE2TInstanceNoLogs(address string) (*entities.E2TInstance, error) { |
| 214 | var e2tInstance *entities.E2TInstance = nil |
| 215 | |
| 216 | err := w.retry("GetE2TInstance", func() (err error) { |
| 217 | e2tInstance, err = w.rnibReader.GetE2TInstance(address) |
| 218 | return |
| 219 | }) |
| 220 | |
| 221 | return e2tInstance, err |
| 222 | } |
| 223 | |
| 224 | func (w *rNibDataService) GetE2TInstances(addresses []string) ([]*entities.E2TInstance, error) { |
| 225 | w.logger.Infof("#RnibDataService.GetE2TInstances - addresses: %s", addresses) |
| 226 | var e2tInstances []*entities.E2TInstance = nil |
| 227 | |
| 228 | err := w.retry("GetE2TInstance", func() (err error) { |
| 229 | e2tInstances, err = w.rnibReader.GetE2TInstances(addresses) |
| 230 | return |
| 231 | }) |
| 232 | |
| 233 | return e2tInstances, err |
| 234 | } |
| 235 | |
| 236 | func (w *rNibDataService) GetE2TInstancesNoLogs(addresses []string) ([]*entities.E2TInstance, error) { |
| 237 | |
| 238 | var e2tInstances []*entities.E2TInstance = nil |
| 239 | |
| 240 | err := w.retry("GetE2TInstance", func() (err error) { |
| 241 | e2tInstances, err = w.rnibReader.GetE2TInstances(addresses) |
| 242 | return |
| 243 | }) |
| 244 | |
| 245 | return e2tInstances, err |
| 246 | } |
| 247 | |
| 248 | func (w *rNibDataService) GetE2TAddresses() ([]string, error) { |
| 249 | |
| 250 | var e2tAddresses []string = nil |
| 251 | |
| 252 | err := w.retry("GetE2TAddresses", func() (err error) { |
| 253 | e2tAddresses, err = w.rnibReader.GetE2TAddresses() |
| 254 | return |
| 255 | }) |
| 256 | |
| 257 | if err == nil { |
| 258 | w.logger.Infof("#RnibDataService.GetE2TAddresses - addresses: %s", e2tAddresses) |
| 259 | } |
| 260 | |
| 261 | return e2tAddresses, err |
| 262 | } |
| 263 | |
| 264 | func (w *rNibDataService) GetE2TAddressesNoLogs() ([]string, error) { |
| 265 | |
| 266 | var e2tAddresses []string = nil |
| 267 | |
| 268 | err := w.retry("GetE2TAddresses", func() (err error) { |
| 269 | e2tAddresses, err = w.rnibReader.GetE2TAddresses() |
| 270 | return |
| 271 | }) |
| 272 | |
| 273 | return e2tAddresses, err |
| 274 | } |
| 275 | |
| 276 | func (w *rNibDataService) SaveE2TInstance(e2tInstance *entities.E2TInstance) error { |
Irina | 4914446 | 2020-04-07 16:37:20 +0300 | [diff] [blame] | 277 | w.logger.Infof("#RnibDataService.SaveE2TInstance - E2T instance address: %s, podName: %s, state: %s, associated RANs count: %d, keep Alive ts: %d", e2tInstance.Address, e2tInstance.PodName, e2tInstance.State, len(e2tInstance.AssociatedRanList), e2tInstance.KeepAliveTimestamp) |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 278 | |
| 279 | return w.SaveE2TInstanceNoLogs(e2tInstance) |
| 280 | } |
| 281 | |
| 282 | func (w *rNibDataService) SaveE2TInstanceNoLogs(e2tInstance *entities.E2TInstance) error { |
| 283 | |
| 284 | err := w.retry("SaveE2TInstance", func() (err error) { |
| 285 | err = w.rnibWriter.SaveE2TInstance(e2tInstance) |
| 286 | return |
| 287 | }) |
| 288 | |
| 289 | return err |
| 290 | } |
| 291 | |
| 292 | func (w *rNibDataService) SaveE2TAddresses(addresses []string) error { |
| 293 | w.logger.Infof("#RnibDataService.SaveE2TAddresses - addresses: %s", addresses) |
| 294 | |
| 295 | err := w.retry("SaveE2TAddresses", func() (err error) { |
| 296 | err = w.rnibWriter.SaveE2TAddresses(addresses) |
| 297 | return |
| 298 | }) |
| 299 | |
| 300 | return err |
| 301 | } |
| 302 | |
Amichai | f846c59 | 2020-01-08 16:45:07 +0200 | [diff] [blame] | 303 | func (w *rNibDataService) RemoveE2TInstance(e2tAddress string) error { |
| 304 | w.logger.Infof("#RnibDataService.RemoveE2TInstance - e2tAddress: %s", e2tAddress) |
| 305 | |
| 306 | err := w.retry("RemoveE2TInstance", func() (err error) { |
| 307 | err = w.rnibWriter.RemoveE2TInstance(e2tAddress) |
| 308 | return |
| 309 | }) |
| 310 | |
| 311 | return err |
| 312 | } |
| 313 | |
ss412g | a07b859 | 2020-06-16 21:51:33 +0300 | [diff] [blame] | 314 | func (w *rNibDataService) GetGeneralConfiguration() (*entities.GeneralConfiguration, error) { |
| 315 | var generalConfiguration *entities.GeneralConfiguration = nil |
| 316 | |
| 317 | err := w.retry("GetGeneralConfiguration", func() (err error) { |
| 318 | generalConfiguration, err = w.rnibReader.GetGeneralConfiguration() |
| 319 | return |
| 320 | }) |
| 321 | |
ss412g | a07b859 | 2020-06-16 21:51:33 +0300 | [diff] [blame] | 322 | return generalConfiguration, err |
| 323 | } |
| 324 | |
| 325 | func (w *rNibDataService) SaveGeneralConfiguration(config *entities.GeneralConfiguration) error { |
ss412g | a07b859 | 2020-06-16 21:51:33 +0300 | [diff] [blame] | 326 | err := w.retry("SaveGeneralConfiguration", func() (err error) { |
| 327 | err = w.rnibWriter.SaveGeneralConfiguration(config) |
| 328 | return |
| 329 | }) |
| 330 | |
| 331 | return err |
| 332 | } |
| 333 | |
Irina | 5830d4d | 2020-07-08 18:11:04 +0000 | [diff] [blame] | 334 | func (w *rNibDataService) RemoveServedCells(inventoryName string, servedCells []*entities.ServedCellInfo) error { |
| 335 | err := w.retry("RemoveServedCells", func() (err error) { |
| 336 | err = w.rnibWriter.RemoveServedCells(inventoryName, servedCells) |
| 337 | return |
| 338 | }) |
| 339 | |
| 340 | return err |
| 341 | } |
| 342 | |
| 343 | func (w *rNibDataService) UpdateEnb(nodebInfo *entities.NodebInfo, servedCells []*entities.ServedCellInfo) error { |
| 344 | err := w.retry("UpdateEnb", func() (err error) { |
| 345 | err = w.rnibWriter.UpdateEnb(nodebInfo, servedCells) |
| 346 | return |
| 347 | }) |
| 348 | |
| 349 | return err |
| 350 | } |
| 351 | |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 352 | func (w *rNibDataService) PingRnib() bool { |
| 353 | err := w.retry("GetListNodebIds", func() (err error) { |
ss412g | efcb452 | 2019-12-02 16:59:19 +0200 | [diff] [blame] | 354 | _, err = w.rnibReader.GetListNodebIds() |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 355 | return |
| 356 | }) |
| 357 | |
| 358 | return !isRnibConnectionError(err) |
| 359 | } |
| 360 | |
ss412g | a07b859 | 2020-06-16 21:51:33 +0300 | [diff] [blame] | 361 | func (w *rNibDataService) UpdateNodebInfoOnConnectionStatusInversion(nodebInfo *entities.NodebInfo, event string) error { |
Amichai | 7e2e493 | 2020-07-07 15:49:07 +0000 | [diff] [blame] | 362 | w.logger.Infof("#RnibDataService.UpdateNodebInfoOnConnectionStatusInversion - event: %s, nodebInfo: %s", event, nodebInfo) |
ss412g | a07b859 | 2020-06-16 21:51:33 +0300 | [diff] [blame] | 363 | |
| 364 | err := w.retry("UpdateNodebInfoOnConnectionStatusInversion", func() (err error) { |
Amichai | 7e2e493 | 2020-07-07 15:49:07 +0000 | [diff] [blame] | 365 | err = w.rnibWriter.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, event) |
ss412g | a07b859 | 2020-06-16 21:51:33 +0300 | [diff] [blame] | 366 | return |
| 367 | }) |
| 368 | |
| 369 | return err |
| 370 | } |
| 371 | |
Amichai | 7ec48b2 | 2020-07-23 11:28:40 +0000 | [diff] [blame] | 372 | func (w *rNibDataService) AddEnb(nodebInfo *entities.NodebInfo) error { |
| 373 | w.logger.Infof("#RnibDataService.AddEnb - nodebInfo: %s", nodebInfo) |
| 374 | |
| 375 | err := w.retry("AddEnb", func() (err error) { |
| 376 | err = w.rnibWriter.AddEnb(nodebInfo) |
| 377 | return |
| 378 | }) |
| 379 | |
| 380 | return err |
| 381 | } |
| 382 | |
Amichai | e3623cf | 2019-09-11 16:59:16 +0300 | [diff] [blame] | 383 | func (w *rNibDataService) retry(rnibFunc string, f func() error) (err error) { |
| 384 | attempts := w.maxAttempts |
| 385 | |
| 386 | for i := 1; ; i++ { |
| 387 | err = f() |
| 388 | if err == nil { |
| 389 | return |
| 390 | } |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 391 | if !isRnibConnectionError(err) { |
Amichai | e3623cf | 2019-09-11 16:59:16 +0300 | [diff] [blame] | 392 | return err |
| 393 | } |
| 394 | if i >= attempts { |
| 395 | w.logger.Errorf("#RnibDataService.retry - after %d attempts of %s, last error: %s", attempts, rnibFunc, err) |
| 396 | return err |
| 397 | } |
| 398 | time.Sleep(w.retryInterval) |
| 399 | |
| 400 | w.logger.Infof("#RnibDataService.retry - retrying %d %s after error: %s", i, rnibFunc, err) |
| 401 | } |
| 402 | } |
| 403 | |
ss412g | de19068 | 2019-10-24 09:29:26 +0300 | [diff] [blame] | 404 | func isRnibConnectionError(err error) bool { |
| 405 | internalErr, ok := err.(*common.InternalError) |
Amichai | e3623cf | 2019-09-11 16:59:16 +0300 | [diff] [blame] | 406 | if !ok { |
| 407 | return false |
| 408 | } |
| 409 | _, ok = internalErr.Err.(*net.OpError) |
| 410 | |
| 411 | return ok |
| 412 | } |