Notification Service - Managing a Persistent Subscription

Overview

This tutorial describes how to manage a persistent subscription in a Disaster Recovery (DR) setup mode where there are 2 data centres (DC1 and DC2). vIP1 (147.75.102.122) and vIP2 (147.75.102.226) are the IP addresses of the 2 data centres.

This tutorial has been tested using the NSP-FAULT category.

Prerequisite

The assumptions for this use case are:

  • The user has already located the 'authentication' and 'notifications' rest API services by using the location services.
  • The user has retrieved a token to be able to use the notification service. The token is refreshed every 15 minutes.
  • The user determined that DC2 is the active NSP initially

Tutorial

  1. Create a subscription using category NSP-FAULT
POST /nbi-notification/api/v1/notifications/subscriptions HTTP/1.1
Host: 147.75.102.226:8544
Content-Type: application/json
Authorization: Bearer VEtOLW9zc19jbGllbnQzMGU3ZjVlNy1hZTQ5LTRhNDItYmFhYi00OTdiZWJmYzkyODY=
Cookie: NSPOSAPP1_JSESSIONID=D8A19AA59536C32BAAA3F9E58EFD3FC6; NSPOS_JSESSIONID=66C1A4A34981EBE0516C83FE6C65D284
Content-Length: 154

{
    "categories": [
        {
            "name": "NSP-FAULT"
        }
    ],
    "asyncCreate": "false",
    "persist": "true",
    "clientId": "FM"
}
{
    "response": {
        "status": 0,
        "startRow": 0,
        "endRow": 0,
        "totalRows": 1,
        "data": {
            "subscriptionId": "fa7fcc34-1801-481c-af09-dfca5f78ee4b",
            "clientId": "FM",
            "topicId": "ns-eg-fa7fcc34-1801-481c-af09-dfca5f78ee4b",
            "timeOfSubscription": 1664479190687,
            "expiresAt": 1664482790688,
            "stage": "ACTIVE",
            "persisted": true
        },
        "errors": null
    }
}

2. Save subscription data
The 'stage' property is 'active' which means the subscription is successfully created and ready to be used. Save the subscription 'data' (i.e. subscriptionId, topicId, timeOfSubscription, expiresAt) that you will need in case NSP or your application stops.

3. Start timer that allows you to renew the subscription every 15 minutes.

Save the subscription response in the OSS persistent store

4. Start polling the kafka topic to retrieve alarms for processing. In this example, we use the apache kafka client CLIs:

kafka-console-consumer.sh --topic ns-eg-fa7fcc34-1801-481c-af09-dfca5f78ee4b --bootstrap-server 147.75.102.226:9192 --consumer.config consumer.properties --from-beginning

A couple of events are shown below.

{
  "data": {
    "ietf-restconf:notification": {
      "eventTime": "2022-09-29T19:21:20Z",
      "nsp-fault:alarm-change": {
        "lastTimeDetected": {
          "old-value": 1664479293349,
          "new-value": 1664479303352
        },
        "numberOfOccurrencesSinceClear": {
          "old-value": 120615,
          "new-value": 120616
        },
        "numberOfOccurrences": {
          "old-value": 130385,
          "new-value": 130386
        },
        "objectId": "fdn:model:fm:Alarm:74488"
      }
    }
  }
}

{
  "data": {
    "ietf-restconf:notification": {
      "eventTime": "2022-09-29T19:26:13Z",
      "nsp-fault:alarm-change": {
        "lastTimeAcknowledged": {
          "old-value": 1663773073251,
          "new-value": 1664479596675
        },
        "numberOfOccurrencesSinceAck": {
          "old-value": 1,
          "new-value": 0
        },
        "acknowledged": {
          "old-value": false,
          "new-value": true
        },
        "objectId": "fdn:model:fm:Alarm:74488"
      }
    }
  }
}

A failover occurs where SD2 shuts down and SD1 is in the process of taking over as the active NSP. The topic 'ns-eg-fa7fcc34-1801-481c-af09-dfca5f78ee4b' in SD2 is no longer available.

  1. The user application fails to retrieve events from the topic. An exception or error is received (see below).

WARN [Consumer clientId=consumer-test-consumer-group-1, groupId=test-consumer-group] Connection to node 1001 (/147.75.102.226:9192) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)

6. Start a repetitive sequence to obtain a token by sending a request to SD2 first, then after 30 seconds, to SD1 until a token is successfully retrieved. SD1 is now the active NSP.

7. Send a request to SD1 to GET the persistent subscription; it takes time for the NSP system in SD1 to be available, so repeat the process every 30 seconds until you successfully retrieve the subscription and the 'stage' property value is 'ACTIVE' (any other 'stage' values indicate that the subscription is not ready yet.
While trying to retrieve the subscription, you may get some of the following errors:

'The NSP is not currently available. 502 Bad Gateway'

or '404 (subscription not found) or

{
    "response": {
        "status": 0,
        "startRow": 0,
        "endRow": 0,
        "totalRows": 1,
        "data": {
            "subscriptionId": "36f6d66e-dcbe-40e7-b23c-515c3563bbc5",
            "clientId": "FM22",
            "topicId": "N/A",
            "timeOfSubscription": 1664903125681,
            "expiresAt": 1664908566520,
            "stage": "RECREATING",
            "persisted": true
        },
        "errors": null
    }
}
GET /nbi-notification/api/v1/notifications/subscriptions/fa7fcc34-1801-481c-af09-dfca5f78ee4b HTTP/1.1
Host: 147.75.102.122:8544
Content-Type: application/json
Authorization: Bearer VEtOLW9zc19jbGllbnQ2MmM1MjFkNy0wNmM0LTRjMmQtYjZiOC05ODVmMWFhOTM0OTQ=
Cookie: NSPOSAPP1_JSESSIONID=7147A44AB149BD30B5E143749AD30F58; NSPOS_JSESSIONID=5FD0D15840AF132BE46A723FC8037875
{
    "response": {
        "status": 0,
        "startRow": 0,
        "endRow": 0,
        "totalRows": 1,
        "data": {
            "subscriptionId": "fa7fcc34-1801-481c-af09-dfca5f78ee4b",
            "clientId": "FM",
            "topicId": "ns-eg-fa7fcc34-1801-481c-af09-dfca5f78ee4b",
            "timeOfSubscription": 1664479190687,
            "expiresAt": 1664484303261,
            "stage": "ACTIVE",
            "persisted": true
        },
        "errors": null
    }
}

Once the subscription is 'active', start retrieving the events from the kafka topic which has been re-created on SD1; also make sure to issue a renewal of the subscription right away.

After successfully retrieving the subscription, if it does not become 'active' after 15 minutes, delete the subscription and re-start the process of creating a new one.

On this page