Prevent oversize user notifications 43/8043/2 master
authorAndrew Gauld <agauld@att.com>
Tue, 2 Jun 2020 20:33:10 +0000 (20:33 +0000)
committerAndrew Gauld <agauld@att.com>
Wed, 3 Jun 2020 14:23:15 +0000 (14:23 +0000)
Change-Id: I039f2fb0e3855060271b37688ce0b7ca543fee3e
Issue-ID: ACUMOS-4177
Signed-off-by: Andrew Gauld <agauld@att.com>
acumos-fgw-client/pom.xml
docs/release-notes.rst
gateway/pom.xml
gateway/src/main/java/org/acumos/federation/gateway/SubscriptionPoller.java

index 9e504fe..c0bfd75 100644 (file)
@@ -28,7 +28,7 @@ limitations under the License.
        </parent>
        <groupId>org.acumos.federation</groupId>
        <artifactId>acumos-fgw-client</artifactId>
-       <version>3.2.2-SNAPSHOT</version>
+       <version>3.2.3-SNAPSHOT</version>
        <name>Federation Gateway Client</name>
        <properties>
                <!-- dependency versions -->
index e36172b..239f27e 100644 (file)
@@ -24,6 +24,10 @@ Federation Gateway Release Notes
 This server is available as a Docker image in a Docker registry at the Linux Foundation.
 The image name is "federation-gateway" and the tag is a version string as shown below.
 
+Version 3.2.3, 2020-06-03
+-------------------------
+* Prevent oversize user notifications (`ACUMOS-4177 <https://jira.acumos.org/browse/ACUMOS-4177>`_)
+
 Version 3.2.2, 2020-03-24
 -------------------------
 * Adding support for updating params to deployed model (`ACUMOS-3742 <https://jira.acumos.org/browse/ACUMOS-3742>`_)
index 7f6f3d8..b621740 100644 (file)
@@ -28,7 +28,7 @@
        </parent>
        <groupId>org.acumos.federation</groupId>
        <artifactId>gateway</artifactId>
-       <version>3.2.2-SNAPSHOT</version>
+       <version>3.2.3-SNAPSHOT</version>
        <name>Federation Gateway</name>
        <description>Federated Acumos Interface for inter-acumos communication</description>
        <properties>
index 1d46ef3..6d6e8a1 100644 (file)
@@ -207,10 +207,37 @@ public class SubscriptionPoller {
                        leaf = new PendingAction(null, action, String.format(item, args), true);
                }
 
+               /*
+                * MLPNotification.java limits the lengths of the title
+                * and message fields.
+                * However, it doesn't define constants with these values, and
+                * the setters are perfectly happy accepting oversize values.
+                * We limit ourselves to use significantly less than those
+                * limits so we don't run into any off-by-one type errors and
+                * will use at most 73 characters in titles and at most 2003
+                * characters in messages (the 3 allows for an elipsis ...)
+                */
+               private static final int NOTIF_TITLE_MAX_USED = 73;
+               private static final int NOTIF_MESSAGE_MAX_USED = 2003;
+               private static final String ELIPSIS = "...";
+               private static final int ELIPSIS_LENGTH = ELIPSIS.length();
+
                private void note(PendingAction cur, String sev, String msg) {
-                       MLPNotification note = new MLPNotification(cur.getItem(), sev, cur.getStart(), Instant.now());
+                       String item = cur.getItem().strip();
+                       if (item.length() > NOTIF_TITLE_MAX_USED) {
+                               msg = item + " - " + msg;
+                               item = item.substring(0, NOTIF_TITLE_MAX_USED - ELIPSIS_LENGTH) + ELIPSIS;
+                       }
+                       if (msg.length() > NOTIF_MESSAGE_MAX_USED) {
+                               msg = msg.substring(0, NOTIF_MESSAGE_MAX_USED - ELIPSIS_LENGTH) + ELIPSIS;
+                       }
+                       MLPNotification note = new MLPNotification(item, sev, cur.getStart(), Instant.now());
                        note.setMessage(msg);
-                       cds.addUserToNotification(cds.createNotification(note).getNotificationId(), userId);
+                       try {
+                               cds.addUserToNotification(cds.createNotification(note).getNotificationId(), userId);
+                       } catch (Exception e) {
+                               log.error("Error notifying user of federation actions", e);
+                       }
                }
 
                public PendingAction end() {