aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/websocketmanager
diff options
context:
space:
mode:
Diffstat (limited to 'sdnr/wt/websocketmanager')
-rw-r--r--sdnr/wt/websocketmanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/model/data/ReducedSchemaInfo.java19
-rw-r--r--sdnr/wt/websocketmanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/model/data/SchemaInfo.java22
-rw-r--r--sdnr/wt/websocketmanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/model/data/Scope.java2
-rw-r--r--sdnr/wt/websocketmanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/WebSocketManagerSocket.java31
-rw-r--r--sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/UserScopeTest.java10
5 files changed, 61 insertions, 23 deletions
diff --git a/sdnr/wt/websocketmanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/model/data/ReducedSchemaInfo.java b/sdnr/wt/websocketmanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/model/data/ReducedSchemaInfo.java
index f6e6c5d0d..9bc51d4c5 100644
--- a/sdnr/wt/websocketmanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/model/data/ReducedSchemaInfo.java
+++ b/sdnr/wt/websocketmanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/model/data/ReducedSchemaInfo.java
@@ -21,7 +21,9 @@
*/
package org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.data;
+import java.util.Optional;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.Revision;
public class ReducedSchemaInfo {
private String namespace;
@@ -34,14 +36,23 @@ public class ReducedSchemaInfo {
public ReducedSchemaInfo(QName qname) {
this.namespace = qname.getNamespace().toString();
- this.revision = qname.getRevision().isPresent() ? qname.getRevision().get().toString() : null;
+ Optional<Revision> orev = qname.getRevision();
+ this.revision = orev.isPresent() ? orev.get().toString() : null;
this.type = qname.getLocalName();
}
public boolean equals(QName obj) {
- return this.namespace.equals(obj.getNamespace().toString()) && this.type.equals(obj.getLocalName())
- && ((this.revision == null && obj.getRevision().isEmpty())
- || (this.revision.equals(obj.getRevision().get().toString())));
+ Optional<Revision> orev = obj.getRevision();
+ if (this.namespace.equals(obj.getNamespace().toString()) && this.type.equals(obj.getLocalName())) {
+ if (this.revision == null) {
+ return orev.isEmpty();
+ } else if (orev.isEmpty()) {
+ return false;
+ } else {
+ return orev.get().toString().equals(this.revision);
+ }
+ }
+ return false;
}
public String getNamespace() {
diff --git a/sdnr/wt/websocketmanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/model/data/SchemaInfo.java b/sdnr/wt/websocketmanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/model/data/SchemaInfo.java
index b920ffe71..032659c47 100644
--- a/sdnr/wt/websocketmanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/model/data/SchemaInfo.java
+++ b/sdnr/wt/websocketmanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/model/data/SchemaInfo.java
@@ -24,7 +24,9 @@ package org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.data;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.Revision;
public class SchemaInfo {
private String namespace;
@@ -33,14 +35,18 @@ public class SchemaInfo {
public SchemaInfo() {}
-
-
public SchemaInfo(QName qname) {
- this(qname.getNamespace().toString(),
- qname.getRevision().isPresent() ? qname.getRevision().get().toString() : null, new ArrayList<>());
+ this(qname.getNamespace().toString(), getRevision(qname), new ArrayList<>());
this.notification.add(qname.getLocalName());
}
+ private static String getRevision(QName qname) {
+ Optional<Revision> orev = qname.getRevision();
+ return orev.isPresent() ? orev.get().toString() : null;
+ }
+
+
+
public SchemaInfo(String namespace, String revision, List<String> notifications) {
this.namespace = namespace;
this.revision = revision;
@@ -78,8 +84,7 @@ public class SchemaInfo {
*/
@JsonIgnore
public boolean isValid() {
- return this.namespace != null
- && (this.notification == null || (this.notification != null && !this.notification.isEmpty()));
+ return this.namespace != null && (this.notification == null || !this.notification.isEmpty());
}
/**
@@ -95,7 +100,7 @@ public class SchemaInfo {
return true;
}
//if namespace does not match => false
- if (!this.namespace.equals(schema.getNamespace().toString())) {
+ if (!this.namespace.equals(schema.getNamespace())) {
return false;
}
//if revision of scope is set and it does not match and is not '*' => false
@@ -120,8 +125,9 @@ public class SchemaInfo {
if (this.revision == null && qname.getRevision().isEmpty()) {
return true;
}
+ Optional<Revision> orev = qname.getRevision();
if (this.revision != null) {
- return this.revision.equals(qname.getRevision().isEmpty() ? null : qname.getRevision().get().toString());
+ return this.revision.equals(orev.isEmpty() ? null : orev.get().toString());
}
return false;
}
diff --git a/sdnr/wt/websocketmanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/model/data/Scope.java b/sdnr/wt/websocketmanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/model/data/Scope.java
index b30aed1a6..4368ed550 100644
--- a/sdnr/wt/websocketmanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/model/data/Scope.java
+++ b/sdnr/wt/websocketmanager/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/model/data/Scope.java
@@ -112,7 +112,7 @@ public class Scope {
public static List<Scope> createList(String nodeId, List<QName> qnames) {
List<Scope> scopes = new ArrayList<>();
- Optional<Scope> listElem = null;
+ Optional<Scope> listElem;
for (QName qname : qnames) {
listElem = scopes.stream().filter(e -> e.schema != null && e.schema.equalsNamespaceAndRevision(qname))
.findFirst();
diff --git a/sdnr/wt/websocketmanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/WebSocketManagerSocket.java b/sdnr/wt/websocketmanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/WebSocketManagerSocket.java
index 7c12c4baa..7cc6d7272 100644
--- a/sdnr/wt/websocketmanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/WebSocketManagerSocket.java
+++ b/sdnr/wt/websocketmanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/WebSocketManagerSocket.java
@@ -80,8 +80,12 @@ public class WebSocketManagerSocket extends WebSocketAdapter {
.get(SEND_MESSAGE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
LOG.info("message sent");
}
- } catch (InterruptedException | ExecutionException | TimeoutException e) {
+ } catch (ExecutionException | TimeoutException e) {
LOG.warn("problem pushing message: ", e);
+ } catch (InterruptedException e) {
+ LOG.warn("Interrupted!", e);
+ // Restore interrupted state...
+ Thread.currentThread().interrupt();
}
if (messageQueue.isEmpty()) {
@@ -163,7 +167,7 @@ public class WebSocketManagerSocket extends WebSocketAdapter {
closed = false;
this.sendingSyncThread.start();
clientList.put(String.valueOf(this.hashCode()), this);
- LOG.debug("client connected from " + this.getRemoteAdr());
+ LOG.debug("client connected from {}", this.getRemoteAdr());
}
@Override
@@ -171,12 +175,12 @@ public class WebSocketManagerSocket extends WebSocketAdapter {
clientList.remove(String.valueOf(this.hashCode()));
this.sendingSyncThread.interrupt();
closed = true;
- LOG.debug("client disconnected from " + this.getRemoteAdr());
+ LOG.debug("client disconnected from {}", this.getRemoteAdr());
}
@Override
public void onWebSocketError(Throwable cause) {
- LOG.debug("error caused on " + this.getRemoteAdr() + " :" + cause.getMessage());
+ LOG.debug("error caused on {}: ",this.getRemoteAdr(), cause);
}
private String getRemoteAdr() {
@@ -212,11 +216,11 @@ public class WebSocketManagerSocket extends WebSocketAdapter {
}
} catch (JsonProcessingException e) {
- LOG.warn("problem set scope: " + e.getMessage());
+ LOG.warn("problem set scope: {}" ,e.getMessage());
try {
this.send(mapper.writeValueAsString(ScopeRegistrationResponse.error(e.getMessage())));
} catch (JsonProcessingException e1) {
- LOG.warn("problem sending error response via ws: " + e1);
+ LOG.warn("problem sending error response via ws: ", e1);
}
}
return ret;
@@ -232,7 +236,7 @@ public class WebSocketManagerSocket extends WebSocketAdapter {
this.sendToAll(notification.getNodeId(), notification.getType(), request);
}
} catch (Exception e) {
- LOG.warn("handle ws request failed:" + e.getMessage());
+ LOG.warn("handle ws request failed:",e);
}
}
@@ -241,7 +245,9 @@ public class WebSocketManagerSocket extends WebSocketAdapter {
LOG.trace("sending {}", msg);
this.messageQueue.put(msg);
} catch (InterruptedException e) {
- LOG.warn("problem putting message into sending queue: " + e.getMessage());
+ LOG.warn("problem putting message into sending queue: {}", e.getMessage());
+ // Restore interrupted state...
+ Thread.currentThread().interrupt();
}
}
@@ -294,8 +300,13 @@ public class WebSocketManagerSocket extends WebSocketAdapter {
}
public static void broadCast(DOMNotificationOutput domNotificationOutput) {
- // TODO Auto-generated method stub
-
+ if (clientList.size() > 0) {
+ Set<Entry<String, WebSocketManagerSocket>> e = clientList.entrySet();
+ WebSocketManagerSocket s = e.iterator().next().getValue();
+ if (s != null) {
+ s.sendToAll(domNotificationOutput);
+ }
+ }
}
}
diff --git a/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/UserScopeTest.java b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/UserScopeTest.java
index 885ded348..ca3d6918c 100644
--- a/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/UserScopeTest.java
+++ b/sdnr/wt/websocketmanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager2/test/UserScopeTest.java
@@ -58,6 +58,16 @@ public class UserScopeTest {
}
+ @Test
+ public void testSchemaInfoClass() {
+ ReducedSchemaInfo si = new ReducedSchemaInfo(ProblemNotification.QNAME);
+ assertTrue(si.equals(ProblemNotification.QNAME));
+ assertFalse(si.equals(ObjectCreationNotification.QNAME));
+ si.setRevision(null);
+ assertFalse(si.equals(ProblemNotification.QNAME));
+
+ }
+
private static final Scope buildScope(String nodeId, String namespace, String revision,
List<String> notifications) {
Scope scope = new Scope();