diff options
Diffstat (limited to 'sdnr/northbound/energysavings')
13 files changed, 927 insertions, 0 deletions
diff --git a/sdnr/northbound/energysavings/README.md b/sdnr/northbound/energysavings/README.md new file mode 100644 index 000000000..ce20d0d94 --- /dev/null +++ b/sdnr/northbound/energysavings/README.md @@ -0,0 +1,14 @@ +# Introduction +You have generated a feature repostiroy using the onap ccsdk feature repository archetype. + +If creation was successful 'mvn clean install' should run without errors. + +# Modules +* provider + - implementation code goes here +* features + - manages packaging the project into a feature repository +* model + - yang models go here +* installer + - packages the project into a zip with an installer script
\ No newline at end of file diff --git a/sdnr/northbound/energysavings/features/pom.xml b/sdnr/northbound/energysavings/features/pom.xml new file mode 100644 index 000000000..a016ad1b4 --- /dev/null +++ b/sdnr/northbound/energysavings/features/pom.xml @@ -0,0 +1,98 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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> + <version>1.0.5-SNAPSHOT</version> + <relativePath /> + </parent> + + <groupId>org.onap.ccsdk.features.sdnr.northbound</groupId> + <artifactId>energysavings-features</artifactId> + <version>0.2.4-SNAPSHOT</version> + <packaging>feature</packaging> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.opendaylight.mdsal.model</groupId> + <artifactId>mdsal-model-artifacts</artifactId> + <version>0.11.1</version> + <type>pom</type> + <scope>import</scope> + </dependency> + <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.opendaylight.controller</groupId> + <artifactId>odl-mdsal-broker</artifactId> + <type>xml</type> + <classifier>features</classifier> + </dependency> + <dependency> + <groupId>org.onap.sdnc.northbound.sdnr</groupId> + <artifactId>energysavings-model</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onap.sdnc.northbound.sdnr</groupId> + <artifactId>energysavings-provider</artifactId> + <version>${project.version}</version> + </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/energysavings/installer/pom.xml b/sdnr/northbound/energysavings/installer/pom.xml new file mode 100755 index 000000000..107912384 --- /dev/null +++ b/sdnr/northbound/energysavings/installer/pom.xml @@ -0,0 +1,132 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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>odlparent-lite</artifactId> + <version>1.0.5-SNAPSHOT</version> + <relativePath/> + </parent> + + <groupId>org.onap.ccsdk.features.sdnr.northbound</groupId> + <artifactId>energysavings-installer</artifactId> + <version>0.2.4-SNAPSHOT</version> + <packaging>pom</packaging> + + <properties> + <application.name>energysavings-features</application.name> + <features.boot>${application.name}</features.boot> + <features.repositories>mvn:org.onap.sdnc.northbound.sdnr/${features.boot}/${project.version}/xml/features</features.repositories> + <include.transitive.dependencies>false</include.transitive.dependencies> + </properties> + + <dependencies> + <dependency> + <groupId>org.onap.ccsdk.features.sdnr.northbound</groupId> + <artifactId>energysavings-model</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onap.ccsdk.features.sdnr.northbound</groupId> + <artifactId>energysavings-provider</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onap.ccsdk.features.sdnr.northbound</groupId> + <artifactId>energysavings-features</artifactId> + <version>${project.version}</version> + <type>xml</type> + <classifier>features</classifier> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <executions> + <execution> + <id>maven-repo-zip</id> + <goals> + <goal>single</goal> + </goals> + <phase>package</phase> + <configuration> + <attach>false</attach> + <finalName>stage/${application.name}-${project.version}</finalName> + <descriptors> + <descriptor>src/assembly/assemble_mvnrepo_zip.xml</descriptor> + </descriptors> + <appendAssemblyId>false</appendAssemblyId> + </configuration> + </execution> + <execution> + <id>installer-zip</id> + <goals> + <goal>single</goal> + </goals> + <phase>package</phase> + <configuration> + <attach>true</attach> + <finalName>${application.name}-${project.version}-installer</finalName> + <descriptors> + <descriptor>src/assembly/assemble_installer_zip.xml</descriptor> + </descriptors> + <appendAssemblyId>false</appendAssemblyId> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <id>copy-dependencies</id> + <goals> + <goal>copy-dependencies</goal> + </goals> + <phase>prepare-package</phase> + <configuration> + <transitive>false</transitive> + <outputDirectory>${project.build.directory}/assembly/system</outputDirectory> + <overWriteReleases>false</overWriteReleases> + <overWriteSnapshots>true</overWriteSnapshots> + <overWriteIfNewer>true</overWriteIfNewer> + <useRepositoryLayout>true</useRepositoryLayout> + <addParentPoms>false</addParentPoms> + <copyPom>false</copyPom> + <includeArtifactIds>energysavings-model,energysavings-provider,energysavings-features</includeArtifactIds> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <artifactId>maven-resources-plugin</artifactId> + <version>2.6</version> + <executions> + <execution> + <id>copy-version</id> + <goals> + <goal>copy-resources</goal> + </goals><!-- here the phase you need --> + <phase>validate</phase> + <configuration> + <outputDirectory>${basedir}/target/stage</outputDirectory> + <resources> + <resource> + <directory>src/main/resources/scripts</directory> + <includes> + <include>install-feature.sh</include> + </includes> + <filtering>true</filtering> + </resource> + </resources> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/sdnr/northbound/energysavings/installer/src/assembly/assemble_installer_zip.xml b/sdnr/northbound/energysavings/installer/src/assembly/assemble_installer_zip.xml new file mode 100644 index 000000000..2d3c0606d --- /dev/null +++ b/sdnr/northbound/energysavings/installer/src/assembly/assemble_installer_zip.xml @@ -0,0 +1,59 @@ +<!-- + ============LICENSE_START======================================================= + ONAP : CCSDK + ================================================================================ + Copyright (C) 2017 AT&T 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========================================================= + --> + +<!-- Defines how we build the .zip file which is our distribution. --> + +<assembly + xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + 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> + <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> + <fileSet> + <directory>target/stage/</directory> + <outputDirectory>${application.name}</outputDirectory> + <fileMode>755</fileMode> + <includes> + <include>*.sh</include> + </includes> + </fileSet> + <fileSet> + <directory>target/stage/</directory> + <outputDirectory>${application.name}</outputDirectory> + <fileMode>644</fileMode> + <excludes> + <exclude>*.sh</exclude> + </excludes> + </fileSet> + </fileSets> + + + +</assembly> diff --git a/sdnr/northbound/energysavings/installer/src/assembly/assemble_mvnrepo_zip.xml b/sdnr/northbound/energysavings/installer/src/assembly/assemble_mvnrepo_zip.xml new file mode 100644 index 000000000..5f3e3af31 --- /dev/null +++ b/sdnr/northbound/energysavings/installer/src/assembly/assemble_mvnrepo_zip.xml @@ -0,0 +1,49 @@ +<!-- + ============LICENSE_START======================================================= + ONAP : CCSDK + ================================================================================ + Copyright (C) 2017 AT&T 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========================================================= + --> + +<!-- Defines how we build the .zip file which is our distribution. --> + +<assembly + xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + 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> + <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> + <fileSet> + <directory>target/assembly/</directory> + <outputDirectory>.</outputDirectory> + <excludes> + </excludes> + </fileSet> + </fileSets> + + + +</assembly> diff --git a/sdnr/northbound/energysavings/installer/src/main/resources/scripts/install-feature.sh b/sdnr/northbound/energysavings/installer/src/main/resources/scripts/install-feature.sh new file mode 100644 index 000000000..aef7a4cce --- /dev/null +++ b/sdnr/northbound/energysavings/installer/src/main/resources/scripts/install-feature.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +### +# ============LICENSE_START======================================================= +# ONAP : CCSDK +# ================================================================================ +# Copyright (C) 2017 AT&T 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} +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} feature:repo-add ${features.repositories} +${ODL_KARAF_CLIENT} feature:install ${features.boot} diff --git a/sdnr/northbound/energysavings/model/pom.xml b/sdnr/northbound/energysavings/model/pom.xml new file mode 100644 index 000000000..d22fbfc34 --- /dev/null +++ b/sdnr/northbound/energysavings/model/pom.xml @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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>binding-parent</artifactId> + <version>1.0.5-SNAPSHOT</version> + <relativePath /> + </parent> + + <groupId>org.onap.ccsdk.features.sdnr.northbound</groupId> + <artifactId>energysavings-model</artifactId> + <version>0.2.4-SNAPSHOT</version> + <packaging>bundle</packaging> + + <dependencies> + <dependency> + <groupId>org.opendaylight.mdsal.model</groupId> + <artifactId>ietf-inet-types</artifactId> + </dependency> + <dependency> + <groupId>org.opendaylight.mdsal.model</groupId> + <artifactId>ietf-yang-types</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> + </pluginExecutions> + </lifecycleMappingMetadata> + </configuration> + </plugin> + </plugins> + </pluginManagement> + </build> +</project> diff --git a/sdnr/northbound/energysavings/model/src/main/yang/Energysavings.yang b/sdnr/northbound/energysavings/model/src/main/yang/Energysavings.yang new file mode 100644 index 000000000..572a9d432 --- /dev/null +++ b/sdnr/northbound/energysavings/model/src/main/yang/Energysavings.yang @@ -0,0 +1,22 @@ +module energysavings { + yang-version 1; + namespace "urn:opendaylight:params:xml:ns:yang:energysavings"; + prefix "energysavings"; + + revision "2015-01-05" { + description "Initial revision of energysavings model"; + } + + rpc payload { + input { + leaf payload { + type string; + } + } + output { + leaf result { + type string; + } + } + } +} diff --git a/sdnr/northbound/energysavings/pom.xml b/sdnr/northbound/energysavings/pom.xml new file mode 100644 index 000000000..395441a12 --- /dev/null +++ b/sdnr/northbound/energysavings/pom.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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>odlparent-lite</artifactId> + <version>1.0.5-SNAPSHOT</version> + <relativePath/> + </parent> + + <groupId>org.onap.ccsdk.features.sdnr.northbound</groupId> + <artifactId>energysavings</artifactId> + <version>0.2.4-SNAPSHOT</version> + <packaging>pom</packaging> + + <modules> + <module>model</module> + <module>features</module> + <module>provider</module> + <module>installer</module> + </modules> + + <properties> + <feature-name>energysavings-features</feature-name> + </properties> + +</project> diff --git a/sdnr/northbound/energysavings/provider/pom.xml b/sdnr/northbound/energysavings/provider/pom.xml new file mode 100644 index 000000000..39ff9a5cb --- /dev/null +++ b/sdnr/northbound/energysavings/provider/pom.xml @@ -0,0 +1,118 @@ +<?xml version="1.0" encoding="UTF-8"?> +<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>binding-parent</artifactId> + <version>1.0.5-SNAPSHOT</version> + <relativePath /> + </parent> + + <groupId>org.onap.ccsdk.features.sdnr.northbound</groupId> + <artifactId>energysavings-provider</artifactId> + <version>0.2.4-SNAPSHOT</version> + <packaging>bundle</packaging> + + <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>energysavings-model</artifactId> + <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> + </dependency> + <dependency> + <groupId>org.opendaylight.controller</groupId> + <artifactId>sal-common-util</artifactId> + </dependency> + <dependency> + <groupId>org.opendaylight.controller</groupId> + <artifactId>sal-core-api</artifactId> + </dependency> + <dependency> + <groupId>org.opendaylight.yangtools</groupId> + <artifactId>yang-data-impl</artifactId> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <!-- <version>${junit.version}</version> --> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.sun.jersey</groupId> + <artifactId>jersey-client</artifactId> + </dependency> + <dependency> + <groupId>com.sun.jersey</groupId> + <artifactId>jersey-core</artifactId> + </dependency> + <!-- <dependency> --> + <!-- <groupId>org.onap.ccsdk.sli.core</groupId> --> + <!-- <artifactId>sli-common</artifactId> --> + <!-- <version>0.1.3</version> --> + <!-- </dependency> --> + <!-- <dependency> --> + <!-- <groupId>org.onap.ccsdk.sli.plugins</groupId> --> + <!-- <artifactId>restapi-call-node-provider</artifactId> --> + <!-- <version>0.1.0</version> --> + <!-- </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> + </pluginExecutions> + </lifecycleMappingMetadata> + </configuration> + </plugin> + </plugins> + </pluginManagement> + </build> + +</project> diff --git a/sdnr/northbound/energysavings/provider/src/main/java/org/onap/ccsdk/features/sdnr/northbound/impl/EnergysavingsProvider.java b/sdnr/northbound/energysavings/provider/src/main/java/org/onap/ccsdk/features/sdnr/northbound/impl/EnergysavingsProvider.java new file mode 100644 index 000000000..d39ce9baa --- /dev/null +++ b/sdnr/northbound/energysavings/provider/src/main/java/org/onap/ccsdk/features/sdnr/northbound/impl/EnergysavingsProvider.java @@ -0,0 +1,273 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 AT&T 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.onap.ccsdk.features.sdnr.northbound.impl; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Collections; +import java.util.HashMap; +import java.util.Properties; +import java.util.concurrent.Future; +import javax.ws.rs.HttpMethod; +import javax.ws.rs.core.MediaType; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.energysavings.rev150105.EnergysavingsService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.energysavings.rev150105.PayloadInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.energysavings.rev150105.PayloadInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.energysavings.rev150105.PayloadOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.energysavings.rev150105.PayloadOutputBuilder; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.common.RpcResultBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration; +import com.google.common.base.Preconditions; +import com.google.common.util.concurrent.Futures; +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; + +public class EnergysavingsProvider implements EnergysavingsService { + + private static final Logger LOG = LoggerFactory.getLogger(EnergysavingsProvider.class); + + private final String appName = "EnergySavings"; + + private final DataBroker dataBroker; + private final RpcProviderRegistry rpcProviderRegistry; + private RpcRegistration<EnergysavingsService> serviceRegistration; + + // Locations and names of the configuration files + private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR"; + private static final String PROPERTIES_FILE_NAME = "sdnr-energy-savings.properties"; + private static final String PARSING_ERROR = + "Could not create the request message to send to the server; no message will be sent"; + + /* + * Use a flag veryFirstTime to ensure that some tasks are done only once. The value is set here and + * during initialization. + */ + private Boolean veryFirstTime = true; + + // Parameters for the REST calls + + // to publish SDNR_TO_POLICY DMaaP topic + private WebResource dmaapSdnrToPolicyWebResource = null; + + // to the Energy Savings server + private WebResource energySavingsWebResource = null; + + public EnergysavingsProvider(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(EnergysavingsService.class, this); + + LOG.debug("Initializing provider for " + appName); + + Preconditions.checkNotNull(dataBroker, "dataBroker must be set"); + + // Set the initialization flag so some tasks will be done only once + veryFirstTime = true; + + // Read parameters from the properties file in SDNC_CONFIG_DIR + 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 + "/"; + } + + // Get the parameters for the REST calls + HashMap<String, String> dmaapPolicyHttpParams = new HashMap<String, String>(); + HashMap<String, String> energySavingsServerHttpParams = 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", "httpMethod", "authentication", "user", "password"}) { + dmaapPolicyHttpParams.put(param, properties.getProperty("dmaapPolicy." + param)); + energySavingsServerHttpParams.put(param, properties.getProperty("energySavingsServer." + param)); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + // Create a web resource for the Energy Savings server + ClientConfig esClientConfig = new DefaultClientConfig(); + // 3 minute read time out + esClientConfig.getProperties().put(ClientConfig.PROPERTY_READ_TIMEOUT, 180000); + // 1 minute connect time out + esClientConfig.getProperties().put(ClientConfig.PROPERTY_CONNECT_TIMEOUT, 60000); + Client esClient = Client.create(esClientConfig); + + // Authentication for the Energy Savings server + if (energySavingsServerHttpParams.get("authentication").equals("basic")) { + esClient.addFilter(new HTTPBasicAuthFilter(energySavingsServerHttpParams.get("user"), + energySavingsServerHttpParams.get("password"))); + energySavingsWebResource = esClient.resource(energySavingsServerHttpParams.get("url")); + } else if (energySavingsServerHttpParams.get("authentication").equals("none")) { + energySavingsWebResource = esClient.resource(energySavingsServerHttpParams.get("url")); + } else { + LOG.error("Unexpected value for energy savings server authentication: " + + energySavingsServerHttpParams.get("authentication")); + } + + // Create a web resource for the DMaaP SDNR_TO_POLICY topic + ClientConfig dmaapClientConfig = new DefaultClientConfig(); + // 3 minute read time out + dmaapClientConfig.getProperties().put(ClientConfig.PROPERTY_READ_TIMEOUT, 180000); + // 1 minute connect time out + dmaapClientConfig.getProperties().put(ClientConfig.PROPERTY_CONNECT_TIMEOUT, 60000); + Client dmaapClient = Client.create(dmaapClientConfig); + + // Authentication for the DMaaP message router + if (dmaapPolicyHttpParams.get("authentication").equals("basic")) { + dmaapClient.addFilter( + new HTTPBasicAuthFilter(dmaapPolicyHttpParams.get("user"), dmaapPolicyHttpParams.get("password"))); + dmaapSdnrToPolicyWebResource = dmaapClient.resource(dmaapPolicyHttpParams.get("url")); + } else if (dmaapPolicyHttpParams.get("authentication").equals("none")) { + dmaapSdnrToPolicyWebResource = dmaapClient.resource(dmaapPolicyHttpParams.get("url")); + } else { + LOG.error("Unexpected value for DMaaP message router authentication: " + + dmaapPolicyHttpParams.get("authentication")); + } + + LOG.debug("energySavingsServerHttpParams: " + Collections.singletonList(energySavingsServerHttpParams)); + LOG.debug("dmaapPolicyHttpParams: " + Collections.singletonList(dmaapPolicyHttpParams)); + LOG.debug("Initialization complete for " + appName); + } + + /** + * Method called when the blueprint container is destroyed. + */ + public void close() { + LOG.debug("EnergysavingsProvider Closed"); + } + + @Override + public Future<RpcResult<PayloadOutput>> payload(PayloadInput input) { + + /* + * Policy has published a POLICY_TO_SDNR DMaaP topic. Currently, this feature simply forwards the + * input to the Energy Savings server untouched. + */ + + // Assume success + Boolean requestSucceeded = true; + + // Build the result now so error messages can be included in the response + PayloadOutputBuilder resultBuilder = new PayloadOutputBuilder(); + + if (input == null) { + LOG.error("Input is null"); + resultBuilder.setResult("Input is null"); + requestSucceeded = false; + } else { + try { + PayloadInputBuilder inputBuilder = new PayloadInputBuilder(input); + input = inputBuilder.build(); + LOG.debug("Received payload: " + input.getPayload()); + } catch (Exception e) { + LOG.error("Cannot build input"); + resultBuilder.setResult(e.toString() + " : " + e.getMessage()); + requestSucceeded = false; + } + } + + /* + * See if the web resources were created during initialization. No use in proceeding if not. + */ + if (energySavingsWebResource == null) { + LOG.error("energySavingsWebResouce is null"); + resultBuilder.setResult("energySavingsWebResource is null"); + requestSucceeded = false; + } + + if (dmaapSdnrToPolicyWebResource == null) { + LOG.error("dmaapSdnrToPolicyWebResouce is null"); + resultBuilder.setResult("dmaapSdnrToPolicyWebResource is null"); + requestSucceeded = false; + } + + /* + * Forward the POLICY_TO_SDNR message to the Energy Savings server + */ + + ClientResponse response = null; + if (requestSucceeded) { + try { + LOG.debug("Sending message to controller: \n" + input.getPayload()); + response = energySavingsWebResource.type(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON) + .method(HttpMethod.POST, ClientResponse.class, input.getPayload()); + LOG.debug("Received response from Energy Savings server: \n" + response.toString()); + } catch (Exception e) { + LOG.error("Error while posting POLICY_TO_SDNR input to server:", e); + resultBuilder.setResult("Error while posting POLICY_TO_SDNR input to server\n" + e.toString()); + requestSucceeded = false; + } + } + + /* + * Return the response from the server to Policy using the SDNR_TO_POLICY topic + */ + + if (requestSucceeded) { + String esServerResponse = response.getEntity(String.class); + try { + LOG.debug("Sending SDNR_TO_POLICY topic: \n" + esServerResponse); + response = + dmaapSdnrToPolicyWebResource.type(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON) + .method(HttpMethod.POST, ClientResponse.class, esServerResponse); + LOG.debug("Received response from DMaaP message router: \n" + response.toString()); + } catch (Exception e) { + LOG.error("Error while posting SDNR_TO_POLICY topic: ", e); + resultBuilder.setResult("Error while posting SDNR_TO_POLICY topic:\n" + e.toString()); + requestSucceeded = false; + } + } + + if (requestSucceeded) { + return Futures.immediateFuture( + RpcResultBuilder.<PayloadOutput>success().withResult(resultBuilder.build()).build()); + } else { + return Futures.immediateFuture( + RpcResultBuilder.<PayloadOutput>failed().withResult(resultBuilder.build()).build()); + } + } +} diff --git a/sdnr/northbound/energysavings/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml b/sdnr/northbound/energysavings/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml new file mode 100644 index 000000000..80d1d1a3f --- /dev/null +++ b/sdnr/northbound/energysavings/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- vi: set et smarttab sw=4 tabstop=4: --> +<!-- +Copyright © ${copyrightYear} ${copyright} and others. All rights reserved. + +This program and the accompanying materials are made available under the +terms of the Eclipse Public License v1.0 which accompanies this distribution, +and is available at http://www.eclipse.org/legal/epl-v10.html +--> +<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"> + + <reference id="dataBroker" + interface="org.opendaylight.controller.md.sal.binding.api.DataBroker" + odl:type="default" /> + + <bean id="provider" + class="org.onap.sdnc.northbound.sdnr.impl.EnergysavingsProvider" + init-method="init" destroy-method="close"> + <argument ref="dataBroker" /> + </bean> + +</blueprint> diff --git a/sdnr/northbound/energysavings/provider/src/main/resources/sdnr-energy-savings.properties b/sdnr/northbound/energysavings/provider/src/main/resources/sdnr-energy-savings.properties new file mode 100644 index 000000000..90c773a7e --- /dev/null +++ b/sdnr/northbound/energysavings/provider/src/main/resources/sdnr-energy-savings.properties @@ -0,0 +1,13 @@ +# Parameters for the different REST messages + +# To the Energy Savings server +energySavings.url = http://energy-savings-server +energySavings.httpMethod = post +energySavings.authentication = none + +# To publish a DMaaP topic that is a response to a energy savings request +dmaapPolicy.url = https://dmaap-message-router/events +dmaapPolicy.httpMethod = post +energySavings.authentication = basic +energySavings.user = user +energySavings.password = password |