Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use query function for Naigara4 nHaystack Server #116

Open
Makorn-Nupakorn opened this issue Dec 22, 2023 · 4 comments
Open

Use query function for Naigara4 nHaystack Server #116

Makorn-Nupakorn opened this issue Dec 22, 2023 · 4 comments

Comments

@Makorn-Nupakorn
Copy link

Makorn-Nupakorn commented Dec 22, 2023

Problem

Example Code:

Code 1

  • Prompt
from pyhaystack.client.niagara import Niagara4HaystackSession
from pyhaystack.client.http.auth import BasicAuthenticationCredentials
import hszinc

URI  = "server endpoint"
USERNAME  = "username"
PASSWORD  = "password"

authenticator = BasicAuthenticationCredentials(
                                                    USERNAME, 
                                                    PASSWORD
                                                )

json = hszinc.MODE_JSON

session = Niagara4HaystackSession(  
                                            uri = URI,
                                            username = authenticator.username,
                                            password = authenticator.password,
                                            pint = True,
                                            grid_format= json
                                        )

session
  • Output
<pyhaystack.client.niagara.Niagara4HaystackSession at 0x12d8aa110>

Code 2

  • Prompt
session.sites

  • Output
HaystackError: java.lang.ClassCastException: org.projecthaystack.HStr cannot be cast to org.projecthaystack.HRef
Screenshot 2566-12-22 at 11 38 09

Code 3

  • Prompt
floor_2 = session.get_entity(
                                ids= "S.Floor_2"
                            )
floor_2.wait()
floor_2.result
  • Output
<@S.Floor_2: {area=0.0, axSlotPath='slot:/HS_Ontology/Floor_2', axType='nhaystack:HSite', dis='Floor_2', geoAddr='', geoCity='', geoCoord......, navName='Floor_2', site, tz='Bangkok'}>

Question

I can get entity by get_entity function but can not find_entity

  • Picture for tagging and ontology
Screenshot 2566-12-22 at 12 26 23 Screenshot 2566-12-22 at 12 26 16
  • Picture for Resource Unit
Screenshot 2566-12-22 at 12 25 25
  • Picture for number of entity
Screenshot 2566-12-22 at 12 23 01
@Makorn-Nupakorn
Copy link
Author

But if i test on another JACE that have ~900+ points and ~250 equips and 3 sites.

It is well everything I can use every function in pyhaystack.

In this problem case, I test on real site that have ~20 in each modbus device(equip).

I don't know where is error from?

@sjlongland
Copy link
Collaborator

Okay, so java.lang.ClassCastException is a server-side exception… caused when you try to cast an object to the wrong sub-class. In this case, it seems to be expecting a HRef and got a HStr instead.

https://github.com/ChristianTremblay/pyhaystack/blob/master/pyhaystack/client/session.py#L405-L420 is pretty simple. So it's doing a find_entity call… unwisely it's not wait()-ing on the result, so this property will only work with the synchronous client (which is default)… but effectively in Haystack-land, it's doing a read?filter="site".

filter= in a read call is supposed to be a HStr, and from what I see in the code, it is a HStr.

If the JACE is expecting something else there, something is seriously wrong. I suspect a bug or misconfiguration in the server.

I'd do the following:

from pyhaystack.exception import HaystackError

try:
    print(session.sites)  # will most likely throw the exception as seen before
except HaystackError as e:
    print(e)
    print(e.traceback)

That'll show you the traceback from the server-side, which you can take up with nHaystack people if needed.

@Makorn-Nupakorn
Copy link
Author

Screenshot 2566-12-22 at 13 32 33

I use your script for testing an error

@sjlongland
Copy link
Collaborator

Right, so server is suppressing the stack trace (probably a good thing, you don't want to show it to an attacker, nHaystack used to reveal it by default)… but you'll have to look in Niagara Workbench (probably the platform manager if I recall correctly) to see what's going on server-side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants