Your SlideShare is downloading. ×
0
Practical Byteman Sample

Jooho Lee(Jay)
JBoss Technical Engineer
Agenda
●

To get Hash Code when deploying application

●

AFTER WRITE example

●

AT CATCH example
Test Environment
●

Test Environment
–

EAP 6.1 (JBoss AS 7.2)

–

Byteman 2.1.3

–

Domain Mode
Why?
●

Hash Code for deployed application
–

Using Domain, when application is deployed, it is copied
under /data/content...
Find Related Source
●

Class : Method
–

org.jboss.as.repository.ContentRepository (Interface)
●

public byte[] addContent...
Which Parameters we should know?
●

repoRoot

●

messageDigest

●

sha1Bytes
Create Byteman Script(1)
●

Script Format
RULE During deployment, Check repoRoot, messageDigest in addContent
INTERFACE ^o...
Create Byteman Script(2)
●

Script Format
RULE During deployment, Check sha1Bytes, in addContent
INTERFACE ^org.jboss.as.r...
Syntax explanation
●

^
–
–

INTERFACE or CLASS

–
●

Interface or Abstract or Root class(java.lang.Object)
Implementation...
AFTER WRITE Script
●

Sample Script(deployment.btm)
–

It is possible to change class like following: CLASS
^org.jboss.as....
Test Source
protected InputStream getContentInputStream(OperationContext operationContext, ModelNode
operation) throws IOE...
Syntax explanation
●

AFTER WRITE $in
–

After the local param in is set, this byteman will call.
AT CATCH example
●

This feature is under consideration

●

https://issues.jboss.org/browse/BYTEMAN-189
AT CATCH Sample
RULE jbossts printStackTrace at-catch 1
CLASS com.arjuna.ats.arjuna.recovery.ActionStatusService
METHOD do...
Upcoming SlideShare
Loading in...5
×

Practical byteman sample 20131128

791

Published on

Published in: Technology, Education
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
791
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
11
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "Practical byteman sample 20131128"

  1. 1. Practical Byteman Sample Jooho Lee(Jay) JBoss Technical Engineer
  2. 2. Agenda ● To get Hash Code when deploying application ● AFTER WRITE example ● AT CATCH example
  3. 3. Test Environment ● Test Environment – EAP 6.1 (JBoss AS 7.2) – Byteman 2.1.3 – Domain Mode
  4. 4. Why? ● Hash Code for deployed application – Using Domain, when application is deployed, it is copied under /data/content/hash/code folder – Copying the folder is one of ways to copy same application to other server. – To make it automation, generating hash code is essencial.
  5. 5. Find Related Source ● Class : Method – org.jboss.as.repository.ContentRepository (Interface) ● public byte[] addContent(InputStream in) throws IOException
  6. 6. Which Parameters we should know? ● repoRoot ● messageDigest ● sha1Bytes
  7. 7. Create Byteman Script(1) ● Script Format RULE During deployment, Check repoRoot, messageDigest in addContent INTERFACE ^org.jboss.as.repository.ContentRepository METHOD addContent AT INVOKE createTempFile IF TRUE DO debug("------- " + $this + " -------"); System.out.println(“repoRoot : “ + $0.repoRoot); System.out.println(“messageDigest : “ + $0. messageDigest); ENDRULE
  8. 8. Create Byteman Script(2) ● Script Format RULE During deployment, Check sha1Bytes, in addContent INTERFACE ^org.jboss.as.repository.ContentRepository METHOD addContent AT INVOKE getDeploymentContentFile IF TRUE DO debug("------- " + $this + " -------"); System.out.println("sha1Bytes = " + $sha1Bytes); ENDRULE
  9. 9. Syntax explanation ● ^ – – INTERFACE or CLASS – ● Interface or Abstract or Root class(java.lang.Object) Implementation class will be intercepted by Byteman $0.(field param name) – ● $0,$1... – ● Local variable value $this – ● Field variable value Class object $METHOD – Called method information
  10. 10. AFTER WRITE Script ● Sample Script(deployment.btm) – It is possible to change class like following: CLASS ^org.jboss.as.server.deployment.AbstractDeploymentUpl oadHandler (Abstract class) RULE During deployment getContentInputStream CLASS org.jboss.as.server.deployment.DeploymentUploadStreamAttachmentHandler METHOD getContentInputStream AFTER WRITE $in IF TRUE DO debug("------- " + $this + " -------"); System.out.println("in = " + $in); System.out.println("streamIndex = " + $streamIndex); ENDRULE
  11. 11. Test Source protected InputStream getContentInputStream(OperationContext operationContext, ModelNode operation) throws IOException, OperationFailedException { // Get the attached stream final int streamIndex = operation.require(INPUT_STREAM_INDEX).asInt(); final InputStream in = operationContext.getAttachmentStream(streamIndex); if (in == null) { throw ServerMessages.MESSAGES.nullStreamAttachment(streamIndex); } return in; }
  12. 12. Syntax explanation ● AFTER WRITE $in – After the local param in is set, this byteman will call.
  13. 13. AT CATCH example ● This feature is under consideration ● https://issues.jboss.org/browse/BYTEMAN-189
  14. 14. AT CATCH Sample RULE jbossts printStackTrace at-catch 1 CLASS com.arjuna.ats.arjuna.recovery.ActionStatusService METHOD doWork AT CATCH java.io.IOException IF TRUE DO debug("---"+$this+"---");$^.printStackTrace() ENDRULE RULE jbossts printStackTrace at-catch 2 CLASS com.arjuna.ats.internal.arjuna.recovery.Connection METHOD run AT CATCH java.io.IOException IF TRUE DO debug("---"+$this+"---");$^.printStackTrace() ENDRULE
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×