2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 * ============LICENSE_END=========================================================
18 package org.onap.ccsdk.sli.core.slipluginutils;
20 import org.apache.commons.lang3.StringUtils;
21 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
22 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
23 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
29 public class SliTopologyUtils implements SvcLogicJavaPlugin {
31 private static final Logger LOG = LoggerFactory.getLogger(SliTopologyUtils.class);
32 public static final String SUCCESS_CONSTANT = "success";
33 public static final String FAILURE_CONSTANT = "failure";
34 public static final String NOT_FOUND_CONSTANT = "not-found";
37 public SliTopologyUtils(){};
39 * Provides simple path computation functionality to Directed Graphs.
41 * @param parameters HashMap<String,String> of parameters passed by the DG to this function
43 * <thead><th>parameter</th><th>Mandatory/Optional</th><th>description</th></thead>
45 * <tr><td>pnfs-pfx</td><td>Mandatory</td><td>Prefix in context memory to get the pnf attributes from.</td></tr>
46 * <tr><td>links-pfx</td><td>Mandatory</td><td>Prefix in context memory to get the link attributes from.</td></tr>
47 * <tr><td>src-node</td><td>Mandatory</td><td>Source pnf name.</td></tr>
48 * <tr><td>dst-node</td><td>Mandatory</td><td>Destination pnf name.</td></tr>
49 * <tr><td>response-pfx</td><td>Mandatory</td><td>Prefix in context memory to populate the resulting attributes in.</td></tr>
50 * <tr><td>output-end-to-end-path</td><td>Optional</td><td>true or false to output end to end full path. If not included, only output cross domain path</td></tr>
53 * @param ctx Reference to context memory
54 * @throws SvcLogicException
56 public static String computePath(Map<String, String> parameters, SvcLogicContext ctx ) throws SvcLogicException {
58 LOG.debug( "ENTERING Execute Node \"computePath\"" );
60 // Validate, Log, & read parameters
61 checkParameters(parameters, new String[]{ "pnfs-pfx", "links-pfx",
62 "src-node", "dst-node", "response-pfx"}, LOG);
64 return SUCCESS_CONSTANT;
67 } catch( Exception e ) {
68 throw new SvcLogicException( "An error occurred in the computePath Execute node", e );
70 LOG.debug( "EXITING Execute Node \"computePath\"" );
75 * Throws an exception and writes an error to the log file if a required
76 * parameters is not found in the parametersMap.
78 * Use at the beginning of functions that can be called by Directed Graphs
79 * and can take parameters to verify that all parameters have been provided
80 * by the Directed Graph.
81 * @param parametersMap parameters Map passed to this node
82 * @param requiredParams Array of parameters required by the calling function
83 * @param log Reference to Logger to log to
84 * @throws SvcLogicException if a String in the requiredParams array is
85 * not a key in parametersMap.
88 public static final void checkParameters(Map<String, String> parametersMap, String[] requiredParams, Logger log) throws SvcLogicException {
89 if( requiredParams == null || requiredParams.length < 1){
90 log.debug("required parameters was empty, exiting early.");
93 if (parametersMap == null || parametersMap.keySet().isEmpty()){
94 String errorMessage = "This method requires the parameters [" + StringUtils.join(requiredParams,",") + "], but no parameters were passed in.";
95 log.error(errorMessage);
96 throw new SvcLogicException(errorMessage);
99 for (String param : requiredParams) {
100 if (!parametersMap.containsKey(param)) {
101 String errorMessage = "Required parameter \"" + param + "\" was not found in parameter list.";
102 log.error(errorMessage);
103 log.error("Total list of required parameters is [" + StringUtils.join(requiredParams, ",") + "].");
104 throw new SvcLogicException(errorMessage);