10 Replies Latest reply on Nov 15, 2009 7:12 PM by rareddy

    Simple Example using ManagedObjects and ProfileService

    rareddy

      Hi,

      I am trying to write a simple example to see how a service defined with @ManagedObject annotation in the JBossAS and then access it using the ProfileService. I wrote below sample code

      Service in JBoss AS

      @ManagementObject(name="MyService")
      @ManagementComponent(type="foo", subtype="service")
      public class MyService {
      
       private String value = "property value";
      
       public void start() {
       System.out.println("Myservice has been started");
       }
      
       public void stop() {
       System.out.println("Myservice has been shut down");
       }
      
       @ManagementProperty(name="Myservice.value")
       public String getValue() {
       return this.value;
       }
      
       @ManagementOperation(description="Call me", impact=Impact.ReadOnly, params={@ManagementParameter(name="message", description="message to invoke")})
       public String callMe(String msg) {
       System.out.println("Somebody called me = "+msg);
       return msg + "called";
       }
      }
      


      I bundled the above in to jar file and deployed into JBossAS. Then to access it, I wrote a simple JSP page like this

      <%@ page import="org.jboss.deployers.spi.management.*, org.jboss.managed.api.*, javax.naming.*, java.util.*, org.jboss.metatype.api.values.*" %>
      <HTML>
       <BODY>
       <%
       InitialContext ic = new InitialContext();
       ManagementView mgtView = (ManagementView)ic.lookup("java:ManagementView");
       ManagedComponent mc = mgtView.getComponent("MyService", new ComponentType("foo", "service"));
      
       SimpleValueSupport result = null;
       Set<ManagedOperation> operations = mc.getOperations();
       for (ManagedOperation op:operations) {
       if (op.getName().equals("callMe")) {
       result = (SimpleValueSupport)op.invoke(SimpleValueSupport.wrap("*"));
       }
       }
       %>
       Response from call is = <%= result.getValue() %>
       </TABLE>
       </BODY>
      </HTML>
      


      When I execute this, I always end up in NPE on the response. I see the metadata on the object like its operations and properties etc, but not seemed to access the property values or invoke operations. I think I may be missing some step, can somebody please help or point toward a example?

      I looked in "admin-console" code, but I did not see any difference from above.

      Thank you.

      Ramesh..
      Teiid Team.

        • 1. Re: Simple Example using ManagedObjects and ProfileService
          emuckenhuber

           

          "rareddy" wrote:

          When I execute this, I always end up in NPE on the response. I see the metadata on the object like its operations and properties etc, but not seemed to access the property values or invoke operations. I think I may be missing some step, can somebody please help or point toward a example?


          With NPE on the response - you mean that the invocation returns null?

          In general you would need to set the "runtime" property in the @ManagementObject annotation to "true". ProfileService should then dispatch the invocation to the correct bean.
          I assume you are using MC or JMX to deploy your test bean?

          "rareddy" wrote:

          I looked in "admin-console" code, but I did not see any difference from above.


          Hmm, the admin-console needs additional metadata descriptors (some mapping between jopr and profileservice) to display the exposed information from ProfileService.

          • 2. Re: Simple Example using ManagedObjects and ProfileService
            rareddy

            Adding the "isRuntime=true" did the trick, now I see profile service invoking the bean correctly. Thank you.

            I am using JBossAS 5.1, I just manually copied the -jboss-beans.xml file to deploy directory to deploy the bean.

            I see that only beans that have @ManagementObject annotation + deployed through bean deployer (thru -jboss-bean.xml) file are accessible through the profile service. Is there a way I can build a bean with @ManagementObject annotation but initialized through "new myBean()", some how injected into managed objects collection?

            Thank you.

            Ramesh..

            • 3. Re: Simple Example using ManagedObjects and ProfileService
              emuckenhuber

               

              "rareddy" wrote:
              Adding the "isRuntime=true" did the trick, now I see profile service invoking the bean correctly. Thank you.

              Ok, good - btw... isRuntime will also fetch the new value of managedProperties with ViewUse.Statistic when getValue() is called. Otherwise the value is set once ManagementView is loaded, which is used for configuration properties.

              "rareddy" wrote:

              I see that only beans that have @ManagementObject annotation + deployed through bean deployer (thru -jboss-bean.xml) file are accessible through the profile service. Is there a way I can build a bean with @ManagementObject annotation but initialized through "new myBean()", some how injected into managed objects collection?


              Hmm, this is difficult to say since i don't really know what you are trying to achieve and the expected behavior for ProfileService. In general we create ManagedObjects based on the attachment meta data in the deployers. So in case you have your own deployers you should be able to explicitly add and expose your ManagedObjects, which is the preferred way.

              Maybe you want to briefly describe what you would like to do and how your integration code works.

              Thanks,
              Emanuel

              • 4. Re: Simple Example using ManagedObjects and ProfileService
                rareddy

                 

                Hmm, this is difficult to say since i don't really know what you are trying to achieve and the expected behavior for ProfileService.


                The existing architecture of our application (Teiid) currently does not depend on MC based POJO framework, I trying to see if I can manage services in there with out lot of re-work to work under AS and profile service.

                In general we create ManagedObjects based on the attachment meta data in the deployers. So in case you have your own deployers you should be able to explicitly add and expose your ManagedObjects, which is the preferred way.

                I do need write couple deployers for Teiid specific artifacts, I will use the above approach.

                Is there anyway I can attach additional attachment metadata for existing deployers? For example, for RAR deployer add more metadata that defines management of some custom properties specific to that connector than that of those already defined for that RAR using its template, like "NoTxConnectionFactoryTemplate". What I am trying to do is expose "config" properties in ra.xml that are specific to my connector to profile service.

                • 5. Re: Simple Example using ManagedObjects and ProfileService
                  emuckenhuber

                   

                  "rareddy" wrote:

                  I do need write couple deployers for Teiid specific artifacts, I will use the above approach.

                  Is there anyway I can attach additional attachment metadata for existing deployers? For example, for RAR deployer add more metadata that defines management of some custom properties specific to that connector than that of those already defined for that RAR using its template, like "NoTxConnectionFactoryTemplate". What I am trying to do is expose "config" properties in ra.xml that are specific to my connector to profile service.


                  Hmm, well if you want to provide a template for creating a teiid specific configuration we have a notion of DeploymentTemplates - where you could extend the current DataSource templates and add specific properties.
                  For this you would not need any specific deployers integration code.

                  In case this has to be exposed differently to JOPR e.g. under a different category then it gets more complicated.

                  • 6. Re: Simple Example using ManagedObjects and ProfileService
                    rareddy

                    Thanks for the reply Emanuel.

                    I just realized I mixed-up two different (closely related by functionality) concepts together. Templates are different from management objects. Sorry about that. Seems like my need is to expose properties in both ends. Like when the template is called I need to expose properties to create a new connection factory. At the same time when somebody looks at properties on a created connection factory expose those properties along with their values.

                    where you could extend the current DataSource templates and add specific properties. For this you would not need any specific deployers integration code.

                    Yeah, this sounds like what I need to do. Is there any code sample you can point me towards.

                    In case this has to be exposed differently to JOPR e.g. under a different category then it gets more complicated.

                    Yes, we want to tie this into JOPR plugin to under a different component type that are specific to Teiid. That is reason I am trying to expose these beans to Profile Service.

                    Thanks again for your help.

                    Ramesh..

                    • 7. Re: Simple Example using ManagedObjects and ProfileService
                      emuckenhuber

                       

                      "rareddy" wrote:

                      where you could extend the current DataSource templates and add specific properties. For this you would not need any specific deployers integration code.

                      Yeah, this sounds like what I need to do. Is there any code sample you can point me towards.


                      Sure. Basically ProfileService DeploymentTemplates are based on ManagedProperties as well. It consists of a Template which actually generates a deployment and a TemplateInfo which contains the values which can be modified and are exposed to JOPR.

                      https://svn.jboss.org/repos/jbossas/branches/Branch_5_x/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplate.java
                      https://svn.jboss.org/repos/jbossas/branches/Branch_5_x/connector/src/main/org/jboss/resource/deployers/management/DsDataSourceTemplateInfo.java

                      Those are the ones related to ConnectionFactories. Unfortunately this seems a bit messy, also the handling of config-properties is a bit weird.
                      Maybe you only need to extend the TemplateInfo and add some different default values.

                      You can also look at jboss-jca.deployer/META-INF/jca-deployers-jboss-beans.xml - on how we instantiate the templates, those should automatically appear in the ManagementView.

                      "rareddy" wrote:

                      In case this has to be exposed differently to JOPR e.g. under a different category then it gets more complicated.

                      Yes, we want to tie this into JOPR plugin to under a different component type that are specific to Teiid. That is reason I am trying to expose these beans to Profile Service.


                      Hmm this might need some changes on our side, when creating the managed objects based on the meta data. I assume the difference between a normal ConnectionFactory deployment and a Teiid one are some specific properties in the deployment descriptor ?


                      • 8. Re: Simple Example using ManagedObjects and ProfileService
                        rareddy

                        Thanks. I will take a look into this.

                        "emuckenhuber" wrote:
                        Hmm this might need some changes on our side, when creating the managed objects based on the meta data. I assume the difference between a normal ConnectionFactory deployment and a Teiid one are some specific properties in the deployment descriptor ?

                        Yes, exactly right. There will be some properties that are specific to Teiid. We should be able to filter those out based on it. This is very similar how the XA and non XA Connection Factories are being put into two separate piles but share the same template.

                        Ramesh..

                        • 9. Re: Simple Example using ManagedObjects and ProfileService
                          emuckenhuber

                           

                          "rareddy" wrote:
                          Thanks. I will take a look into this.

                          "emuckenhuber" wrote:
                          Hmm this might need some changes on our side, when creating the managed objects based on the meta data. I assume the difference between a normal ConnectionFactory deployment and a Teiid one are some specific properties in the deployment descriptor ?

                          Yes, exactly right. There will be some properties that are specific to Teiid. We should be able to filter those out based on it. This is very similar how the XA and non XA Connection Factories are being put into two separate piles but share the same template.


                          Ok, just give it a try. Feel free to ask if something is not clear or just post a link to a svn repo where i can take a look.

                          In case of overriding we might be able to use a ManagedObjectDefintion to override certain aspects of the created managed object. I would need to take a look again at that, but it would be easier once i know the differences between those definitions. Most probably we need to override the annotation attached to the ManagedObject, since the ManagementView is doing some processing later on.
                          https://svn.jboss.org/repos/jbossas/branches/Branch_5_x/messaging/src/main/org/jboss/jms/server/destination/QueueMODefinition.java

                          We are actually working on a meta data descriptor for ManagedObjects, where you would be able to define the view in an xml file. Where i will try to take you requirements into account as well. Although this will most likely go in one of the future releases and not in AS5.

                          • 10. Re: Simple Example using ManagedObjects and ProfileService
                            rareddy

                             

                            "emuckenhuber" wrote:

                            Ok, just give it a try. Feel free to ask if something is not clear or just post a link to a svn repo where i can take a look.


                            So, my aim here is to some how extended the "DsDataSourceTemplate" template to add some custom properties specific to my "ConnectionFactory" and when I write the template write those properties as "config-properties" using "DsDataSourceTemplate" so that it generates "-ds.xml" file.

                            After few tries with configuration, I ended up like this configuration below

                             <bean name="ConnectorTypeTemplate" class="org.teiid.templates.connector.ConnectorTypeTemplate">
                             <property name="info"><inject bean="ConnectorTypeTemplateInfo"/></property>
                             <property name="targetTemplate"><inject bean="NoTxConnectionFactoryTemplate"/></property>
                             </bean>
                             <bean name="ConnectorTypeTemplateInfo" class="org.teiid.templates.connector.ConnectorTypeTemplateInfo">
                             <constructor factoryMethod="createTemplateInfo">
                             <factory bean="DSDeploymentTemplateInfoFactory"/>
                             <parameter class="java.lang.Class">org.teiid.templates.connector.ConnectorTypeTemplateInfo</parameter>
                             <parameter class="java.lang.Class">org.jboss.resource.metadata.mcf.NoTxConnectionFactoryDeploymentMetaData</parameter>
                             <parameter class="java.lang.String">ConnectorTypeTemplate</parameter>
                             <parameter class="java.lang.String">A template for no-tx-connection-factory *-ds.xml deployments</parameter>
                             </constructor>
                             <property name="connectorXML">foo.xml</property>
                             </bean>
                            


                            Where in "ConnectorTypeTemplateInfo" template, I passed "NoTxConnectionFactoryDeploymentMetaData" as the attachment class, which supplied basic ConnectionFactory properties, then in the "ConnectorTypeTemplateInfo" it self I added my own property definitions. Then on the "ConnectorTypeTemplate", I passed the original "DSDataSourceTemplate" to my template, then in "applyTemplate" call I added all the custom properties defined on my template into "DSDataSourceTemplate" as "config-properties" and called DSDataSourceTemplate's applyTemplate call, and that created my "-ds.xml" file the way I wanted. This is cool.


                            "emuckenhuber" wrote:

                            We are actually working on a meta data descriptor for ManagedObjects, where you would be able to define the view in an xml file. Where i will try to take you requirements into account as well. Although this will most likely go in one of the future releases and not in AS5.

                            This is exactly what I need, and what functionality we have in Teiid. Also, one another requirement we have is to dynamically add these templates based on the given XML file though admin functionality, which is important to support custom connectors.

                            Since these features are not currently available in AS 5, I will be looking into extending the above configuration to read the custom properties from a XML file. So, in this respect I have couple questions

                            1) Ideally I would like this XML file be the "ra.xml" in my RAR file, is there way I can access that file, management object or otherwise?

                            2) In case, if (1) is not possible, if I supply copy of "ra.xml" file in "deploy" directory, how can I get access to it? like how can I get file handle to it?

                            I could embed XML in a property in the above configuration with in a CDATA section, but I would like to avoid that.

                            Thank you again for your valuable help.

                            Ramesh..