summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xpom.xml1
-rw-r--r--template-node/features/ccsdk-template-node/pom.xml28
-rw-r--r--template-node/features/features-template-node/pom.xml27
-rw-r--r--template-node/features/pom.xml20
-rw-r--r--template-node/installer/pom.xml136
-rw-r--r--template-node/installer/src/assembly/assemble_installer_zip.xml59
-rw-r--r--template-node/installer/src/assembly/assemble_mvnrepo_zip.xml49
-rw-r--r--template-node/installer/src/main/resources/scripts/install-feature.sh39
-rw-r--r--template-node/pom.xml21
-rw-r--r--template-node/provider/pom.xml40
-rw-r--r--template-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/template/TemplateNode.java108
-rw-r--r--template-node/provider/src/main/resources/OSGI-INF/blueprint/blueprint.xml8
-rw-r--r--template-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/template/MockTemplateNode.java7
-rw-r--r--template-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/template/TemplateNodeTest.java85
-rw-r--r--template-node/provider/src/test/resources/basic.vtl12
-rw-r--r--template-node/provider/src/test/resources/template-node.properties4
16 files changed, 644 insertions, 0 deletions
diff --git a/pom.xml b/pom.xml
index 164d81e27..a41f2311c 100755
--- a/pom.xml
+++ b/pom.xml
@@ -26,6 +26,7 @@
<module>sshapi-call-node</module>
<module>restconf-client</module>
<module>features</module>
+ <module>template-node</module>
</modules>
<scm>
diff --git a/template-node/features/ccsdk-template-node/pom.xml b/template-node/features/ccsdk-template-node/pom.xml
new file mode 100644
index 000000000..fd3a92457
--- /dev/null
+++ b/template-node/features/ccsdk-template-node/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>single-feature-parent</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <relativePath />
+ </parent>
+
+ <groupId>org.onap.ccsdk.sli.plugins</groupId>
+ <artifactId>ccsdk-template-node</artifactId>
+ <version>0.3.3-SNAPSHOT</version>
+ <packaging>feature</packaging>
+
+ <properties>
+ <skip.karaf.featureTest>true</skip.karaf.featureTest>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>template-node-provider</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/template-node/features/features-template-node/pom.xml b/template-node/features/features-template-node/pom.xml
new file mode 100644
index 000000000..c352ba514
--- /dev/null
+++ b/template-node/features/features-template-node/pom.xml
@@ -0,0 +1,27 @@
+<?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.1.0-SNAPSHOT</version>
+ <relativePath/>
+ </parent>
+
+ <groupId>org.onap.ccsdk.sli.plugins</groupId>
+ <artifactId>features-template-node</artifactId>
+ <version>0.3.3-SNAPSHOT</version>
+ <packaging>feature</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>ccsdk-template-node</artifactId>
+ <version>${project.version}</version>
+ <type>xml</type>
+ <classifier>features</classifier>
+ </dependency>
+
+ </dependencies>
+</project>
diff --git a/template-node/features/pom.xml b/template-node/features/pom.xml
new file mode 100644
index 000000000..1abcdbe3e
--- /dev/null
+++ b/template-node/features/pom.xml
@@ -0,0 +1,20 @@
+<?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.1.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.onap.ccsdk.sli.plugins</groupId>
+ <artifactId>template-node-features</artifactId>
+ <version>0.3.3-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <modules>
+ <module>ccsdk-template-node</module>
+ <module>features-template-node</module>
+ </modules>
+</project>
diff --git a/template-node/installer/pom.xml b/template-node/installer/pom.xml
new file mode 100644
index 000000000..1e4d24cd3
--- /dev/null
+++ b/template-node/installer/pom.xml
@@ -0,0 +1,136 @@
+<?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.1.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.onap.ccsdk.sli.plugins</groupId>
+ <artifactId>template-node-installer</artifactId>
+ <version>0.3.3-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <properties>
+ <application.name>ccsdk-template-node</application.name>
+ <features.boot>${application.name}</features.boot>
+ <features.repositories>mvn:org.onap.ccsdk.sli.plugins/${features.boot}/${project.version}/xml/features</features.repositories>
+ <include.transitive.dependencies>false</include.transitive.dependencies>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.ccsdk.sli.plugins</groupId>
+ <artifactId>${application.name}</artifactId>
+ <version>${project.version}</version>
+ <type>xml</type>
+ <classifier>features</classifier>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.ccsdk.sli.plugins</groupId>
+ <artifactId>template-node-provider</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.6</version>
+ <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>
+ <includeGroupIds>org.onap.ccsdk.sli.plugins,org.apache.velocity</includeGroupIds>
+ <scope>provided</scope>
+ </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/template-node/installer/src/assembly/assemble_installer_zip.xml b/template-node/installer/src/assembly/assemble_installer_zip.xml
new file mode 100644
index 000000000..b6fd65582
--- /dev/null
+++ b/template-node/installer/src/assembly/assemble_installer_zip.xml
@@ -0,0 +1,59 @@
+<!--
+ ============LICENSE_START=======================================================
+ openECOMP : SDN-C
+ ================================================================================
+ 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>installer_zip</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/template-node/installer/src/assembly/assemble_mvnrepo_zip.xml b/template-node/installer/src/assembly/assemble_mvnrepo_zip.xml
new file mode 100644
index 000000000..2ee224477
--- /dev/null
+++ b/template-node/installer/src/assembly/assemble_mvnrepo_zip.xml
@@ -0,0 +1,49 @@
+<!--
+ ============LICENSE_START=======================================================
+ openECOMP : SDN-C
+ ================================================================================
+ 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>mvnrepo_zip</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/template-node/installer/src/main/resources/scripts/install-feature.sh b/template-node/installer/src/main/resources/scripts/install-feature.sh
new file mode 100644
index 000000000..0eab001d5
--- /dev/null
+++ b/template-node/installer/src/main/resources/scripts/install-feature.sh
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+###
+# ============LICENSE_START=======================================================
+# openECOMP : SDN-C
+# ================================================================================
+# 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/template-node/pom.xml b/template-node/pom.xml
new file mode 100644
index 000000000..21ab127f3
--- /dev/null
+++ b/template-node/pom.xml
@@ -0,0 +1,21 @@
+<?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.1.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.onap.ccsdk.sli.plugins</groupId>
+ <artifactId>template-node</artifactId>
+ <version>0.3.3-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <modules>
+ <module>provider</module>
+ <module>features</module>
+ <module>installer</module>
+ </modules>
+</project>
diff --git a/template-node/provider/pom.xml b/template-node/provider/pom.xml
new file mode 100644
index 000000000..936f76f37
--- /dev/null
+++ b/template-node/provider/pom.xml
@@ -0,0 +1,40 @@
+<?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.1.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.onap.ccsdk.sli.plugins</groupId>
+ <artifactId>template-node-provider</artifactId>
+ <version>0.3.3-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.ccsdk.sli.core</groupId>
+ <artifactId>sli-common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.ccsdk.sli.core</groupId>
+ <artifactId>sli-provider</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.velocity</groupId>
+ <artifactId>velocity</artifactId>
+ <version>1.7</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/template-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/template/TemplateNode.java b/template-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/template/TemplateNode.java
new file mode 100644
index 000000000..8a9676817
--- /dev/null
+++ b/template-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/template/TemplateNode.java
@@ -0,0 +1,108 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * 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.sli.plugins.template;
+
+import java.io.FileInputStream;
+import java.io.StringWriter;
+import java.util.Map;
+import java.util.Properties;
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.runtime.RuntimeConstants;
+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 TemplateNode implements SvcLogicJavaPlugin {
+ private static final Logger logger = LoggerFactory.getLogger(TemplateNode.class);
+ public final static String TEMPLATE_PATH = "templatePath";
+ public final static String OUTPUT_PATH_KEY = "output";
+ public final static String PREFIX_KEY = "prefix";
+ public final static String REQUIRED_PARAMETERS_ERROR_MESSAGE = "templateName & outputPath are required fields";
+ protected static final String TEMPLATE_PROPERTIES_FILE_NAME = "template-node.properties";
+ protected static final String DEFAULT_PROPERTIES_DIR = "/opt/onap/ccsdk/data/properties";
+ protected static final String PROPERTIES_DIR_KEY = "SDNC_CONFIG_DIR";
+
+ protected VelocityEngine ve;
+
+ public TemplateNode() {
+ ve = new VelocityEngine();
+ setProperties();
+ ve.init();
+ }
+
+ protected void setProperties() {
+ String configDir = System.getProperty(PROPERTIES_DIR_KEY, DEFAULT_PROPERTIES_DIR);
+ Properties props = new Properties();
+
+ try (FileInputStream in = new FileInputStream(configDir + "/" + TEMPLATE_PROPERTIES_FILE_NAME)) {
+ props.load(in);
+ } catch (Exception e) {
+ logger.error("Caught exception loading properties!", e);
+ }
+
+ // give sensible defaults for required properties
+ ve.setProperty(RuntimeConstants.RESOURCE_LOADER, props.getProperty("velocity.resource.loader", "file"));
+ ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH,
+ props.getProperty("velocity.file.resource.loader.path", "/opt/onap/sdnc/restapi/templates"));
+ ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE,
+ props.getProperty("velocity.file.resource.loader.cache", "false"));
+
+ // allow flexible reading of additional velocity properties
+ for (String propertyName : props.stringPropertyNames()) {
+ if (propertyName.startsWith("velocity")) {
+ logger.error("set " + propertyName.substring(9) + "=" + props.get(propertyName));
+ ve.setProperty(propertyName.substring(9), props.get(propertyName));
+ }
+ }
+ }
+
+ public void evaluateTemplate(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
+ String templateName = params.get(TEMPLATE_PATH);
+ String outputPath = params.get(OUTPUT_PATH_KEY);
+ String prefix = params.get(PREFIX_KEY);
+
+ if (prefix != null && prefix.length() > 0) {
+ outputPath = prefix + "." + outputPath;
+ }
+
+ if (templateName == null || outputPath == null) {
+ throw new SvcLogicException(REQUIRED_PARAMETERS_ERROR_MESSAGE);
+ } else {
+ try {
+ Template template = ve.getTemplate(templateName);
+ VelocityContext context = new VelocityContext();
+ context.put("ctx", ctx);
+ context.put("params", params);
+ StringWriter sw = new StringWriter();
+ template.merge(context, sw);
+ ctx.setAttribute(outputPath, sw.toString());
+ } catch (Exception e) {
+ throw new SvcLogicException(e.getMessage());
+ }
+ }
+ }
+
+} \ No newline at end of file
diff --git a/template-node/provider/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/template-node/provider/src/main/resources/OSGI-INF/blueprint/blueprint.xml
new file mode 100644
index 000000000..a8006b9b0
--- /dev/null
+++ b/template-node/provider/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+ <bean id="templateNode" class="org.onap.ccsdk.sli.plugins.template.TemplateNode" />
+
+ <service id="templateNodeService" ref="templateNode" interface="org.onap.ccsdk.sli.plugins.template.TemplateNode" />
+
+</blueprint> \ No newline at end of file
diff --git a/template-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/template/MockTemplateNode.java b/template-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/template/MockTemplateNode.java
new file mode 100644
index 000000000..d628ac929
--- /dev/null
+++ b/template-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/template/MockTemplateNode.java
@@ -0,0 +1,7 @@
+package org.onap.ccsdk.sli.plugins.template;
+
+public class MockTemplateNode extends TemplateNode {
+ protected void setProperties() {
+ // do nothing
+ }
+}
diff --git a/template-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/template/TemplateNodeTest.java b/template-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/template/TemplateNodeTest.java
new file mode 100644
index 000000000..29c5c973e
--- /dev/null
+++ b/template-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/template/TemplateNodeTest.java
@@ -0,0 +1,85 @@
+package org.onap.ccsdk.sli.plugins.template;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Vector;
+import org.apache.velocity.runtime.RuntimeConstants;
+import org.junit.Test;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+
+public class TemplateNodeTest {
+
+ @Test
+ public void sunnyDay() throws Exception {
+ String requestId = "REQ001";
+ String uniqueKey = "UNIQUE_TEST";
+ String action = "uPdaTe";
+ String serviceType = "VPN";
+
+ TemplateNode t = new MockTemplateNode();
+
+ Map<String, String> params = new HashMap<String, String>();
+ params.put(TemplateNode.PREFIX_KEY, "output");
+ params.put(TemplateNode.OUTPUT_PATH_KEY, "mycontainer");
+ params.put(TemplateNode.TEMPLATE_PATH, "src/test/resources/basic.vtl");
+ params.put("service-type", serviceType);
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("input.svc-request-id", requestId);
+ ctx.setAttribute("input.unique-key", uniqueKey);
+ ctx.setAttribute("action", action);
+
+ t.evaluateTemplate(params, ctx);
+ String result = ctx.getAttribute("output.mycontainer");
+ assertNotNull(result);
+ assertTrue(result.contains(requestId));
+ assertTrue(result.contains(uniqueKey));
+ assertTrue(result.contains(action.toUpperCase()));
+ assertTrue(result.contains(serviceType));
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void parameterException() throws Exception {
+ TemplateNode t = new MockTemplateNode();
+ Map<String, String> params = new HashMap<String, String>();
+ SvcLogicContext ctx = new SvcLogicContext();
+ t.evaluateTemplate(params, ctx);
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void missingTemplate() throws Exception {
+ TemplateNode t = new MockTemplateNode();
+ Map<String, String> params = new HashMap<String, String>();
+ params.put(TemplateNode.PREFIX_KEY, "output");
+ params.put(TemplateNode.OUTPUT_PATH_KEY, "mycontainer");
+ params.put(TemplateNode.TEMPLATE_PATH, "src/test/resources/missing.vtl");
+ SvcLogicContext ctx = new SvcLogicContext();
+ t.evaluateTemplate(params, ctx);
+ }
+
+ @Test
+ public void withProperties() throws Exception {
+ System.setProperty(TemplateNode.PROPERTIES_DIR_KEY, "src/test/resources");
+ TemplateNode t = new TemplateNode();
+ Vector<String> loader = (Vector<String>) t.ve.getProperty(RuntimeConstants.RESOURCE_LOADER);
+ assertTrue(loader.contains("class"));
+ assertEquals("/home/my/example", t.ve.getProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH));
+ assertEquals("true", t.ve.getProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE));
+ assertEquals("customValue", t.ve.getProperty("custom.property"));
+ }
+
+ @Test
+ public void withNoProperties() throws Exception {
+ System.setProperty(TemplateNode.PROPERTIES_DIR_KEY, "i/do/not/exist");
+ TemplateNode t = new TemplateNode();
+ Vector<String> loader = (Vector<String>) t.ve.getProperty(RuntimeConstants.RESOURCE_LOADER);
+ assertTrue(loader.contains("file"));
+ assertEquals("/opt/onap/sdnc/restapi/templates", t.ve.getProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH));
+ assertEquals("false", t.ve.getProperty(RuntimeConstants.FILE_RESOURCE_LOADER_CACHE));
+ assertEquals(null, t.ve.getProperty("custom.property"));
+ }
+
+} \ No newline at end of file
diff --git a/template-node/provider/src/test/resources/basic.vtl b/template-node/provider/src/test/resources/basic.vtl
new file mode 100644
index 000000000..63fcc670a
--- /dev/null
+++ b/template-node/provider/src/test/resources/basic.vtl
@@ -0,0 +1,12 @@
+{
+ "input": {
+ "sdnc-request-header": {
+ "svc-request-id": "$ctx.getAttribute("input.svc-request-id")",
+ "svc-action": "$ctx.getAttribute("action").toUpperCase()"
+ },
+ "service-information": {
+ "service-type": "$params.get("service-type")",
+ "service-instance-id": "$ctx.getAttribute("input.unique-key")"
+ }
+ }
+} \ No newline at end of file
diff --git a/template-node/provider/src/test/resources/template-node.properties b/template-node/provider/src/test/resources/template-node.properties
new file mode 100644
index 000000000..1199a0cde
--- /dev/null
+++ b/template-node/provider/src/test/resources/template-node.properties
@@ -0,0 +1,4 @@
+velocity.resource.loader=class
+velocity.file.resource.loader.path=/home/my/example
+velocity.file.resource.loader.cache=true
+velocity.custom.property=customValue \ No newline at end of file