1 2 Previous Next 23 Replies Latest reply on May 15, 2012 11:38 AM by ziuziu Go to original post
      • 15. Re: Basic configuration
        adinn

        Hi Albert,

        Albert Tresens wrote:

         

        Hi Andrew,

        I get then to the initial point. An then the exception is fired:

         

        [altr@test-newyork-002 ~]$ jps -l

        4042 sun.tools.jps.Jps

        29415 org.codehaus.plexus.classworlds.launcher.Launcher

        [altr@test-newyork-002 ~]$ $BYTEMAN_HOME/bin/bminstall.sh -Dorg.jboss.byteman.verbose 29415

        com.sun.tools.attach.AgentInitializationException: Agent JAR loaded but agent failed to initialize

        Ok, so first let's try an experiment to see if this is a port issue. Try running

         

        bminstall.sh -p 12345 -Dorg.jboss.byteman.verbose 29415

         

        The agent opens a listener on port 9090 and Jetty may be disallowing this.

         

        The only other possibility I can think of is that Jetty may be employing a restrictive security policy and this might stop Byteman's agent Main class from using reflection to create the agent transformer and call its addListener routine. If you can idenitfy what security policy Jetty is using it may be possibel to check this.

         

        The only other  way to find out if why teh agent install is failing is to attach a debugger to the Jetty JVM but this would require you being able to configure a debug listener when Jetty is run and it does not look like you can do that from the maven Jetty plugin.

        • 16. Re: Basic configuration

          I managed to load the agent using Tomcat by adding it the JVM path. So I left Jetty for a while.

          I need however to do a first test and see the Injection happening.

          I created a very basic RULE to output a message in the stdout;

           

          RULE Exception during loing process

          CLASS com.gtech.engine.starter.implementation.ActorManagerImpl

          METHOD <Init>(int)

          DO System.out.println("Byteman was here!!!")

          ENDRULE

           

          Seems that can't load the class com.gtech.engine.starter.implementation.ActorManagerImpl when I do a bmcheck.sh on teh .btm file.

           

          Do I need to specify the path to the class somewhere? how does Byteman find the classes?

           

          Thanks a lot!!

          • 17. Re: Basic configuration

            I finally managed to inject some rules on Tomcat.

            So working well know. Thanks a lot.

            Is there any document to learn how to creat advanced rules or examples? Like to be used as common test cases etc...

             

            Thanks!!

            • 18. Re: Basic configuration
              adinn

              HI Albert,

              Albert Tresens wrote:

               

              I managed to load the agent using Tomcat by adding it the JVM path. So I left Jetty for a while.

              I need however to do a first test and see the Injection happening.

              I created a very basic RULE to output a message in the stdout;

               

              RULE Exception during loing process

              CLASS com.gtech.engine.starter.implementation.ActorManagerImpl

              METHOD <Init>(int)

              DO System.out.println("Byteman was here!!!")

              ENDRULE

               

              Seems that can't load the class com.gtech.engine.starter.implementation.ActorManagerImpl when I do a bmcheck.sh on teh .btm file.

               

              Do I need to specify the path to the class somewhere? how does Byteman find the classes?

               

              Glad to see you are making progress.

               

              When you run bmcheck.sh you can point it at jars containing the classes mentioned in the rule using the -cp option e.g.

               

              bmcheck.sh -cp /path/to/my.jar myscript.btm

               

              If you have several jars then use -cp several times.

              • 19. Re: Basic configuration

                I am trying now to do an advanced .btm script.

                Is it possible to make a call that passes other objects as parameters on the DO instruction?

                Let's say I have something like this;

                 

                RULE update message on Terminal everytime the server receive a notification.

                CLASS com.gtech.engine.starter.implementation.TerminalActorImpl

                METHOD notififyServer

                DO com.gtech.engine.starter.implementation.DriverTerminalConnetionImpl.Updatemessage(Message msg, TerminaID id)

                ENDRULE

                 

                On the DO i need to populate a Message with the content. Do I have to do it using BIND?

                 

                Are there any examples with btm scripts like this?

                • 20. Re: Basic configuration
                  adinn

                  Hi Albert,

                  Albert Tresens wrote:

                   

                  I finally managed to inject some rules on Tomcat.

                  So working well know. Thanks a lot.

                  Is there any document to learn how to creat advanced rules or examples? Like to be used as common test cases etc...

                   

                  Thanks!!

                  Hurrah! and well done for perservering!

                   

                  The second tutorial uses some example rules which do a few tricky things which the tutorial text explains. Other than that there are not many other examples which have good accompanying explanations. There are  rule sets you could  look at in quite a few of the JBoss projects. For example, the  JBossTS project which I used to work on uses some Byteman rule scripts to tests several of the project components such as the ArjunaCore unit tests and the Web Services Transactions crash recovery tests. However, you may not find it easy to understand what these scripts are doing without knowing something about the code under test.

                   

                  I suggest you work thorugh the 2nd tutorial and then try reading the Programmer's Guide and using some of the built-in operations to build up more and more  interesting and sophisticated tests. If you post your progress here I'll be happy to procide advice -- that would be especially good because it will document the learning process which shodl be helpful to other Byteman users. For a start let's see your first rule -- were you not tryin to intercept the login process and cause an exception to be thrown?

                  • 21. Re: Basic configuration

                    Hi,

                    Yes the Login proces and the Exception interception already works!! Getting excited with Byteman :-)

                    I did 3 different injections by intercepting some method calls and DOing some injections.

                    However now I need to have a bit more complex DO calls than just a Debug or Throwing and Exception.

                    I would like to make a call in the DO that fires a message to a Terminal.

                    That requires that a method call also passes some objects populated by messages as parameters. Something like;

                     

                    RULE update message on Terminal everytime the server receive a notification.

                    CLASS com.gtech.engine.starter.implementation.TerminalActorImpl

                    METHOD notififyServer

                    DO com.gtech.engine.starter.implementation.DriverTerminalConnetionImpl.Updatemessage(Message msg, TerminaID id)

                    ENDRULE

                     

                    Where can I load and populate the Message object and the TerminalID? Using BIND?

                    • 22. Re: Basic configuration
                      adinn

                      Hi Albert,

                      Albert Tresens wrote:

                       

                      I am trying now to do an advanced .btm script.

                      Is it possible to make a call that passes other objects as parameters on the DO instruction?

                      Let's say I have something like this;

                       

                      RULE update message on Terminal everytime the server receive a notification.

                      CLASS com.gtech.engine.starter.implementation.TerminalActorImpl

                      METHOD notififyServer

                      DO com.gtech.engine.starter.implementation.DriverTerminalConnetionImpl.Updatemessage(Message msg, TerminaID id)

                      ENDRULE

                       

                      On the DO i need to populate a Message with the content. Do I have to do it using BIND?

                       

                      Are there any examples with btm scripts like this?

                       

                      Yes, you can make calls to other methods in the DO part and yes you have to provide arguments. However, you may be able to use values available in the METHOD the rule is injected into. If not then you may need to create an object to make the call. Alternatively you can refer to an object located in a static field or call a satic method and pass literal (constant) values.

                       

                      Here's an example which shows how you can call out to methods in both the condition (IF) and action (DO) clauses of your rule.

                       

                      RULE example

                      CLASS Thread

                      METHOD exit()

                      AT ENTRY

                      IF $0.getName().contains("JBoss")

                      DO System.out.println("***");

                         System.println("exit for Thread " + $0.getName());

                         System.out.println("***")

                      ENDRULE

                       

                      The rule will be injected into Thread.exit() which is an instance method. So, this means there is a thread object handling the call to exit(). $0 can be used in the rule to refer to this Thread instance. Byteman knows that the target method is Thread.exit() so it knows that $0 is a reference to an object of type Thread.

                       

                      Now class Thread has an instance method called getName() which returns the Thread's name as a String. And String has a method contains(String) which returns true if the arguemnt is contained in the String object which is running contains(). So, the expression in the condition calls the getName() method of the thread $0 to retrieve a String and then calls the contains() method of that String to see if the thread name includes "JBoss". The result is a boolean which is good because Byteman expects a boolean expression to be used in the IF part of the rule.

                       

                      The action contains 3 expressions separated by ';'. Each of them prints a value to System.out. Now System.out is a static field which identiifes a PrintStream instance. Class PrintStream has a void method called println(String). So, Byteman knows that each of these calls is valid. The middle call uses a + operator to glue together a message from a String litera; and the String returned by calling getName() again.

                       

                      So, the condition and action can include pretty much any Java code, including classes which are in your application. $0 i snto the only value passed thorugh rom the target METHOD into the rule If you inject code into a method which has parameters then you can refer to the parameter values using $1, $2 etc. So, for example if you inject your rule into METHOD MessageChecker.check(Message m) you woudl be able to refer to the Message argument using as $1. If Message implements a method called asText() then your action include a call like System.out.println($1.asText()).

                      • 23. Re: Basic configuration

                        I will read the developer documentation. Probably I will have a bit more clear idea after that.

                        I also need to figure out the role of the Helper classes.

                         

                        Thanks a lot for your help Andrew!!!

                        1 2 Previous Next