SlideShare 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

PPTX
Byteman - Carving up your Java code
PPTX
Scripting robot
PPTX
Integration Group - Robot Framework
PDF
Appium & Robot Framework
PDF
Network Protocol Testing Using Robot Framework
PPTX
Robot framework
PDF
Introduction to Robot Framework (external)
PDF
Robot Framework Introduction
Byteman - Carving up your Java code
Scripting robot
Integration Group - Robot Framework
Appium & Robot Framework
Network Protocol Testing Using Robot Framework
Robot framework
Introduction to Robot Framework (external)
Robot Framework Introduction

What's hot (20)

PDF
Acceptance testing plone sites and add ons with robot framework and selenium
PDF
ATDD Using Robot Framework
PDF
JavaCro'14 - Test Automation using RobotFramework Libraries – Stojan Peshov
PPT
Rational Robot (http://www.geektester.blogspot.com)
PPT
Log4j Logging Mechanism
PPTX
SLF4J Explained........
PDF
Test all the things! Automated testing with Drupal 8
PDF
Gatling Performance Workshop
PDF
Log4j in 8 slides
PDF
Variables in Pharo5
PPT
SLF4J (Simple Logging Facade for Java)
PPTX
SLF4J+Logback
PDF
PPTX
Log4j slideshare
PPTX
Automated php unit testing in drupal 8
PPT
Functional Testing Swing Applications with Frankenstein
PDF
Quick tour to front end unit testing using jasmine
PDF
Drupal and testing (2010 - 2011 / 2)
PDF
PDF
Testing sync engine
Acceptance testing plone sites and add ons with robot framework and selenium
ATDD Using Robot Framework
JavaCro'14 - Test Automation using RobotFramework Libraries – Stojan Peshov
Rational Robot (http://www.geektester.blogspot.com)
Log4j Logging Mechanism
SLF4J Explained........
Test all the things! Automated testing with Drupal 8
Gatling Performance Workshop
Log4j in 8 slides
Variables in Pharo5
SLF4J (Simple Logging Facade for Java)
SLF4J+Logback
Log4j slideshare
Automated php unit testing in drupal 8
Functional Testing Swing Applications with Frankenstein
Quick tour to front end unit testing using jasmine
Drupal and testing (2010 - 2011 / 2)
Testing sync engine
Ad

More from Jooho Lee (8)

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

Recently uploaded (20)

PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Spectroscopy.pptx food analysis technology
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPT
Teaching material agriculture food technology
PDF
Approach and Philosophy of On baking technology
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Spectral efficient network and resource selection model in 5G networks
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Diabetes mellitus diagnosis method based random forest with bat algorithm
Spectroscopy.pptx food analysis technology
Programs and apps: productivity, graphics, security and other tools
Encapsulation_ Review paper, used for researhc scholars
Digital-Transformation-Roadmap-for-Companies.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
The AUB Centre for AI in Media Proposal.docx
MYSQL Presentation for SQL database connectivity
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Teaching material agriculture food technology
Approach and Philosophy of On baking technology
Chapter 3 Spatial Domain Image Processing.pdf
Unlocking AI with Model Context Protocol (MCP)
NewMind AI Weekly Chronicles - August'25 Week I
Per capita expenditure prediction using model stacking based on satellite ima...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx

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