diff options
Diffstat (limited to 'fabric-discovery-plugin')
2 files changed, 59 insertions, 3 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 7a0c68f4..99e171f6 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,18 +39,39 @@ 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); - streamMap = new ConcurrentHashMap<String, WebSocketClient> (); + streamMap = new ConcurrentHashMap<>(); } @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); - LOG.info("{} monitoring notification stream: {}", (enable) ? "START" : "STOP", stream); try { service.execute(new Runnable () { public void run () { diff --git a/fabric-discovery-plugin/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/fabricdiscovery/TestFabricDiscoveryPlugin.java b/fabric-discovery-plugin/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/fabricdiscovery/TestFabricDiscoveryPlugin.java new file mode 100644 index 00000000..f5dc7cbc --- /dev/null +++ b/fabric-discovery-plugin/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/fabricdiscovery/TestFabricDiscoveryPlugin.java @@ -0,0 +1,35 @@ +package jtest.org.onap.ccsdk.sli.plugins.fabricdiscovery; + +import java.util.HashMap; +import java.util.Map; +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.plugins.fabricdiscovery.FabricDiscoveryPlugin; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Created by arun on 9/18/17. + */ + +public class TestFabricDiscoveryPlugin { + private static final Logger LOG = LoggerFactory.getLogger(TestFabricDiscoveryPlugin.class); + private static final String C_STREAM = + "ws://localhost:8185/data-change-event-subscription/network-topology:network-topology/datastore=CONFIGURATION/scope=BASE"; + private final String FB_DISCOVERY_STATUS = "fb-response"; + + @Test + public void connectToNotificationServerSuccess() throws Exception { + SvcLogicContext ctx = new SvcLogicContext(); + String stream = C_STREAM; + + Map<String, String> p = new HashMap<String, String>(); + p.put("stream", stream); + p.put("enable", "true"); + + FabricDiscoveryPlugin fdp = new FabricDiscoveryPlugin(); + fdp.processDcNotificationStream(p, ctx); + Assert.assertEquals("Success", ctx.getAttribute(FB_DISCOVERY_STATUS)); + } +} |