Development of NETCONF RPCs for tr-069 adapter to
[oam/tr069-adapter.git] / netconf-server / src / main / java / org / commscope / tr069adapter / netconf / boot / NetConfServiceBooter.java
index 9614865..f051dd6 100644 (file)
-/*\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.boot;\r
-\r
-import java.util.Arrays;\r
-import javax.jms.ConnectionFactory;\r
-import org.apache.activemq.ActiveMQConnectionFactory;\r
-import org.apache.activemq.RedeliveryPolicy;\r
-import org.apache.activemq.broker.BrokerService;\r
-import org.apache.activemq.broker.region.policy.RedeliveryPolicyMap;\r
-import org.apache.activemq.command.ActiveMQQueue;\r
-import org.commscope.tr069adapter.netconf.server.NetConfServerManagerImpl;\r
-import org.commscope.tr069adapter.netconf.server.utils.NetConfServerConstants;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-import org.springframework.boot.SpringApplication;\r
-import org.springframework.boot.autoconfigure.SpringBootApplication;\r
-import org.springframework.boot.autoconfigure.domain.EntityScan;\r
-import org.springframework.boot.autoconfigure.jms.DefaultJmsListenerContainerFactoryConfigurer;\r
-import org.springframework.context.ApplicationContext;\r
-import org.springframework.context.annotation.Bean;\r
-import org.springframework.context.annotation.ComponentScan;\r
-import org.springframework.data.jpa.repository.config.EnableJpaRepositories;\r
-import org.springframework.jms.annotation.EnableJms;\r
-import org.springframework.jms.config.DefaultJmsListenerContainerFactory;\r
-import org.springframework.jms.config.JmsListenerContainerFactory;\r
-import org.springframework.jms.listener.MessageListenerContainer;\r
-import org.springframework.jms.support.converter.MappingJackson2MessageConverter;\r
-import org.springframework.jms.support.converter.MessageConverter;\r
-import org.springframework.jms.support.converter.MessageType;\r
-import org.springframework.retry.annotation.EnableRetry;\r
-\r
-@EnableJms\r
-@SpringBootApplication\r
-@ComponentScan({"org.commscope.tr069adapter.netconf", "org.opendaylight.netconf.test",\r
-    "org.commscope.tr069adapter.common"})\r
-@EnableJpaRepositories("org.commscope.tr069adapter.netconf.dao")\r
-@EntityScan("org.commscope.tr069adapter.netconf.entity")\r
-@EnableRetry\r
-public class NetConfServiceBooter {\r
-\r
-  private static final Logger LOG = LoggerFactory.getLogger(NetConfServiceBooter.class);\r
-\r
-  private static ApplicationContext appContext;\r
-\r
-  public static void main(String[] args) {\r
-    if (args != null)\r
-      appContext = SpringApplication.run(NetConfServiceBooter.class, args);\r
-    NetConfServerManagerImpl serverManager =\r
-        NetConfServiceBooter.getApplicationContext().getBean(NetConfServerManagerImpl.class);\r
-    boolean isSchemaLoaded = serverManager.loadSchemas();\r
-    if (!isSchemaLoaded) {\r
-      LOG.error("Loading the schema failed while starting the container");\r
-      System.exit(1);\r
-    }\r
-    serverManager.restartServers();\r
-  }\r
-\r
-  public static ApplicationContext getApplicationContext() {\r
-    return appContext;\r
-  }\r
-\r
-  /*\r
-   * JMS Configuration Defining the connection factories used in the application Setting the\r
-   * Re-delivery configuration goes here\r
-   */\r
-  @Bean\r
-  public BrokerService broker() throws Exception {\r
-    final BrokerService broker = new BrokerService();\r
-    broker.addConnector("tcp://localhost:61616");\r
-    broker.addConnector("vm://localhost");\r
-    broker.setPersistent(false);\r
-    return broker;\r
-  }\r
-\r
-  @Bean\r
-  public ConnectionFactory jmsConnectionFactory() {\r
-    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();\r
-    connectionFactory\r
-        .setTrustedPackages(Arrays.asList("org.commscope", "org.commscope.tr069adapter"));\r
-    connectionFactory.setMaxThreadPoolSize(7);\r
-\r
-    ActiveMQQueue notificationQueue = new ActiveMQQueue(NetConfServerConstants.NETCONF_NOTIFICATION_Q);\r
-    RedeliveryPolicy notificationQueuePolicy = new RedeliveryPolicy();\r
-    notificationQueuePolicy.setInitialRedeliveryDelay(2* 60 * 1000L);\r
-    notificationQueuePolicy.setUseCollisionAvoidance(true);\r
-    notificationQueuePolicy.setRedeliveryDelay(2* 60 * 1000L);\r
-    notificationQueuePolicy.setUseExponentialBackOff(false);\r
-    notificationQueuePolicy.setMaximumRedeliveries(3);\r
-    notificationQueuePolicy.setDestination(notificationQueue);\r
-\r
-    RedeliveryPolicyMap rdMap = connectionFactory.getRedeliveryPolicyMap();\r
-    rdMap.put(notificationQueue, notificationQueuePolicy);\r
-    return connectionFactory;\r
-  }\r
-\r
-  @Bean\r
-  public JmsListenerContainerFactory<MessageListenerContainer> netConfNotificationCF(\r
-      ConnectionFactory connectionFactory,\r
-      DefaultJmsListenerContainerFactoryConfigurer configurer) {\r
-    return handleJMSCommonConfiguration(connectionFactory, configurer);\r
-  }\r
-\r
-  public JmsListenerContainerFactory handleJMSCommonConfiguration(\r
-      ConnectionFactory connectionFactory,\r
-      DefaultJmsListenerContainerFactoryConfigurer configurer) {\r
-    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();\r
-    configurer.configure(factory, connectionFactory);\r
-    return factory;\r
-  }\r
-\r
-  @Bean\r
-  public MessageConverter jacksonJmsMessageConverter() {\r
-    MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();\r
-    converter.setTargetType(MessageType.TEXT);\r
-    converter.setTypeIdPropertyName("_type");\r
-    return converter;\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.netconf.boot;
+
+import java.util.Arrays;
+import javax.jms.ConnectionFactory;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.RedeliveryPolicy;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.broker.region.policy.RedeliveryPolicyMap;
+import org.apache.activemq.command.ActiveMQQueue;
+import org.commscope.tr069adapter.netconf.server.NetConfServerManagerImpl;
+import org.commscope.tr069adapter.netconf.server.utils.NetConfServerConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.domain.EntityScan;
+import org.springframework.boot.autoconfigure.jms.DefaultJmsListenerContainerFactoryConfigurer;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
+import org.springframework.jms.annotation.EnableJms;
+import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
+import org.springframework.jms.config.JmsListenerContainerFactory;
+import org.springframework.jms.listener.MessageListenerContainer;
+import org.springframework.jms.support.converter.MappingJackson2MessageConverter;
+import org.springframework.jms.support.converter.MessageConverter;
+import org.springframework.jms.support.converter.MessageType;
+import org.springframework.retry.annotation.EnableRetry;
+
+@EnableJms
+@SpringBootApplication
+@ComponentScan({"org.commscope.tr069adapter.netconf", "org.opendaylight.netconf.test",
+    "org.commscope.tr069adapter.common"})
+@EnableJpaRepositories("org.commscope.tr069adapter.netconf.dao")
+@EntityScan("org.commscope.tr069adapter.netconf.entity")
+@EnableRetry
+public class NetConfServiceBooter {
+
+  private static final Logger LOG = LoggerFactory.getLogger(NetConfServiceBooter.class);
+
+  private static ApplicationContext appContext;
+
+  public static void main(String[] args) {
+    if (args != null)
+      appContext = SpringApplication.run(NetConfServiceBooter.class, args);
+    NetConfServerManagerImpl serverManager =
+        NetConfServiceBooter.getApplicationContext().getBean(NetConfServerManagerImpl.class);
+    boolean isSchemaLoaded = serverManager.loadSchemas();
+    if (!isSchemaLoaded) {
+      LOG.error("Loading the schema failed while starting the container");
+      System.exit(1);
+    }
+    serverManager.restartServers();
+  }
+
+  public static ApplicationContext getApplicationContext() {
+    return appContext;
+  }
+
+  /*
+   * JMS Configuration Defining the connection factories used in the application Setting the
+   * Re-delivery configuration goes here
+   */
+  @Bean
+  public BrokerService broker() throws Exception {
+    final BrokerService broker = new BrokerService();
+    broker.addConnector("tcp://localhost:61616");
+    broker.addConnector("vm://localhost");
+    broker.setPersistent(false);
+    return broker;
+  }
+
+  @Bean
+  public ConnectionFactory jmsConnectionFactory() {
+    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
+    connectionFactory
+        .setTrustedPackages(Arrays.asList("org.commscope", "org.commscope.tr069adapter"));
+    connectionFactory.setMaxThreadPoolSize(7);
+
+    ActiveMQQueue notificationQueue = new ActiveMQQueue(NetConfServerConstants.NETCONF_NOTIFICATION_Q);
+    RedeliveryPolicy notificationQueuePolicy = new RedeliveryPolicy();
+    notificationQueuePolicy.setInitialRedeliveryDelay(2* 60 * 1000L);
+    notificationQueuePolicy.setUseCollisionAvoidance(true);
+    notificationQueuePolicy.setRedeliveryDelay(2* 60 * 1000L);
+    notificationQueuePolicy.setUseExponentialBackOff(false);
+    notificationQueuePolicy.setMaximumRedeliveries(3);
+    notificationQueuePolicy.setDestination(notificationQueue);
+
+    RedeliveryPolicyMap rdMap = connectionFactory.getRedeliveryPolicyMap();
+    rdMap.put(notificationQueue, notificationQueuePolicy);
+    return connectionFactory;
+  }
+
+  @Bean
+  public JmsListenerContainerFactory<MessageListenerContainer> netConfNotificationCF(
+      ConnectionFactory connectionFactory,
+      DefaultJmsListenerContainerFactoryConfigurer configurer) {
+    return handleJMSCommonConfiguration(connectionFactory, configurer);
+  }
+
+  public JmsListenerContainerFactory handleJMSCommonConfiguration(
+      ConnectionFactory connectionFactory,
+      DefaultJmsListenerContainerFactoryConfigurer configurer) {
+    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
+    configurer.configure(factory, connectionFactory);
+    return factory;
+  }
+
+  @Bean
+  public MessageConverter jacksonJmsMessageConverter() {
+    MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
+    converter.setTargetType(MessageType.TEXT);
+    converter.setTypeIdPropertyName("_type");
+    return converter;
+  }
+}