From ea5bf0a1c8a4e525d2cee03841b8e8f9b3563ed0 Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Tue, 18 Jul 2017 20:32:15 -0400 Subject: [CCSDK-6] Populate seed code Add seed code for sli/northbound repository Update groupId to org.onap.ccsdk.sli.northbound Update to use CCSDK version of sli core Change-Id: Id3a154a53150a74f4b65060544e76f3e0cad932e Signed-off-by: Dan Timoney --- dataChange/.gitignore | 34 ++++ dataChange/.sonar/checkstyle.xml | 1 + dataChange/.sonar/pmd.xml | 67 ++++++++ dataChange/README.txt | 35 ++++ dataChange/features/pom.xml | 136 ++++++++++++++++ .../features/src/main/resources/features.xml | 39 +++++ dataChange/installer/pom.xml | 140 ++++++++++++++++ .../src/assembly/assemble_installer_zip.xml | 59 +++++++ .../src/assembly/assemble_mvnrepo_zip.xml | 55 +++++++ .../src/main/resources/scripts/install-feature.sh | 40 +++++ dataChange/model/pom.xml | 82 ++++++++++ dataChange/model/src/main/yang/DataChange.yang | 73 +++++++++ dataChange/pom.xml | 59 +++++++ dataChange/provider/pom.xml | 137 ++++++++++++++++ .../impl/rev140523/DataChangeProviderModule.java | 55 +++++++ .../rev140523/DataChangeProviderModuleFactory.java | 34 ++++ .../sdnc/datachange/DataChangeClient.java | 115 +++++++++++++ .../sdnc/datachange/DataChangeProvider.java | 181 +++++++++++++++++++++ .../main/resources/initial/dataChange-provider.xml | 72 ++++++++ .../src/main/yang/DataChange-provider-impl.yang | 61 +++++++ 20 files changed, 1475 insertions(+) create mode 100755 dataChange/.gitignore create mode 100755 dataChange/.sonar/checkstyle.xml create mode 100755 dataChange/.sonar/pmd.xml create mode 100755 dataChange/README.txt create mode 100755 dataChange/features/pom.xml create mode 100644 dataChange/features/src/main/resources/features.xml create mode 100755 dataChange/installer/pom.xml create mode 100644 dataChange/installer/src/assembly/assemble_installer_zip.xml create mode 100644 dataChange/installer/src/assembly/assemble_mvnrepo_zip.xml create mode 100644 dataChange/installer/src/main/resources/scripts/install-feature.sh create mode 100755 dataChange/model/pom.xml create mode 100755 dataChange/model/src/main/yang/DataChange.yang create mode 100755 dataChange/pom.xml create mode 100755 dataChange/provider/pom.xml create mode 100644 dataChange/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/sdnc/datachange/provider/impl/rev140523/DataChangeProviderModule.java create mode 100644 dataChange/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/sdnc/datachange/provider/impl/rev140523/DataChangeProviderModuleFactory.java create mode 100644 dataChange/provider/src/main/java/org/openecomp/sdnc/datachange/DataChangeClient.java create mode 100644 dataChange/provider/src/main/java/org/openecomp/sdnc/datachange/DataChangeProvider.java create mode 100644 dataChange/provider/src/main/resources/initial/dataChange-provider.xml create mode 100755 dataChange/provider/src/main/yang/DataChange-provider-impl.yang (limited to 'dataChange') diff --git a/dataChange/.gitignore b/dataChange/.gitignore new file mode 100755 index 000000000..b73caf31e --- /dev/null +++ b/dataChange/.gitignore @@ -0,0 +1,34 @@ +#####standard .git ignore entries##### + +## IDE Specific Files ## +org.eclipse.core.resources.prefs +.classpath +.project +.settings +.idea +.externalToolBuilders +maven-eclipse.xml +workspace + +## Compilation Files ## +*.class +**/target +target +target-ide +MANIFEST.MF + +## Misc Ignores (OS specific etc) ## +bin/ +dist +*~ +*.ipr +*.iml +*.iws +classes +out/ +.DS_STORE +.metadata + +## Folders which contain auto generated source code ## +yang-gen-config +yang-gen-sal diff --git a/dataChange/.sonar/checkstyle.xml b/dataChange/.sonar/checkstyle.xml new file mode 100755 index 000000000..3fa231535 --- /dev/null +++ b/dataChange/.sonar/checkstyle.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/dataChange/.sonar/pmd.xml b/dataChange/.sonar/pmd.xml new file mode 100755 index 000000000..80343b3bd --- /dev/null +++ b/dataChange/.sonar/pmd.xml @@ -0,0 +1,67 @@ + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + 2 + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + 5 + + + 2 + + + 3 + + + 3 + + + diff --git a/dataChange/README.txt b/dataChange/README.txt new file mode 100755 index 000000000..f9f4a2ab5 --- /dev/null +++ b/dataChange/README.txt @@ -0,0 +1,35 @@ +====================== +Introduction +====================== +You have generated an MD-SAL module using the Brocade Archetype. + +* You should be able to successfully run 'mvn clean install' on this project. +* This will produce a .zip file under the karaf.extension directory which you can deploy using +Brocade's extension deployment mechanism. + +====================== +Next Steps: +====================== +* run a 'mvn clean install' if you haven't already. This will generate some code from the yang models. +* Modify the model yang file under the model project. +* Follow the comments in the generated provider class to wire your new provider into the generated +code. +* Modify the generated provider model to respond to and handle the yang model. Depending on what +you added to your model you may need to inherit additional interfaces or make other changes to +the provider model. + +====================== +Generated Bundles: +====================== +* model + - Provides the yang model for your application. This is your primary northbound interface. +* provider + - Provides a template implementation for a provider to respond to your yang model. +* features + - Defines a karaf feature. If you add dependencies on third-party bundles then you will need to + modify the features.xml to list out the dependencies. +* karaf.extension + - Bundles all of the jars and third party dependencies (minus ODL dependencies) into a single + .zip file with the necessary configuration files to work correctly with the Brocade extension + mechanism. + diff --git a/dataChange/features/pom.xml b/dataChange/features/pom.xml new file mode 100755 index 000000000..123404479 --- /dev/null +++ b/dataChange/features/pom.xml @@ -0,0 +1,136 @@ + + + 4.0.0 + + dataChange + org.onap.ccsdk.sli.northbound + 0.0.1-SNAPSHOT + + org.onap.ccsdk.sli.northbound + dataChange-features + 0.0.1-SNAPSHOT + + jar + + + + org.onap.ccsdk.sli.northbound + dataChange-model + + + org.onap.ccsdk.sli.northbound + dataChange-provider + config + xml + + + org.onap.ccsdk.sli.northbound + dataChange-provider + + + + org.opendaylight.mdsal + features-mdsal + features + ${odl.mdsal.features.version} + xml + + runtime + + + + + + + org.opendaylight.controller + opendaylight-karaf-empty + ${odl.karaf.empty.distro.version} + zip + + + + + + org.opendaylight.odlparent + features-test + test + ${odl.commons.opendaylight.version} + + + + org.opendaylight.yangtools + features-yangtools + ${odl.yangtools.version} + features + xml + runtime + + + + + + + true + src/main/resources + + + + + org.apache.maven.plugins + maven-resources-plugin + + + filter + + resources + + generate-resources + + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + attach-artifacts + + attach-artifact + + package + + + + ${project.build.directory}/classes/${features.file} + xml + features + + + + + + + + + diff --git a/dataChange/features/src/main/resources/features.xml b/dataChange/features/src/main/resources/features.xml new file mode 100644 index 000000000..2b4ac946f --- /dev/null +++ b/dataChange/features/src/main/resources/features.xml @@ -0,0 +1,39 @@ + + + + + + + mvn:org.opendaylight.mdsal/features-mdsal/${odl.mdsal.features.version}/xml/features + + + + odl-mdsal-broker + sdnc-sli + mvn:org.openecomp.sdnc.northbound/dataChange-model/${project.version} + mvn:org.openecomp.sdnc.northbound/dataChange-provider/${project.version} + mvn:org.openecomp.sdnc.northbound/dataChange-provider/${project.version}/xml/config + + + diff --git a/dataChange/installer/pom.xml b/dataChange/installer/pom.xml new file mode 100755 index 000000000..414719e10 --- /dev/null +++ b/dataChange/installer/pom.xml @@ -0,0 +1,140 @@ + + + 4.0.0 + + dataChange + org.onap.ccsdk.sli.northbound + 0.0.1-SNAPSHOT + + dataChange-installer + dataChange - Karaf Installer + pom + + + sdnc-dataChange + sdnc-dataChange + mvn:org.onap.ccsdk.sli.northbound/dataChange-features/${project.version}/xml/features + false + + + + + + org.onap.ccsdk.sli.northbound + dataChange-features + ${project.version} + features + xml + + + * + * + + + + + + org.onap.ccsdk.sli.northbound + dataChange-provider + ${project.version} + + + + + + + + + maven-assembly-plugin + 2.6 + + + maven-repo-zip + + single + + package + + false + stage/${application.name}-${project.version} + + src/assembly/assemble_mvnrepo_zip.xml + + false + + + + installer-zip + + single + + package + + true + ${application.name}-${project.version}-installer + + src/assembly/assemble_installer_zip.xml + + false + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + + copy-dependencies + + prepare-package + + false + ${project.build.directory}/assembly/system + false + true + true + true + false + false + org.openecomp.sdnc + sli-common,sli-provider,dblib-provider + provided + + + + + + maven-resources-plugin + 2.6 + + + copy-version + + copy-resources + + validate + + ${basedir}/target/stage + + + src/main/resources/scripts + + install-feature.sh + + true + + + + + + + + + + + + diff --git a/dataChange/installer/src/assembly/assemble_installer_zip.xml b/dataChange/installer/src/assembly/assemble_installer_zip.xml new file mode 100644 index 000000000..e278872a1 --- /dev/null +++ b/dataChange/installer/src/assembly/assemble_installer_zip.xml @@ -0,0 +1,59 @@ + + + + + + installer_zip + + zip + + + + false + + + + target/stage/ + ${application.name} + 755 + + *.sh + + + + target/stage/ + ${application.name} + 644 + + *.sh + + + + + + + diff --git a/dataChange/installer/src/assembly/assemble_mvnrepo_zip.xml b/dataChange/installer/src/assembly/assemble_mvnrepo_zip.xml new file mode 100644 index 000000000..608200da1 --- /dev/null +++ b/dataChange/installer/src/assembly/assemble_mvnrepo_zip.xml @@ -0,0 +1,55 @@ + + + + + + mvnrepo_zip + + zip + + + + false + + + + target/assembly/ + . + + + + + + + + ../provider/src/main/resources/initial/${feature-name}-provider.xml + ./etc/opendaylight/karaf/200-${feature-name}-provider.xml + + + + + diff --git a/dataChange/installer/src/main/resources/scripts/install-feature.sh b/dataChange/installer/src/main/resources/scripts/install-feature.sh new file mode 100644 index 000000000..9a47d2225 --- /dev/null +++ b/dataChange/installer/src/main/resources/scripts/install-feature.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +### +# ============LICENSE_START======================================================= +# openECOMP : SDN-C +# ================================================================================ +# Copyright (C) 2017 ONAP Intellectual Property. All rights +# reserved. +# ================================================================================ +# 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========================================================= +### + +ODL_HOME=${ODL_HOME:-/opt/opendaylight/current} +ODL_KARAF_CLIENT=${ODL_KARAF_CLIENT:-${ODL_HOME}/bin/client} +ODL_KARAF_CLIENT_OPTS=${ODL_KARAF_CLIENT_OPTS:-"-u karaf"} +INSTALLERDIR=$(dirname $0) + +REPOZIP=${INSTALLERDIR}/${features.boot}-${project.version}.zip + +if [ -f ${REPOZIP} ] +then + unzip -d ${ODL_HOME} ${REPOZIP} +else + echo "ERROR : repo zip ($REPOZIP) not found" + exit 1 +fi + +${ODL_KARAF_CLIENT} ${ODL_KARAF_CLIENT_OPTS} feature:repo-add ${features.repositories} +${ODL_KARAF_CLIENT} ${ODL_KARAF_CLIENT_OPTS} feature:install ${features.boot} diff --git a/dataChange/model/pom.xml b/dataChange/model/pom.xml new file mode 100755 index 000000000..0d16ebfc0 --- /dev/null +++ b/dataChange/model/pom.xml @@ -0,0 +1,82 @@ + + + 4.0.0 + + dataChange + org.onap.ccsdk.sli.northbound + 0.0.1-SNAPSHOT + + org.onap.ccsdk.sli.northbound + dataChange-model + 0.0.1-SNAPSHOT + bundle + + + + + + org.apache.felix + maven-bundle-plugin + true + + + * + + + + + org.opendaylight.yangtools + yang-maven-plugin + ${odl.yangtools.yang.maven.plugin.version} + + + org.opendaylight.mdsal + maven-sal-api-gen-plugin + ${odl.sal.api.gen.plugin.version} + jar + + + + + + generate-sources + + + ${yang.file.directory} + + + org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl + ${salGeneratorPath} + + + true + + + + + + + + + + org.opendaylight.mdsal + yang-binding + ${odl.mdsal.yang.binding.version} + + + org.opendaylight.yangtools + yang-common + ${odl.yangtools.version} + + + org.opendaylight.mdsal.model + ietf-inet-types + ${odl.ietf-inet-types.version} + + + org.opendaylight.mdsal.model + ietf-yang-types + ${odl.ietf-yang-types.version} + + + diff --git a/dataChange/model/src/main/yang/DataChange.yang b/dataChange/model/src/main/yang/DataChange.yang new file mode 100755 index 000000000..3d326f7be --- /dev/null +++ b/dataChange/model/src/main/yang/DataChange.yang @@ -0,0 +1,73 @@ +module DataChange { + + yang-version 1; + + namespace "org:openecomp:sdnc:datachange"; + + prefix datachg; + + organization "AT&T, Inc."; + + contact + "Dan Timoney "; + + description + "Defines API interface for notification of data changes"; + + revision "2015-05-19" { + description + "Initial draft"; + } + + grouping data-change-request { + + leaf aai-event-id { + type string; + } + + leaf aai-node-type { + type string; + } + + leaf aai-event-trigger { + type enumeration { + enum "Update"; + enum "Delete"; + } + } + + list key-data { + key key-name; + leaf key-name { + type string; + } + leaf key-value { + type string; + } + } + + leaf selflink { + type string; + } + + } + + grouping data-change-response { + + leaf data-change-response-code { + type string; + } + } + + rpc data-change-notification { + + input { + uses data-change-request; + } + + output { + uses data-change-response; + } + } + +} diff --git a/dataChange/pom.xml b/dataChange/pom.xml new file mode 100755 index 000000000..2e3d87494 --- /dev/null +++ b/dataChange/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + + + org.onap.ccsdk.sli.northbound + sdnc-northbound + 0.0.1-SNAPSHOT + + + pom + org.onap.ccsdk.sli.northbound + dataChange + 0.0.1-SNAPSHOT + + + dataChange + + + + + + + org.onap.ccsdk.sli.northbound + dataChange-features + features + xml + ${project.version} + + + + org.onap.ccsdk.sli.northbound + dataChange-model + ${project.version} + + + org.onap.ccsdk.sli.northbound + dataChange-provider + ${project.version} + config + xml + + + org.onap.ccsdk.sli.northbound + dataChange-provider + ${project.version} + + + + + + + + model + features + provider + installer + + diff --git a/dataChange/provider/pom.xml b/dataChange/provider/pom.xml new file mode 100755 index 000000000..5a7c7003d --- /dev/null +++ b/dataChange/provider/pom.xml @@ -0,0 +1,137 @@ + + + 4.0.0 + + dataChange + org.onap.ccsdk.sli.northbound + 0.0.1-SNAPSHOT + + dataChange-provider + bundle + + + + + org.apache.felix + maven-bundle-plugin + true + + + org.opendaylight.controller.config.yang.config.DataChange_provider.impl + * + + + + + org.opendaylight.yangtools + yang-maven-plugin + ${odl.yangtools.yang.maven.plugin.version} + + + + config + + generate-sources + + + + + org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator + ${jmxGeneratorPath} + + urn:opendaylight:params:xml:ns:yang:controller==org.opendaylight.controller.config.yang + + + + org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl + ${salGeneratorPath} + + + true + + + + + + org.opendaylight.mdsal + maven-sal-api-gen-plugin + ${odl.sal.api.gen.plugin.version} + jar + + + org.opendaylight.controller + yang-jmx-generator-plugin + ${odl.yang.jmx.generator.version} + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + attach-artifacts + + attach-artifact + + package + + + + ${project.build.directory}/classes/initial/${feature-name}-provider.xml + xml + config + + + + + + + + + + + + org.onap.ccsdk.sli.northbound + dataChange-model + + + org.opendaylight.controller + config-api + + ${odl.controller.config.api.version} + + + org.opendaylight.controller + sal-binding-config + ${odl.mdsal.version} + + + org.opendaylight.controller + sal-binding-api + ${odl.mdsal.version} + + + org.opendaylight.controller + sal-common-util + ${odl.mdsal.version} + + + org.onap.ccsdk.sli.core + sli-common + ${sdnctl.sli.version} + + + org.onap.ccsdk.sli.core + sli-provider + ${sdnctl.sli.version} + + + junit + junit + ${junit.version} + test + + + diff --git a/dataChange/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/sdnc/datachange/provider/impl/rev140523/DataChangeProviderModule.java b/dataChange/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/sdnc/datachange/provider/impl/rev140523/DataChangeProviderModule.java new file mode 100644 index 000000000..c3dd110a9 --- /dev/null +++ b/dataChange/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/sdnc/datachange/provider/impl/rev140523/DataChangeProviderModule.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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.opendaylight.yang.gen.v1.org.openecomp.sdnc.datachange.provider.impl.rev140523; + +import org.openecomp.sdnc.datachange.DataChangeProvider; + +public class DataChangeProviderModule extends org.opendaylight.yang.gen.v1.org.openecomp.sdnc.datachange.provider.impl.rev140523.AbstractDataChangeProviderModule { + public DataChangeProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public DataChangeProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.org.openecomp.sdnc.datachange.provider.impl.rev140523.DataChangeProviderModule oldModule, java.lang.AutoCloseable oldInstance) { + super(identifier, dependencyResolver, oldModule, oldInstance); + } + + @Override + public void customValidation() { + // add custom validation form module attributes here. + } + + @Override + public java.lang.AutoCloseable createInstance() { + final DataChangeProvider provider = new DataChangeProvider(getDataBrokerDependency() + , getNotificationServiceDependency() + , getRpcRegistryDependency()); + + return new AutoCloseable() { + + @Override + public void close() throws Exception { + provider.close(); + } + }; + } + +} diff --git a/dataChange/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/sdnc/datachange/provider/impl/rev140523/DataChangeProviderModuleFactory.java b/dataChange/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/sdnc/datachange/provider/impl/rev140523/DataChangeProviderModuleFactory.java new file mode 100644 index 000000000..2f4724961 --- /dev/null +++ b/dataChange/provider/src/main/java/org/opendaylight/yang/gen/v1/org/openecomp/sdnc/datachange/provider/impl/rev140523/DataChangeProviderModuleFactory.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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========================================================= + */ + +/* +* Generated file +* +* Generated from: yang module name: DataChange-provider-impl yang module local name: DataChange-provider-impl +* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator +* Generated at: Wed Nov 02 06:00:03 EDT 2016 +* +* Do not modify this file unless it is present under src/main directory +*/ +package org.opendaylight.yang.gen.v1.org.openecomp.sdnc.datachange.provider.impl.rev140523; +public class DataChangeProviderModuleFactory extends org.opendaylight.yang.gen.v1.org.openecomp.sdnc.datachange.provider.impl.rev140523.AbstractDataChangeProviderModuleFactory { + +} diff --git a/dataChange/provider/src/main/java/org/openecomp/sdnc/datachange/DataChangeClient.java b/dataChange/provider/src/main/java/org/openecomp/sdnc/datachange/DataChangeClient.java new file mode 100644 index 000000000..5db3eff6d --- /dev/null +++ b/dataChange/provider/src/main/java/org/openecomp/sdnc/datachange/DataChangeClient.java @@ -0,0 +1,115 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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.openecomp.sdnc.datachange; + +import java.util.Properties; + +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.provider.MdsalHelper; +import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService; +import org.opendaylight.yang.gen.v1.org.openecomp.sdnc.datachange.rev150519.DataChangeNotificationOutputBuilder; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.ServiceReference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DataChangeClient { + + private static final Logger LOG = LoggerFactory + .getLogger(DataChangeClient.class); + + private SvcLogicService svcLogic = null; + + public DataChangeClient() + { + BundleContext bctx = FrameworkUtil.getBundle(SvcLogicService.class).getBundleContext(); + + // Get SvcLogicService reference + ServiceReference sref = bctx.getServiceReference(SvcLogicService.NAME); + if (sref != null) + { + svcLogic = (SvcLogicService) bctx.getService(sref); + + } + else + { + LOG.warn("Cannot find service reference for "+SvcLogicService.NAME); + + } + } + + public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException + { + return(svcLogic.hasGraph(module, rpc, version, mode)); + } + + public Properties execute(String module, String rpc, String version, String mode, DataChangeNotificationOutputBuilder serviceData) + throws SvcLogicException { + + Properties parms = new Properties(); + + return execute(module,rpc,version, mode,serviceData,parms); + } + + public Properties execute(String module, String rpc, String version, String mode, DataChangeNotificationOutputBuilder serviceData, Properties parms) + throws SvcLogicException { + + parms = MdsalHelper.toProperties(parms, serviceData); + + if (LOG.isDebugEnabled()) + { + LOG.debug("Parameters passed to SLI"); + + for (Object key : parms.keySet()) { + String parmName = (String) key; + String parmValue = parms.getProperty(parmName); + + LOG.debug(parmName+" = "+parmValue); + + } + } + + Properties respProps = svcLogic.execute(module, rpc, version, mode, parms); + + if (LOG.isDebugEnabled()) + { + LOG.debug("Parameters returned by SLI"); + + for (Object key : respProps.keySet()) { + String parmName = (String) key; + String parmValue = respProps.getProperty(parmName); + + LOG.debug(parmName+" = "+parmValue); + + } + } + if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) { + return (respProps); + } + + MdsalHelper.toBuilder(respProps, serviceData); + + return (respProps); + } + +} diff --git a/dataChange/provider/src/main/java/org/openecomp/sdnc/datachange/DataChangeProvider.java b/dataChange/provider/src/main/java/org/openecomp/sdnc/datachange/DataChangeProvider.java new file mode 100644 index 000000000..791da5c05 --- /dev/null +++ b/dataChange/provider/src/main/java/org/openecomp/sdnc/datachange/DataChangeProvider.java @@ -0,0 +1,181 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 ONAP Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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.openecomp.sdnc.datachange; + +import java.util.Properties; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + +import org.onap.ccsdk.sli.core.sli.provider.MdsalHelper; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; +import org.opendaylight.controller.sal.binding.api.NotificationProviderService; +import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; +import org.opendaylight.yang.gen.v1.org.openecomp.sdnc.datachange.rev150519.DataChangeNotificationInput; +import org.opendaylight.yang.gen.v1.org.openecomp.sdnc.datachange.rev150519.DataChangeNotificationInputBuilder; +import org.opendaylight.yang.gen.v1.org.openecomp.sdnc.datachange.rev150519.DataChangeNotificationOutput; +import org.opendaylight.yang.gen.v1.org.openecomp.sdnc.datachange.rev150519.DataChangeNotificationOutputBuilder; +import org.opendaylight.yang.gen.v1.org.openecomp.sdnc.datachange.rev150519.DataChangeService; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.common.RpcResultBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.util.concurrent.Futures; + +/** + * Defines a base implementation for your provider. This class extends from a helper class + * which provides storage for the most commonly used components of the MD-SAL. Additionally the + * base class provides some basic logging and initialization / clean up methods. + * + */ +public class DataChangeProvider implements AutoCloseable, DataChangeService{ + + private final Logger log = LoggerFactory.getLogger( DataChangeProvider.class ); + private final String appName = "DataChange"; + private final ExecutorService executor; + + protected DataBroker dataBroker; + protected NotificationProviderService notificationService; + protected RpcProviderRegistry rpcRegistry; + protected BindingAwareBroker.RpcRegistration rpcRegistration; + + + public DataChangeProvider(DataBroker dataBroker2, + NotificationProviderService notificationProviderService, + RpcProviderRegistry rpcProviderRegistry) { + this.log.info( "Creating provider for " + appName ); + executor = Executors.newFixedThreadPool(1); + dataBroker = dataBroker2; + notificationService = notificationProviderService; + rpcRegistry = rpcProviderRegistry; + initialize(); + } + + public void initialize(){ + log.info( "Initializing provider for " + appName ); + rpcRegistration = rpcRegistry.addRpcImplementation(DataChangeService.class, this); + log.info( "Initialization complete for " + appName ); + } + + protected void initializeChild() { + //Override if you have custom initialization intelligence + } + + @Override + public void close() throws Exception { + log.info( "Closing provider for " + appName ); + executor.shutdown(); + rpcRegistration.close(); + log.info( "Successfully closed provider for " + appName ); + } + + public void setDataBroker(DataBroker dataBroker) { + this.dataBroker = dataBroker; + if( log.isDebugEnabled() ){ + log.debug( "DataBroker set to " + (dataBroker==null?"null":"non-null") + "." ); + } + } + + public void setNotificationService( + NotificationProviderService notificationService) { + this.notificationService = notificationService; + if( log.isDebugEnabled() ){ + log.debug( "Notification Service set to " + (notificationService==null?"null":"non-null") + "." ); + } + } + + public void setRpcRegistry(RpcProviderRegistry rpcRegistry) { + this.rpcRegistry = rpcRegistry; + if( log.isDebugEnabled() ){ + log.debug( "RpcRegistry set to " + (rpcRegistry==null?"null":"non-null") + "." ); + } + } + + @Override + public Future> dataChangeNotification( + DataChangeNotificationInput input) { + final String SVC_OPERATION = "data-change-notification"; + + Properties parms = new Properties(); + DataChangeNotificationOutputBuilder serviceDataBuilder = new DataChangeNotificationOutputBuilder(); + + log.info( SVC_OPERATION +" called." ); + + if(input == null || input.getAaiEventId() == null) { + log.debug("exiting " +SVC_OPERATION+ " because of invalid input"); + serviceDataBuilder.setDataChangeResponseCode("403"); + RpcResult rpcResult = + RpcResultBuilder. status(true).withResult(serviceDataBuilder.build()).build(); + return Futures.immediateFuture(rpcResult); + } + + // add input to parms + log.info("Adding INPUT data for "+SVC_OPERATION+" input: " + input); + DataChangeNotificationInputBuilder inputBuilder = new DataChangeNotificationInputBuilder(input); + MdsalHelper.toProperties(parms, inputBuilder.build()); + + // Call SLI sync method + // Get SvcLogicService reference + + DataChangeClient svcLogicClient = new DataChangeClient(); + Properties respProps = null; + + try + { + if (svcLogicClient.hasGraph("DataChange", SVC_OPERATION , null, "sync")) + { + try + { + respProps = svcLogicClient.execute("DataChange", SVC_OPERATION, null, "sync", serviceDataBuilder, parms); + } + catch (Exception e) + { + log.error("Caught exception executing service logic for "+ SVC_OPERATION, e); + serviceDataBuilder.setDataChangeResponseCode("500"); + } + } else { + log.error("No service logic active for DataChange: '" + SVC_OPERATION + "'"); + serviceDataBuilder.setDataChangeResponseCode("503"); + } + } + catch (Exception e) + { + log.error("Caught exception looking for service logic", e); + serviceDataBuilder.setDataChangeResponseCode("500"); + } + + String errorCode = serviceDataBuilder.getDataChangeResponseCode(); + + if ( errorCode != null && errorCode.length() != 0 && !( errorCode.equals("0")|| errorCode.equals("200"))) { + log.error("Returned FAILED for "+SVC_OPERATION+" error code: '" + errorCode + "'"); + } else { + log.info("Returned SUCCESS for "+SVC_OPERATION+" "); + } + + RpcResult rpcResult = + RpcResultBuilder. status(true).withResult(serviceDataBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } +} diff --git a/dataChange/provider/src/main/resources/initial/dataChange-provider.xml b/dataChange/provider/src/main/resources/initial/dataChange-provider.xml new file mode 100644 index 000000000..2812ca4d7 --- /dev/null +++ b/dataChange/provider/src/main/resources/initial/dataChange-provider.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + prefix:DataChange-provider-impl + + DataChange-provider-impl + + + + binding:binding-rpc-registry + binding-rpc-broker + + + + binding:binding-async-data-broker + binding-data-broker + + + + + binding:binding-notification-service + + binding-notification-broker + + + + + + + + + + + org:openecomp:sdnc:datachange:provider:impl?module=DataChange-provider-impl&revision=2014-05-23 + + + diff --git a/dataChange/provider/src/main/yang/DataChange-provider-impl.yang b/dataChange/provider/src/main/yang/DataChange-provider-impl.yang new file mode 100755 index 000000000..fe1dab235 --- /dev/null +++ b/dataChange/provider/src/main/yang/DataChange-provider-impl.yang @@ -0,0 +1,61 @@ +module DataChange-provider-impl { + + yang-version 1; + namespace "org:openecomp:sdnc:datachange:provider:impl"; + prefix "DataChange-provider-impl"; + + import config { prefix config; revision-date 2013-04-05; } + import opendaylight-md-sal-binding { prefix mdsal; revision-date 2013-10-28; } + + description + "This module contains the base YANG definitions for + DataChange-provider impl implementation."; + + revision "2014-05-23" { + description + "Initial revision."; + } + + // This is the definition of the service implementation as a module identity. + identity DataChange-provider-impl { + base config:module-type; + + // Specifies the prefix for generated java classes. + config:java-name-prefix DataChangeProvider; + } + + // Augments the 'configuration' choice node under modules/module. + // We consume the three main services, RPCs, DataStore, and Notifications + augment "/config:modules/config:module/config:configuration" { + case DataChange-provider-impl { + when "/config:modules/config:module/config:type = 'DataChange-provider-impl'"; + + container rpc-registry { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity mdsal:binding-rpc-registry; + } + } + } + + container notification-service { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity mdsal:binding-notification-service; + } + } + } + + container data-broker { + uses config:service-ref { + refine type { + mandatory false; + config:required-identity mdsal:binding-async-data-broker; + } + } + } + } + } +} -- cgit 1.2.3-korg