3 Replies Latest reply on Sep 19, 2012 4:29 AM by bova

    How to get EventDefinitions for ResourceType via RHQ API

    bova

      Hello,

       

      I would very appreciated if someone could help me with question: I need to load RHQ ResourceType and its EventDefinitions from RHQ using RHQ API

       

      To load ResourceType I use

      getResourceTypeManagerLocal().getResourceTypeById(<Subject>, <RHQ ResourceType ID>)  method and ResourceType is loaded successfully

      but when I try to load EventDefinitions for ResourceType I always get null well as in rhq_event_def there are definitions for Resourcetype

       

      My code is looks like

      ---

      ResourceType rt = getResourceTypeManagerLocal().getResourceTypeById(subject, 10251);

      Set<EventDefinition> newEventDefs = rt.getEventDefinitions();

      ---

       

      and newEventDefs  is always = null

       

      So, if there any way to retrieve EventDefinitions for chosen ResourceType via RHQ API?

        • 1. Re: How to get EventDefinitions for ResourceType via RHQ API
          pilhuhn

          The snippet of your code you are showing looks good to me. In fact I am doing almost the same in the REST-Api's EventHandlerBean.addEventSource

          The eventDefinitions are a 1:n relation on the ResourceType and are thus lazy loaded. In theory if no EntityManager is available you should get a lazy load exception.

          In what context are you running that code?

          Does the 'subject' have enough access rights?

          • 2. Re: How to get EventDefinitions for ResourceType via RHQ API
            lkrejci

            As Heiko said, the Event definitions are lazy loaded, so for your code to work, you must not leave the transactional context of the EntityManager.

            If for some reason you're not able to make that happen, you can try using the criteria queries:

             

            ResourceTypeCriteria rtc = new ResourceTypeCriteria();

            rtc.addFilterId(<ID>);

            rtc.fetchEventDefinitions(true);

             

            List<ResoureType> results = getResourceTypeManagerLocal().findResourceTypesByCriteria(<SUBJECT>, rtc);

            • 3. Re: How to get EventDefinitions for ResourceType via RHQ API
              bova

              Lukas and Heiko, thanks a lot for this usefull answer

              seems that key things here is rtc.fetchEventDefinitions(true);

              because I tried this method early but without setting fetchEventDefinitions to true

               

              Now it works - thank you !!!!!!