11 Replies Latest reply on Apr 24, 2014 6:51 AM by Mike Zboray

    GetActiveInstances() method of ANNotificationList does not return anything

    MBanchuzhnyy

      Good morning everyone!

       

      We've just experienced strange issue. In our application we retrieve list of active notifications using common algorithm (that was mentioned in vcampus many times):

       
      // 1. Get all notifications using filter 
      ANNotificationList notificationList = new ANNotificationList(AFNotification.FindNotifications(myDatabase, "", filteredCategory, null, AFSortField.Name, AFSortOrder.Ascending, 10000));
      
      // 2. Extract Notification instances using given timeframe or extract active notifications
      List<ANNotificationInstances> notificationInstances = notificationList.GetInstances(new AFTime(StartTime), new AFTime(EndTime));
      
      // or for active – DOES NOT WORK!
      List<ANNotificationInstances> notificationInstances = notificationList.GetActiveInstances();
      

      So

       
      notificationList.GetActiveInstances()
      

       does not return anything. The most interesting thing that sometime it works, and sometime it doesn't. We were not able to figure out what does influence on it. We have other test machine with old PI NOtifications installed (version 1.2.1205.6 ) and there is no any problem there. The version of Pi Notifications on machine where we have problem is 1.2.1205.10. We downgraded version to 1.2.1205.6, and probably accidentially method started to work, but today morning we again see no Active notifcations using GetActiveInstances() method.

       

       

       

       If I use 

       
      notificationList.GetInstances(new AFTime(StartTime), new AFTime(EndTime));
      

       then I can find notifications using its Id and AFNotification class from AF SDK. Then filter them using property IsActive like this:

       
      foreach (ANNotificationInstances instance in notificationInstances)           {
      {
          AFNotification notification = AFNotification.FindNotification(mySystem, instance.NotificationID);
          ...
          // get metadata
          foreach (var item in instance.Instances)
             {
                    if (item.IsActive == true)
                    {
                     ...
                    }
             }                 
        }
      

      It supports that there are active notifications in the system.

       

       

       

      Has anybody seen something similar?

       

      Thank you.

       

       

        • Re: GetActiveInstances() method of ANNotificationList does not return anything
          Mike Zboray

          Hi Maxim,

           

          I'm not aware of a difference between 1.2.1205.6 and 1205.10 in this regard. Can you verify that you can communicate with both the Notifications service and the history PI server from the machine with the issue? To check communication with the service, go to Tools > Notification Settings > Service and make sure it lists your service instance. For the history server, just use About PISDK to connect. You may want to check that you can read the history tags from that machine as well.

           

          If the Notifications are running we will try to get the information from the Notifications Service directly, if not (or there is problem talking to the service) we talk directly to the history pi server.

           

          Mike

            • Re: GetActiveInstances() method of ANNotificationList does not return anything
              MBanchuzhnyy

              Hi Mike,

               

              Thank you for answer.

               

              I think I should added that we are able to see notifications through PI Explorer on the same machine (doesn't matter history or active). The only problem is we don't get active ones through the code ( GetActiveInstances() method).

               

              I checked communication with service - everything is ok.

               

              Thank you.

               

              Maxim.

                • Re: GetActiveInstances() method of ANNotificationList does not return anything
                  Mike Zboray

                  Hey Maxim,

                   

                  Ok I had a look at the ANSDK code. Here's a few things to try:

                   

                  1. What does GetLastInstances() return? Under the hood GetActiveInstances calls this method and just filters client-side using IsActive, so I suspect it is not returning the correct results.

                   

                  2. The ANNotificationInstances object has an Exception property on it. Can you check whether the objects in the list returned from GetActiveInstances have an Exception object set?

                   

                  3. Can you turn on AFSDK tracing for your application? If it is .NET 3.5 by default it should log to the pi sdk message log. For .NET 4 you will have to turn it on manually. If you have a simple console app, the easiest way would be to add a ConsoleTraceListener using AFTrace.AddListener at the start. Then recompile and run. So if there are any errors logged from ANNotificationList or ANNotificationHistoryManager when you make the call to GetActiveInstances.

                   

                  Mike

                    • Re: GetActiveInstances() method of ANNotificationList does not return anything
                      MBanchuzhnyy

                      Mike,

                       

                      Ok, I will try and let you know.

                       

                      Thank you.

                        • Re: GetActiveInstances() method of ANNotificationList does not return anything
                          MBanchuzhnyy

                          Mike,

                           

                          I checked what you suggested to do, here is answer:

                           

                          1). In time when GetActiveInstances() is not able to reiterative data, I tried to call GetLastInstances() . It returns two ANNotificationInstances objects (what I actually have in system). Please check screenshots below:

                           

                          Picture shows that I have two notifications. "Maxim-test" one is on active mode.

                           

                           

                           

                          7840.sh01.png

                           

                          Debug screen shows that Maxim-Test notification doesn't have exception , but Instances property is empty. So I think it is not right it should show some instances and some of them should be with IsActive = true flag.

                           

                          0513.sh02.png

                           

                          Debug screen shows that CDT158 notification doesn't have exception , Instances are not empty.

                           

                          7043.sh03.png

                           

                           

                           

                          2). According to screenshots above, no exception is found.

                           

                          3). I tried to add listener. I placed in console app entry point method the following code:

                           

                           

                           
                          ConsoleTraceListener listener = new ConsoleTraceListener();
                          AFTrace.AddListener(listener);
                          

                           

                           

                          Listener didn't show in a console any problem. Also I flicked through its props and I didn't find anything interesting. I don't have experience with it, probably I have to check some particular propertiy, please let me know if I did it wrong.

                           

                          Thank you.

                            • Re: GetActiveInstances() method of ANNotificationList does not return anything
                              Mike Zboray

                              Hey Maxim,

                               

                              Ok, that is interesting. Its ok that you don't see any thing being traced, we would only trace errors and it looks like you aren't getting any.

                               

                              I noticed that the start and end times don't match what is shown in PSE. This makes me think that what is happening is that you hitting the history provider, but that it, for some reason, is out of sync with the history PI server.

                               

                              1. Can you try a "Recent" query in PSE for say the last day and see if gives you the correct instances. By default, queries for times less than 7 days will be serviced by the history provider. Longer time ranges will go to the history PI server (via the history provider). What was the time range your for your call to GetInstances?

                               

                              2. You can try to reinitialize the history provider. Go to the service machine's Program Files\PIPC\Analytics (note: 32-bit directory on a 64-bit OS) and in the command line run:

                               

                              PINotificationsHistoryProvider.exe /reinitialize

                               

                              Then re-run your console app and see if you get the correct instances.

                               

                              Mike

                                • Re: GetActiveInstances() method of ANNotificationList does not return anything
                                  MBanchuzhnyy

                                  Thank you Mike for answer. I will check it and let you know, hope it will help.

                                   

                                  Also we contacted OSI Soft support, they suggested to upgrade AF Server to version 2.6.

                                   

                                  Thank you.

                                   

                                  Maxim.

                                    • Re: GetActiveInstances() method of ANNotificationList does not return anything
                                      MBanchuzhnyy

                                      Mike,

                                       

                                      Probably I didn't understand you, the problem was with Active notifications, is PINotificationsHistoryProvider linked with Active notifications too?

                                       

                                      Thank you.

                                        • Re: GetActiveInstances() method of ANNotificationList does not return anything
                                          Mike Zboray

                                          Maxim,

                                           

                                          As far as I can tell, AF Server has nothing to do with this so upgrading it would not solve them problem.

                                           

                                          History Provider comes into play with almost all calls that get notification history. The logic is something like this:

                                           

                                          1. Request history from history provider.

                                           

                                          2. History provider checks its cache, if it can service the request it does so.

                                           

                                          3. If not it goes to the pi server and gets the history and returns that to the caller.

                                           

                                          4. If the call to history provider fails (e.g. the notifications service is not running) then the SDK will directly query the history from the pi server.

                                           

                                          You've got some history in PSE with a current active instance. Yet that instance does not come back when you do GetLastInstance. That suggests to me that you are hitting different sources that are out of sync. PSE does a signup up for updates on the history tags, so one possibility is that the your calls through the ANSDK are hitting the history provider's cache which is out of sync with the history in the PI server. Another possibility could be a PI server collective that is out of sync and we are hitting two different members, but that is less likely.

                                           

                                          One way to force a bypass of history provider is to request a time range outside its cache range (default is 7 days). Try comparing the history in PSE when you do a "recent" search that is 1 day vs 8 days and see if they are the same.

                                           

                                          I suggested you reinitialize history provider so that it dumps its cache and reinitializes with data from the history pi server. If you continue to get the incorrect result after that, we have some more work to do.

                                           

                                          Mike

                                            • Re: GetActiveInstances() method of ANNotificationList does not return anything
                                              MBanchuzhnyy

                                              MIke,

                                               

                                              Sorry for delay.  We had meeting with OSISoft support, unfortunately they don't have answer for this issue.

                                               

                                              Regarding your last response - as you remember the problem is that the active notifications cannot be retrieved using GetActiveNotifcations() method -  is history provider linked somehow with active notifications? Could you please explain.

                                               

                                              Thank you.

                                                • Re: GetActiveInstances() method of ANNotificationList does not return anything
                                                  Mike Zboray

                                                  Maxim,

                                                   

                                                  Almost all ANSDK calls that retrieve history will go through the History Provider. The History Provider caches the notification history and improves history query performance and reduces load on the history PI server. My thinking is that what you are seeing is caused by an out-of-sync cache in the history provider and one of these clients is bypassing it and going directly to the history server. This could happen for example if one of them could not communicate with the Notifications service but could connect to the history PI server.

                                                   

                                                  The one prominent case where the ANSDK always goes directly to the history server is ANNotification.GetLastInstance. GetLastInstance only requires snapshot values so it is relatively easy for the PI server to service this call. Note however, that ANNotificationList.GetLastInstances uses the History Provider. So the question is, if you query using ANNotification.GetLastInstance are you getting different results from ANNotificationList.GetLastInstances?

                                                   

                                                  Also note that PSE can behave a little differently because, while it will try to use history provider, it will also signup for updates on the history tags. Then it will show instances that are created as it receives the updates.

                                                   

                                                  Mike