8 Replies Latest reply on Mar 22, 2013 9:06 AM by Arun Raj

    ERROR : Incompatible Type  while writing plugin

    Arun Raj Expert

      Hi Developers,


          I have been trying to solve this error( Incompatible Type ) for a week. But Still no improvement. I hope for you guys it is very easy. Please help me out.


          I am trying to discover my child resourceType (Service), from my parent resourceType(Server) which has been discovered by other java classes. My Parent resourceType(Server) is working perfect, meaning It is being discovered by java classes. But I can't create a child resourceType(Service) inside of that parent resourceType(Server). Following is my childDiscoveryComponent Code. In the following code, I am trying to list out the discovered parent resourceTypes. Why Because, For that each parent resourceType(Server), I have to create child resourceType(Service).


          Now My Problem is in the code, line no 17. It is putting me Incompatible Type. Please give me idea to identify the parent resourceType in child reourceType or atleast help me to solve this error.


      1     package org.rhq.plugins.service;
      2       import java.util.HashSet;
      3       import java.util.Map;
      4       import java.util.Set;
      6       import org.rhq.core.domain.configuration.Configuration;
      7       import org.rhq.core.domain.resource.ResourceType;
      8       import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
      9       import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
      10     import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
      11     import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
      12     public class userDiscoveryComponent implements ResourceDiscoveryComponent<customerComponent>
      13     {
      14        public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext<customerComponent> context) throws InvalidPluginConfigurationException,
      15            Exception {
      16             Set<DiscoveredResourceDetails> user = new HashSet<DiscoveredResourceDetails>();
      17             Set<ResourceDiscoveryComponent> users    =    context.getParentResourceComponent();
      18             for(ResourceDiscoveryComponent l : users)
      19            {
      20                 System.out.println(l);
      21             }
      /* The following striked out lines has to be created for all the discovered parent resourceTypes(Server). The following are child resourceType(Service) details. These has to be created for the times of parent resourceTypes(Server).
             String key                            =    "My Users";
              String name                            =    "User";
              String description                    =    "It will display Users details of CUSTOMERS";
              Configuration configuration            =    null;
              ResourceType resourceType            =     context.getResourceType();
              DiscoveredResourceDetails detail    =    new DiscoveredResourceDetails(resourceType, key, name, null,description,configuration,null);
              return user;*/

          Thanks for your help in advance.





      Message was edited by: Arun Raj

        • 1. Re: ERROR : Incompatible Type  while writing plugin
          Heiko Rupp Master

          You are mixing ResourceDiscoveryComponent (left side on line 17) and  ResourceComponent (right side, context.getResourceCOmponent)


          The "standard" way of implementing child services is to have their resource component and resource discovery componentn in their own classes and to pass them in the plugin descriptor. I think this is illustrated in the "How to write a plugin" document (see my repo on github to get a relatively up to date issue -- comments are welcome).

          1 of 1 people found this helpful
          • 2. Re: ERROR : Incompatible Type  while writing plugin
            Arun Raj Expert

            Hi Heiko,


                Thanks for your guidance. I have completely studied your following document. Thanks for encouraging me.

            my repo on github


              But I am having many doubts while I have experimented with hardcoded value by reading your documents.


            1 )     I am using the following structure <Server  Customers> and two child service resource <Service email> </service>   <Service user> </service>    </Server>


                    For my above structure, I have to find multiple servers and multiple services. But In that document, the service(HttpServiceDiscovery) discovering multiple services, Not that server.


                    Help : I Have discovered multiple customers by the Server's customerDiscoveryComponent Class. But Having no idea to create a child resource for that multiple discovered Server. Email and User server should be discovered based on the multiple discovered Server. Here, I have attached my code, find the area where I have to change.


            2 )     Tried to make a configurable .properties file by RHQ itself with the help of your code. But It is also not working. If you can help me out on this too.


            3 )     In the document, You have mentioned an example about Log Event. But It is not in there. If you are having, Please share me that code too.





            • 3. Re: ERROR : Incompatible Type  while writing plugin
              Lukas Krejci Apprentice

              The resources in RHQ form a tree structure. In your example, it means that under each discovered server there can be multiple emails and users, but one email or user can only ever have just one parent.

              In the discovery components for your email and user resources, you are given the parent "server" component under which the discovery is expected to run in the form of ResourceDiscoveryContext.getParentResourceComponent() and ResourceDiscoveryContext.getParentResourceContext(). In another words the discovery is supposed to discover the children of a single resource.

              • 4. Re: ERROR : Incompatible Type  while writing plugin
                Arun Raj Expert

                Hi Lukas,


                    I tried in your way. But Still getting in my user and email DiscoveryClasses. Please help me to bypass this error.

                package org.rhq.plugins.service;
                import java.util.HashSet;
                import java.util.Map;
                import java.util.Set;
                import org.rhq.core.domain.configuration.Configuration;
                import org.rhq.core.domain.resource.ResourceType;
                import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
                import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
                import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
                import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
                public class userDiscoveryComponent implements ResourceDiscoveryComponent
                    public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext context) throws InvalidPluginConfigurationException,
                        Exception {
                        Set<DiscoveredResourceDetails> user     =     new HashSet<DiscoveredResourceDetails>();
                        Set<ResourceDiscoveryContext> parents    =    ResourceDiscoveryContext.getParentResourceComponent(); // Got ERROR for this line
                        //ERROR 1 : userDiscoveryComponent.java:[21,66] error: non-static method getParentResourceComponent() cannot be referenced from a static context
                        //ERROR 2 : userDiscoveryComponent.java:[21,93] error: incompatible types 
                        for(ResourceDiscoveryContext list : parents)
                            System.out.println(list); // Trying to check whether can I able to get all my parent class.
                        String key                                =    " Users";
                        String name                                =    "User";
                        String description                        =    "It will display Users details of CUSTOMERS";
                        Configuration configuration                =    null;
                        ResourceType resourceType                =     context.getResourceType();
                        DiscoveredResourceDetails detail        =    new DiscoveredResourceDetails(resourceType, key, name, null,description,configuration,null);
                        return user;




                • 5. Re: ERROR : Incompatible Type  while writing plugin
                  Lukas Krejci Apprentice

                  Ok, this is basic Java type system question. I recommend you study the java language more thoroughly to better understand those errors. I will explain it this time to get you moving, but please only ask questions that are related to RHQ in the future.


                  When I told you to use "ResourceDiscoveryContext.getParentResourceComponent()" I used the class name and method name because from my point of view I cannot know what variable name you will use to hold an instance of ResourceDiscoveryContext class. Therefore in you concrete code above, you need to write context.getParentResourceComponent();


                  Secondly, that method returns a single instance of ResoureComponent class - please check the signature (i.e. return type and parameters) of that method in your IDE. You are trying to assign the return value of that method with type "ResourceComponent" to a variable with type "Set<ResourceDiscoveryContext>" which is illegal - it is the same as if you tried to write:

                  int x = "Guess what!";


                  As I tried to explain above, the discovery is only meant to run under a single parent at a time. Therefore, it is not possible, nor would it make sense, to be able to retrieve multiple parents.

                  So instead of:

                  Set<ResourceDiscoveryContext> parents = ResourceDiscoveryContext.getParentResourceComponent();


                  you need to write:

                  ResourceComponent parent = context.getParentResourceComponent();


                  The for-loop below that therefore will not work either - again, a resource cannot have multiple parents.


                  Hope this gets you further, but please don't misuse this forum for asking trivial non-related questions. While we will try to help you in any way we can with RHQ related questions, this is not stackoverflow.com or other forum for asking generic programming questions.

                  • 6. Re: ERROR : Incompatible Type  while writing plugin
                    Arun Raj Expert

                    Hi Lukas Krejci,


                        I am extremely sorry for misused this community forum. I thought it is a community for RHQ Development. Now I understood, What kind of forum is this.


                        And Very Thanks, for pushing me in the correct way by your sample code.


                        Where can I post doubts related to RHQ Development? ? ? Because, I am a student. So I am not good at anything. But Curious to know about technology. That is why I have picked up RHQ as my Academic Project. Again, Please push me up into the perfect way.




                    • 7. Re: ERROR : Incompatible Type  while writing plugin
                      Lukas Krejci Apprentice

                      Well, this is a forum for RHQ related things, so you're at the right place for RHQ-related questions


                      While you encountered the problem while doing stuff with RHQ, the problem was not related to RHQ at all.. That's what I was trying to say and why I asked you to try to understand your problem first before choosing a forum to post it to.


                      When you get a compiler error (which is what you got here), the problem is in 99.99% of the cases on your side because you tried to do something that the java language itself doesn't allow.


                      I am sure you will only get better in the future and we wil try to help you..


                      Good luck and don't hesitate to post to this forum. Just make sure it is really related to RHQ...



                      1 of 1 people found this helpful
                      • 8. Re: ERROR : Incompatible Type  while writing plugin
                        Arun Raj Expert

                        Hi Lukas,


                            I understood, I will try my extreme to post a questions related to RHQ. I will avoid questions related to JAVA. Thanks for guiding me, again.