4 Replies Latest reply on Aug 1, 2013 10:22 AM by Julio Saura

    jboss cli java client remote command

    Julio Saura Newbie

      Hello

       

      i have just developed a little java program ( i am not developer i am sysadmin )

       

      is working great, i connect to remote controller but the problem i am facing is that i cannot send commands like "ls /host=master/server-config=server-one" cause it throws and exception saying its impossible to translate it to a command ..

       

      what i want to do is that my program connects to controller to check if a server is started or not and if not start it on a jboss domain setup, pretty easy at first sight ....

       

      why can´t i send this kinda commands using the jboss cli api? is there a way of doing this using the api?

       

      in the same way i cannot start o stop a server doing

       

      /host=master/server-config=server-one:stop

      /host=master/server-config=server-one:start

       

      all this commands work perfectly if i connect to console using de jboss-cli.sh, but it seems i cannot send this command using my code that uses jboss cli jars ... for example

       

      ./jboss-cli.sh --connect --controller=10.12.0.108:9999 --command='ls /host=master/server-config=server-one' | grep 'status='

       

      status=STARTED

       

      thanks in advance

        • 1. Re: jboss cli java client remote command
          Nicklas Karlsson Master

          Show you code. Working with the libraries are usually a bit more low-level (nodes and stuff) but I think there are helper functions somewhere(tm) that the CLI uses that parses stuff like that directly.

          • 2. Re: jboss cli java client remote command
            Julio Saura Newbie

            hi, first of all thanks for answering

             

            this is my code

             

            i do not enclose all xml conf parse i have done to read controller ip, port , pass etc etc

             

            connection part, working fine

             

            public void setUp() throws Exception {

             

                                  ctx = org.jboss.as.cli.CommandContextFactory.getInstance().newCommandContext(this.usuario, this.pass.toCharArray());

                                   ctx.connectController(this.ip, Integer.parseInt(this.puerto));

                                

                      }

             

             

            sending command

             

            public void testExecuteCLICommand() throws Exception {

                                String CLIcmd = "ls /host=master/server-config=server-one";

             

              ModelControllerClient client = ctx.getModelControllerClient();

              ModelNode commandRequest = ctx.buildRequest(CLIcmd);

              ModelNode result;

              result = client.execute(commandRequest);

              System.out.println(result);

              }

             

            this throws this exception


            org.jboss.as.cli.operation.OperationFormatException: The command does not translate to an operation request.

                      at org.jboss.as.cli.impl.CommandContextImpl.buildRequest(CommandContextImpl.java:955)

                      at org.jboss.as.cli.impl.CommandContextImpl.buildRequest(CommandContextImpl.java:916)

                      at TestBasicCLI.testExecuteCLICommand(TestBasicCLI.java:105)

                      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                      at java.lang.reflect.Method.invoke(Method.java:597)

                      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)

                      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

                      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)

                      at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33)

                      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)

                      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)

                      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)

                      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)

                      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)

                      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)

                      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)

                      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)

                      at org.junit.runners.ParentRunner.run(ParentRunner.java:309)

                      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)

                      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

                      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

                      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

                      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

                      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

             

            maybe is just i am using the wrong method to send this commands, seems it expects an operation

             

            i also used dmr method

             

            ModelNode deployRequest = ctx.buildRequest("ls /host=master/server-config=server-one");

             

            no luck either


            • 3. Re: jboss cli java client remote command
              Tomaz Cerar Master

              Hi,

               

              ls is high level command that only standalone CLI understands.

               

              you should run

               

              ModelNode deployRequest = ctx.buildRequest("/host=master/server-config=server-one:read-resource");

              which is equivalent in dmr syntax

               

               

              --

              tomaz

              • 4. Re: jboss cli java client remote command
                Julio Saura Newbie

                ahhh, ok i thought i could pass whatever command this way, i see that i need to pass it in other way

                 

                that works for stopping and starting the server, but i do not find anyway to check if is up or down with this dmr syntax

                 

                read-resource does not show me the status

                 

                /host=master/server-config=server-one:read-resource

                {

                    "outcome" => "success",

                    "result" => {

                        "auto-start" => true,

                        "cpu-affinity" => undefined,

                        "group" => "main-server-group",

                        "interface" => undefined,

                        "name" => "server-one",

                        "path" => undefined,

                        "priority" => undefined,

                        "socket-binding-group" => undefined,

                        "socket-binding-port-offset" => 0,

                        "system-property" => undefined,

                        "jvm" => {"default" => undefined}

                    }

                }

                 

                any idea how should i ask to see if is started or not? i do not find any combination to check if its up or not

                 

                thanks !

                 

                 

                UPDATE :

                 

                nevermind, i found it

                 

                /host=master/server-config=server-one:read-resource(include-runtime=true)

                {

                    "outcome" => "success",

                    "result" => {

                        "auto-start" => true,

                        "cpu-affinity" => undefined,

                        "group" => "main-server-group",

                        "interface" => undefined,

                        "name" => "server-one",

                        "path" => undefined,

                        "priority" => undefined,

                        "socket-binding-group" => undefined,

                        "socket-binding-port-offset" => 0,

                        "status" => "STARTED",

                        "system-property" => undefined,

                        "jvm" => {"default" => undefined}

                    }

                }

                 

                just need to inclide runtime=true

                 

                thanks guys!