From 103495d08e2f69f2d63389695f3d2a0d4a69630e Mon Sep 17 00:00:00 2001 From: Decheng Zhang Date: Fri, 19 Feb 2021 08:49:21 -0500 Subject: Creating prototype of SliTopologyUtils, a topology utility for simple topology manipulation. Change-Id: I3c83eeb9c44f04a8d7b0e45429594de96f162c3d Signed-off-by: Decheng Zhang --- .../sli/core/slipluginutils/SliTopologyUtils.java | 108 +++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 core/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliTopologyUtils.java (limited to 'core') diff --git a/core/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliTopologyUtils.java b/core/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliTopologyUtils.java new file mode 100644 index 000000000..9cfc305c9 --- /dev/null +++ b/core/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliTopologyUtils.java @@ -0,0 +1,108 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * 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.core.slipluginutils; + +import org.apache.commons.lang3.StringUtils; +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; + +import java.util.Map; + +public class SliTopologyUtils implements SvcLogicJavaPlugin { + + private static final Logger LOG = LoggerFactory.getLogger(SliTopologyUtils.class); + public static final String SUCCESS_CONSTANT = "success"; + public static final String FAILURE_CONSTANT = "failure"; + public static final String NOT_FOUND_CONSTANT = "not-found"; + + + public SliTopologyUtils(){}; + /** + * Provides simple path computation functionality to Directed Graphs. + *

+ * @param parameters HashMap of parameters passed by the DG to this function + * + * + * + * + * + * + * + * + * + * + *
parameterMandatory/Optionaldescription
pnfs-pfxMandatoryPrefix in context memory to get the pnf attributes from.
links-pfxMandatoryPrefix in context memory to get the link attributes from.
src-nodeMandatorySource pnf name.
dst-nodeMandatoryDestination pnf name.
response-pfxMandatoryPrefix in context memory to populate the resulting attributes in.
output-end-to-end-pathOptionaltrue or false to output end to end full path. If not included, only output cross domain path
+ * @param ctx Reference to context memory + * @throws SvcLogicException + */ + public static String computePath(Map parameters, SvcLogicContext ctx ) throws SvcLogicException { + try{ + LOG.debug( "ENTERING Execute Node \"computePath\"" ); + + // Validate, Log, & read parameters + checkParameters(parameters, new String[]{ "pnfs-pfx", "links-pfx", + "src-node", "dst-node", "response-pfx"}, LOG); + + return SUCCESS_CONSTANT; + + + } catch( Exception e ) { + throw new SvcLogicException( "An error occurred in the computePath Execute node", e ); + } finally { + LOG.debug( "EXITING Execute Node \"computePath\"" ); + } + } + + /** + * Throws an exception and writes an error to the log file if a required + * parameters is not found in the parametersMap. + *

+ * Use at the beginning of functions that can be called by Directed Graphs + * and can take parameters to verify that all parameters have been provided + * by the Directed Graph. + * @param parametersMap parameters Map passed to this node + * @param requiredParams Array of parameters required by the calling function + * @param log Reference to Logger to log to + * @throws SvcLogicException if a String in the requiredParams array is + * not a key in parametersMap. + * @since 1.0 + */ + public static final void checkParameters(Map parametersMap, String[] requiredParams, Logger log) throws SvcLogicException { + if( requiredParams == null || requiredParams.length < 1){ + log.debug("required parameters was empty, exiting early."); + return; + } + if (parametersMap == null || parametersMap.keySet().isEmpty()){ + String errorMessage = "This method requires the parameters [" + StringUtils.join(requiredParams,",") + "], but no parameters were passed in."; + log.error(errorMessage); + throw new SvcLogicException(errorMessage); + } + + for (String param : requiredParams) { + if (!parametersMap.containsKey(param)) { + String errorMessage = "Required parameter \"" + param + "\" was not found in parameter list."; + log.error(errorMessage); + log.error("Total list of required parameters is [" + StringUtils.join(requiredParams, ",") + "]."); + throw new SvcLogicException(errorMessage); + } + } + } +} \ No newline at end of file -- cgit 1.2.3-korg