diff options
author | Niranjana <niranjana.y60@wipro.com> | 2021-09-16 09:05:06 +0000 |
---|---|---|
committer | KAPIL SINGAL <ks220y@att.com> | 2021-09-16 14:03:26 +0000 |
commit | a5498e53ed66e74fcbf2141e969433920b877282 (patch) | |
tree | fbac3e09770467804aa655ba7c76801420bc2d01 /sdnr/northbound/addCMHandle | |
parent | cc85f28e57c7d25dfa82573dda036bea34aa951a (diff) |
Modify cm-handle feature
Issue-ID: CCSDK-3342
Signed-off-by: Niranjana <niranjana.y60@wipro.com>
Change-Id: Id25c420ee7a0020c634d37f7afc354bed8dfcf6b
Diffstat (limited to 'sdnr/northbound/addCMHandle')
11 files changed, 323 insertions, 299 deletions
diff --git a/sdnr/northbound/addCMHandle/feature/pom.xml b/sdnr/northbound/addCMHandle/feature/pom.xml index 2bae14acb..1e10acddd 100644 --- a/sdnr/northbound/addCMHandle/feature/pom.xml +++ b/sdnr/northbound/addCMHandle/feature/pom.xml @@ -19,12 +19,13 @@ ~ ============LICENSE_END======================================================= ~ --> -<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.onap.ccsdk.parent</groupId> - <artifactId>feature-repo-parent</artifactId> + <artifactId>single-feature-parent</artifactId> <version>2.2.1</version> <relativePath/> </parent> @@ -36,96 +37,11 @@ <name>ccsdk-features :: sdnr-northbound :: ${project.artifactId}</name> - <dependencyManagement> - <dependencies> - <dependency> - <groupId>org.opendaylight.controller</groupId> - <artifactId>mdsal-artifacts</artifactId> - <version>1.6.1</version> - <type>pom</type> - <scope>import</scope> - </dependency> - </dependencies> - </dependencyManagement> - <dependencies> <dependency> - <groupId>org.onap.ccsdk.features.sdnr.northbound</groupId> - <artifactId>addCMHandle-model</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onap.ccsdk.features.sdnr.northbound</groupId> + <groupId>${project.groupId}</groupId> <artifactId>addCMHandle-provider</artifactId> <version>${project.version}</version> </dependency> - <dependency> - <groupId>org.onap.ccsdk.sli.core</groupId> - <artifactId>sli-common</artifactId> - <version>${ccsdk.sli.version}</version> - <scope>compile</scope> - </dependency> - <dependency> - <groupId>org.onap.ccsdk.sli.core</groupId> - <artifactId>sli-provider</artifactId> - <version>${ccsdk.sli.version}</version> - <scope>compile</scope> - </dependency> - <dependency> - <groupId>org.onap.ccsdk.sli.core</groupId> - <artifactId>utils-provider</artifactId> - <version>${ccsdk.sli.version}</version> - </dependency> - <dependency> - <groupId>org.apache.velocity</groupId> - <artifactId>velocity-engine-core</artifactId> - </dependency> - <dependency> - <groupId>commons-codec</groupId> - <artifactId>commons-codec</artifactId> - </dependency> </dependencies> - <build> - <pluginManagement> - <plugins> - <plugin> - <groupId>org.eclipse.m2e</groupId> - <artifactId>lifecycle-mapping</artifactId> - <version>1.0.0</version> - <configuration> - <lifecycleMappingMetadata> - <pluginExecutions> - <pluginExecution> - <pluginExecutionFilter> - <groupId>org.codehaus.mojo</groupId> - <artifactId>properties-maven-plugin</artifactId> - <versionRange>[1.0.0,)</versionRange> - <goals> - <goal>set-system-properties</goal> - </goals> - </pluginExecutionFilter> - <action> - <execute/> - </action> - </pluginExecution> - <pluginExecution> - <pluginExecutionFilter> - <groupId>org.apache.karaf.tooling</groupId> - <artifactId>karaf-maven-plugin</artifactId> - <versionRange>[4.0.0,)</versionRange> - <goals> - <goal>features-generate-descriptor</goal> - </goals> - </pluginExecutionFilter> - <action> - <execute/> - </action> - </pluginExecution> - </pluginExecutions> - </lifecycleMappingMetadata> - </configuration> - </plugin> - </plugins> - </pluginManagement> - </build> </project> diff --git a/sdnr/northbound/addCMHandle/installer/pom.xml b/sdnr/northbound/addCMHandle/installer/pom.xml index 4ea1e5e41..41c14d08b 100755 --- a/sdnr/northbound/addCMHandle/installer/pom.xml +++ b/sdnr/northbound/addCMHandle/installer/pom.xml @@ -19,7 +19,8 @@ ~ ============LICENSE_END======================================================= ~ --> -<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -42,15 +43,10 @@ </properties> <dependencies> - <dependency> - <groupId>org.opendaylight.controller</groupId> - <artifactId>sal-binding-broker-impl</artifactId> - <version>1.11.3</version> - <scope>test</scope> - </dependency> + <dependency> <groupId>org.onap.ccsdk.features.sdnr.northbound</groupId> - <artifactId>addCMHandle-feature</artifactId> + <artifactId>${application.name}-feature</artifactId> <version>${project.version}</version> <type>xml</type> <classifier>features</classifier> diff --git a/sdnr/northbound/addCMHandle/installer/src/assembly/assemble_mvnrepo_zip.xml b/sdnr/northbound/addCMHandle/installer/src/assembly/assemble_mvnrepo_zip.xml index fcfb7aa8a..c0eacf9a7 100644 --- a/sdnr/northbound/addCMHandle/installer/src/assembly/assemble_mvnrepo_zip.xml +++ b/sdnr/northbound/addCMHandle/installer/src/assembly/assemble_mvnrepo_zip.xml @@ -2,7 +2,7 @@ ~ ============LICENSE_START======================================================= ~ ONAP : ccsdk features ~ ================================================================================ - ~ Copyright (C) 2021 Wipro Limited. + ~ Copyright (C) 2021 Wipro Limited. ~ ================================================================================ ~ Licensed under the Apache License, Version 2.0 (the "License"); ~ you may not use this file except in compliance with the License. @@ -19,16 +19,20 @@ ~ --> +<!-- Defines how we build the .zip file which is our distribution. --> <assembly xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> - <id>bin</id> + <id>repo</id> <formats> <format>zip</format> </formats> + <!-- we want "system" and related files right at the root level + as this file is suppose to be unzip on top of a karaf + distro. --> <includeBaseDirectory>false</includeBaseDirectory> <fileSets> diff --git a/sdnr/northbound/addCMHandle/model/pom.xml b/sdnr/northbound/addCMHandle/model/pom.xml index b472dbd99..57a70e36a 100644 --- a/sdnr/northbound/addCMHandle/model/pom.xml +++ b/sdnr/northbound/addCMHandle/model/pom.xml @@ -19,7 +19,8 @@ ~ ============LICENSE_END======================================================= ~ --> -<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -38,44 +39,40 @@ <dependencies> <dependency> - <groupId>org.opendaylight.mdsal.model</groupId> - <artifactId>ietf-inet-types</artifactId> - <version>2010.09.24.12.4</version> + <groupId>org.opendaylight.mdsal.binding.model.ietf</groupId> + <artifactId>rfc6991</artifactId> + </dependency> + <dependency> + <groupId>org.opendaylight.mdsal.binding.model.ietf</groupId> + <artifactId>rfc6991-ietf-inet-types</artifactId> + </dependency> + <dependency> + <groupId>org.opendaylight.netconf</groupId> + <artifactId>sal-netconf-connector</artifactId> + <scope>provided</scope> </dependency> <dependency> - <groupId>org.opendaylight.mdsal.model</groupId> - <artifactId>ietf-yang-types</artifactId> - <version>2010.09.24.12.4</version> + <groupId>org.opendaylight.mdsal.binding.model.ietf</groupId> + <artifactId>rfc6991-ietf-yang-types</artifactId> + <scope>provided</scope> </dependency> - </dependencies> + </dependencies> + + <build> - <pluginManagement> - <plugins> - <plugin> - <groupId>org.eclipse.m2e</groupId> - <artifactId>lifecycle-mapping</artifactId> - <version>1.0.0</version> - <configuration> - <lifecycleMappingMetadata> - <pluginExecutions> - <pluginExecution> - <pluginExecutionFilter> - <groupId>org.codehaus.mojo</groupId> - <artifactId>properties-maven-plugin</artifactId> - <versionRange>[1.0.0,)</versionRange> - <goals> - <goal>set-system-properties</goal> - </goals> - </pluginExecutionFilter> - <action> - <execute/> - </action> - </pluginExecution> - </pluginExecutions> - </lifecycleMappingMetadata> - </configuration> - </plugin> - </plugins> - </pluginManagement> + <plugins> + <plugin> + <groupId>org.jacoco</groupId> + <artifactId>jacoco-maven-plugin</artifactId> + <configuration> + <excludes> + <exclude>**/gen/**</exclude> + <exclude>**/generated-sources/**</exclude> + <exclude>**/yang-gen-sal/**</exclude> + <exclude>**/pax/**</exclude> + </excludes> + </configuration> + </plugin> + </plugins> </build> </project> diff --git a/sdnr/northbound/addCMHandle/pom.xml b/sdnr/northbound/addCMHandle/pom.xml index 9c33e676a..9e25b9155 100644 --- a/sdnr/northbound/addCMHandle/pom.xml +++ b/sdnr/northbound/addCMHandle/pom.xml @@ -19,7 +19,8 @@ ~ ============LICENSE_END======================================================= ~ --> -<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -34,7 +35,7 @@ <version>1.0.0-SNAPSHOT</version> <packaging>pom</packaging> - <name>ccsdk-features :: sdnr-northbound :: addCMHandle</name> + <name>ccsdk-features :: sdnr-northbound :: ${project.artifactId}</name> <modules> <module>model</module> @@ -44,7 +45,6 @@ </modules> <properties> - <feature-name>addCMHandle-features</feature-name> + <feature-name>addCMHandle</feature-name> </properties> - </project> diff --git a/sdnr/northbound/addCMHandle/provider/pom.xml b/sdnr/northbound/addCMHandle/provider/pom.xml index 242aeca63..c0bc47f72 100644 --- a/sdnr/northbound/addCMHandle/provider/pom.xml +++ b/sdnr/northbound/addCMHandle/provider/pom.xml @@ -19,7 +19,8 @@ ~ ============LICENSE_END======================================================= ~ --> -<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -36,18 +37,6 @@ <name>ccsdk-features :: sdnr-northbound :: ${project.artifactId}</name> - <dependencyManagement> - <dependencies> - <dependency> - <groupId>org.opendaylight.controller</groupId> - <artifactId>mdsal-artifacts</artifactId> - <version>1.6.1</version> - <type>pom</type> - <scope>import</scope> - </dependency> - </dependencies> - </dependencyManagement> - <dependencies> <dependency> <groupId>org.onap.ccsdk.features.sdnr.northbound</groupId> @@ -55,20 +44,12 @@ <version>${project.version}</version> </dependency> <dependency> - <groupId>org.opendaylight.controller</groupId> - <artifactId>sal-binding-config</artifactId> - </dependency> - <dependency> - <groupId>org.opendaylight.controller</groupId> - <artifactId>sal-binding-api</artifactId> + <groupId>org.opendaylight.mdsal</groupId> + <artifactId>mdsal-binding-api</artifactId> </dependency> <dependency> - <groupId>org.opendaylight.controller</groupId> - <artifactId>sal-common-util</artifactId> - </dependency> - <dependency> - <groupId>org.opendaylight.controller</groupId> - <artifactId>sal-core-api</artifactId> + <groupId>org.opendaylight.mdsal</groupId> + <artifactId>mdsal-dom-api</artifactId> </dependency> <dependency> <groupId>org.opendaylight.yangtools</groupId> @@ -77,7 +58,11 @@ <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> - <!-- <version>${junit.version}</version> --> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> <scope>test</scope> </dependency> <dependency> @@ -86,14 +71,77 @@ <scope>test</scope> </dependency> <dependency> - <groupId>com.sun.jersey</groupId> - <artifactId>jersey-client</artifactId> - <version>1.19.4</version> + <groupId>org.apache.derby</groupId> + <artifactId>derby</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.onap.ccsdk.sli.core</groupId> + <artifactId>sli-common</artifactId> + <version>${ccsdk.sli.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.onap.ccsdk.sli.core</groupId> + <artifactId>sli-provider</artifactId> + <version>${ccsdk.sli.version}</version> + <scope>provided</scope> </dependency> <dependency> + <groupId>org.onap.ccsdk.sli.core</groupId> + <artifactId>utils-provider</artifactId> + <version>${ccsdk.sli.version}</version> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.onap.ccsdk.sli.core</groupId> + <artifactId>sli-provider-base</artifactId> + <version>${ccsdk.sli.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.onap.ccsdk.features.sdnr.wt</groupId> + <artifactId>sdnr-wt-netconfnode-state-service-model</artifactId> + <version>1.2.0</version> + </dependency> + <dependency> + <groupId>javax</groupId> + <artifactId>javaee-web-api</artifactId> + <version>6.0</version> + <scope>provided</scope> + </dependency> + <dependency> <groupId>com.sun.jersey</groupId> - <artifactId>jersey-core</artifactId> + <artifactId>jersey-bundle</artifactId> <version>1.19.4</version> + </dependency> + <dependency> + <groupId>org.opendaylight.mdsal.model</groupId> + <artifactId>ietf-topology</artifactId> + </dependency> + <dependency> + <groupId>org.opendaylight.netconf</groupId> + <artifactId>sal-netconf-connector</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.opendaylight.mdsal.binding.model.ietf</groupId> + <artifactId>rfc6991-ietf-yang-types</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.opendaylight.mdsal</groupId> + <artifactId>yang-binding</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.opendaylight.mdsal</groupId> + <artifactId>mdsal-singleton-common-api</artifactId> + <scope>provided</scope> </dependency> </dependencies> @@ -123,9 +171,8 @@ </pluginExecutions> </lifecycleMappingMetadata> </configuration> - </plugin> - </plugins> + </plugin> + </plugins> </pluginManagement> </build> - </project> diff --git a/sdnr/northbound/addCMHandle/provider/src/main/java/org/onap/ccsdk/features/sdnr/northbound/addCMHandle/AddCMHandleProvider.java b/sdnr/northbound/addCMHandle/provider/src/main/java/org/onap/ccsdk/features/sdnr/northbound/addCMHandle/AddCMHandleProvider.java index 013e71440..1756615cb 100644 --- a/sdnr/northbound/addCMHandle/provider/src/main/java/org/onap/ccsdk/features/sdnr/northbound/addCMHandle/AddCMHandleProvider.java +++ b/sdnr/northbound/addCMHandle/provider/src/main/java/org/onap/ccsdk/features/sdnr/northbound/addCMHandle/AddCMHandleProvider.java @@ -20,49 +20,120 @@ package org.onap.ccsdk.features.sdnr.northbound.addCMHandle; +import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION; + import com.google.common.base.Preconditions; import com.google.common.util.concurrent.ListenableFuture; - -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration; -import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.WebResource; +import com.sun.jersey.api.client.config.ClientConfig; +import com.sun.jersey.api.client.config.DefaultClientConfig; +import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Properties; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +import javax.ws.rs.HttpMethod; +import javax.ws.rs.core.MediaType; + +import org.eclipse.jdt.annotation.NonNull; +import org.json.JSONObject; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfNodeStateListener; +import org.onap.ccsdk.sli.core.sli.provider.MdsalHelper; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.DataObjectModification; +import org.opendaylight.mdsal.binding.api.DataTreeChangeListener; +import org.opendaylight.mdsal.binding.api.DataTreeIdentifier; +import org.opendaylight.mdsal.binding.api.DataTreeModification; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.mdsal.binding.api.RpcProviderService; +import org.opendaylight.mdsal.dom.api.DOMDataBroker; import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev210615.AddCMHandleInput; import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev210615.AddCMHandleOutput; import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev210615.CMHandleAPIService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.network.topology.topology.topology.types.TopologyNetconf; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.concepts.ObjectRegistration; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class AddCMHandleProvider implements CMHandleAPIService { +public class AddCMHandleProvider implements CMHandleAPIService, NetconfNodeStateListener, AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(AddCMHandleProvider.class); - - private final String appName = "addCMHandle"; - - private final DataBroker dataBroker; - private final RpcProviderRegistry rpcProviderRegistry; - private RpcRegistration<CMHandleAPIService> serviceRegistration; - + private final String APPLICATION_NAME = "addCMHandle"; private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR"; private static final String PROPERTIES_FILE_NAME = "cm-handle.properties"; private static final String PARSING_ERROR = "Could not create the request message to send to the server; no message will be sent"; + private final ExecutorService executor; + protected DataBroker dataBroker; + protected DOMDataBroker domDataBroker; + protected NotificationPublishService notificationService; + protected RpcProviderService rpcProviderRegistry; + private ObjectRegistration<CMHandleAPIService> rpcRegistration; + public static final InstanceIdentifier<Topology> NETCONF_TOPO_IID = InstanceIdentifier.create(NetworkTopology.class) + .child(Topology.class, new TopologyKey(new TopologyId(TopologyNetconf.QNAME.getLocalName()))); + private static HashMap<String, String> config; + + public AddCMHandleProvider() { + + LOG.info("Creating provider for {}", APPLICATION_NAME); + executor = Executors.newFixedThreadPool(1); + this.dataBroker = null; + this.domDataBroker = null; + this.notificationService = null; + this.rpcProviderRegistry = null; + this.rpcRegistration = null; + } - public AddCMHandleProvider(final DataBroker dataBroker, RpcProviderRegistry rpcProviderRegistry) { + public void setDataBroker(DataBroker dataBroker) { this.dataBroker = dataBroker; - this.rpcProviderRegistry = rpcProviderRegistry; } - /** - * Method called when the blueprint container is created. - */ - public void init() { - serviceRegistration = rpcProviderRegistry.addRpcImplementation(CMHandleAPIService.class, this); + public void setDomDataBroker(DOMDataBroker domDataBroker) { + this.domDataBroker = domDataBroker; + } - LOG.debug("Initializing provider for " + appName); + public void setRpcProviderRegistry(RpcProviderService rpcProviderRegistry) { + this.rpcProviderRegistry = rpcProviderRegistry; + } - Preconditions.checkNotNull(dataBroker, "dataBroker must be set"); + public void setNotificationPublishService(NotificationPublishService notificationPublishService) { + this.notificationService = notificationPublishService; + } + + public void init() { + LOG.info("Initializing {} for {}", this.getClass().getName(), APPLICATION_NAME); + + if (rpcRegistration == null) { + if (rpcProviderRegistry != null) { + rpcRegistration = rpcProviderRegistry.registerRpcImplementation(CMHandleAPIService.class, this); + LOG.info("Initialization complete for {}", APPLICATION_NAME); + } else { + LOG.warn("Error initializing {} : rpcRegistry unset", APPLICATION_NAME); + } + } String propDir = System.getenv(SDNC_CONFIG_DIR); if (propDir == null) { @@ -72,13 +143,74 @@ public class AddCMHandleProvider implements CMHandleAPIService { propDir = propDir + "/"; } - LOG.debug("Initialization complete for " + appName); + // GET configuration from properties file + config = new HashMap<String, String>(); + + try { + FileInputStream fileInput = new FileInputStream(propDir + PROPERTIES_FILE_NAME); + Properties properties = new Properties(); + properties.load(fileInput); + fileInput.close(); + + for (String param : new String[] {"url", "user", "password", + "authentication, dmi-service-name"}) { + config.put(param, properties.getProperty(param)); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + LOG.info("addCMHandle Session Initiated"); + } + + @Override + public void onCreated(NodeId nNodeId, NetconfNode netconfNode) { + LOG.info("NetConf device connected ", nNodeId.getValue()); + JSONObject obj = new JSONObject(); + obj.put("cm-handle-id", nNodeId.getValue()); + obj.put("dmi-service-name", config.get("dmi-service-name")); + ClientConfig dmaapClientConfig = new DefaultClientConfig(); + dmaapClientConfig.getProperties().put(ClientConfig.PROPERTY_READ_TIMEOUT, 180000); + dmaapClientConfig.getProperties().put(ClientConfig.PROPERTY_CONNECT_TIMEOUT, 60000); + Client dmaapClient = Client.create(dmaapClientConfig); + String authenticationMethod = config.get("authentication"); + ClientResponse response = null; + try { + if (authenticationMethod.equals("basic")) { + LOG.debug("Sending message to dmaap-message-router: {}", obj.toString()); + dmaapClient.addFilter(new HTTPBasicAuthFilter(config.get("user"), config.get("password"))); + + response = dmaapClient.resource(config.get("url")).type(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, obj); + } else { + response = dmaapClient.resource(config.get("url")).type(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, obj); + } + } catch (Exception e) { + LOG.error("Error while posting message to CM_HANDLE topic: {}", e); + } + + LOG.info("Received response from dmaap-message-router: \n {}", response.toString()); + } + + @Override + public void onRemoved(NodeId nNodeId) { + + LOG.info("NetConf device removed - nNodeId = {}", nNodeId); + } + + @Override + public void onStateChange(NodeId nNodeId, NetconfNode netconfNode) { + LOG.info("NetConf device state changed nNodeId = {}}", nNodeId); } /** * Method called when the blueprint container is destroyed. */ public void close() { + rpcRegistration.close(); LOG.debug("AddCMHandleProvider Closed"); } diff --git a/sdnr/northbound/addCMHandle/provider/src/main/java/org/onap/ccsdk/features/sdnr/northbound/impl/AddCMHandleProvider.java b/sdnr/northbound/addCMHandle/provider/src/main/java/org/onap/ccsdk/features/sdnr/northbound/impl/AddCMHandleProvider.java deleted file mode 100644 index 6e59e072d..000000000 --- a/sdnr/northbound/addCMHandle/provider/src/main/java/org/onap/ccsdk/features/sdnr/northbound/impl/AddCMHandleProvider.java +++ /dev/null @@ -1,91 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * Copyright (C) 2021 Wipro Limited. - * ================================================================================ - * Licensed 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 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License 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.onap.ccsdk.features.sdnr.northbound.impl; - -import com.google.common.base.Preconditions; -import com.google.common.util.concurrent.ListenableFuture; - -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration; -import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; -import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev210615.AddCMHandleInput; -import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev210615.AddCMHandleOutput; -import org.opendaylight.yang.gen.v1.org.onap.ccsdk.rev210615.CMHandleAPIService; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.opendaylight.yangtools.yang.common.RpcResultBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class AddCMHandleProvider implements CMHandleAPIService { - - private static final Logger LOG = LoggerFactory.getLogger(AddCMHandleProvider.class); - - private final String appName = "addCMHandle"; - - private final DataBroker dataBroker; - private final RpcProviderRegistry rpcProviderRegistry; - private RpcRegistration<CMHandleAPIService> serviceRegistration; - - private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR"; - private static final String PROPERTIES_FILE_NAME = "cm-handle.properties"; - private static final String PARSING_ERROR = - "Could not create the request message to send to the server; no message will be sent"; - - public AddCMHandleProvider(final DataBroker dataBroker, RpcProviderRegistry rpcProviderRegistry) { - this.dataBroker = dataBroker; - this.rpcProviderRegistry = rpcProviderRegistry; - } - - /** - * Method called when the blueprint container is created. - */ - public void init() { - serviceRegistration = rpcProviderRegistry.addRpcImplementation(CMHandleAPIService.class, this); - - LOG.debug("Initializing provider for " + appName); - - Preconditions.checkNotNull(dataBroker, "dataBroker must be set"); - - String propDir = System.getenv(SDNC_CONFIG_DIR); - if (propDir == null) { - LOG.error("Environment variable SDNC_CONFIG_DIR is not set"); - propDir = "/opt/onap/ccsdk/data/properties/"; - } else if (!propDir.endsWith("/")) { - propDir = propDir + "/"; - } - - LOG.debug("Initialization complete for " + appName); - } - - /** - * Method called when the blueprint container is destroyed. - */ - public void close() { - LOG.debug("AddCMHandleProvider Closed"); - } - - @Override - public ListenableFuture<RpcResult<AddCMHandleOutput>> addCMHandle(AddCMHandleInput input) { - - return null; - } - -} diff --git a/sdnr/northbound/addCMHandle/provider/src/main/resources/cm-handle.properties b/sdnr/northbound/addCMHandle/provider/src/main/resources/cm-handle.properties index ed3db009f..f027f5939 100644 --- a/sdnr/northbound/addCMHandle/provider/src/main/resources/cm-handle.properties +++ b/sdnr/northbound/addCMHandle/provider/src/main/resources/cm-handle.properties @@ -20,4 +20,8 @@ # -dmaap.url = https://dmaap-message-router/events +url = https://dmaap-message-router/events/CM_HANDLE +user = user +password = password +authentication = basic +dmi-service-name = dmi-service-name diff --git a/sdnr/northbound/addCMHandle/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml b/sdnr/northbound/addCMHandle/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml index 8e543d458..9cc6c39ca 100644 --- a/sdnr/northbound/addCMHandle/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml +++ b/sdnr/northbound/addCMHandle/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml @@ -20,18 +20,37 @@ ~ --> -<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" - xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0" - odl:use-default-for-reference-types="true"> +<blueprint xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0" + xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" odl:use-default-for-reference-types="true"> + + <reference id="svcLogicService" + interface="org.onap.ccsdk.sli.core.sli.provider.SvcLogicService"/> + + <bean id="client" class="org.onap.ccsdk.features.sdnr.northbound.ranSlice.RANSliceClient"> + <argument ref="svcLogicService"/> + </bean> <reference id="dataBroker" - interface="org.opendaylight.controller.md.sal.binding.api.DataBroker" - odl:type="default"/> + interface="org.opendaylight.mdsal.binding.api.DataBroker"/> + + <reference id="domDataBroker" + interface="org.opendaylight.mdsal.dom.api.DOMDataBroker"/> - <bean id="provider" - class="org.onap.sdnc.northbound.sdnr.impl.AddCMHandleProvider" - init-method="init" destroy-method="close"> - <argument ref="dataBroker"/> + <reference id="notificationPublishService" + interface="org.opendaylight.mdsal.binding.api.NotificationPublishService" /> + + <reference id="rpcProviderRegistry" + interface="org.opendaylight.mdsal.binding.api.RpcProviderService" /> + + <bean id="provider" class="org.onap.ccsdk.features.sdnr.northbound.ranSlice.RANSliceProvider" + init-method="init" destroy-method="close"> + <property name="dataBroker" ref="dataBroker"/> + <property name="domDataBroker" ref="domDataBroker"/> + <property name="rpcProviderRegistry" ref="rpcProviderRegistry"/> + <property name="notificationPublishService" ref="notificationPublishService"/> + <property name="client" ref="client"/> </bean> + <odl:rpc-implementation ref="provider"/> + </blueprint> diff --git a/sdnr/northbound/addCMHandle/provider/src/test/java/org/onap/ccsdk/features/sdnr/northbound/addCMHandle/AddCMHandleProviderTest.java b/sdnr/northbound/addCMHandle/provider/src/test/java/org/onap/ccsdk/features/sdnr/northbound/addCMHandle/AddCMHandleProviderTest.java index 37711c630..0dfe88c1f 100644 --- a/sdnr/northbound/addCMHandle/provider/src/test/java/org/onap/ccsdk/features/sdnr/northbound/addCMHandle/AddCMHandleProviderTest.java +++ b/sdnr/northbound/addCMHandle/provider/src/test/java/org/onap/ccsdk/features/sdnr/northbound/addCMHandle/AddCMHandleProviderTest.java @@ -11,10 +11,10 @@ import java.util.concurrent.Future; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.RpcProviderService; import org.opendaylight.yangtools.yang.common.RpcResult; - +import org.onap.ccsdk.features.sdnr.northbound.addCMHandle.AddCMHandleProvider; public class AddCMHandleProviderTest { private AddCMHandleProvider esProvider; @@ -22,8 +22,8 @@ public class AddCMHandleProviderTest { @Before public void setUp() throws Exception { DataBroker dataBroker = mock(DataBroker.class); - RpcProviderRegistry rpcRegistry = mock(RpcProviderRegistry.class); - esProvider = new AddCMHandleProvider(dataBroker, rpcRegistry); + RpcProviderService rpcRegistry = mock(RpcProviderService.class); + esProvider = new AddCMHandleProvider(); } @After |