2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
19 // platform project (RICP).
28 "e2mgr/services/rmrsender"
32 type E2TKeepAliveWorker struct {
34 e2tShutdownManager IE2TShutdownManager
35 e2TInstancesManager IE2TInstancesManager
36 rmrSender *rmrsender.RmrSender
37 config *configuration.Configuration
40 func NewE2TKeepAliveWorker(logger *logger.Logger, rmrSender *rmrsender.RmrSender, e2TInstancesManager IE2TInstancesManager, e2tShutdownManager IE2TShutdownManager, config *configuration.Configuration) E2TKeepAliveWorker {
41 return E2TKeepAliveWorker{
43 e2tShutdownManager: e2tShutdownManager,
44 e2TInstancesManager: e2TInstancesManager,
50 func (h E2TKeepAliveWorker) Execute() {
52 h.logger.Infof("#E2TKeepAliveWorker.Execute - keep alive started")
54 ticker := time.NewTicker(time.Duration(h.config.KeepAliveDelayMs) * time.Millisecond)
56 for _= range ticker.C {
58 h.SendKeepAliveRequest()
59 h.E2TKeepAliveExpired()
63 func (h E2TKeepAliveWorker) E2TKeepAliveExpired() {
65 e2tInstances, err := h.e2TInstancesManager.GetE2TInstancesNoLogs()
67 if err != nil || len(e2tInstances) == 0 {
71 for _, e2tInstance := range e2tInstances {
73 delta := int64(time.Now().UnixNano()) - e2tInstance.KeepAliveTimestamp
74 timestampNanosec := int64(time.Duration(h.config.KeepAliveResponseTimeoutMs) * time.Millisecond)
76 if delta > timestampNanosec {
78 h.logger.Warnf("#E2TKeepAliveWorker.E2TKeepAliveExpired - e2t address: %s time expired, shutdown e2 instance", e2tInstance.Address)
80 h.e2tShutdownManager.Shutdown(e2tInstance)
85 func (h E2TKeepAliveWorker) SendKeepAliveRequest() {
87 request := models.RmrMessage{MsgType: rmrCgo.E2_TERM_KEEP_ALIVE_REQ}
88 h.rmrSender.SendWithoutLogs(&request)