-/*\r
- * ============LICENSE_START========================================================================\r
- * ONAP : tr-069-adapter\r
- * =================================================================================================\r
- * Copyright (C) 2020 CommScope Inc Intellectual Property.\r
- * =================================================================================================\r
- * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,\r
- * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You\r
- * may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,\r
- * either express or implied. See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ===============LICENSE_END=======================================================================\r
- */\r
-\r
-package org.commscope.tr069adapter.acs.cpe.processor;\r
-\r
-import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.CONNECTION_REQUEST;\r
-import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.CONNECTION_RETRY_SLEEP_TIME;\r
-import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.CR_TIMEOUT;\r
-import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.CR_TIMEOUT_CALLBACK;\r
-import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.HTTP_OP_FAILED;\r
-import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.MAX_CONNECT_RETRY_COUNT;\r
-import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.SEPERATOR;\r
-\r
-import java.io.IOException;\r
-\r
-import org.commscope.tr069adapter.acs.common.DeviceRPCResponse;\r
-import org.commscope.tr069adapter.acs.common.dto.TR069DeviceDetails;\r
-import org.commscope.tr069adapter.acs.common.exception.SessionManagerException;\r
-import org.commscope.tr069adapter.acs.common.utils.ErrorCode;\r
-import org.commscope.tr069adapter.acs.cpe.utils.DeviceConnector;\r
-import org.commscope.tr069adapter.common.timer.TimerException;\r
-import org.commscope.tr069adapter.common.timer.TimerServiceManagerAPI;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-import org.springframework.beans.factory.annotation.Autowired;\r
-import org.springframework.stereotype.Component;\r
-\r
-@Component\r
-public class ConnectionReqEventProcessor {\r
-\r
- private static final Logger logger = LoggerFactory.getLogger(ConnectionReqEventProcessor.class);\r
-\r
- @Autowired\r
- private DeviceConnector deviceConnector;\r
-\r
- @Autowired\r
- private TimerServiceManagerAPI timerServiceManagerAPI;\r
-\r
- public void initiateConnectionRequest(TR069DeviceDetails tr069DeviceDetails, Boolean isRetry)\r
- throws SessionManagerException, IOException {\r
- DeviceRPCResponse deviceRPCResponse = null;\r
-\r
- for (int retryCount = 0; retryCount < MAX_CONNECT_RETRY_COUNT; retryCount++) {\r
- logger.info("Initiating connection request on the device. Connection request URL is : {}",\r
- tr069DeviceDetails.getConnectionRequestURL());\r
- deviceRPCResponse = deviceConnector.requestConnectionHttp(tr069DeviceDetails);\r
-\r
- if (deviceRPCResponse.getOperationResponse().getStatus() == HTTP_OP_FAILED) {\r
- onFailedHTTPGetOperation(deviceRPCResponse);\r
- logger.debug("Connection Request Retry attempt - {}", retryCount + 1);\r
-\r
- if ((retryCount + 1) == MAX_CONNECT_RETRY_COUNT) {\r
- SessionManagerException e = new SessionManagerException(\r
- ErrorCode.SESSION_INITIATION_FAILED, tr069DeviceDetails.getDeviceId());\r
- logger.error(e.getMessage());\r
- throw e;\r
- }\r
- } else {\r
- onSuccessHTTPGetOperation(tr069DeviceDetails, isRetry);\r
- break;\r
- }\r
- }\r
- }\r
-\r
- private void onFailedHTTPGetOperation(DeviceRPCResponse deviceRPCResponse) {\r
- logger.warn("Connection request failed with device, Error: {}",\r
- deviceRPCResponse.getFaultString());\r
- logger.debug("Waiting for " + CONNECTION_RETRY_SLEEP_TIME + " millisec before retry");\r
- try {\r
- Thread.sleep(CONNECTION_RETRY_SLEEP_TIME);\r
- } catch (InterruptedException e1) {\r
- logger.error("Interrupted exception while waiting for CR retry");\r
- Thread.currentThread().interrupt();\r
- }\r
- }\r
-\r
- private void onSuccessHTTPGetOperation(TR069DeviceDetails tr069DeviceDetails, Boolean isRetry) {\r
- try {\r
- String timerId = tr069DeviceDetails.getDeviceId() + SEPERATOR + CONNECTION_REQUEST;\r
- if (isRetry.booleanValue()) {\r
- timerServiceManagerAPI.modifyTimer(timerId, CR_TIMEOUT, tr069DeviceDetails);\r
- } else {\r
- timerServiceManagerAPI.startTimer(timerId, CR_TIMEOUT_CALLBACK, CR_TIMEOUT,\r
- tr069DeviceDetails);\r
- }\r
- logger.debug(\r
- "Successfully started the timer task for connection request initiation on device : {}",\r
- tr069DeviceDetails.getDeviceId());\r
- } catch (TimerException e) {\r
- logger.error("Couldn't start the timer task for connection request initiation on device : {}",\r
- tr069DeviceDetails.getDeviceId());\r
- }\r
- }\r
-\r
- public DeviceConnector getDeviceConnector() {\r
- return deviceConnector;\r
- }\r
-\r
- public void setDeviceConnector(DeviceConnector deviceConnector) {\r
- this.deviceConnector = deviceConnector;\r
- }\r
-\r
- public TimerServiceManagerAPI getTimerServiceManagerAPI() {\r
- return timerServiceManagerAPI;\r
- }\r
-\r
- public void setTimerServiceManagerAPI(TimerServiceManagerAPI timerServiceManagerAPI) {\r
- this.timerServiceManagerAPI = timerServiceManagerAPI;\r
- }\r
-\r
-}\r
+/*
+ * ============LICENSE_START========================================================================
+ * ONAP : tr-069-adapter
+ * =================================================================================================
+ * Copyright (C) 2020 CommScope Inc Intellectual Property.
+ * =================================================================================================
+ * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You
+ * may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ===============LICENSE_END=======================================================================
+ */
+
+package org.commscope.tr069adapter.acs.cpe.processor;
+
+import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.CONNECTION_REQUEST;
+import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.CR_TIMEOUT;
+import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.CR_TIMEOUT_CALLBACK;
+import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.HTTP_OP_FAILED;
+import static org.commscope.tr069adapter.acs.common.utils.AcsConstants.SEPERATOR;
+
+import java.io.IOException;
+
+import org.commscope.tr069adapter.acs.common.DeviceRPCResponse;
+import org.commscope.tr069adapter.acs.common.dto.TR069DeviceDetails;
+import org.commscope.tr069adapter.acs.common.exception.SessionManagerException;
+import org.commscope.tr069adapter.acs.common.requestprocessor.service.TR069DeviceEventHandler;
+import org.commscope.tr069adapter.acs.common.utils.ErrorCode;
+import org.commscope.tr069adapter.acs.cpe.utils.DeviceConnector;
+import org.commscope.tr069adapter.common.timer.TimerException;
+import org.commscope.tr069adapter.common.timer.TimerServiceManagerAPI;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class ConnectionReqEventProcessor {
+
+ private static final Logger logger = LoggerFactory.getLogger(ConnectionReqEventProcessor.class);
+
+ @Autowired
+ private DeviceConnector deviceConnector;
+
+ @Autowired
+ private TimerServiceManagerAPI timerServiceManagerAPI;
+
+ @Autowired
+ TR069DeviceEventHandler tr069EventHandler;
+
+ public void initiateConnectionRequest(TR069DeviceDetails tr069DeviceDetails, Boolean isRetry)
+ throws SessionManagerException, IOException {
+ DeviceRPCResponse deviceRPCResponse = null;
+
+ logger.info("Initiating connection request on the device. Connection request URL is : {}",
+ tr069DeviceDetails.getConnectionRequestURL());
+ boolean isConnectionFailed = true;
+ try {
+ deviceRPCResponse = deviceConnector.requestConnectionHttp(tr069DeviceDetails);
+ } catch (Exception e) {
+ logger.error("Connection Failed with the Device: {}", e.getMessage());
+ isConnectionFailed = false;
+ }
+
+ if (!isConnectionFailed
+ || deviceRPCResponse.getOperationResponse().getStatus() == HTTP_OP_FAILED) {
+ tr069DeviceDetails.setCrRetryCount(tr069DeviceDetails.getCrRetryCount() + 1);
+ String faultStr = "";
+ if (deviceRPCResponse != null) {
+ faultStr = deviceRPCResponse.getFaultString();
+ }
+ logger.warn("Connection request failed with device, Error: {}, on attempt- {}", faultStr,
+ tr069DeviceDetails.getCrRetryCount());
+ if (tr069DeviceDetails.getCrRetryCount() == 1) {
+ logger.error("CONNECT request is failed, not retrying the CR to device");
+ } else {
+ SessionManagerException e = new SessionManagerException(ErrorCode.SESSION_INITIATION_FAILED,
+ tr069DeviceDetails.getDeviceId());
+ logger.error(e.getMessage());
+ throw e;
+ }
+ } else {
+ onSuccessHTTPGetOperation(tr069DeviceDetails, isRetry);
+ }
+ }
+
+ private void onSuccessHTTPGetOperation(TR069DeviceDetails tr069DeviceDetails, Boolean isRetry) {
+ try {
+ String timerId = tr069DeviceDetails.getDeviceId() + SEPERATOR + CONNECTION_REQUEST;
+ if (isRetry.booleanValue()) {
+ timerServiceManagerAPI.modifyTimer(timerId, CR_TIMEOUT, tr069DeviceDetails);
+ } else {
+ timerServiceManagerAPI.startTimer(timerId, CR_TIMEOUT_CALLBACK, CR_TIMEOUT,
+ tr069DeviceDetails);
+ }
+ logger.debug(
+ "Successfully started the timer task for connection request initiation on device : {}",
+ tr069DeviceDetails.getDeviceId());
+ } catch (TimerException e) {
+ logger.error("Couldn't start the timer task for connection request initiation on device : {}",
+ tr069DeviceDetails.getDeviceId());
+ }
+ }
+
+ public DeviceConnector getDeviceConnector() {
+ return deviceConnector;
+ }
+
+ public void setDeviceConnector(DeviceConnector deviceConnector) {
+ this.deviceConnector = deviceConnector;
+ }
+
+ public TimerServiceManagerAPI getTimerServiceManagerAPI() {
+ return timerServiceManagerAPI;
+ }
+
+ public void setTimerServiceManagerAPI(TimerServiceManagerAPI timerServiceManagerAPI) {
+ this.timerServiceManagerAPI = timerServiceManagerAPI;
+ }
+
+}