2 * ============LICENSE_START========================================================================
\r
3 * ONAP : tr-069-adapter
\r
4 * =================================================================================================
\r
5 * Copyright (C) 2020 CommScope Inc Intellectual Property.
\r
6 * =================================================================================================
\r
7 * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,
\r
8 * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You
\r
9 * may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
\r
14 * either express or implied. See the License for the specific language governing permissions and
\r
15 * limitations under the License.
\r
16 * ===============LICENSE_END=======================================================================
\r
19 package org.commscope.tr069adapter.acs.requestprocessor;
\r
21 import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.*;
\r
23 import org.commscope.tr069adapter.acs.common.DeviceInform;
\r
24 import org.commscope.tr069adapter.acs.common.DeviceRPCRequest;
\r
25 import org.commscope.tr069adapter.acs.common.DeviceRPCResponse;
\r
26 import org.commscope.tr069adapter.acs.common.dto.DeviceOperationRequestDetails;
\r
27 import org.commscope.tr069adapter.acs.common.dto.TR069DeviceDetails;
\r
28 import org.commscope.tr069adapter.acs.common.exception.DeviceOperationException;
\r
29 import org.commscope.tr069adapter.acs.common.exception.SessionConcurrentAccessException;
\r
30 import org.commscope.tr069adapter.acs.common.exception.SessionManagerException;
\r
31 import org.commscope.tr069adapter.acs.common.requestprocessor.service.TR069DeviceEventHandler;
\r
32 import org.commscope.tr069adapter.acs.common.response.DeviceInformResponse;
\r
33 import org.commscope.tr069adapter.acs.requestprocessor.impl.TR069RequestProcessEngine;
\r
34 import org.slf4j.Logger;
\r
35 import org.slf4j.LoggerFactory;
\r
36 import org.slf4j.MDC;
\r
37 import org.springframework.beans.factory.annotation.Autowired;
\r
38 import org.springframework.stereotype.Component;
\r
39 import org.springframework.transaction.annotation.Isolation;
\r
40 import org.springframework.transaction.annotation.Propagation;
\r
41 import org.springframework.transaction.annotation.Transactional;
\r
44 public class TR069DeviceEventHandlerImpl implements TR069DeviceEventHandler {
\r
46 private static final String RETRY_LIMIT_REACHED_AND_FAILING_THE_DEVICE_UNREGISTER_REQUEST =
\r
47 "Retry limit reached and failing the device unregister request";
\r
49 private static final Logger logger = LoggerFactory.getLogger(TR069DeviceEventHandlerImpl.class);
\r
51 private static final String CLIENT_STR = "client";
\r
54 private TR069RequestProcessEngine tr069RequestProcessEngine;
\r
56 public TR069RequestProcessEngine getProcessEngine() {
\r
57 return tr069RequestProcessEngine;
\r
60 public void setProcessEngine(TR069RequestProcessEngine processEngine) {
\r
61 this.tr069RequestProcessEngine = processEngine;
\r
65 @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, timeout = 300,
\r
66 rollbackFor = RuntimeException.class)
\r
67 public DeviceInformResponse processDeviceInform(final DeviceInform deviceNotification)
\r
69 DeviceInformResponse deviceNotificationResponse = null;
\r
71 String deviceId = deviceNotification.getDeviceDetails().getDeviceId();
\r
72 MDC.put(CLIENT_STR, deviceId);
\r
73 deviceNotificationResponse =
\r
74 processDeviceInformWithRetryOnConcurrentAccess(deviceNotification);
\r
76 MDC.remove(CLIENT_STR);
\r
79 return deviceNotificationResponse;
\r
83 @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, timeout = 300,
\r
84 rollbackFor = RuntimeException.class)
\r
85 public DeviceRPCRequest processDeviceRPCResponse(DeviceRPCResponse operationResult)
\r
87 DeviceRPCRequest deviceRPCRequest = null;
\r
89 String deviceId = operationResult.getDeviceDetails().getDeviceId();
\r
90 MDC.put(CLIENT_STR, deviceId);
\r
91 deviceRPCRequest = processDeviceRPCResponseWithRetryOnConcurrentAccess(operationResult);
\r
93 MDC.remove(CLIENT_STR);
\r
95 return deviceRPCRequest;
\r
99 @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, timeout = 300,
\r
100 rollbackFor = RuntimeException.class)
\r
101 public DeviceRPCRequest processEmptyDeviceRequest(TR069DeviceDetails deviceDetails)
\r
103 DeviceRPCRequest deviceRPCRequest = null;
\r
105 String deviceId = deviceDetails.getDeviceId();
\r
106 MDC.put(CLIENT_STR, deviceId);
\r
107 deviceRPCRequest = processEmptyDeviceRequestWithRetryOnConcurrentAccess(deviceDetails);
\r
109 MDC.remove(CLIENT_STR);
\r
111 return deviceRPCRequest;
\r
115 @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, timeout = 300,
\r
116 rollbackFor = RuntimeException.class)
\r
117 public DeviceOperationRequestDetails getOpRequestDetailsBySessionId(String sessionId)
\r
118 throws SessionManagerException {
\r
119 return tr069RequestProcessEngine.getOpRequestDetailsBySessionId(sessionId);
\r
123 @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, timeout = 300,
\r
124 rollbackFor = RuntimeException.class)
\r
125 public TR069DeviceDetails getDeviceDetails(String deviceId) throws DeviceOperationException {
\r
126 return tr069RequestProcessEngine.getDeviceDetails(deviceId);
\r
130 * @param deviceNotification
\r
132 * @throws InterruptedException
\r
134 private DeviceInformResponse processDeviceInformWithRetryOnConcurrentAccess(
\r
135 DeviceInform deviceNotification)
\r
136 throws SessionConcurrentAccessException, InterruptedException {
\r
137 logger.debug("Processing Device Inform Event");
\r
138 DeviceInformResponse deviceNotificationResponse = null;
\r
139 for (int i = 0; i < MAX_RETRY_LIMIT; i++) {
\r
141 deviceNotificationResponse =
\r
142 tr069RequestProcessEngine.processDeviceInform(deviceNotification);
\r
143 logger.debug("Successfully processed Device Inform Event");
\r
145 } catch (SessionConcurrentAccessException scae) {
\r
146 if ((i + 1) == MAX_RETRY_LIMIT) {
\r
147 logger.error(RETRY_LIMIT_REACHED_AND_FAILING_THE_DEVICE_UNREGISTER_REQUEST);
\r
150 Long delay = (i == 0) ? DELAY : DELAY * i;
\r
151 Thread.sleep(delay);
\r
154 return deviceNotificationResponse;
\r
158 * @param operationResult
\r
160 * @throws InterruptedException
\r
161 * @throws Exception
\r
163 private DeviceRPCRequest processDeviceRPCResponseWithRetryOnConcurrentAccess(
\r
164 DeviceRPCResponse operationResult)
\r
165 throws SessionConcurrentAccessException, InterruptedException {
\r
166 DeviceRPCRequest deviceRPCRequest = null;
\r
167 logger.debug("Processing Device operation response");
\r
168 for (int i = 0; i < MAX_RETRY_LIMIT; i++) {
\r
170 deviceRPCRequest = tr069RequestProcessEngine.processDeviceRPCResponse(operationResult);
\r
171 logger.debug("Successfully processed Device operation response");
\r
173 } catch (SessionConcurrentAccessException scae) {
\r
174 if ((i + 1) == MAX_RETRY_LIMIT) {
\r
175 logger.error(RETRY_LIMIT_REACHED_AND_FAILING_THE_DEVICE_UNREGISTER_REQUEST);
\r
178 Long delay = (i == 0) ? DELAY : DELAY * i;
\r
179 Thread.sleep(delay);
\r
182 return deviceRPCRequest;
\r
186 * @param deviceDetails
\r
188 * @throws InterruptedException
\r
189 * @throws Exception
\r
191 private DeviceRPCRequest processEmptyDeviceRequestWithRetryOnConcurrentAccess(
\r
192 TR069DeviceDetails deviceDetails)
\r
193 throws SessionConcurrentAccessException, InterruptedException {
\r
194 DeviceRPCRequest deviceRPCRequest = null;
\r
195 logger.debug("Processing Empty request");
\r
196 for (int i = 0; i < MAX_RETRY_LIMIT; i++) {
\r
198 deviceRPCRequest = tr069RequestProcessEngine.processEmptyDeviceRequest(deviceDetails);
\r
199 logger.debug("Successfully processed Empty request");
\r
201 } catch (SessionConcurrentAccessException scae) {
\r
202 if ((i + 1) == MAX_RETRY_LIMIT) {
\r
203 logger.error(RETRY_LIMIT_REACHED_AND_FAILING_THE_DEVICE_UNREGISTER_REQUEST);
\r
206 Long delay = (i == 0) ? DELAY : DELAY * i;
\r
207 Thread.sleep(delay);
\r
210 return deviceRPCRequest;
\r