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.cpe.processor;
21 import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.CONNECTION_REQUEST;
22 import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.CR_TIMEOUT;
23 import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.CR_TIMEOUT_CALLBACK;
24 import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.HTTP_OP_FAILED;
25 import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.SEPERATOR;
27 import java.io.IOException;
29 import org.commscope.tr069adapter.acs.common.DeviceRPCResponse;
30 import org.commscope.tr069adapter.acs.common.dto.TR069DeviceDetails;
31 import org.commscope.tr069adapter.acs.common.exception.SessionManagerException;
32 import org.commscope.tr069adapter.acs.common.requestprocessor.service.TR069DeviceEventHandler;
33 import org.commscope.tr069adapter.acs.common.utils.ErrorCode;
34 import org.commscope.tr069adapter.acs.cpe.utils.DeviceConnector;
35 import org.commscope.tr069adapter.common.timer.TimerException;
36 import org.commscope.tr069adapter.common.timer.TimerServiceManagerAPI;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.stereotype.Component;
43 public class ConnectionReqEventProcessor {
45 private static final Logger logger = LoggerFactory.getLogger(ConnectionReqEventProcessor.class);
48 private DeviceConnector deviceConnector;
51 private TimerServiceManagerAPI timerServiceManagerAPI;
54 TR069DeviceEventHandler tr069EventHandler;
56 public void initiateConnectionRequest(TR069DeviceDetails tr069DeviceDetails, Boolean isRetry)
57 throws SessionManagerException, IOException {
58 DeviceRPCResponse deviceRPCResponse = null;
60 logger.info("Initiating connection request on the device. Connection request URL is : {}",
61 tr069DeviceDetails.getConnectionRequestURL());
62 boolean isConnectionFailed = true;
64 deviceRPCResponse = deviceConnector.requestConnectionHttp(tr069DeviceDetails);
65 } catch (Exception e) {
66 logger.error("Connection Failed with the Device: {}", e.getMessage());
67 isConnectionFailed = false;
70 if (!isConnectionFailed
71 || deviceRPCResponse.getOperationResponse().getStatus() == HTTP_OP_FAILED) {
72 tr069DeviceDetails.setCrRetryCount(tr069DeviceDetails.getCrRetryCount() + 1);
74 if (deviceRPCResponse != null) {
75 faultStr = deviceRPCResponse.getFaultString();
77 logger.warn("Connection request failed with device, Error: {}, on attempt- {}", faultStr,
78 tr069DeviceDetails.getCrRetryCount());
79 if (tr069DeviceDetails.getCrRetryCount() == 1) {
80 logger.error("CONNECT request is failed, not retrying the CR to device");
82 SessionManagerException e = new SessionManagerException(ErrorCode.SESSION_INITIATION_FAILED,
83 tr069DeviceDetails.getDeviceId());
84 logger.error(e.getMessage());
88 onSuccessHTTPGetOperation(tr069DeviceDetails, isRetry);
92 private void onSuccessHTTPGetOperation(TR069DeviceDetails tr069DeviceDetails, Boolean isRetry) {
94 String timerId = tr069DeviceDetails.getDeviceId() + SEPERATOR + CONNECTION_REQUEST;
95 if (isRetry.booleanValue()) {
96 timerServiceManagerAPI.modifyTimer(timerId, CR_TIMEOUT, tr069DeviceDetails);
98 timerServiceManagerAPI.startTimer(timerId, CR_TIMEOUT_CALLBACK, CR_TIMEOUT,
102 "Successfully started the timer task for connection request initiation on device : {}",
103 tr069DeviceDetails.getDeviceId());
104 } catch (TimerException e) {
105 logger.error("Couldn't start the timer task for connection request initiation on device : {}",
106 tr069DeviceDetails.getDeviceId());
110 public DeviceConnector getDeviceConnector() {
111 return deviceConnector;
114 public void setDeviceConnector(DeviceConnector deviceConnector) {
115 this.deviceConnector = deviceConnector;
118 public TimerServiceManagerAPI getTimerServiceManagerAPI() {
119 return timerServiceManagerAPI;
122 public void setTimerServiceManagerAPI(TimerServiceManagerAPI timerServiceManagerAPI) {
123 this.timerServiceManagerAPI = timerServiceManagerAPI;