6 Replies Latest reply: Oct 28, 2011 12:39 PM by Andrew Dinn RSS

    invalid text outside of RULE/ENDRULE

    swimablefish Newbie

      this is my script:

       

          

      RULE trace assignTasks

      CLASS CapacityTaskScheduler

      METHOD assignTasks

      HELPER TraceHelper

      IF TRUE

      DO  traceOpen($0, "/home/hbase/panjy/tools/test_schedule/assignTask.log");

          traceln($0, "assign task")

      ENDRULE

       

       

      class TraceHelper extends Helper {

          public boolean traceln(Object identifier, String message) {

              Date d = new Date();

              SimpleDataFormat sdf = new SimpleDateFormat("HH:mm:ss");

              String str = sdf.format(d);

             

              return super.traceln(identifier, str + ": " + message)

          }  

      }  

       

      when i submit it, it print's error message as follow:

        

      Failed to process request: java.lang.Exception: The remote byteman agent reported an error:

      EXCEPTION java.lang.Exception: org.jboss.byteman.agent.Transformer : invalid text outside of RULE/ENDRULE at line 10 in script assignTask.btm

      java.lang.Exception: org.jboss.byteman.agent.Transformer : invalid text outside of RULE/ENDRULE at line 10 in script assignTask.btm

      at org.jboss.byteman.agent.ScriptRepository.processScripts(ScriptRepository.java:101)

      at org.jboss.byteman.agent.Retransformer.installScript(Retransformer.java:62)

      at org.jboss.byteman.agent.TransformListener.handleScripts(TransformListener.java:337)

      at org.jboss.byteman.agent.TransformListener.loadScripts(TransformListener.java:260)

      at org.jboss.byteman.agent.TransformListener.handleConnection(TransformListener.java:213)

      at org.jboss.byteman.agent.TransformListener.run(TransformListener.java:146)

       

       

      -- Args were: [assignTask.btm]

      java.lang.Exception: The remote byteman agent reported an error:

      EXCEPTION java.lang.Exception: org.jboss.byteman.agent.Transformer : invalid text outside of RULE/ENDRULE at line 10 in script assignTask.btm

      java.lang.Exception: org.jboss.byteman.agent.Transformer : invalid text outside of RULE/ENDRULE at line 10 in script assignTask.btm

      at org.jboss.byteman.agent.ScriptRepository.processScripts(ScriptRepository.java:101)

      at org.jboss.byteman.agent.Retransformer.installScript(Retransformer.java:62)

      at org.jboss.byteman.agent.TransformListener.handleScripts(TransformListener.java:337)

      at org.jboss.byteman.agent.TransformListener.loadScripts(TransformListener.java:260)

      at org.jboss.byteman.agent.TransformListener.handleConnection(TransformListener.java:213)

      at org.jboss.byteman.agent.TransformListener.run(TransformListener.java:146)

       

       

              at org.jboss.byteman.agent.submit.Submit$Comm.readResponse(Submit.java:882)

              at org.jboss.byteman.agent.submit.Submit.submitRequest(Submit.java:738)

              at org.jboss.byteman.agent.submit.Submit.addScripts(Submit.java:574)

              at org.jboss.byteman.agent.submit.Submit.addRulesFromFiles(Submit.java:547)

              at org.jboss.byteman.agent.submit.Submit.main(Submit.java:1063)

       

      what is the problem? There is an example in Byteman Programmer's Guide like this.

        • 1. Re: invalid text outside of RULE/ENDRULE
          swimablefish Newbie

          furthermore, if i change script like this

           

           

          RULE trace assignTasks

          CLASS CapacityTaskScheduler

          METHOD assignTasks

          #HELPER TraceHelper

          BIND i = new Date();

               j = 2;

               k = 3

          IF TRUE

          DO  traceOpen($0, "/home/hbase/panjy/tools/test_schedule/assignTask.log");

               traceln($0, "assign task")

          ENDRULE

           

          it will tell:

           

          # File assignTask.btm line 5

          RULE trace assignTasks

          CLASS CapacityTaskScheduler

          METHOD assignTasks

          AT ENTRY

           

           

          BIND i = new java.utils.Date();

          j = 2;

          k = 3

          IF TRUE

          DO  traceOpen($0, "/home/hbase/panjy/tools/test_schedule/assignTask.log");

          traceln($0, "assign task")

          ENDRULE

          Transformed in:

          loader: sun.misc.Launcher$AppClassLoader@553f5d07

          trigger method: org.apache.hadoop.mapred.CapacityTaskScheduler.assignTasks(org.apache.hadoop.mapred.TaskTrackerStatus) java.util.List

          failed to compile

          Rule.ensureTypeCheckedCompiled : error type checking rule trace assignTasks

          org.jboss.byteman.rule.exception.TypeException: NewExpression.typeCheck : unknown type java.utils.Date file assignTask.btm line 6

          at org.jboss.byteman.rule.expression.NewExpression.typeCheck(NewExpression.java:122)

          at org.jboss.byteman.rule.binding.Binding.typeCheck(Binding.java:119)

          at org.jboss.byteman.rule.Event.typeCheck(Event.java:114)

          at org.jboss.byteman.rule.Event.typeCheck(Event.java:106)

          at org.jboss.byteman.rule.Rule.typeCheck(Rule.java:521)

          at org.jboss.byteman.rule.Rule.ensureTypeCheckedCompiled(Rule.java:449)

          at org.jboss.byteman.rule.Rule.execute(Rule.java:670)

          at org.jboss.byteman.rule.Rule.execute(Rule.java:651)

          • 2. Re: invalid text outside of RULE/ENDRULE
            Andrew Dinn Master

            swimablefish wrote:

             

            this is my script:

             

                

            RULE trace assignTasks

            CLASS CapacityTaskScheduler

            METHOD assignTasks

            HELPER TraceHelper

            IF TRUE

            DO  traceOpen($0, "/home/hbase/panjy/tools/test_schedule/assignTask.log");

                traceln($0, "assign task")

            ENDRULE

             

             

            class TraceHelper extends Helper {

                public boolean traceln(Object identifier, String message) {

                    Date d = new Date();

                    SimpleDataFormat sdf = new SimpleDateFormat("HH:mm:ss");

                    String str = sdf.format(d);

                   

                    return super.traceln(identifier, str + ": " + message)

                }  

            }

             

            It looks to me like your script includes the definiiton of class TraceHelper.Is that the case? If so then this is what is causng the syntax error.

             

            If you want to use a helper class then you need to compile the helper using javac, place the helper class in a jar and then install the jar into the relevant classpath. So,for example in this case you would need to execute something like

             

            $javac -classpath $BYTEMAN_HOME/lib/byteman.jar TraceHelper.java

            . . .

            $jar cvf tracehelper.jar TraceHelper.class

            . . .

            bmjava -b tracehelper.jar -l myscript.btm MyApp foo bar baz

             

            A few words of explanation might help

             

            • you need to compile the helper class with byteman.jar i teh classpath because it refers to class Helper
            • the -s option to bmjava tells the agent to add your jar file tracehelper.jar into the bootstrap classpath so it is visible to all classes in the system
            • you can also use flag -s to load your jar into the system classpath which is ok if you only want to inject rules into application code but will not work if you inject rules into JVM classes

             

            You can also use bmsubmit to install a helper jar into a running program e.g.

             

            $ bmsubmit -b tracehelper.jar

            $ bmsubmit myscript.btm

             

            Obviously you need to load the jar before you submit any rules which refer to your helper class.

            • 3. Re: invalid text outside of RULE/ENDRULE
              swimablefish Newbie

              I used the 2nd method

                   

              ${BYTEMAN_HOME}/bin/bminstall.sh -p $BYTEMAN_PORT $pid

               

              ${BYTEMAN_HOME}/bin/bmsubmit.sh -p $BYTEMAN_PORT -b "tracehelper.jar"

              ${BYTEMAN_HOME}/bin/bmsubmit.sh -p $BYTEMAN_PORT -l "assignTask.btm"

               

              but it still failed...

               

              Failed to process request: java.lang.Exception: The remote byteman agent reported an error:

              EXCEPTION Unable to add jar file tracehelper.jar

              java.util.zip.ZipException: error in opening zip file

              java.util.zip.ZipException: error in opening zip file

              at java.util.zip.ZipFile.open(Native Method)

              at java.util.zip.ZipFile.<init>(ZipFile.java:114)

              at java.util.jar.JarFile.<init>(JarFile.java:133)

              at java.util.jar.JarFile.<init>(JarFile.java:97)

              at org.jboss.byteman.agent.TransformListener.loadJars(TransformListener.java:269)

              at org.jboss.byteman.agent.TransformListener.handleConnection(TransformListener.java:211)

              at org.jboss.byteman.agent.TransformListener.run(TransformListener.java:146)

               

               

              -- Args were: [tracehelper.jar]

              java.lang.Exception: The remote byteman agent reported an error:

              EXCEPTION Unable to add jar file tracehelper.jar

              java.util.zip.ZipException: error in opening zip file

              java.util.zip.ZipException: error in opening zip file

              at java.util.zip.ZipFile.open(Native Method)

              at java.util.zip.ZipFile.<init>(ZipFile.java:114)

              at java.util.jar.JarFile.<init>(JarFile.java:133)

              at java.util.jar.JarFile.<init>(JarFile.java:97)

              at org.jboss.byteman.agent.TransformListener.loadJars(TransformListener.java:269)

              at org.jboss.byteman.agent.TransformListener.handleConnection(TransformListener.java:211)

              at org.jboss.byteman.agent.TransformListener.run(TransformListener.java:146)

               

               

                      at org.jboss.byteman.agent.submit.Submit$Comm.readResponse(Submit.java:882)

                      at org.jboss.byteman.agent.submit.Submit.submitRequest(Submit.java:738)

                      at org.jboss.byteman.agent.submit.Submit.addJarsToSystemClassloader(Submit.java:485)

                      at org.jboss.byteman.agent.submit.Submit.main(Submit.java:1047)

              install rule trace assignTasks

              • 4. Re: invalid text outside of RULE/ENDRULE
                Andrew Dinn Master

                swimablefish wrote:

                 

                I used the 2nd method

                 

                ${BYTEMAN_HOME}/bin/bminstall.sh -p $BYTEMAN_PORT $pid

                 

                ${BYTEMAN_HOME}/bin/bmsubmit.sh -p $BYTEMAN_PORT -b "tracehelper.jar"

                ${BYTEMAN_HOME}/bin/bmsubmit.sh -p $BYTEMAN_PORT -l "assignTask.btm"

                 

                but it still failed...

                 

                Failed to process request: java.lang.Exception: The remote byteman agent reported an error:

                EXCEPTION Unable to add jar file tracehelper.jar

                java.util.zip.ZipException: error in opening zip file

                java.util.zip.ZipException: error in opening zip file

                at java.util.zip.ZipFile.open(Native Method)

                at java.util.zip.ZipFile.<init>(ZipFile.java:114)

                at java.util.jar.JarFile.<init>(JarFile.java:133)

                at java.util.jar.JarFile.<init>(JarFile.java:97)

                at org.jboss.byteman.agent.TransformListener.loadJars(TransformListener.java:269)

                at org.jboss.byteman.agent.TransformListener.handleConnection(TransformListener.java:211)

                at org.jboss.byteman.agent.TransformListener.run(TransformListener.java:146)

                 

                Ah, closer. In fact, almost there :-)

                 

                It looks to me like the agent is running in a JVM process which has a working directory different to the one you are running the bmsubmit command from. So, when the agent checks to see if it canr ead tracehelper.jar it tries to open it in its working directory and does not find it. If you pass an absolute path fo rthe helper jar then this should resolve the problem i.e. execute this

                 

                $BYTEMAN_HONE/bin/bmsubmit.sh -p $BYTEMAN_PORT -b "$PWD/tracehelper.jar"

                 

                where $PWD should identify the current working directory something like

                 

                /home/adinn/byteman/helpertest

                • 5. Re: invalid text outside of RULE/ENDRULE
                  swimablefish Newbie

                  yeah, it can work now,

                     but I used "-s", not "-b". Although "-b" didn't print any error message, the script didn't work.  "-s" worked well.

                   

                     by the way, I still can't figure out the differences between "-s" and "-b", 3ks,

                  • 6. Re: invalid text outside of RULE/ENDRULE
                    Andrew Dinn Master

                    swimablefish wrote:

                     

                    yeah, it can work now,

                       but I used "-s", not "-b". Although "-b" didn't print any error message, the script didn't work.  "-s" worked well.

                     

                    Well, -b does also work.

                     

                     

                    swimablefish wrote:

                     

                    by the way, I still can't figure out the differences between "-s" and "-b", 3ks,

                     

                    It's to do with the visibility of the helper classes. You need to use -b if you want to inject a rule which uses your helper into a method of a JVM class like java.lang.Thread or java.io.FileInputstream. These classes are loaded by the bootstrap classloader which is different  to the system classloader normally used to load application code. Installing your helperc jar in the bootstrap classpath means that references to it can be injected into the JVM classes. If you install it into the system loader and then try ot inject a rule into a JVM class the you will get an unresolved reference to you helper class. The same applies when you load the the agent. If you want to install ruels into JVM classes then you need to load the agent jar into the bootstrap classpath. You can do this by passing-b to the bminstall.sh command or to bmjava.sh or by specifying boot:byteman.jar as an option to the -javaagennt java command line argument