15 Replies Latest reply on Apr 13, 2017 6:21 PM by MateusAmarante

    AFAnalysisService.QueueCalculation - PI Analysis Service is not available

    MateusAmarante

      Hello everyone.

       

      I'm getting the error "PI Analysis Service is not available" when I try to run AFAnalysisService.QueueCalculation method.

       

      I was able to backfill analyses with Keith Fong's code (GitHub - kfong257/AnalysisBackfill: Programmatically backfill and recalculate AF Analyses, thanks a lot) on the machine where both PI Server and PI Analysis Service are installed.

       

      The code uses AD credentials, then I changed it a little bit to run analysis from another machine using explicit credentials. The connection is established so I can find the elements and the Analyses I want. However, when it runs the AFAnalysisService.QueueCalculation method, I get this error:

       

      "PI Analysis Service is not available."

       

      When I call AFAnalysisService.CanQueueCalculation method, it returns False and outputs the same message.

       

      What may be the problem?

       

      Related Post:

      PI AF SDK Scheduled Backfill

        • Re: AFAnalysisService.QueueCalculation - PI Analysis Service is not available
          kfong

          Hi Mateus,

           

          I'm glad my code was helpful to you.  If the analysis service isn't available, I would expect this issue to affect more than just the custom AF SDK application.  Can you try backfilling with PI System Explorer? 

           

          If that does work, then your user running the code might not have correct permissions to backfill. 

          If it doesn't work, then you'll have to troubleshoot the Analysis Service.  Is the service running?  What do the message logs say? etc.

            • Re: AFAnalysisService.QueueCalculation - PI Analysis Service is not available
              MateusAmarante

              I can backfill with the PI System Explorer from both server and remote machines.

               

              I'm using a PI User that is in the "piadmins" group, that is, it has permissions to access and alter af server and data archive. I can find the AF Elements, Analysis and Tags with no problem.

               

              Checking the log, I noticed that the connection from the server machine is stablished by a trust. When I try to connect from a remote machine, it tries to connect through trust and Windows Account, then fails. On a third chance, it logs in with explicit credentials.

               

              I've tried to configure a trust, but I had no sucess. The server is in the cloud, so I'm accessing it throught internet. Is there a way to configure a trust with this architecture?

                • Re: AFAnalysisService.QueueCalculation - PI Analysis Service is not available
                  kfong

                  Thanks for testing the backfill from PSE.  Because it works from there, that tells me the issue is with the custom app.

                   

                  The error "PI Analysis Service is not available." is returned by the PI Analysis Service, not the PI Data Archive.  So, for now, let's focus our troubleshooting efforts there.  On the analysis machine, can you look for errors backfilling in the recalculation processor logs?  Go to %ProgramData%\OSIsoft\PIAnalysisNotifications\Logs and open up the pirecalculationprocess-log.txt file. 

                   

                  Also, what version of the PI Analysis service do you have? 

                  1 of 1 people found this helpful
                    • Re: AFAnalysisService.QueueCalculation - PI Analysis Service is not available
                      MateusAmarante

                      When I run the application from the remote machine, nothing is logged in pirecalculationprocess-log.txt.

                       

                      On the other hand, when I run it from the server machine it logs accordingly, as well as when I manually backfill from PSE from both machines.

                       

                      I have the PIAnalysisService_2.8.5.7759 version installed.

                        • Re: AFAnalysisService.QueueCalculation - PI Analysis Service is not available
                          MateusAmarante

                          However, on the message logs I see a different INFO message.

                           

                          [Server] 52.67.105.197 [ID] 7121 [Time] 3/24/2017 6:52:48 PM [Program] pinetmgr [Priority] 10 [ProcessOSUser] SYSTEM [ProcessID] 1876 [Severity] Information

                          Deleting connection:  AnalysisBackfill.exe(2296):remote(2296), Asynch read failed. [10054] An existing connection was forcibly closed by the remote host., ID: 629  177.191.200.188:56229

                          • Re: AFAnalysisService.QueueCalculation - PI Analysis Service is not available
                            kfong

                            What is the actual command you're using from the remote machine?  If the application works when it's local to the analysis service machine, but not a remote machine, I would expect that the root cause is the app's connection logic.  Could you post that part of your code?  In addition, if you reach out to the PI Developers Club , they should be able to give you more specific assistance with the code.

                              • Re: AFAnalysisService.QueueCalculation - PI Analysis Service is not available
                                MateusAmarante

                                I'm basically using your code. I only changed it in 2 parts:

                                 

                                Adapted the Connect method of AFSystemHelper.cs

                                public static PISystem Connect(string PISystemName, string AFDatabaseName, string afUserName, string afUserPswd)

                                {

                                //connections

                                PISystems allAFServers = new PISystems();

                                PISystem aAFServer = allAFServers[PISystemName];

                                 

                                var securePassword = new SecureString();

                                 

                                foreach (var c in afUserPswd)

                                securePassword.AppendChar(c);

                                 

                                var cred = new NetworkCredential(afUserName, securePassword);

                                 

                                try

                                {

                                aAFServer.Connect(cred);

                                //aAFServer.Connect(true,null); //also tried this way with no sucess

                                }

                                ...

                                return aAFServer;

                                 

                                And Program.cs

                                ...

                                string usernameAf = Convert.ToString(ConfigurationManager.AppSettings[ConstUtils.AppSettingsAfuser]);

                                string passwordAf = Convert.ToString(ConfigurationManager.AppSettings[ConstUtils.AppSettingsAfpassword]);

                                ...

                                aSystem = AFSystemHelper.Connect(user_serv, user_db,usernameAf,passwordAf);

                                 

                                 

                                The same code works on the server machine with de same credentials. I also ran the code connecting to the Data Archive, but I get the same error.

                                  • Re: AFAnalysisService.QueueCalculation - PI Analysis Service is not available
                                    kfong

                                    Authentication against an AF Server should be using Windows Security and mappings, not explicit log on with a username and password.  I expect this is why the application is failing to authenticate.  Why are you using explicit credentials instead of a Windows user?

                                    1 of 1 people found this helpful
                                      • Re: AFAnalysisService.QueueCalculation - PI Analysis Service is not available
                                        MateusAmarante

                                        At first, I'm really sorry to take too long time to answer. I stopped this activity for a while and the "runas" strategy solved my problem.

                                         

                                        I've been studying more about PI AF Server and confirmed that its authentication needs to be through Windows AD. However, it still is weird the fact I can get information about the AF Server with explicit credentials but I can't access the Analysis Service and call QueueCalculation method.

                                         

                                        I was using explicit credentials instead of a Windows User because the server is in an online virtual machine (Amazon Cloud8) and my application was on my machine, that means they are not on the same network. Since it is just a development environment, the "runas" solution was acceptable. In the production environment, I should not have that problem.

                                         

                                        If I have more problems I'll call the Tech Support.

                                         

                                        Thanks!

                          • Re: AFAnalysisService.QueueCalculation - PI Analysis Service is not available
                            Mike Zboray

                            This error is generated on the client side when it is trying to connect to the Analysis Service and the client is not able to configure a connection. This typically happens because the client is unable to read the configuration needed from the Configuration database. To get a detailed error you need to run AFGetTrace. The failure to configure the client is written at Error level so we can just filter that level and higher. In a command prompt run: "C:\Program Files (x86)\PIPC\AF\AFGetTrace.exe" /L:Error

                            Then run your program and you should get some information on the error. This tool captures information from all AFSDK applications on the machine by default so stopping other programs using AFSDK is helpful.

                            1 of 1 people found this helpful
                              • Re: AFAnalysisService.QueueCalculation - PI Analysis Service is not available
                                MateusAmarante

                                I got something different (the error means: "The server rejected the client credentials"):

                                 

                                2017-03-27 10:24:49.640 [9772:5712]: Error: O servidor rejeitou as credenciais do cliente.

                                   

                                    Server stack trace:

                                       em System.ServiceModel.Channels.WindowsStreamSecurityUpgradeProvider.WindowsStreamSecurityUpgradeInitiator.OnInitiateUpgrade(Stream stream, SecurityMessageProperty& remoteSecurity)

                                       em System.ServiceModel.Channels.StreamSecurityUpgradeInitiatorBase.InitiateUpgrade(Stream stream)

                                       em System.ServiceModel.Channels.ConnectionUpgradeHelper.InitiateUpgrade(StreamUpgradeInitiator upgradeInitiator, IConnection& connection, ClientFramingDecoder decoder, IDefaultCommunicationTimeouts defaultTimeouts, TimeoutHelper& timeoutHelper)

                                       em System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.SendPreamble(IConnection connection, ArraySegment`1 preamble, TimeoutHelper& timeoutHelper)

                                       em System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.DuplexConnectionPoolHelper.AcceptPooledConnection(IConnection connection, TimeoutHelper& timeoutHelper)

                                       em System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnection(TimeSpan timeout)

                                       em System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout)

                                       em System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)

                                       em System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)

                                       em System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)

                                       em System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout)

                                       em System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade)

                                       em System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)

                                       em System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)

                                       em System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

                                   

                                    Exception rethrown at [0]:

                                       em System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)

                                       em System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)

                                       em OSIsoft.AN.WCF.IANClientToManagerWCFContract.GetServiceStatus()

                                       em OSIsoft.AF.Analysis.AFAnalysisService.TryCanConnect(Client client, String& reason)

                                    

                                2017-03-27 10:24:49.796 [9772:5712]: Error: O servidor rejeitou as credenciais do cliente.

                                   

                                    Server stack trace:

                                       em System.ServiceModel.Channels.WindowsStreamSecurityUpgradeProvider.WindowsStreamSecurityUpgradeInitiator.OnInitiateUpgrade(Stream stream, SecurityMessageProperty& remoteSecurity)

                                       em System.ServiceModel.Channels.StreamSecurityUpgradeInitiatorBase.InitiateUpgrade(Stream stream)

                                       em System.ServiceModel.Channels.ConnectionUpgradeHelper.InitiateUpgrade(StreamUpgradeInitiator upgradeInitiator, IConnection& connection, ClientFramingDecoder decoder, IDefaultCommunicationTimeouts defaultTimeouts, TimeoutHelper& timeoutHelper)

                                       em System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.SendPreamble(IConnection connection, ArraySegment`1 preamble, TimeoutHelper& timeoutHelper)

                                       em System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.DuplexConnectionPoolHelper.AcceptPooledConnection(IConnection connection, TimeoutHelper& timeoutHelper)

                                       em System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnection(TimeSpan timeout)

                                       em System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout)

                                       em System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)

                                       em System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)

                                       em System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)

                                       em System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout)

                                       em System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade)

                                       em System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)

                                       em System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)

                                       em System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

                                   

                                    Exception rethrown at [0]:

                                       em System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)

                                       em System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)

                                       em OSIsoft.AN.WCF.IANClientToManagerWCFContract.GetServiceStatus()

                                       em OSIsoft.AF.Analysis.AFAnalysisService.TryCanConnect(Client client, String& reason)

                                    

                                2017-03-27 10:24:49.802 [9772:1780]: PI.Net (Thread Id: 2): SessionManager deleted. AppDomain Id: 1

                                • Re: AFAnalysisService.QueueCalculation - PI Analysis Service is not available
                                  MateusAmarante

                                  The first time I open the "Management" panel on PI System Explorer from the remote machine, I need to reenter user/pswd credentials ("Connect to PI Analysis Service ..."). The same happens if I access the "Analyses" tab of e an element.

                                   

                                  Do I need to connect to the Analysis Service explicitily? Am I missing an extra configuration step?

                                • Re: AFAnalysisService.QueueCalculation - PI Analysis Service is not available
                                  MateusAmarante

                                  I was able to run the program with the following command:

                                   

                                  runas /user:AD_USER /netonly "COMMAND"

                                   

                                  It partially solves my problem. However, it does not seem to be the best way.