diff options
author | Arun S. Yerra <arun.yerra@huawei.com> | 2017-09-18 23:23:54 -0700 |
---|---|---|
committer | Arun S. Yerra <arun.yerra@huawei.com> | 2017-09-18 23:36:28 -0700 |
commit | da4d77a5a127b3297fe15ecf012d05df721a90c7 (patch) | |
tree | a2bb9d2639d5f092c8d610453fe7ba4bcc8638b7 /fabric-discovery-plugin/provider/src | |
parent | 8157702b387b11e942614108d56ee9b8826c772a (diff) |
Implement fabric discovery DG parameter validation
Directed Graph to establish notification stream session with local domain
controller passes the REST notification server address. It also passes a
a boolean parameter to to either start or stop the session. This change
adds logic to validate these input parameters,
Issue-Id: CCSDK-88
Change-Id: I3fa05f5badeafbaa15e5ae89a3a60b8e237f212b
Signed-off-by: Arun S. Yerra <arun.yerra@huawei.com>
Diffstat (limited to 'fabric-discovery-plugin/provider/src')
-rw-r--r-- | fabric-discovery-plugin/provider/src/main/java/org/onap/ccsdk/sli/plugins/fabricdiscovery/FabricDiscoveryPlugin.java | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/fabric-discovery-plugin/provider/src/main/java/org/onap/ccsdk/sli/plugins/fabricdiscovery/FabricDiscoveryPlugin.java b/fabric-discovery-plugin/provider/src/main/java/org/onap/ccsdk/sli/plugins/fabricdiscovery/FabricDiscoveryPlugin.java index 7a0c68f41..66452758d 100644 --- a/fabric-discovery-plugin/provider/src/main/java/org/onap/ccsdk/sli/plugins/fabricdiscovery/FabricDiscoveryPlugin.java +++ b/fabric-discovery-plugin/provider/src/main/java/org/onap/ccsdk/sli/plugins/fabricdiscovery/FabricDiscoveryPlugin.java @@ -39,6 +39,8 @@ public class FabricDiscoveryPlugin implements SvcLogicJavaPlugin, IFabricDiscove private ExecutorService service; private Map<String, WebSocketClient> streamMap; private static final Logger LOG = LoggerFactory.getLogger(FabricDiscoveryPlugin.class); + private static final String STREAM_PREFIX = "ws://"; + private static final String FB_DISCOVERY_STATUS = "fb-response"; public FabricDiscoveryPlugin() { service = Executors.newFixedThreadPool(10); @@ -47,10 +49,29 @@ public class FabricDiscoveryPlugin implements SvcLogicJavaPlugin, IFabricDiscove @Override public void processDcNotificationStream (Map<String, String> paramMap, SvcLogicContext ctx) throws SvcLogicException { - boolean enable = Boolean.parseBoolean(parseParam(paramMap, "enable", true, null)); + boolean enable; String stream = parseParam(paramMap, "stream", true, null); + String prefix = parseParam(paramMap, "contextPrefix", false, null); + String enableStr = parseParam(paramMap, "enable", true, null); + // Validate the input parameters + String pfx = (prefix != null) ? prefix + '.' : ""; + if ("true".equalsIgnoreCase(enableStr)) { + enable = true; + } else if ("false".equalsIgnoreCase(enableStr)) { + enable = false; + } else { + ctx.setAttribute(pfx + FB_DISCOVERY_STATUS, "Failure"); + throw new SvcLogicException("Incorrect parameter: enable. Valid values are ['true', 'false']"); + } + if (!STREAM_PREFIX.equalsIgnoreCase(stream.substring(0, 5))) { + ctx.setAttribute(pfx + FB_DISCOVERY_STATUS, "Failure"); + throw new SvcLogicException("Incorrect parameter: stream, Input is not a web socket address"); + } + + ctx.setAttribute(pfx + FB_DISCOVERY_STATUS, "Success"); LOG.info("{} monitoring notification stream: {}", (enable) ? "START" : "STOP", stream); + try { service.execute(new Runnable () { public void run () { |