8 Replies Latest reply on Apr 18, 2013 7:16 AM by Sueleyman Vurucu

    JBoss AS7 Command-line public API --> Write Attribute

    Sueleyman Vurucu Expert

      Hi guys,

       

      I try to configure JBoss with Command-line public API. I try to add a jndi-name to subsystem infinipan.

       

      With that CLI command works fine:

      /subsystem=infinispan/cache-container=hibernate:write-attribute(name=jndi-name, value=java:jboss/infinispan/hibernate)

       

      So I try to that same thing from javacode by using the modelnode.

       

       

       

        ModelNode request = new ModelNode();
          request.get(ADRESS).add(ClientConstants.SUBSYSTEM, "infinispan");
          request.get(ADRESS).add("cache-container","hibernate");
          request.get("jndi-name").set("java:jboss/infinispan/hibernate");
          request.get(ClientConstants.OP).set(ClientConstants.WRITE_ATTRIBUTE_OPERATION);
      

       

      If I excecute that command with ctx.getModelControllerClient().execute(request); then I get the exception shown below:

       

      java.lang.RuntimeException: Operation failed: "JBAS014746: name may not be null"

          at com.siemag.wan.jbossconfig.JBoss7ServerConfigurator.reportFailure(JBoss7ServerConfigurator.java:203)

          at com.siemag.wan.jbossconfig.JBoss7ServerConfigurator.excecute(JBoss7ServerConfigurator.java:153)

          at com.siemag.wan.jbossconfig.JBoss7ServerConfigurator.addInfinispanJNDIName(JBoss7ServerConfigurator.java:145)

          at com.siemag.wan.jbossconfig.JBoss7ServerConfigurator.main(JBoss7ServerConfigurator.java:43)

       

      The read resources operation works well:

       

      ModelNode request = new ModelNode();
      request.get(ADRESS).add(ClientConstants.SUBSYSTEM, "infinispan");
      request.get(ADRESS).add("cache-container","hibernate");
      request.get(ClientConstants.OP).set(ClientConstants.READ_RESOURCE_OPERATION);

       

      Did i miss something ?

       

      I use JBoss 7.2.0.Final on windows 7 64-bit with oracle 64 bit JVM.

        • 1. Re: JBoss AS7 Command-line public API --> Write Attribute
          jaikiran pai Master

          Sueleyman Vurucu wrote:

           

           

           

           

              request.get("jndi-name").set("java:jboss/infinispan/hibernate");
          
          

           

           

          That's not the right way. The right way is:

           

          request.get("name").set("jndi-name");
          request.get("value").set("java:jboss/infinispan/hibernate");
          

           

          Of course, you can use the constants for "name" and "value" from the ClientConstants.

          • 2. Re: JBoss AS7 Command-line public API --> Write Attribute
            Sueleyman Vurucu Expert

            So I try the folowing steps,

             

            1. try to add name

                request.get("name").set("hibernate");

            then I get this exception:

            java.lang.RuntimeException: Operation failed: "JBAS014792: Unknown attribute hibernate"

                at com.siemag.wan.jbossconfig.JBoss7ServerConfigurator.reportFailure(JBoss7ServerConfigurator.java:195)

                at com.siemag.wan.jbossconfig.JBoss7ServerConfigurator.excecute(JBoss7ServerConfigurator.java:145)

                at com.siemag.wan.jbossconfig.JBoss7ServerConfigurator.addInfinispanJNDIName(JBoss7ServerConfigurator.java:137)

                at com.siemag.wan.jbossconfig.JBoss7ServerConfigurator.main(JBoss7ServerConfigurator.java:43)

             

            2. Try to read attributes wit CLI.

                

            [standalone@localhost:9999 /] /subsystem=infinispan/cache-container=hibernate:read-attribute(name=module)

            {

                "outcome" => "success",

                "result" => "org.jboss.as.jpa.hibernate:4"

            }

            [standalone@localhost:9999 /] /subsystem=infinispan/cache-container=hibernate:read-attribute(name=name)

            {

                "outcome" => "failed",

                "failure-description" => "JBAS014792: Unknown attribute name",

                "rolled-back" => true

            }

             

            Why I can't read the name attribute ? Is there a BUG ??

            • 3. Re: JBoss AS7 Command-line public API --> Write Attribute
              Tomaz Cerar Master

              name is not na attribute but part of path

               

              try this commands so you will get few ideas:

               

              /subsystem=infinispan/cache-container=hibernate:read-resource()

              /subsystem=infinispan:read-children(type=cache-container)

               

               

              plus why you need name of cache container if you already have it

              cache-container=hibernate would translate into here is cache container with name hibernate.

               

              so in short, no need to read it again

               

               

              --

              tomaz

              1 of 1 people found this helpful
              • 4. Re: JBoss AS7 Command-line public API --> Write Attribute
                Sueleyman Vurucu Expert

                jaikiran pai schrieb:

                 

                That's not the right way. The right way is:

                 

                request.get("name").set("jndi-name");
                request.get("value").set("java:jboss/infinispan/hibernate");
                

                 

                Of course, you can use the constants for "name" and "value" from the ClientConstants.

                So that's a litte strange but it works . The documentation is a little bit rare. Is there a link that you can suggest ?

                • 5. Re: JBoss AS7 Command-line public API --> Write Attribute
                  Sueleyman Vurucu Expert

                  Tomaz Cerar schrieb:

                   

                   

                  plus why you need name of cache container if you already have it

                  cache-container=hibernate would translate into here is cache container with name hibernate.

                   

                  so in short, no need to read it again

                   

                   

                  --

                  tomaz

                  For nothing I'll understand the API

                  • 6. Re: JBoss AS7 Command-line public API --> Write Attribute
                    jaikiran pai Master

                    Sueleyman Vurucu wrote:

                     

                    jaikiran pai schrieb:

                     

                    That's not the right way. The right way is:

                     

                    request.get("name").set("jndi-name");
                    request.get("value").set("java:jboss/infinispan/hibernate");
                    

                     

                    Of course, you can use the constants for "name" and "value" from the ClientConstants.

                    So that's a litte strange but it works .

                    It's not strange, really. If you take a look at the CLI version of it:

                     

                    :write-attribute(name=jndi-name, value=java:jboss/infinispan/hibernate)

                     

                    You are telling it what the "name" of the attribute is and what the "value" of the attribute is. In other words, you are providing/setting a value for the "name" and a (different) value for the "value".

                     

                    That's exactly what translates to:

                     

                    request.get("name").set("jndi-name"); // set a value for the "name"
                    request.get("value").set("java:jboss/infinispan/hibernate"); // set a value for the "value"
                    
                    • 7. Re: JBoss AS7 Command-line public API --> Write Attribute
                      Sueleyman Vurucu Expert

                      jaikiran pai schrieb:

                      It's not strange, really. If you take a look at the CLI version of it:

                      That's depends on how familar you'r with the api .

                       

                      How can I set List values. I want add a global module for example.

                       

                      /subsystem=ee/:write-attribute(name=global-modules,value=[{\"name\" => \"my.module.com\",\"slot\" => \"main\"}])");

                      • 8. Re: JBoss AS7 Command-line public API --> Write Attribute
                        Sueleyman Vurucu Expert

                        Ok I think I understand the api little bit more

                         

                           ModelNode module= new ModelNode();

                            module.get("name").set("my.module.com");

                            module.get("slot").set("main");

                         

                                ModelNode request = new ModelNode();

                                request.get(ADRESS).add(ClientConstants.SUBSYSTEM, "ee");

                                request.get("name").set("global-modules");

                                request.get("value").add(test);

                                request.get(ClientConstants.OP).set(ClientConstants.WRITE_ATTRIBUTE_OPERATION);

                                excecute(request);

                         

                        Does the same job with /subsystem=ee/:write-attribute(name=global-modules,value=[{\"name\" => \"my.module.com\",\"slot\" => \"main\"}])");