--- /dev/null
+/*\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.netconf.server;\r
+\r
+import java.util.List;\r
+\r
+import org.commscope.tr069adapter.netconf.entity.NetConfServerDetailsEntity;\r
+import org.commscope.tr069adapter.netconf.error.RetryFailedException;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.retry.annotation.Backoff;\r
+import org.springframework.retry.annotation.Recover;\r
+import org.springframework.retry.annotation.Retryable;\r
+import org.springframework.stereotype.Service;\r
+\r
+@Service\r
+public class RestartNetconfServerHandler {\r
+\r
+ private static final Logger logger = LoggerFactory.getLogger(RestartNetconfServerHandler.class);\r
+\r
+ @Autowired\r
+ NetConfServerManagerImpl manager;\r
+\r
+ @Retryable(value = {RetryFailedException.class}, maxAttempts = 100,\r
+ backoff = @Backoff(delay = 15000))\r
+ public void restart(List<NetConfServerDetailsEntity> serverDetailsList)\r
+ throws RetryFailedException {\r
+ try {\r
+ // restart netconf servers\r
+ manager.restartServersOnStartup(serverDetailsList);\r
+ } catch (Exception e) {\r
+ logger.error("Retry to netconf servers has is failed. {}", e.toString());\r
+ throw new RetryFailedException(e);\r
+ }\r
+\r
+ if (!serverDetailsList.isEmpty()) {\r
+ logger.error("Failed to start some of netconf servers. Retrying starting servers : {}",\r
+ serverDetailsList);\r
+ throw new RetryFailedException(\r
+ "Failed to start some of netconf servers. server list : " + serverDetailsList);\r
+ }\r
+ logger.debug("Successfully started all failed netconf servers.");\r
+ }\r
+\r
+ @Recover\r
+ public void recover(List<NetConfServerDetailsEntity> serverDetailsList) {\r
+ logger.debug("Retrying starting failed netconf servers.");\r
+ try {\r
+ restart(serverDetailsList);\r
+ } catch (RetryFailedException e) {\r
+ logger.error("Failed to start failed netconf servers. {}", e.toString());\r
+ }\r
+ }\r
+}\r