4 Replies Latest reply on Aug 5, 2013 4:44 AM by Arun Raj

    Failed to create instance for Resource ? ? ? How to solve it...

    Arun Raj Expert

      Hi Developers,

       

         I am creating custom plugin. For that I am discovering 5 child resources. Resources are being discovered by container. I have updated my plugin (haven't changed anything in discoveryComponent) , I got the following error without capturing any exception or stackTrace.

       

      2013-07-22 19:26:29,021 ERROR [ResourceDiscoveryComponent.invoker.daemon-3] (org.rhq.plugins.customQA.EmailDiscoveryComponent)- 
      2013-07-22 19:26:29,021 ERROR [ResourceDiscoveryComponent.invoker.daemon-3] (org.rhq.plugins.customQA.UserDiscoveryComponent)- 
      2013-07-22 19:26:29,021 ERROR [ResourceDiscoveryComponent.invoker.daemon-2] (org.rhq.plugins.customQA.WebServiceDiscoveryComponent)- 
      

      Appart from this log(Agent Log) , I dont find anything.

       

      Due to this error, Not sure. I cant collect values for my child resources.

       

      Out of five child resources, Only One child resource is collecting values. All other resources are not collecting values. Please help me to find this problem.

       

      Sample of my code is following :

       


      Class EmailComponent implements ResourceComponent<ParentClass> , MeasurementFacet
      {
       private ResourceComponent<ParentClass> Email;
       private ArrayList<Integer> mEmailCount =     new ArrayList<Integer>();
      
           public void start(ResourceContext<ParentClass> context) throws InvalidPluginConfigurationException, Exception{
                Email     =     context;
           }
      
           public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> request) throws Exception {
                mEmailCount.addAll(Email.getParentResourceComponent().getPARENT_CLASS_METHOD_NAME()); // Collecting arrayList values from parentResource.
      
                for(MeasurementScheduleRequest metric : request ) {
                     if(metric.getName.equals("EmailCount")) {
                          report.addData( new MeasurementDataNumeric( metric, new Double(mEmailCount(index).doubleValue()))); //index will be dependent on each customer based on some good logic.
      /* Logic is not a issue. It will work fine. */ 
                     }
                }
           }
      }
      

      Above is my sample code which I have written to collect the values.

       

      In the above code, Out of my five child resource, One child resource is collecting value. Other resources are putting error message like the following

       

      2013-07-23 17:51:32,809 WARN  [MeasurementManager.collector-1] (rhq.core.pc.measurement.MeasurementCollectorRunner)- Failure to collect measurement data for Resource[id=30232, uuid=5a81cb69-4839-4f65-81e5-c1b4639d867d, type={Monitoring System-RHQ Plugin-Final-05}User Service, key=keyword, name=monitor, parent=Monitoring System] - cause: java.lang.IndexOutOfBoundsException: Size: 0
      

       

      Then Only I came to know, values are not being collected for all other child resources. Could anyone please tell me why I got this problem. I think, Object is not instantiated due to the error which i have mentioned before. please guide me to solve this problem.


      Regards,

      ArunRaj

        • 1. Re: Failed to create instance for Resource ? ? ? How to solve it...
          Arun Raj Expert

          Hi Developers,

           

              I have tried to create localVariable in getValues(). The result has not been changed.( Again, Only one child resource is collecting data).

           

          public void getValues () {
               ArrayList<Integer> EmailCount     =     new ArrayList<Integer>();
            EmailCount.addAll(Email.getParentResourceComponent().getPARENT_CLASS_METHOD_NAME()); // Collecting arrayList values from parentResource.
           
            for(MeasurementScheduleRequest metric : request ) {
                 if(metric.getName.equals("EmailCount")) {
                      report.addData( new MeasurementDataNumeric( metric, new Double(EmailCount(index).doubleValue()))); //index will be dependent on each customer based on some good logic.
                      /* Logic is not a issue. It will work fine. */ 
                 }
            }
          }
          

           

          Regards,

          ArunRaj.

          • 2. Re: Failed to create instance for Resource ? ? ? How to solve it...
            jay shaughnessy Expert

            It looks to me like mEmailCount(index) is invalid, meaning your grab of the parent values is not returning what you need or your 'index' var is set incorrectly.   In general this code does not do much to be safe, so you may want to add some guards here.  Instead of trying to get info from the parent would it be possible to query for the info directly?

             

            As Thomas mentioned, parent and child metric collection schedules are unrelated to each other.  Child metric collection depending on a parent's metric collection seems dangerous.

             

            A couple of minor comments:

            - you may want to use your own package naming and not org.rhq, since this is custom plugin.

            - variable naming convention would not start with uppercase, so 'Email' would be better as 'email' (although

            - have you been able to run your code in the debugger?  if not then look at rhq-agent-env.sh|bat and uncomment

             

              RHQ_AGENT_ADDITIONAL_JAVA_OPTS=-agentlib:jdwp=transport=dt_socket,address=9797,server=y,suspend=n

             

              and then you can attach your debugger to port 9797 to catch a metric collection call.

            • 3. Re: Failed to create instance for Resource ? ? ? How to solve it...
              Arun Raj Expert

              Hi Jay,

               

                 Thanks for your detailed explanation and your guidelines. I will follow your guidelines.

               

                 I am extremely sorry, mEmailCount(index) is not a valid one. It is mEmailCount.get(index).doubleValue() ( I was typed wrongly ). When I was tried to print the values in the console , I found that all other child resources are not collecting values. What about my mEmailCount variable scope. Is my variable common to all child resources ? ? ?  Is my variable can collect from parent resource for all child resources ? ? ? (I have used addAll method to iterate it, that makes me doubt ... ).

               

              jay shaughnessy wrote:

               

                then you can attach your debugger to port 9797 to catch a metric collection call.

               

              I am running my agent and server and rhq database in three different machines. When I have attached my debugger in my agent machine, will it work ? ? ?

              • 4. Re: Failed to create instance for Resource ? ? ? How to solve it...
                Arun Raj Expert

                Debugger mode is working perfectly without any errors.

                 

                Regards,

                ArunRaj