summaryrefslogtreecommitdiffstats
path: root/sdnr/wt
diff options
context:
space:
mode:
authorHerbert Eiselt <herbert.eiselt@highstreet-technologies.com>2019-02-28 17:43:35 +0100
committerHerbert Eiselt <herbert.eiselt@highstreet-technologies.com>2019-02-28 17:46:05 +0100
commitb4d7ca85b122f914fb43a4a3f4300e36dede9e2b (patch)
tree3f138a832f0bf10fa59eb636b98bd6912b8a3efd /sdnr/wt
parent49b155ec687cdf58fb51fe8245a2f5f4582b68f0 (diff)
Replace depreciated MDSAL interfaces
SDN-R websocketmanager2 Change-Id: I69c12ee993bf8e2740d8f72778d06c89bf758051 Issue-ID: SDNC-680 Signed-off-by: Herbert Eiselt <herbert.eiselt@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt')
-rw-r--r--sdnr/wt/websocketmanager2/model/pom.xml2
-rw-r--r--sdnr/wt/websocketmanager2/provider/pom.xml267
-rw-r--r--sdnr/wt/websocketmanager2/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/Blueprint.java8
-rw-r--r--sdnr/wt/websocketmanager2/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/WebSocketManager.java79
-rw-r--r--sdnr/wt/websocketmanager2/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/WebSocketManagerProvider.java125
-rw-r--r--sdnr/wt/websocketmanager2/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/WebSocketManagerSocket.java31
-rw-r--r--sdnr/wt/websocketmanager2/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/websocket/SyncWebSocketClient.java36
-rw-r--r--sdnr/wt/websocketmanager2/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml30
-rw-r--r--sdnr/wt/websocketmanager2/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/AkkaConfigTest.java4
-rw-r--r--sdnr/wt/websocketmanager2/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/UserScopeTest.java46
-rw-r--r--sdnr/wt/websocketmanager2/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsockerProviderTest.java46
-rw-r--r--sdnr/wt/websocketmanager2/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsocketClientTest.java48
-rw-r--r--sdnr/wt/websocketmanager2/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsocketMessageTest.java74
-rw-r--r--sdnr/wt/websocketmanager2/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsocketServerConnectTest.java79
-rw-r--r--sdnr/wt/websocketmanager2/provider/src/test/resources/akka-cluster-local.cfg49
-rw-r--r--sdnr/wt/websocketmanager2/provider/src/test/resources/simplelogger.properties37
16 files changed, 709 insertions, 252 deletions
diff --git a/sdnr/wt/websocketmanager2/model/pom.xml b/sdnr/wt/websocketmanager2/model/pom.xml
index 02b210cc8..6a9ffb9d0 100644
--- a/sdnr/wt/websocketmanager2/model/pom.xml
+++ b/sdnr/wt/websocketmanager2/model/pom.xml
@@ -35,6 +35,4 @@
<version>1.2.1-SNAPSHOT</version>
<relativePath />
</parent>
- <dependencies>
- </dependencies>
</project>
diff --git a/sdnr/wt/websocketmanager2/provider/pom.xml b/sdnr/wt/websocketmanager2/provider/pom.xml
index 4bf680599..6fc46b427 100644
--- a/sdnr/wt/websocketmanager2/provider/pom.xml
+++ b/sdnr/wt/websocketmanager2/provider/pom.xml
@@ -1,116 +1,157 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- ============LICENSE_START=======================================================
- ONAP : ccsdk feature sdnr wt websocketmanager2 ================================================================================
- Copyright (C) 2019 highstreet technologies GmbH 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========================================================= -->
+<!-- ============LICENSE_START=======================================================
+ ONAP : ccsdk feature sdnr wt websocketmanager2 ================================================================================
+ Copyright (C) 2019 highstreet technologies GmbH 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========================================================= -->
<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.onap.ccsdk.features.sdnr.wt</groupId>
- <artifactId>sdnr-wt-websocketmanager2-provider</artifactId>
- <version>0.4.1-SNAPSHOT</version>
- <name>ccsdk-features-sdnr-wt :: ${project.artifactId}</name>
- <packaging>bundle</packaging>
- <parent>
- <groupId>org.onap.ccsdk.parent</groupId>
- <artifactId>binding-parent</artifactId>
- <version>1.2.1-SNAPSHOT</version>
- <relativePath></relativePath>
- </parent>
- <properties>
- <maven.javadoc.skip>true</maven.javadoc.skip>
- <checkstyle.skip>true</checkstyle.skip>
- </properties>
- <licenses>
- <license>
- <name>Apache License, Version 2.0</name>
- <url>http://www.apache.org/licenses/LICENSE-2.0</url>
- </license>
- </licenses>
- <dependencies>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>sdnr-wt-websocketmanager2-model</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <version>2.5</version>
- </dependency>
- <dependency>
- <groupId>org.eclipse.jetty.websocket</groupId>
- <artifactId>websocket-api</artifactId>
- <version>9.3.21.v20170918</version>
- </dependency>
- <dependency>
- <groupId>org.eclipse.jetty.websocket</groupId>
- <artifactId>websocket-servlet</artifactId>
- <version>9.3.21.v20170918</version>
- </dependency>
- <dependency>
- <groupId>io.netty</groupId>
- <artifactId>netty-transport</artifactId>
- </dependency>
- <dependency>
- <groupId>io.netty</groupId>
- <artifactId>netty-all</artifactId>
- <!-- <version>${netty.version}</version> -->
- </dependency>
- <dependency>
- <groupId>org.json</groupId>
- <artifactId>json</artifactId>
- </dependency>
- <dependency>
- <groupId>com.typesafe.akka</groupId>
- <artifactId>akka-actor_2.12</artifactId>
- </dependency>
- <dependency>
- <groupId>com.typesafe.akka</groupId>
- <artifactId>akka-cluster_2.12</artifactId>
- </dependency>
- <dependency>
- <groupId>org.java-websocket</groupId>
- <artifactId>Java-WebSocket</artifactId>
- <version>1.3.8</version>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <!-- <version>2.23.4</version> -->
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>sal-binding-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.compendium</artifactId>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.8</source>
- <target>1.8</target>
- </configuration>
- </plugin>
- </plugins>
- </build>
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.onap.ccsdk.features.sdnr.wt</groupId>
+ <artifactId>sdnr-wt-websocketmanager2-provider</artifactId>
+ <version>0.4.1-SNAPSHOT</version>
+ <name>ccsdk-features-sdnr-wt :: ${project.artifactId}</name>
+ <packaging>bundle</packaging>
+ <parent>
+ <groupId>org.onap.ccsdk.parent</groupId>
+ <artifactId>binding-parent</artifactId>
+ <version>1.2.1-SNAPSHOT</version>
+ <relativePath></relativePath>
+ </parent>
+ <properties>
+ <maven.javadoc.skip>true</maven.javadoc.skip>
+ <checkstyle.skip>true</checkstyle.skip>
+ </properties>
+ <licenses>
+ <license>
+ <name>Apache License, Version 2.0</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0</url>
+ </license>
+ </licenses>
+<!-- <dependencyManagement> -->
+<!-- <dependencies> -->
+<!-- <dependency> -->
+<!-- <groupId>org.opendaylight.controller</groupId> -->
+<!-- <artifactId>mdsal-artifacts</artifactId> -->
+<!-- <version>1.6.1</version> -->
+<!-- <type>pom</type> -->
+<!-- <scope>import</scope> -->
+<!-- </dependency> -->
+<!-- </dependencies> -->
+<!-- </dependencyManagement> -->
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>sdnr-wt-websocketmanager2-model</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty.websocket</groupId>
+ <artifactId>websocket-api</artifactId>
+ <version>9.3.24.v20180605</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty.websocket</groupId>
+ <artifactId>websocket-servlet</artifactId>
+ <version>9.3.24.v20180605</version>
+ </dependency>
+ <dependency>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-transport</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-all</artifactId>
+ <!-- <version>${netty.version}</version> -->
+ </dependency>
+ <dependency>
+ <groupId>org.json</groupId>
+ <artifactId>json</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.typesafe.akka</groupId>
+ <artifactId>akka-actor_2.12</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.typesafe.akka</groupId>
+ <artifactId>akka-cluster_2.12</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.java-websocket</groupId>
+ <artifactId>Java-WebSocket</artifactId>
+ <version>1.3.8</version>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <!-- <version>2.23.4</version> -->
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-binding-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-server</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-servlet</artifactId>
+ <version>9.3.24.v20180605</version>
+ <scope>test</scope>
+ </dependency>
+<!-- <dependency> -->
+<!-- <groupId>org.eclipse.jetty.websocket</groupId> -->
+<!-- <artifactId>websocket-api</artifactId> -->
+<!-- <version>9.3.24.v20180605</version> -->
+<!-- </dependency> -->
+ <!-- To run websockets in embedded server -->
+ <!-- <dependency> -->
+ <!-- <groupId>org.eclipse.jetty.websocket</groupId> -->
+ <!-- <artifactId>websocket-server</artifactId> -->
+ <!-- <version>9.3.24.v20180605</version> -->
+ <!-- </dependency> -->
+ <!-- <dependency> -->
+ <!-- <groupId>org.eclipse.jetty.websocket</groupId> -->
+ <!-- <artifactId>websocket-server</artifactId> -->
+ <!-- <version>9.3.24.v20180605</version> -->
+ <!-- <scope>test</scope> -->
+ <!-- </dependency> -->
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ </configuration>
+ </plugin>
+ </plugins>
+
+ </build>
</project>
diff --git a/sdnr/wt/websocketmanager2/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/Blueprint.java b/sdnr/wt/websocketmanager2/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/Blueprint.java
index 32d9d7a4b..bd84043a2 100644
--- a/sdnr/wt/websocketmanager2/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/Blueprint.java
+++ b/sdnr/wt/websocketmanager2/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/Blueprint.java
@@ -17,19 +17,19 @@
******************************************************************************/
package org.onap.ccsdk.features.sdnr.wt.websocketmanager2;
-import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
public abstract class Blueprint implements AutoCloseable {
- private RpcProviderRegistry rpcProviderRegistry = null;
+ private RpcProviderService rpcProviderRegistry = null;
public abstract void init();
- public void setRpcProviderRegistry(RpcProviderRegistry rpcProviderRegistry) {
+ public void setRpcProviderRegistry(RpcProviderService rpcProviderRegistry) {
this.rpcProviderRegistry = rpcProviderRegistry;
}
- public RpcProviderRegistry getRpcProviderRegistry() {
+ public RpcProviderService getRpcProviderRegistry() {
return this.rpcProviderRegistry;
}
diff --git a/sdnr/wt/websocketmanager2/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/WebSocketManager.java b/sdnr/wt/websocketmanager2/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/WebSocketManager.java
index 18066128f..51554e3a6 100644
--- a/sdnr/wt/websocketmanager2/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/WebSocketManager.java
+++ b/sdnr/wt/websocketmanager2/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/WebSocketManager.java
@@ -18,9 +18,13 @@
package org.onap.ccsdk.features.sdnr.wt.websocketmanager2;
import com.google.common.util.concurrent.ListenableFuture;
+import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
import org.json.JSONObject;
@@ -47,7 +51,7 @@ public class WebSocketManager extends WebSocketServlet implements Websocketmanag
private static final String APPLICATION_NAME = WebSocketManager.class.getName();
private static final int PORT = 8181;
private final EventInputCallback rpcEventInputCallback;
-
+ private final AkkaConfig akkaConfig;
/**
* timeout for websocket with no messages in ms
*/
@@ -56,16 +60,25 @@ public class WebSocketManager extends WebSocketServlet implements Websocketmanag
private final ArrayList<URI> clusterNodeClients = new ArrayList<>();
public WebSocketManager() {
- super();
- rpcEventInputCallback = message -> {
- LOG.debug("onMessagePushed: " + message);
- SyncWebSocketClient client;
- for (URI clientURI : WebSocketManager.this.clusterNodeClients) {
- client = new SyncWebSocketClient(clientURI);
- LOG.debug("try to push message to " + client.getURI());
- client.openAndSendAndCloseSync(message);
+ this(null, null);
+ }
+
+ public WebSocketManager(AkkaConfig akkaconfig, EventInputCallback cb) {
+ super();
+ this.akkaConfig = akkaconfig;
+ if (cb != null) {
+ this.rpcEventInputCallback = cb;
+ } else {
+ this.rpcEventInputCallback = message -> {
+ LOG.debug("onMessagePushed: " + message);
+ SyncWebSocketClient client;
+ for (URI clientURI : WebSocketManager.this.clusterNodeClients) {
+ client = new SyncWebSocketClient(clientURI);
+ LOG.debug("try to push message to " + client.getURI());
+ client.openAndSendAndCloseSync(message);
+ }
+ };
}
- };
LOG.info("Create servlet for {}", APPLICATION_NAME);
}
@@ -80,11 +93,13 @@ public class WebSocketManager extends WebSocketServlet implements Websocketmanag
// register Socket as the WebSocket to create on Upgrade
factory.register(WebSocketManagerSocket.class);
- AkkaConfig cfg = null;
- try {
- cfg = AkkaConfig.load();
- } catch (Exception e) {
- LOG.warn("problem loading akka config: " + e.getMessage());
+ AkkaConfig cfg = this.akkaConfig;
+ if (cfg == null) {
+ try {
+ cfg = AkkaConfig.load();
+ } catch (Exception e) {
+ LOG.warn("problem loading akka config: " + e.getMessage());
+ }
}
if (cfg != null && cfg.isCluster()) {
this.initWSClients(cfg.getClusterConfig());
@@ -96,25 +111,30 @@ public class WebSocketManager extends WebSocketServlet implements Websocketmanag
public ListenableFuture<RpcResult<WebsocketEventOutput>> websocketEvent(WebsocketEventInput input) {
LOG.debug("Send message '{}'", input);
RpcResultBuilder<WebsocketEventOutput> result;
- try {
- WebsocketEventOutputBuilder outputBuilder = new WebsocketEventOutputBuilder();
- final String s = input.getXmlEvent();
- WebSocketManagerSocket.broadCast(input.getNodeName(), input.getEventType(), s);
- outputBuilder.setResponse("OK");
+
+ final String eventAsXmlString = input.getXmlEvent();
+ if (eventAsXmlString != null) {
+ WebSocketManagerSocket.broadCast(input.getNodeName(), input.getEventType(), eventAsXmlString);
try {
JSONObject o = new JSONObject();
o.put(WebSocketManagerSocket.KEY_NODENAME, input.getNodeName());
o.put(WebSocketManagerSocket.KEY_EVENTTYPE, input.getEventType());
o.put(WebSocketManagerSocket.KEY_XMLEVENT, input.getXmlEvent());
this.rpcEventInputCallback.onMessagePushed(o.toString());
+
+ WebsocketEventOutputBuilder outputBuilder = new WebsocketEventOutputBuilder();
+ outputBuilder.setResponse("OK");
+ result = RpcResultBuilder.success(outputBuilder);
} catch (Exception err) {
LOG.warn("problem pushing messsage to other nodes: " + err.getMessage());
+ result = RpcResultBuilder.failed();
+ result.withError(ErrorType.APPLICATION, "Exception", err);
}
- result = RpcResultBuilder.success(outputBuilder);
- } catch (Exception e) {
- LOG.warn("Socketproblem: {}", e);
+ } else {
+ String msg = "Emtpy event received";
+ LOG.warn(msg);
result = RpcResultBuilder.failed();
- result.withError(ErrorType.APPLICATION, "Exception", e);
+ result.withError(ErrorType.APPLICATION, msg);
}
return result.buildFuture();
}
@@ -123,6 +143,17 @@ public class WebSocketManager extends WebSocketServlet implements Websocketmanag
* Private functions
*/
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ if (req.getHeader("Upgrade") != null) {
+ /* Accept upgrade request */
+ resp.setStatus(101);
+ resp.setHeader("Upgrade", "XYZP");
+ resp.setHeader("Connection", "Upgrade");
+ resp.setHeader("OtherHeaderB", "Value");
+ }
+ }
+
private void initWSClients(ClusterConfig clusterConfig) {
for (ClusterNodeInfo nodeConfig : clusterConfig.getSeedNodes()) {
if (clusterConfig.isMe(nodeConfig)) {
diff --git a/sdnr/wt/websocketmanager2/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/WebSocketManagerProvider.java b/sdnr/wt/websocketmanager2/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/WebSocketManagerProvider.java
index 737fe5463..2c54d2a78 100644
--- a/sdnr/wt/websocketmanager2/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/WebSocketManagerProvider.java
+++ b/sdnr/wt/websocketmanager2/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/WebSocketManagerProvider.java
@@ -6,9 +6,9 @@
* =================================================================================================
* 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
@@ -18,10 +18,9 @@
package org.onap.ccsdk.features.sdnr.wt.websocketmanager2;
import javax.servlet.ServletException;
-
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
-import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.websocketmanager.rev150105.WebsocketmanagerService;
+import org.opendaylight.yangtools.concepts.ObjectRegistration;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;
import org.slf4j.Logger;
@@ -29,67 +28,73 @@ import org.slf4j.LoggerFactory;
public class WebSocketManagerProvider extends Blueprint {
- private static final Logger LOG = LoggerFactory.getLogger(WebSocketManagerProvider.class);
- private static final String APPLICATION_NAME = WebSocketManagerProvider.class.getName();
- private static final String ALIAS = "/websocket";
+ private static final Logger LOG = LoggerFactory.getLogger(WebSocketManagerProvider.class);
+ private static final String APPLICATION_NAME = WebSocketManagerProvider.class.getName();
+ private static final String ALIAS = "/websocket";
+
+ private WebSocketManager wsServlet = null;
+ private ObjectRegistration<WebSocketManager> websocketService = null;
+
+ public WebSocketManagerProvider() {
+ LOG.info("Creating provider for {}", APPLICATION_NAME);
+ }
- private WebSocketManager wsServlet = null;
- private RpcRegistration<WebsocketmanagerService> websocketService = null;
-
- public WebSocketManagerProvider() {
- LOG.info("Creating provider for {}", APPLICATION_NAME);
- }
+ @Override
+ public void init() {
+ LOG.info("Init provider for {}", APPLICATION_NAME);
+ RpcProviderService rpcProviderRegistry = this.getRpcProviderRegistry();
+ if (rpcProviderRegistry != null) {
+ if (wsServlet != null) {
+ this.websocketService =
+ rpcProviderRegistry.registerRpcImplementation(WebsocketmanagerService.class, wsServlet);
+ LOG.info("websocketservice initialized");
+ } else {
+ LOG.debug("wsServlet not yet provided");
+ }
+ } else {
+ LOG.error("rpcProviderRegistry not provided");
+ }
+ }
- @Override
- public void init() {
- LOG.info("Init provider for {}", APPLICATION_NAME);
- RpcProviderRegistry rpcProviderRegistry = this.getRpcProviderRegistry();
- if (rpcProviderRegistry != null) {
- if (wsServlet != null) {
- this.websocketService = rpcProviderRegistry.addRpcImplementation(WebsocketmanagerService.class,
- wsServlet);
- } else {
- LOG.error("wsServlet not provided");
- }
- } else {
- LOG.error("rpcProviderRegistry not provided");
- }
- }
+ @Override
+ public void close() throws Exception {
+ LOG.info("Close provider for {}", APPLICATION_NAME);
+ if (websocketService != null) {
+ websocketService.close();
+ }
+ }
- @Override
- public void close() throws Exception {
- LOG.info("Close provider for {}", APPLICATION_NAME);
- if (websocketService != null) {
- websocketService.close();
- }
- }
+ public void onUnbindService(HttpService httpService) {
+ httpService.unregister(ALIAS);
+ wsServlet = null;
+ }
- public void onUnbindService(HttpService httpService) {
- httpService.unregister(ALIAS);
- wsServlet = null;
- }
+ public void onBindService(HttpService httpService) throws ServletException, NamespaceException {
+ if (httpService == null) {
+ LOG.warn("Unable to inject HttpService into DluxLoader. dlux modules won't work without httpService");
+ } else {
- public void onBindService(HttpService httpService) throws ServletException, NamespaceException {
- if (httpService == null) {
- LOG.warn("Unable to inject HttpService into DluxLoader. dlux modules won't work without httpService");
- } else {
-
- wsServlet = new WebSocketManager();
- httpService.registerServlet(ALIAS, wsServlet, null, null);
- LOG.info("websocket servlet registered.");
- if(this.websocketService==null)
- this.init();
- else
- LOG.info("websocketservice already initialized");
- }
+ if (wsServlet == null) {
+ wsServlet = new WebSocketManager();
+ httpService.registerServlet(ALIAS, wsServlet, null, null);
+ LOG.info("websocket servlet registered.");
+ if (this.websocketService == null) {
+ this.init();
+ } else {
+ LOG.info("websocketservice already initialized");
+ }
+ } else {
+ LOG.warn("Servelt ");
+ }
+ }
- }
+ }
- public WebSocketManager getWsServlet() {
- return wsServlet;
- }
+ public WebSocketManager getWsServlet() {
+ return wsServlet;
+ }
- public void setWsServlet(WebSocketManager wsServlet) {
- this.wsServlet = wsServlet;
- }
+ public void setWsServlet(WebSocketManager wsServlet) {
+ this.wsServlet = wsServlet;
+ }
}
diff --git a/sdnr/wt/websocketmanager2/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/WebSocketManagerSocket.java b/sdnr/wt/websocketmanager2/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/WebSocketManagerSocket.java
index f445bcd23..0fd2cae4e 100644
--- a/sdnr/wt/websocketmanager2/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/WebSocketManagerSocket.java
+++ b/sdnr/wt/websocketmanager2/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/WebSocketManagerSocket.java
@@ -21,7 +21,9 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Random;
+import java.util.Set;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
@@ -33,7 +35,6 @@ import org.slf4j.LoggerFactory;
public class WebSocketManagerSocket extends WebSocketAdapter {
private static final Logger LOG = LoggerFactory.getLogger(WebSocketManagerSocket.class.getName());
-
public static final String MSG_KEY_DATA = "data";
public static final String MSG_KEY_SCOPES = "scopes";
public static final String MSG_KEY_PARAM = "param";
@@ -87,16 +88,15 @@ public class WebSocketManagerSocket extends WebSocketAdapter {
@Override
public void onWebSocketText(String message) {
- LOG.info(this.getRemoteAdr() + " has sent " + message);
+ LOG.info("{} has sent {}",this.getRemoteAdr(), message);
if (!this.manageClientRequest(message)) {
this.manageClientRequest2(message);
}
-
}
@Override
public void onWebSocketBinary(byte[] payload, int offset, int len) {
-
+ LOG.debug("Binary not supported");
}
@Override
@@ -114,7 +114,6 @@ public class WebSocketManagerSocket extends WebSocketAdapter {
@Override
public void onWebSocketError(Throwable cause) {
-
LOG.debug("error caused on " + this.getRemoteAdr() + " :" + cause.getMessage());
// super.onWebSocketError(cause);
}
@@ -166,14 +165,14 @@ public class WebSocketManagerSocket extends WebSocketAdapter {
try {
JSONObject o = new JSONObject(request);
if (o.has(KEY_NODENAME) && o.has(KEY_EVENTTYPE)) {
- broadCast(o.getString(KEY_NODENAME), o.getString(KEY_EVENTTYPE), o.getString(KEY_XMLEVENT));
+ this.sendToAll(o.getString(KEY_NODENAME), o.getString(KEY_EVENTTYPE), o.getString(KEY_XMLEVENT));
}
} catch (Exception e) {
LOG.warn("handle ws request failed:" + e.getMessage());
}
}
- private void send(String msg) {
+ public void send(String msg) {
try {
LOG.trace("sending {}", msg);
this.session.getRemote().sendString(msg);
@@ -181,18 +180,16 @@ public class WebSocketManagerSocket extends WebSocketAdapter {
LOG.warn("problem sending message: " + e.getMessage());
}
}
-
- private String getSessionId() {
+ public String getSessionId() {
return this.myUniqueSessionId;
}
- public static void broadCast(String nodeName, String eventType, String xmlEvent) {
- if (clientList != null && clientList.size() > 0) {
+ private void sendToAll(String nodeName, String eventType, String xmlEvent) {
+ if (clientList.size() > 0) {
for (Map.Entry<String, WebSocketManagerSocket> entry : clientList.entrySet()) {
WebSocketManagerSocket socket = entry.getValue();
if (socket != null) {
try {
-
UserScopes clientScopes = userScopesList.get(socket.getSessionId());
if (clientScopes != null) {
if (clientScopes.hasScope(eventType)) {
@@ -212,5 +209,15 @@ public class WebSocketManagerSocket extends WebSocketAdapter {
}
}
}
+ public static void broadCast(String nodeName, String eventType, String xmlEvent) {
+ if(clientList.size()>0) {
+ Set<Entry<String, WebSocketManagerSocket>> e = clientList.entrySet();
+ WebSocketManagerSocket s = e.iterator().next().getValue();
+ if(s!=null)
+ {
+ s.sendToAll(nodeName, eventType, xmlEvent);
+ }
+ }
+ }
}
diff --git a/sdnr/wt/websocketmanager2/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/websocket/SyncWebSocketClient.java b/sdnr/wt/websocketmanager2/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/websocket/SyncWebSocketClient.java
index 0afe06e13..fb2384ee5 100644
--- a/sdnr/wt/websocketmanager2/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/websocket/SyncWebSocketClient.java
+++ b/sdnr/wt/websocketmanager2/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/websocket/SyncWebSocketClient.java
@@ -19,6 +19,8 @@ package org.onap.ccsdk.features.sdnr.wt.websocketmanager2.websocket;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
@@ -27,33 +29,53 @@ import org.slf4j.LoggerFactory;
public class SyncWebSocketClient extends WebSocketClient {
+ public interface WebsocketEventHandler{
+ void onMessageReceived(String message);
+ void onOpen(ServerHandshake arg0);
+ void onClose(int arg0, String arg1, boolean arg2);
+ void onError(Exception e);
+ }
+
private static final Logger LOG = LoggerFactory.getLogger(SyncWebSocketClient.class.getName());
private String messageToSend;
-
+ private final List<WebsocketEventHandler> handlers;
public SyncWebSocketClient(URI serverUri) {
super(serverUri);
+ this.handlers = new ArrayList<WebsocketEventHandler>();
}
public SyncWebSocketClient(String uri) throws URISyntaxException {
this(new URI(uri));
}
-
+ public void addEventHandler(WebsocketEventHandler h) {
+ this.handlers.add(h);
+ }
+ public void removeEventHandler(WebsocketEventHandler h) {
+ this.handlers.remove(h);
+ }
+
@Override
public void onClose(int arg0, String arg1, boolean arg2) {
LOG.debug("socket closed: {} {} {}", arg0, arg1, arg2);
-
+ for(WebsocketEventHandler h:this.handlers) {
+ h.onClose(arg0,arg1,arg2);
+ }
}
@Override
public void onError(Exception arg0) {
LOG.warn("error on socket: {}", arg0.getMessage());
-
+ for(WebsocketEventHandler h:this.handlers) {
+ h.onError(arg0);
+ }
}
@Override
public void onMessage(String arg0) {
LOG.debug("received message: {}", arg0);
-
+ for(WebsocketEventHandler h:this.handlers) {
+ h.onMessageReceived(arg0);
+ }
}
@Override
@@ -64,7 +86,9 @@ public class SyncWebSocketClient extends WebSocketClient {
this.send(this.messageToSend);
this.messageToSend = null;
}
-
+ for(WebsocketEventHandler h:this.handlers) {
+ h.onOpen(arg0);
+ }
}
public void openAndSendAsync(String message) {
diff --git a/sdnr/wt/websocketmanager2/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml b/sdnr/wt/websocketmanager2/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml
index 315921dbb..5e95b7b74 100644
--- a/sdnr/wt/websocketmanager2/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml
+++ b/sdnr/wt/websocketmanager2/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml
@@ -7,9 +7,9 @@
=================================================================================================
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
@@ -20,30 +20,14 @@
xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
odl:use-default-for-reference-types="true">
-<!-- <bean id="wsServlet" -->
-<!-- class="org.onap.ccsdk.sdnr.wt.websocketmanager2.WebSocketManager"> -->
-<!-- </bean> -->
-
- <reference id="rpcProviderRegistry"
- interface="org.opendaylight.controller.sal.binding.api.RpcProviderRegistry"
- odl:type="default" />
+ <reference id="rpcProviderRegistry" interface="org.opendaylight.mdsal.binding.api.RpcProviderService" odl:type="default" />
- <bean id="provider"
- class="org.onap.ccsdk.features.sdnr.wt.websocketmanager2.WebSocketManagerProvider"
- init-method="init" destroy-method="close">
+ <bean id="provider" class="org.onap.ccsdk.features.sdnr.wt.websocketmanager2.WebSocketManagerProvider" init-method="init" destroy-method="close">
<property name="rpcProviderRegistry" ref="rpcProviderRegistry" />
-<!-- <property name="wsServlet" ref="wsServlet" /> -->
</bean>
- <reference id="onBindService" availability="mandatory" activation="eager" interface="org.osgi.service.http.HttpService">
- <reference-listener ref="provider" bind-method="onBindService" unbind-method="onUnbindService"/>
- </reference>
-<!-- <service -->
-<!-- interface="org.eclipse.jetty.websocket.servlet.WebSocketServlet" -->
-<!-- ref="wsServlet"> -->
-<!-- <service-properties> -->
-<!-- <entry key="alias" value="/websocket" /> -->
-<!-- </service-properties> -->
-<!-- </service> -->
+ <reference id="onBindService" availability="mandatory" activation="eager" interface="org.osgi.service.http.HttpService">
+ <reference-listener ref="provider" bind-method="onBindService" unbind-method="onUnbindService" />
+ </reference>
</blueprint>
diff --git a/sdnr/wt/websocketmanager2/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/AkkaConfigTest.java b/sdnr/wt/websocketmanager2/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/AkkaConfigTest.java
index 217088b33..2460ca42f 100644
--- a/sdnr/wt/websocketmanager2/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/AkkaConfigTest.java
+++ b/sdnr/wt/websocketmanager2/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/AkkaConfigTest.java
@@ -54,11 +54,11 @@ public class AkkaConfigTest {
assertTrue("only one node detected",config.getClusterConfig().getSeedNodes().size()>1);
}
- private String loadResourceContentAsString(String resourceName) throws URISyntaxException, FileNotFoundException, IOException {
+ public static String loadResourceContentAsString(String resourceName) throws URISyntaxException, FileNotFoundException, IOException {
StringBuilder sb = new StringBuilder();
- ClassLoader classLoader = getClass().getClassLoader();
+ ClassLoader classLoader = AkkaConfigTest.class.getClassLoader();
File file = Paths.get(classLoader.getResource(resourceName).toURI()).toFile();
try(BufferedReader br = new BufferedReader(new FileReader(file))) {
String line = br.readLine();
diff --git a/sdnr/wt/websocketmanager2/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/UserScopeTest.java b/sdnr/wt/websocketmanager2/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/UserScopeTest.java
new file mode 100644
index 000000000..52eedb994
--- /dev/null
+++ b/sdnr/wt/websocketmanager2/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/UserScopeTest.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * ============LICENSE_START========================================================================
+ * ONAP : ccsdk feature sdnr wt
+ * =================================================================================================
+ * Copyright (C) 2019 highstreet technologies GmbH 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.ccsdk.features.sdnr.wt.websocketmanager2.test;
+
+import static org.junit.Assert.*;
+
+import org.json.JSONArray;
+import org.junit.Test;
+import org.onap.ccsdk.features.sdnr.wt.websocketmanager2.utils.UserScopes;
+
+public class UserScopeTest {
+
+ private static final String SCOPE1 ="scope1";
+ private static final String SCOPE2 ="scope2";
+ private static final String SCOPE3 ="scope3";
+ private static final String SCOPE4 ="scope4";
+
+ @Test
+ public void test() {
+ UserScopes scopes1 = new UserScopes();
+ JSONArray json1=new JSONArray();
+ json1.put(SCOPE1);
+ json1.put(SCOPE2);
+ json1.put(SCOPE3);
+ scopes1.setScopes(json1);
+
+ assertTrue(scopes1.hasScope(SCOPE1));
+ assertFalse(scopes1.hasScope(SCOPE4));
+ }
+
+}
diff --git a/sdnr/wt/websocketmanager2/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsockerProviderTest.java b/sdnr/wt/websocketmanager2/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsockerProviderTest.java
new file mode 100644
index 000000000..57d79602b
--- /dev/null
+++ b/sdnr/wt/websocketmanager2/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsockerProviderTest.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * ============LICENSE_START========================================================================
+ * ONAP : ccsdk feature sdnr wt
+ * =================================================================================================
+ * Copyright (C) 2019 highstreet technologies GmbH 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.ccsdk.features.sdnr.wt.websocketmanager2.test;
+
+import static org.junit.Assert.*;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.ccsdk.features.sdnr.wt.websocketmanager2.WebSocketManagerProvider;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
+import org.osgi.service.http.HttpService;
+
+public class WebsockerProviderTest extends Mockito {
+
+ @Test
+ public void test() {
+ RpcProviderService rpcProviderServiceMock = mock(RpcProviderService.class);
+ HttpService httpService = mock(HttpService.class);
+
+ try (WebSocketManagerProvider provider = new WebSocketManagerProvider();) {
+ provider.setRpcProviderRegistry(rpcProviderServiceMock);
+ provider.init();
+ provider.onBindService(httpService);
+ provider.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+
+ }
+
+}
diff --git a/sdnr/wt/websocketmanager2/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsocketClientTest.java b/sdnr/wt/websocketmanager2/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsocketClientTest.java
new file mode 100644
index 000000000..f56e1a686
--- /dev/null
+++ b/sdnr/wt/websocketmanager2/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsocketClientTest.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * ============LICENSE_START========================================================================
+ * ONAP : ccsdk feature sdnr wt
+ * =================================================================================================
+ * Copyright (C) 2019 highstreet technologies GmbH 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.ccsdk.features.sdnr.wt.websocketmanager2.test;
+
+import static org.junit.Assert.*;
+import org.java_websocket.handshake.ServerHandshake;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.ccsdk.features.sdnr.wt.websocketmanager2.websocket.SyncWebSocketClient;
+import org.onap.ccsdk.features.sdnr.wt.websocketmanager2.websocket.SyncWebSocketClient.WebsocketEventHandler;
+
+public class WebsocketClientTest extends Mockito {
+
+ @Test
+ public void test() {
+
+ WebsocketEventHandler clientHandlerMock = mock(WebsocketEventHandler.class);
+ ServerHandshake serverHandshakeMock = mock(ServerHandshake.class);
+
+ try {
+ SyncWebSocketClient client = new SyncWebSocketClient("url");
+
+ client.addEventHandler(clientHandlerMock);
+ client.onMessage("TestMessage");
+ client.onOpen(serverHandshakeMock);
+ client.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Exception "+e.getMessage());
+ }
+ }
+
+}
diff --git a/sdnr/wt/websocketmanager2/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsocketMessageTest.java b/sdnr/wt/websocketmanager2/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsocketMessageTest.java
new file mode 100644
index 000000000..f769dd40d
--- /dev/null
+++ b/sdnr/wt/websocketmanager2/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsocketMessageTest.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * ============LICENSE_START========================================================================
+ * ONAP : ccsdk feature sdnr wt
+ * =================================================================================================
+ * Copyright (C) 2019 highstreet technologies GmbH 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.ccsdk.features.sdnr.wt.websocketmanager2.test;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.*;
+
+import java.net.InetSocketAddress;
+
+import org.eclipse.jetty.websocket.api.Session;
+import org.junit.Test;
+import org.onap.ccsdk.features.sdnr.wt.websocketmanager2.WebSocketManagerSocket;
+
+public class WebsocketMessageTest {
+
+ private static final String MSG1 = "{\"data\":\"scopes\",\"scopes\":[\"scope1\"]}";
+ private static final String MSG2 = "{}";
+ private static final String MSG3 = "{\""+WebSocketManagerSocket.KEY_NODENAME+":\"xy\","+WebSocketManagerSocket.KEY_EVENTTYPE+":\"zu\"}";
+ private static final String MSG4 = "{ Not correct messga}";
+
+ @Test
+ public void test() {
+ MyWebSocketManagerSocket socketToTest = new MyWebSocketManagerSocket();
+ Session sess = mock(Session.class);
+ InetSocketAddress remoteAdr = new InetSocketAddress("127.0.0.1", 4444);
+ when(sess.getRemoteAddress()).thenReturn(remoteAdr);
+ socketToTest.onWebSocketConnect(sess);
+ // message from client
+ socketToTest.setExpected(MSG1);
+ socketToTest.onWebSocketText(MSG1);
+ socketToTest.setExpected(MSG2);
+ socketToTest.onWebSocketText(MSG2);
+ socketToTest.setExpected(MSG3);
+ socketToTest.onWebSocketText(MSG3);
+ socketToTest.setExpected(MSG4);
+ socketToTest.onWebSocketText(MSG4);
+ socketToTest.onWebSocketClose(0, "by default");
+ sess.close();
+
+ }
+
+ private static class MyWebSocketManagerSocket extends WebSocketManagerSocket {
+
+ private String expected;
+
+ public MyWebSocketManagerSocket() {
+ }
+ void setExpected(String expected) {
+ this.expected = expected;
+ }
+
+ @Override
+ public void send(String msg) {
+ System.out.println(msg);
+ assertTrue("Expected '"+expected+"' answer '"+msg+"'", msg.contains(expected));
+ }
+
+ }
+}
diff --git a/sdnr/wt/websocketmanager2/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsocketServerConnectTest.java b/sdnr/wt/websocketmanager2/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsocketServerConnectTest.java
index b380beca3..e59c343f2 100644
--- a/sdnr/wt/websocketmanager2/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsocketServerConnectTest.java
+++ b/sdnr/wt/websocketmanager2/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/WebsocketServerConnectTest.java
@@ -6,9 +6,9 @@
* =================================================================================================
* 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
@@ -17,17 +17,84 @@
******************************************************************************/
package org.onap.ccsdk.features.sdnr.wt.websocketmanager2.test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import com.google.common.util.concurrent.ListenableFuture;
+import java.util.concurrent.ExecutionException;
+import org.eclipse.jetty.websocket.api.WebSocketPolicy;
+import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
+import org.json.JSONObject;
import org.junit.Test;
import org.onap.ccsdk.features.sdnr.wt.websocketmanager2.WebSocketManager;
+import org.onap.ccsdk.features.sdnr.wt.websocketmanager2.WebSocketManagerSocket;
+import org.onap.ccsdk.features.sdnr.wt.websocketmanager2.WebSocketManagerSocket.EventInputCallback;
+import org.onap.ccsdk.features.sdnr.wt.websocketmanager2.utils.AkkaConfig;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.websocketmanager.rev150105.WebsocketEventInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.websocketmanager.rev150105.WebsocketEventOutput;
+import org.opendaylight.yangtools.yang.common.RpcResult;
public class WebsocketServerConnectTest {
- @Test
- public void test() {
+ private static final String XML1 = "<notification></notification>";
+ private static final String NODENAME = "abc";
+ private static final String EVENTTYPE = "test";
+ protected boolean responseReceived;
- WebSocketManager servlet =new WebSocketManager();
+ @Test
+ public void test() {
+ responseReceived = false;
+ AkkaConfig config = null;
+ try {
+ // config = AkkaConfig.load("akka-singlenode.cfg", true);
+ config = AkkaConfig.loadContent(AkkaConfigTest.loadResourceContentAsString("akka-cluster-local.cfg"));
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("error loading singlenode config");
+ }
+ EventInputCallback callback = message -> {
+ JSONObject o = new JSONObject(message);
+ assertEquals("message which was pushed is not as expected", XML1,
+ o.get(WebSocketManagerSocket.KEY_XMLEVENT));
+ assertEquals("nodename which was pushed is not as expected", NODENAME,
+ o.get(WebSocketManagerSocket.KEY_NODENAME));
+ assertEquals("eventtype which was pushed is not as expected", EVENTTYPE,
+ o.get(WebSocketManagerSocket.KEY_EVENTTYPE));
+ responseReceived = true;
+ };
+ WebSocketManager servlet = new WebSocketManager(config, callback);
+ WebsocketEventInput input = mock(WebsocketEventInput.class);
+ when(input.getXmlEvent()).thenReturn(XML1);
+ when(input.getNodeName()).thenReturn(NODENAME);
+ when(input.getEventType()).thenReturn(EVENTTYPE);
+ ListenableFuture<RpcResult<WebsocketEventOutput>> result = servlet.websocketEvent(input);
+ assertNotNull(result);
+ RpcResult<WebsocketEventOutput> rpc = null;
+ try {
+ rpc = result.get();
+ } catch (InterruptedException | ExecutionException e) {
+ fail(e.getMessage());
+ }
+ assertNotNull(rpc);
+ assertTrue("rpc result was not successful", rpc.isSuccessful());
+ assertTrue(rpc.getResult().getResponse().equals("OK"));
+ while (!responseReceived) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ WebSocketServletFactory factory = mock(WebSocketServletFactory.class);
+ WebSocketPolicy wspolicy = mock(WebSocketPolicy.class);
+ when(factory.getPolicy()).thenReturn(wspolicy);
+ servlet.configure(factory);
+
+ }
- }
}
diff --git a/sdnr/wt/websocketmanager2/provider/src/test/resources/akka-cluster-local.cfg b/sdnr/wt/websocketmanager2/provider/src/test/resources/akka-cluster-local.cfg
new file mode 100644
index 000000000..465dcad83
--- /dev/null
+++ b/sdnr/wt/websocketmanager2/provider/src/test/resources/akka-cluster-local.cfg
@@ -0,0 +1,49 @@
+odl-cluster-data {
+ akka {
+ remote {
+ artery {
+ enabled = off
+ canonical.hostname = "192.168.178.143"
+ canonical.port = 2550
+ }
+ netty.tcp {
+ hostname = "192.168.178.143"
+ port = 2550
+ }
+ # when under load we might trip a false positive on the failure detector
+ # transport-failure-detector {
+ # heartbeat-interval = 4 s
+ # acceptable-heartbeat-pause = 16s
+ # }
+ }
+
+ cluster {
+ # Remove ".tcp" when using artery.
+ seed-nodes = ["akka.tcp://opendaylight-cluster-data@192.168.178.142:2550",
+ "akka.tcp://opendaylight-cluster-data@192.168.178.143:2550",
+ "akka.tcp://opendaylight-cluster-data@192.168.178.144:2550",
+ "akka.tcp://opendaylight-cluster-data@192.168.178.145:2550"]
+
+ roles = ["member-2"]
+
+ }
+
+ persistence {
+ # By default the snapshots/journal directories live in KARAF_HOME. You can choose to put it somewhere else by
+ # modifying the following two properties. The directory location specified may be a relative or absolute path.
+ # The relative path is always relative to KARAF_HOME.
+
+ # snapshot-store.local.dir = "target/snapshots"
+ # journal.leveldb.dir = "target/journal"
+
+ journal {
+ leveldb {
+ # Set native = off to use a Java-only implementation of leveldb.
+ # Note that the Java-only version is not currently considered by Akka to be production quality.
+
+ # native = off
+ }
+ }
+ }
+ }
+}
diff --git a/sdnr/wt/websocketmanager2/provider/src/test/resources/simplelogger.properties b/sdnr/wt/websocketmanager2/provider/src/test/resources/simplelogger.properties
new file mode 100644
index 000000000..6f38b507a
--- /dev/null
+++ b/sdnr/wt/websocketmanager2/provider/src/test/resources/simplelogger.properties
@@ -0,0 +1,37 @@
+# SLF4J's SimpleLogger configuration file
+# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err.
+
+# Default logging detail level for all instances of SimpleLogger.
+# Must be one of ("trace", "debug", "info", "warn", or "error").
+# If not specified, defaults to "info".
+org.slf4j.simpleLogger.defaultLogLevel=trace
+
+# Logging detail level for a SimpleLogger instance named "xxx.yyy.zzz".
+# Must be one of ("trace", "debug", "info", "warn", or "error").
+# If not specified, the default logging detail level is used.
+# org.slf4j.simpleLogger.log.xxx.yyy=debug
+org.slf4j.simpleLogger.log.org.onap.ccsdk.features.sdnr.wt.devicemanager=debug
+org.slf4j.simpleLogger.log.org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.Resources=info
+org.slf4j.simpleLogger.log.org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.container=trace
+
+# Set to true if you want the current date and time to be included in output messages.
+# Default is false, and will output the number of milliseconds elapsed since startup.
+#org.slf4j.simpleLogger.showDateTime=false
+
+# The date and time format to be used in the output messages.
+# The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat.
+# If the format is not specified or is invalid, the default format is used.
+# The default format is yyyy-MM-dd HH:mm:ss:SSS Z.
+#org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z
+
+# Set to true if you want to output the current thread name.
+# Defaults to true.
+#org.slf4j.simpleLogger.showThreadName=true
+
+# Set to true if you want the Logger instance name to be included in output messages.
+# Defaults to true.
+#org.slf4j.simpleLogger.showLogName=true
+
+# Set to true if you want the last component of the name to be included in output messages.
+# Defaults to false.
+#org.slf4j.simpleLogger.showShortLogName=false