summaryrefslogtreecommitdiffstats
path: root/properties-node/provider
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2017-07-18 20:35:53 -0400
committerDan Timoney <dtimoney@att.com>2017-08-01 11:35:12 -0400
commit7dbb6441c95aa5691a59dc918f864b4bf4e2e2ed (patch)
tree3386db7a205fbab8b1ef337396f4e57afbed9873 /properties-node/provider
parent2471b171ea1f3703950176691e4f7b228b9e2b60 (diff)
[CCSDK-6] Populate seed code
Add seed code for sli/plugins repository Changed groupId to org.onap.ccsdk.sli.plugins Updated to compile against CCSDK version of SLI Change-Id: Ib392530ea79b8544087692964bd65179896aa595 Signed-off-by: Dan Timoney <dtimoney@att.com>
Diffstat (limited to 'properties-node/provider')
-rwxr-xr-xproperties-node/provider/pom.xml89
-rw-r--r--properties-node/provider/src/main/java/org/openecomp/sdnc/prop/PropertiesNode.java97
-rw-r--r--properties-node/provider/src/main/resources/META-INF/spring/properties-node-context.xml32
-rw-r--r--properties-node/provider/src/main/resources/META-INF/spring/properties-node-osgi-context.xml32
4 files changed, 250 insertions, 0 deletions
diff --git a/properties-node/provider/pom.xml b/properties-node/provider/pom.xml
new file mode 100755
index 000000000..43369adf7
--- /dev/null
+++ b/properties-node/provider/pom.xml
@@ -0,0 +1,89 @@
+<?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.sli.plugins</groupId>
+ <artifactId>properties-node</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ </parent>
+ <groupId>org.onap.ccsdk.sli.plugins</groupId>
+ <version>0.0.1-SNAPSHOT</version>
+ <artifactId>properties-node-provider</artifactId>
+ <packaging>bundle</packaging>
+ <name>Properties Node - Provider</name>
+ <url>http://maven.apache.org</url>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>${spring.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.ccsdk.sli.core</groupId>
+ <artifactId>sli-common</artifactId>
+ <version>${sdnctl.sli.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.ccsdk.sli.core</groupId>
+ <artifactId>sli-provider</artifactId>
+ <version>${sdnctl.sli.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${slf4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jcl-over-slf4j</artifactId>
+ <version>${slf4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-beans</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+
+
+
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>org.onap.ccsdk.sli.prop</Bundle-SymbolicName>
+ <Export-Package>org.onap.ccsdk.sli.prop</Export-Package>
+ <Import-Package>*</Import-Package>
+ </instructions>
+
+
+ </configuration>
+
+ </plugin>
+
+
+ </plugins>
+
+ </build>
+</project>
diff --git a/properties-node/provider/src/main/java/org/openecomp/sdnc/prop/PropertiesNode.java b/properties-node/provider/src/main/java/org/openecomp/sdnc/prop/PropertiesNode.java
new file mode 100644
index 000000000..9856b1948
--- /dev/null
+++ b/properties-node/provider/src/main/java/org/openecomp/sdnc/prop/PropertiesNode.java
@@ -0,0 +1,97 @@
+/*-
+ * ============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.prop;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+import java.util.Properties;
+
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PropertiesNode implements SvcLogicJavaPlugin {
+
+ private static final Logger log = LoggerFactory.getLogger(PropertiesNode.class);
+
+ public void readProperties(Map<String, String> paramMap, SvcLogicContext ctx) throws SvcLogicException {
+ String fileName = parseParam(paramMap, "fileName", true, null);
+ String contextPrefix = parseParam(paramMap, "contextPrefix", false, null);
+
+ try {
+ Properties pp = new Properties();
+ InputStream in = new FileInputStream(fileName);
+ pp.load(in);
+ for (Object key : pp.keySet()) {
+ String pfx = contextPrefix != null ? contextPrefix + '.' : "";
+ String name = (String) key;
+ String value = pp.getProperty(name);
+ if (value != null && value.trim().length() > 0) {
+ ctx.setAttribute(pfx + name, value.trim());
+ log.info("+++ " + pfx + name + ": [" + value + "]");
+ }
+ }
+ } catch (IOException e) {
+ throw new SvcLogicException("Cannot read property file: " + fileName + ": " + e.getMessage(), e);
+ }
+ }
+
+ private String parseParam(Map<String, String> paramMap, String name, boolean required, String def)
+ throws SvcLogicException {
+ String s = paramMap.get(name);
+
+ if (s == null || s.trim().length() == 0) {
+ if (!required)
+ return def;
+ throw new SvcLogicException("Parameter " + name + " is required in PropertiesNode");
+ }
+
+ s = s.trim();
+ String value = "";
+ int i = 0;
+ int i1 = s.indexOf('%');
+ while (i1 >= 0) {
+ int i2 = s.indexOf('%', i1 + 1);
+ if (i2 < 0)
+ throw new SvcLogicException("Cannot parse parameter " + name + ": " + s + ": no matching %");
+
+ String varName = s.substring(i1 + 1, i2);
+ String varValue = System.getenv(varName);
+ if (varValue == null)
+ varValue = "";
+
+ value += s.substring(i, i1);
+ value += varValue;
+
+ i = i2 + 1;
+ i1 = s.indexOf('%', i);
+ }
+ value += s.substring(i);
+
+ log.info("Parameter " + name + ": " + value);
+ return value;
+ }
+}
diff --git a/properties-node/provider/src/main/resources/META-INF/spring/properties-node-context.xml b/properties-node/provider/src/main/resources/META-INF/spring/properties-node-context.xml
new file mode 100644
index 000000000..a53ea1414
--- /dev/null
+++ b/properties-node/provider/src/main/resources/META-INF/spring/properties-node-context.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ============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=========================================================
+ -->
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+ <bean id="propertiesNode" class="org.openecomp.sdnc.prop.PropertiesNode">
+ </bean>
+
+</beans>
diff --git a/properties-node/provider/src/main/resources/META-INF/spring/properties-node-osgi-context.xml b/properties-node/provider/src/main/resources/META-INF/spring/properties-node-osgi-context.xml
new file mode 100644
index 000000000..7d74fd4f0
--- /dev/null
+++ b/properties-node/provider/src/main/resources/META-INF/spring/properties-node-osgi-context.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============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=========================================================
+ -->
+
+<beans:beans xmlns="http://www.springframework.org/schema/osgi"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
+ xsi:schemaLocation="http://www.springframework.org/schema/osgi
+ http://www.springframework.org/schema/osgi/spring-osgi.xsd
+ http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+ <service ref="propertiesNode" interface="org.openecomp.sdnc.prop.PropertiesNode" />
+
+</beans:beans>