2 * ============LICENSE_START========================================================================
3 * ONAP : tr-069-adapter
4 * =================================================================================================
5 * Copyright (C) 2020 CommScope Inc Intellectual Property.
6 * =================================================================================================
7 * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You
9 * may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14 * either express or implied. See the License for the specific language governing permissions and
15 * limitations under the License.
16 * ===============LICENSE_END=======================================================================
19 package org.commscope.tr069adapter.acs.requestprocessor;
21 import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.*;
23 import java.util.Date;
25 import org.commscope.tr069adapter.acs.common.DeviceInform;
26 import org.commscope.tr069adapter.acs.common.DeviceRPCRequest;
27 import org.commscope.tr069adapter.acs.common.DeviceRPCResponse;
28 import org.commscope.tr069adapter.acs.common.dto.DeviceOperationRequestDetails;
29 import org.commscope.tr069adapter.acs.common.dto.TR069DeviceDetails;
30 import org.commscope.tr069adapter.acs.common.exception.DeviceOperationException;
31 import org.commscope.tr069adapter.acs.common.exception.SessionConcurrentAccessException;
32 import org.commscope.tr069adapter.acs.common.exception.SessionManagerException;
33 import org.commscope.tr069adapter.acs.common.requestprocessor.service.TR069DeviceEventHandler;
34 import org.commscope.tr069adapter.acs.common.response.DeviceInformResponse;
35 import org.commscope.tr069adapter.acs.requestprocessor.dao.DeviceRepository;
36 import org.commscope.tr069adapter.acs.requestprocessor.entity.TR069DeviceEntity;
37 import org.commscope.tr069adapter.acs.requestprocessor.impl.TR069RequestProcessEngine;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
41 import org.springframework.beans.factory.annotation.Autowired;
42 import org.springframework.stereotype.Component;
43 import org.springframework.transaction.annotation.Isolation;
44 import org.springframework.transaction.annotation.Propagation;
45 import org.springframework.transaction.annotation.Transactional;
48 public class TR069DeviceEventHandlerImpl implements TR069DeviceEventHandler {
50 private static final String RETRY_LIMIT_REACHED_AND_FAILING_THE_DEVICE_UNREGISTER_REQUEST =
51 "Retry limit reached and failing the device unregister request";
53 private static final Logger logger = LoggerFactory.getLogger(TR069DeviceEventHandlerImpl.class);
55 private static final String CLIENT_STR = "client";
58 private TR069RequestProcessEngine tr069RequestProcessEngine;
61 private DeviceRepository deviceRepository;
63 public TR069RequestProcessEngine getProcessEngine() {
64 return tr069RequestProcessEngine;
67 public void setProcessEngine(TR069RequestProcessEngine processEngine) {
68 this.tr069RequestProcessEngine = processEngine;
72 @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRES_NEW,
73 timeout = 300, rollbackFor = RuntimeException.class)
74 public void processConnectionRequest(String errorMsg, String deviceId, boolean isSuccess) {
75 TR069DeviceEntity tr069DeviceEntity = deviceRepository.findByDeviceId(deviceId);
78 logger.debug("processConnectionRequest success case");
79 tr069DeviceEntity.setConnStatus(true);
80 tr069DeviceEntity.setLastUpdatedTime(new Date());
82 logger.debug("processConnectionRequest failed case");
83 tr069DeviceEntity.setConnStatus(false);
84 tr069DeviceEntity.setLastFailedAttemptTime(new Date());
86 tr069DeviceEntity.setErrorMsg(errorMsg);
87 deviceRepository.save(tr069DeviceEntity);
91 @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, timeout = 300,
92 rollbackFor = RuntimeException.class)
93 public DeviceInformResponse processDeviceInform(final DeviceInform deviceNotification)
94 throws SessionConcurrentAccessException, InterruptedException {
95 DeviceInformResponse deviceNotificationResponse = null;
97 String deviceId = deviceNotification.getDeviceDetails().getDeviceId();
98 MDC.put(CLIENT_STR, deviceId);
99 deviceNotificationResponse =
100 processDeviceInformWithRetryOnConcurrentAccess(deviceNotification);
102 MDC.remove(CLIENT_STR);
105 return deviceNotificationResponse;
109 @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, timeout = 300,
110 rollbackFor = RuntimeException.class)
111 public DeviceRPCRequest processDeviceRPCResponse(DeviceRPCResponse operationResult)
112 throws SessionConcurrentAccessException, InterruptedException {
113 DeviceRPCRequest deviceRPCRequest = null;
115 String deviceId = operationResult.getDeviceDetails().getDeviceId();
116 MDC.put(CLIENT_STR, deviceId);
117 deviceRPCRequest = processDeviceRPCResponseWithRetryOnConcurrentAccess(operationResult);
119 MDC.remove(CLIENT_STR);
121 return deviceRPCRequest;
125 @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, timeout = 300,
126 rollbackFor = RuntimeException.class)
127 public DeviceRPCRequest processEmptyDeviceRequest(TR069DeviceDetails deviceDetails)
128 throws SessionConcurrentAccessException, InterruptedException {
129 DeviceRPCRequest deviceRPCRequest = null;
131 String deviceId = deviceDetails.getDeviceId();
132 MDC.put(CLIENT_STR, deviceId);
133 deviceRPCRequest = processEmptyDeviceRequestWithRetryOnConcurrentAccess(deviceDetails);
135 MDC.remove(CLIENT_STR);
137 return deviceRPCRequest;
141 @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, timeout = 300,
142 rollbackFor = RuntimeException.class)
143 public DeviceOperationRequestDetails getOpRequestDetailsBySessionId(String sessionId)
144 throws SessionManagerException {
145 return tr069RequestProcessEngine.getOpRequestDetailsBySessionId(sessionId);
149 @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, timeout = 300,
150 rollbackFor = RuntimeException.class)
151 public TR069DeviceDetails getDeviceDetails(String deviceId) throws DeviceOperationException {
152 return tr069RequestProcessEngine.getDeviceDetails(deviceId);
156 * @param deviceNotification
158 * @throws InterruptedException
160 private DeviceInformResponse processDeviceInformWithRetryOnConcurrentAccess(
161 DeviceInform deviceNotification)
162 throws SessionConcurrentAccessException, InterruptedException {
163 logger.debug("Processing Device Inform Event");
164 DeviceInformResponse deviceNotificationResponse = null;
165 for (int i = 0; i < MAX_RETRY_LIMIT; i++) {
167 deviceNotificationResponse =
168 tr069RequestProcessEngine.processDeviceInform(deviceNotification);
169 logger.debug("Successfully processed Device Inform Event");
171 } catch (SessionConcurrentAccessException scae) {
172 if ((i + 1) == MAX_RETRY_LIMIT) {
173 logger.error(RETRY_LIMIT_REACHED_AND_FAILING_THE_DEVICE_UNREGISTER_REQUEST);
176 Long delay = (i == 0) ? DELAY : DELAY * i;
180 return deviceNotificationResponse;
184 * @param operationResult
186 * @throws InterruptedException
189 private DeviceRPCRequest processDeviceRPCResponseWithRetryOnConcurrentAccess(
190 DeviceRPCResponse operationResult)
191 throws SessionConcurrentAccessException, InterruptedException {
192 DeviceRPCRequest deviceRPCRequest = null;
193 logger.debug("Processing Device operation response");
194 for (int i = 0; i < MAX_RETRY_LIMIT; i++) {
196 deviceRPCRequest = tr069RequestProcessEngine.processDeviceRPCResponse(operationResult);
197 logger.debug("Successfully processed Device operation response");
199 } catch (SessionConcurrentAccessException scae) {
200 if ((i + 1) == MAX_RETRY_LIMIT) {
201 logger.error(RETRY_LIMIT_REACHED_AND_FAILING_THE_DEVICE_UNREGISTER_REQUEST);
204 Long delay = (i == 0) ? DELAY : DELAY * i;
208 return deviceRPCRequest;
212 * @param deviceDetails
214 * @throws InterruptedException
217 private DeviceRPCRequest processEmptyDeviceRequestWithRetryOnConcurrentAccess(
218 TR069DeviceDetails deviceDetails)
219 throws SessionConcurrentAccessException, InterruptedException {
220 DeviceRPCRequest deviceRPCRequest = null;
221 logger.debug("Processing Empty request");
222 for (int i = 0; i < MAX_RETRY_LIMIT; i++) {
224 deviceRPCRequest = tr069RequestProcessEngine.processEmptyDeviceRequest(deviceDetails);
225 logger.debug("Successfully processed Empty request");
227 } catch (SessionConcurrentAccessException scae) {
228 if ((i + 1) == MAX_RETRY_LIMIT) {
229 logger.error(RETRY_LIMIT_REACHED_AND_FAILING_THE_DEVICE_UNREGISTER_REQUEST);
232 Long delay = (i == 0) ? DELAY : DELAY * i;
236 return deviceRPCRequest;