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.cpe.processor;
\r
21 import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.CONNECTION_REQUEST;
\r
22 import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.CONNECTION_RETRY_SLEEP_TIME;
\r
23 import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.CR_TIMEOUT;
\r
24 import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.CR_TIMEOUT_CALLBACK;
\r
25 import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.HTTP_OP_FAILED;
\r
26 import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.MAX_CONNECT_RETRY_COUNT;
\r
27 import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.SEPERATOR;
\r
29 import java.io.IOException;
\r
31 import org.commscope.tr069adapter.acs.common.DeviceRPCResponse;
\r
32 import org.commscope.tr069adapter.acs.common.dto.TR069DeviceDetails;
\r
33 import org.commscope.tr069adapter.acs.common.exception.SessionManagerException;
\r
34 import org.commscope.tr069adapter.acs.common.utils.ErrorCode;
\r
35 import org.commscope.tr069adapter.acs.cpe.utils.DeviceConnector;
\r
36 import org.commscope.tr069adapter.common.timer.TimerException;
\r
37 import org.commscope.tr069adapter.common.timer.TimerServiceManagerAPI;
\r
38 import org.slf4j.Logger;
\r
39 import org.slf4j.LoggerFactory;
\r
40 import org.springframework.beans.factory.annotation.Autowired;
\r
41 import org.springframework.stereotype.Component;
\r
44 public class ConnectionReqEventProcessor {
\r
46 private static final Logger logger = LoggerFactory.getLogger(ConnectionReqEventProcessor.class);
\r
49 private DeviceConnector deviceConnector;
\r
52 private TimerServiceManagerAPI timerServiceManagerAPI;
\r
54 public void initiateConnectionRequest(TR069DeviceDetails tr069DeviceDetails, Boolean isRetry)
\r
55 throws SessionManagerException, IOException {
\r
56 DeviceRPCResponse deviceRPCResponse = null;
\r
58 for (int retryCount = 0; retryCount < MAX_CONNECT_RETRY_COUNT; retryCount++) {
\r
59 logger.info("Initiating connection request on the device. Connection request URL is : {}",
\r
60 tr069DeviceDetails.getConnectionRequestURL());
\r
61 deviceRPCResponse = deviceConnector.requestConnectionHttp(tr069DeviceDetails);
\r
63 if (deviceRPCResponse.getOperationResponse().getStatus() == HTTP_OP_FAILED) {
\r
64 onFailedHTTPGetOperation(deviceRPCResponse);
\r
65 logger.debug("Connection Request Retry attempt - {}", retryCount + 1);
\r
67 if ((retryCount + 1) == MAX_CONNECT_RETRY_COUNT) {
\r
68 SessionManagerException e = new SessionManagerException(
\r
69 ErrorCode.SESSION_INITIATION_FAILED, tr069DeviceDetails.getDeviceId());
\r
70 logger.error(e.getMessage());
\r
74 onSuccessHTTPGetOperation(tr069DeviceDetails, isRetry);
\r
80 private void onFailedHTTPGetOperation(DeviceRPCResponse deviceRPCResponse) {
\r
81 logger.warn("Connection request failed with device, Error: {}",
\r
82 deviceRPCResponse.getFaultString());
\r
83 logger.debug("Waiting for " + CONNECTION_RETRY_SLEEP_TIME + " millisec before retry");
\r
85 Thread.sleep(CONNECTION_RETRY_SLEEP_TIME);
\r
86 } catch (InterruptedException e1) {
\r
87 logger.error("Interrupted exception while waiting for CR retry");
\r
88 Thread.currentThread().interrupt();
\r
92 private void onSuccessHTTPGetOperation(TR069DeviceDetails tr069DeviceDetails, Boolean isRetry) {
\r
94 String timerId = tr069DeviceDetails.getDeviceId() + SEPERATOR + CONNECTION_REQUEST;
\r
95 if (isRetry.booleanValue()) {
\r
96 timerServiceManagerAPI.modifyTimer(timerId, CR_TIMEOUT, tr069DeviceDetails);
\r
98 timerServiceManagerAPI.startTimer(timerId, CR_TIMEOUT_CALLBACK, CR_TIMEOUT,
\r
99 tr069DeviceDetails);
\r
102 "Successfully started the timer task for connection request initiation on device : {}",
\r
103 tr069DeviceDetails.getDeviceId());
\r
104 } catch (TimerException e) {
\r
105 logger.error("Couldn't start the timer task for connection request initiation on device : {}",
\r
106 tr069DeviceDetails.getDeviceId());
\r
110 public DeviceConnector getDeviceConnector() {
\r
111 return deviceConnector;
\r
114 public void setDeviceConnector(DeviceConnector deviceConnector) {
\r
115 this.deviceConnector = deviceConnector;
\r
118 public TimerServiceManagerAPI getTimerServiceManagerAPI() {
\r
119 return timerServiceManagerAPI;
\r
122 public void setTimerServiceManagerAPI(TimerServiceManagerAPI timerServiceManagerAPI) {
\r
123 this.timerServiceManagerAPI = timerServiceManagerAPI;
\r