際際滷

際際滷Share a Scribd company logo
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/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.
Find Related Source


Class : Method


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


public byte[] addContent(InputStream in) throws IOException
Which Parameters we should know?


repoRoot



messageDigest



sha1Bytes
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
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
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
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
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;
}
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 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

More Related Content

What's hot (20)

PDF
Acceptance testing plone sites and add ons with robot framework and selenium
Asko Soukka
PDF
ATDD Using Robot Framework
Pekka Kl辰rck
PDF
JavaCro'14 - Test Automation using RobotFramework Libraries Stojan Peshov
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
PPT
Rational Robot (http://www.geektester.blogspot.com)
raj.kamal13
PPT
Log4j Logging Mechanism
Kunal Dabir
PPTX
SLF4J Explained........
Sunitha Satyadas
PDF
Test all the things! Automated testing with Drupal 8
Sam Becker
PDF
Gatling Performance Workshop
Sai Krishna
PDF
Log4j in 8 slides
Tarin Gamberini
PDF
Variables in Pharo5
Marcus Denker
PPT
SLF4J (Simple Logging Facade for Java)
Guo Albert
PPTX
SLF4J+Logback
Guo Albert
PDF
Flow
zupzup.org
PPTX
Log4j slideshare
Ahmed M. Gomaa
PPTX
Automated php unit testing in drupal 8
Jay Friendly
PPT
Functional Testing Swing Applications with Frankenstein
vivek_prahlad
PDF
Quick tour to front end unit testing using jasmine
Gil Fink
PDF
Drupal and testing (2010 - 2011 / 2)
Peter Arato
PDF
Log4j2
joergreichert
PDF
Testing sync engine
Ilya Puchka
Acceptance testing plone sites and add ons with robot framework and selenium
Asko Soukka
ATDD Using Robot Framework
Pekka Kl辰rck
JavaCro'14 - Test Automation using RobotFramework Libraries Stojan Peshov
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
Rational Robot (http://www.geektester.blogspot.com)
raj.kamal13
Log4j Logging Mechanism
Kunal Dabir
SLF4J Explained........
Sunitha Satyadas
Test all the things! Automated testing with Drupal 8
Sam Becker
Gatling Performance Workshop
Sai Krishna
Log4j in 8 slides
Tarin Gamberini
Variables in Pharo5
Marcus Denker
SLF4J (Simple Logging Facade for Java)
Guo Albert
SLF4J+Logback
Guo Albert
Flow
zupzup.org
Log4j slideshare
Ahmed M. Gomaa
Automated php unit testing in drupal 8
Jay Friendly
Functional Testing Swing Applications with Frankenstein
vivek_prahlad
Quick tour to front end unit testing using jasmine
Gil Fink
Drupal and testing (2010 - 2011 / 2)
Peter Arato
Log4j2
joergreichert
Testing sync engine
Ilya Puchka

More from Jooho Lee (8)

PDF
Quay 3.3 installation
Jooho Lee
PPTX
OpenShift4 Installation by UPI on kvm
Jooho Lee
PDF
Hello istio
Jooho Lee
PPTX
Docker, Atomic Host and Kubernetes.
Jooho Lee
PDF
OpenSCAP Overview(security scanning for docker image and container)
Jooho Lee
PDF
OpenSCAP Overview(security scanning for docker image and container)
Jooho Lee
PPTX
Tcp summary
Jooho Lee
PPTX
Consistent hashing
Jooho Lee
Quay 3.3 installation
Jooho Lee
OpenShift4 Installation by UPI on kvm
Jooho Lee
Hello istio
Jooho Lee
Docker, Atomic Host and Kubernetes.
Jooho Lee
OpenSCAP Overview(security scanning for docker image and container)
Jooho Lee
OpenSCAP Overview(security scanning for docker image and container)
Jooho Lee
Tcp summary
Jooho Lee
Consistent hashing
Jooho Lee
Ad

Recently uploaded (20)

PDF
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
PDF
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
PDF
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
PDF
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
PPTX
UserCon Belgium: Honey, VMware increased my bill
stijn40
PPTX
reInforce 2025 Lightning Talk - Scott Francis.pptx
ScottFrancis51
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
PPTX
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
PDF
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
PDF
How to Visualize the Spatio-Temporal Data Using CesiumJS
SANGHEE SHIN
PDF
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
PDF
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
PDF
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
DOCX
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
PDF
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
PPTX
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
PPTX
叶Wondershare Filmora Crack 14.0.7 + Key Download 2025
sebastian aliya
PDF
The Future of Product Management in AI ERA.pdf
Alyona Owens
PDF
UiPath Agentic AI ile Ak脹ll脹 Otomasyonun Yeni a脹
UiPathCommunity
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
UserCon Belgium: Honey, VMware increased my bill
stijn40
reInforce 2025 Lightning Talk - Scott Francis.pptx
ScottFrancis51
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
How to Visualize the Spatio-Temporal Data Using CesiumJS
SANGHEE SHIN
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
叶Wondershare Filmora Crack 14.0.7 + Key Download 2025
sebastian aliya
The Future of Product Management in AI ERA.pdf
Alyona Owens
UiPath Agentic AI ile Ak脹ll脹 Otomasyonun Yeni a脹
UiPathCommunity
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
Ad

Practical byteman sample 20131128

  • 1. Practical Byteman Sample Jooho Lee(Jay) JBoss Technical Engineer
  • 2. Agenda To get Hash Code when deploying application AFTER WRITE example AT CATCH example
  • 3. Test Environment Test Environment EAP 6.1 (JBoss AS 7.2) Byteman 2.1.3 Domain Mode
  • 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. Find Related Source Class : Method org.jboss.as.repository.ContentRepository (Interface) public byte[] addContent(InputStream in) throws IOException
  • 6. Which Parameters we should know? repoRoot messageDigest sha1Bytes
  • 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. 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. 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. 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. 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. Syntax explanation AFTER WRITE $in After the local param in is set, this byteman will call.
  • 13. AT CATCH example This feature is under consideration https://issues.jboss.org/browse/BYTEMAN-189
  • 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