From eb2d40205c8fa043166027a10d9cdb10415e6cbf Mon Sep 17 00:00:00 2001 From: Marcus G K Williams Date: Wed, 30 Aug 2017 19:32:32 -0700 Subject: Update SDNC NB to depend on CCSDK Refactor code to use CCSDK Issue-Id: SDNC-50 Change-Id: If637d1a0609ec5ae9df60939f72eb64888e61e71 Signed-off-by: Marcus G K Williams --- vnftools/provider/pom.xml | 16 +- .../main/java/org/onap/sdnc/vnftools/VnfTools.java | 205 +++++++++++++++++++++ .../org/onap/sdnc/vnftools/VnfToolsActivator.java | 87 +++++++++ .../java/org/openecomp/sdnc/vnftools/VnfTools.java | 205 --------------------- .../openecomp/sdnc/vnftools/VnfToolsActivator.java | 87 --------- 5 files changed, 300 insertions(+), 300 deletions(-) create mode 100644 vnftools/provider/src/main/java/org/onap/sdnc/vnftools/VnfTools.java create mode 100644 vnftools/provider/src/main/java/org/onap/sdnc/vnftools/VnfToolsActivator.java delete mode 100644 vnftools/provider/src/main/java/org/openecomp/sdnc/vnftools/VnfTools.java delete mode 100644 vnftools/provider/src/main/java/org/openecomp/sdnc/vnftools/VnfToolsActivator.java (limited to 'vnftools/provider') diff --git a/vnftools/provider/pom.xml b/vnftools/provider/pom.xml index 22512d0f..146453ef 100644 --- a/vnftools/provider/pom.xml +++ b/vnftools/provider/pom.xml @@ -2,7 +2,7 @@ 4.0.0 - org.openecomp.sdnc.northbound + org.onap.sdnc.northbound vnftools 1.2.0-SNAPSHOT @@ -21,13 +21,13 @@ test - org.openecomp.sdnc.core + org.onap.ccsdk.sli.core sli-common ${sdnctl.sli.version} compile - org.openecomp.sdnc.core + org.onap.ccsdk.sli.core sli-provider ${sdnctl.sli.version} compile @@ -49,7 +49,7 @@ - org.openecomp.sdnc.core + org.onap.ccsdk.sli.core sliPluginUtils-provider ${sdnctl.slipluginutils.version} jar @@ -68,10 +68,10 @@ true - org.openecomp.sdnc.vnftools - org.openecomp.sdnc.vnftools.VnfToolsActivator - org.openecomp.sdnc.vnftools - org.openecomp.sdnc.*,org.osgi.framework.*,org.slf4j.*,java.net.*,org.apache.commons.* + org.onap.sdnc.vnftools + org.onap.sdnc.vnftools.VnfToolsActivator + org.onap.sdnc.vnftools + org.onap.sdnc.*,org.osgi.framework.*,org.slf4j.*,java.net.*,org.apache.commons.* *;scope=compile|runtime;artifactId=!sli-common|org.eclipse.osgi|mysql-connector-java|slf4j-api|jcl-over-slf4j|xml-apis|InetAddress|commons-lang3 true diff --git a/vnftools/provider/src/main/java/org/onap/sdnc/vnftools/VnfTools.java b/vnftools/provider/src/main/java/org/onap/sdnc/vnftools/VnfTools.java new file mode 100644 index 00000000..b3497bd5 --- /dev/null +++ b/vnftools/provider/src/main/java/org/onap/sdnc/vnftools/VnfTools.java @@ -0,0 +1,205 @@ +/*- + * ============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.sdnc.vnftools; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.List; +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.onap.ccsdk.sli.core.slipluginutils.SliPluginUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class VnfTools implements SvcLogicJavaPlugin { + // ========== FIELDS ========== + + private static final Logger LOG = LoggerFactory.getLogger(VnfTools.class); + + // ========== CONSTRUCTORS ========== + + public VnfTools(Properties props) { + if (props != null) { + LOG.debug("props is not null."); + } + } + + + public void checkIfActivateReady( Map parameters, SvcLogicContext ctx ) throws SvcLogicException { + LOG.debug("Checking if enough data is available to send the NCS Activate request..."); + + SliPluginUtils.checkParameters(parameters, new String[]{"return-key"}, LOG); + final String returnKey = parameters.get("return-key"); + ctx.setAttribute(returnKey, "true"); + + } + + /** + * DG node performs a java String.contains(String) and writes true or false + * to a key in context memory. + * @param parameters Hashmap in context memory must contain the following: + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
KeyDescription
string_to_searchString to perform java String.contains(String) on
string_to_findString to find in the string_to_search
result_ctx_stringContext memory key to write the result ("true" or "false") to
+ * @param ctx Reference to context memory + * @throws SvcLogicException + */ + public void stringContains( Map parameters, SvcLogicContext ctx ) throws SvcLogicException { + SliPluginUtils.checkParameters(parameters, new String[]{"string_to_search","string_to_find","result_ctx_string"}, LOG); + ctx.setAttribute(parameters.get("result_ctx_string"), Boolean.toString(parameters.get("string_to_search").contains(parameters.get("string_to_find")))); + } + + + public void generateName( Map parameters, SvcLogicContext ctx ) throws SvcLogicException { + LOG.debug("generateName"); + + SliPluginUtils.checkParameters(parameters, new String[]{"base","suffix","return-path"}, LOG); + + String base = parameters.get("base"); + ctx.setAttribute( parameters.get("return-path"), base.substring(0, base.length() - 4) + parameters.get("suffix") + base.substring(base.length() - 2) ); + } + + + private boolean matches(String str1, String str2) { + if (str1 == null) { + if (str2 == null) { + return true; + } else { + return false; + } + } else { + if (str2 == null) { + return false; + } else { + return str1.equals(str2); + } + } + } + + private void setIfNotNull(String property, String value, SvcLogicContext ctx) { + if (value != null) { + LOG.debug("Setting " + property + " to " + value); + ctx.setAttribute(property, value); + } + } + + /* + * Moves an array element from one index to another + */ + private void copyArrayEntry(String srcRoot, String destRoot, SvcLogicContext ctx) { + LOG.debug("copyArrayEntry called: srcRoot=" + srcRoot + ", destRoot=" + destRoot); + + // Record all of the source keys + List keysToMove = new ArrayList(); + for (String key : ctx.getAttributeKeySet()) { + if (key.startsWith(srcRoot)) { + keysToMove.add(key); + } + } + + // Now loop through and copy those keys to the destination, and then delete the source + for (String key : keysToMove) { + String suffix = key.substring(srcRoot.length()); + LOG.debug("Move " + key + " to " + destRoot + suffix); + ctx.setAttribute(destRoot + suffix, ctx.getAttribute(key)); + ctx.setAttribute(key, null); + } + + } + + public void printContext(Map parameters, SvcLogicContext ctx) throws SvcLogicException { + if (parameters == null) { + throw new SvcLogicException("no parameters passed"); + } + + String fileName = parameters.get("filename"); + + if ((fileName == null) || (fileName.length() == 0)) { + throw new SvcLogicException("printContext requires 'filename' parameter"); + } + + PrintStream pstr = null; + + try { + pstr = new PrintStream(new FileOutputStream(new File(fileName), true)); + } catch (Exception e) { + throw new SvcLogicException("Cannot open file " + fileName, e); + } + pstr.println("#######################################"); + for (String attr : ctx.getAttributeKeySet()) { + pstr.println(attr + " = " + ctx.getAttribute(attr)); + } + pstr.flush(); + pstr.close(); + } + + static int getArrayLength( SvcLogicContext ctx, String key ) { + try { + return Integer.parseInt(ctx.getAttribute(key)); + } catch( NumberFormatException e ) {} + + return 0; + } + + static int getArrayLength( SvcLogicContext ctx, String key, String debug ) { + try { + return Integer.parseInt(ctx.getAttribute(key)); + } catch( NumberFormatException e ) { + LOG.debug(debug); + } + + return 0; + } + + /** + * Returns true if string is null or empty. + * @param str + * @return + */ + private static boolean stringIsBlank( String str ) { + return str == null || str.isEmpty(); + } + +} diff --git a/vnftools/provider/src/main/java/org/onap/sdnc/vnftools/VnfToolsActivator.java b/vnftools/provider/src/main/java/org/onap/sdnc/vnftools/VnfToolsActivator.java new file mode 100644 index 00000000..5a06b07c --- /dev/null +++ b/vnftools/provider/src/main/java/org/onap/sdnc/vnftools/VnfToolsActivator.java @@ -0,0 +1,87 @@ +/*- + * ============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.sdnc.vnftools; + +import java.io.File; +import java.io.FileInputStream; +import java.util.LinkedList; +import java.util.List; +import java.util.Properties; + +import org.onap.ccsdk.sli.core.sli.ConfigurationException; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class VnfToolsActivator implements BundleActivator { + + private static final String VNFTOOLS_PROP_VAR = "/vnftools.properties"; + private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR"; + + @SuppressWarnings("rawtypes") + private List registrations = new LinkedList(); + + private static final Logger LOG = LoggerFactory.getLogger(VnfToolsActivator.class); + + @Override + public void start(BundleContext ctx) throws Exception { + // Read properties + Properties props = new Properties(); + + String propDir = System.getenv(SDNC_CONFIG_DIR); + if (propDir == null) { + propDir = "/opt/sdnc/data/properties"; + } + + String propPath = propDir + VNFTOOLS_PROP_VAR; + + File propFile = new File(propPath); + + if (!propFile.exists()) { + props = null; + } else { + + try { + props.load(new FileInputStream(propFile)); + } catch (Exception e) { + throw new ConfigurationException("Could not load properties file " + propPath, e); + } + } + VnfTools plugin = new VnfTools(props); + + LOG.info("Registering service " + plugin.getClass().getName()); + registrations.add(ctx.registerService(plugin.getClass().getName(), plugin, null)); + } + + @Override + public void stop(BundleContext ctx) throws Exception { + + for (@SuppressWarnings("rawtypes") + ServiceRegistration registration : registrations) { + registration.unregister(); + registration = null; + } + } + +} diff --git a/vnftools/provider/src/main/java/org/openecomp/sdnc/vnftools/VnfTools.java b/vnftools/provider/src/main/java/org/openecomp/sdnc/vnftools/VnfTools.java deleted file mode 100644 index 33acace9..00000000 --- a/vnftools/provider/src/main/java/org/openecomp/sdnc/vnftools/VnfTools.java +++ /dev/null @@ -1,205 +0,0 @@ -/*- - * ============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.openecomp.sdnc.vnftools; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.openecomp.sdnc.sli.SvcLogicException; -import org.openecomp.sdnc.sli.SvcLogicJavaPlugin; -import org.openecomp.sdnc.sli.SliPluginUtils.SliPluginUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class VnfTools implements SvcLogicJavaPlugin { - // ========== FIELDS ========== - - private static final Logger LOG = LoggerFactory.getLogger(VnfTools.class); - - // ========== CONSTRUCTORS ========== - - public VnfTools(Properties props) { - if (props != null) { - LOG.debug("props is not null."); - } - } - - - public void checkIfActivateReady( Map parameters, SvcLogicContext ctx ) throws SvcLogicException { - LOG.debug("Checking if enough data is available to send the NCS Activate request..."); - - SliPluginUtils.checkParameters(parameters, new String[]{"return-key"}, LOG); - final String returnKey = parameters.get("return-key"); - ctx.setAttribute(returnKey, "true"); - - } - - /** - * DG node performs a java String.contains(String) and writes true or false - * to a key in context memory. - * @param parameters Hashmap in context memory must contain the following: - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
KeyDescription
string_to_searchString to perform java String.contains(String) on
string_to_findString to find in the string_to_search
result_ctx_stringContext memory key to write the result ("true" or "false") to
- * @param ctx Reference to context memory - * @throws SvcLogicException - */ - public void stringContains( Map parameters, SvcLogicContext ctx ) throws SvcLogicException { - SliPluginUtils.checkParameters(parameters, new String[]{"string_to_search","string_to_find","result_ctx_string"}, LOG); - ctx.setAttribute(parameters.get("result_ctx_string"), Boolean.toString(parameters.get("string_to_search").contains(parameters.get("string_to_find")))); - } - - - public void generateName( Map parameters, SvcLogicContext ctx ) throws SvcLogicException { - LOG.debug("generateName"); - - SliPluginUtils.checkParameters(parameters, new String[]{"base","suffix","return-path"}, LOG); - - String base = parameters.get("base"); - ctx.setAttribute( parameters.get("return-path"), base.substring(0, base.length() - 4) + parameters.get("suffix") + base.substring(base.length() - 2) ); - } - - - private boolean matches(String str1, String str2) { - if (str1 == null) { - if (str2 == null) { - return true; - } else { - return false; - } - } else { - if (str2 == null) { - return false; - } else { - return str1.equals(str2); - } - } - } - - private void setIfNotNull(String property, String value, SvcLogicContext ctx) { - if (value != null) { - LOG.debug("Setting " + property + " to " + value); - ctx.setAttribute(property, value); - } - } - - /* - * Moves an array element from one index to another - */ - private void copyArrayEntry(String srcRoot, String destRoot, SvcLogicContext ctx) { - LOG.debug("copyArrayEntry called: srcRoot=" + srcRoot + ", destRoot=" + destRoot); - - // Record all of the source keys - List keysToMove = new ArrayList(); - for (String key : ctx.getAttributeKeySet()) { - if (key.startsWith(srcRoot)) { - keysToMove.add(key); - } - } - - // Now loop through and copy those keys to the destination, and then delete the source - for (String key : keysToMove) { - String suffix = key.substring(srcRoot.length()); - LOG.debug("Move " + key + " to " + destRoot + suffix); - ctx.setAttribute(destRoot + suffix, ctx.getAttribute(key)); - ctx.setAttribute(key, null); - } - - } - - public void printContext(Map parameters, SvcLogicContext ctx) throws SvcLogicException { - if (parameters == null) { - throw new SvcLogicException("no parameters passed"); - } - - String fileName = parameters.get("filename"); - - if ((fileName == null) || (fileName.length() == 0)) { - throw new SvcLogicException("printContext requires 'filename' parameter"); - } - - PrintStream pstr = null; - - try { - pstr = new PrintStream(new FileOutputStream(new File(fileName), true)); - } catch (Exception e) { - throw new SvcLogicException("Cannot open file " + fileName, e); - } - pstr.println("#######################################"); - for (String attr : ctx.getAttributeKeySet()) { - pstr.println(attr + " = " + ctx.getAttribute(attr)); - } - pstr.flush(); - pstr.close(); - } - - static int getArrayLength( SvcLogicContext ctx, String key ) { - try { - return Integer.parseInt(ctx.getAttribute(key)); - } catch( NumberFormatException e ) {} - - return 0; - } - - static int getArrayLength( SvcLogicContext ctx, String key, String debug ) { - try { - return Integer.parseInt(ctx.getAttribute(key)); - } catch( NumberFormatException e ) { - LOG.debug(debug); - } - - return 0; - } - - /** - * Returns true if string is null or empty. - * @param str - * @return - */ - private static boolean stringIsBlank( String str ) { - return str == null || str.isEmpty(); - } - -} diff --git a/vnftools/provider/src/main/java/org/openecomp/sdnc/vnftools/VnfToolsActivator.java b/vnftools/provider/src/main/java/org/openecomp/sdnc/vnftools/VnfToolsActivator.java deleted file mode 100644 index 23338d5d..00000000 --- a/vnftools/provider/src/main/java/org/openecomp/sdnc/vnftools/VnfToolsActivator.java +++ /dev/null @@ -1,87 +0,0 @@ -/*- - * ============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.openecomp.sdnc.vnftools; - -import java.io.File; -import java.io.FileInputStream; -import java.util.LinkedList; -import java.util.List; -import java.util.Properties; - -import org.openecomp.sdnc.sli.ConfigurationException; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class VnfToolsActivator implements BundleActivator { - - private static final String VNFTOOLS_PROP_VAR = "/vnftools.properties"; - private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR"; - - @SuppressWarnings("rawtypes") - private List registrations = new LinkedList(); - - private static final Logger LOG = LoggerFactory.getLogger(VnfToolsActivator.class); - - @Override - public void start(BundleContext ctx) throws Exception { - // Read properties - Properties props = new Properties(); - - String propDir = System.getenv(SDNC_CONFIG_DIR); - if (propDir == null) { - propDir = "/opt/sdnc/data/properties"; - } - - String propPath = propDir + VNFTOOLS_PROP_VAR; - - File propFile = new File(propPath); - - if (!propFile.exists()) { - props = null; - } else { - - try { - props.load(new FileInputStream(propFile)); - } catch (Exception e) { - throw new ConfigurationException("Could not load properties file " + propPath, e); - } - } - VnfTools plugin = new VnfTools(props); - - LOG.info("Registering service " + plugin.getClass().getName()); - registrations.add(ctx.registerService(plugin.getClass().getName(), plugin, null)); - } - - @Override - public void stop(BundleContext ctx) throws Exception { - - for (@SuppressWarnings("rawtypes") - ServiceRegistration registration : registrations) { - registration.unregister(); - registration = null; - } - } - -} -- cgit 1.2.3-korg