Practical byteman sample 20131128
Upcoming SlideShare
Loading in...5
×
 

Practical byteman sample 20131128

on

  • 602 views

 

Statistics

Views

Total Views
602
Views on SlideShare
602
Embed Views
0

Actions

Likes
1
Downloads
5
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Practical byteman sample 20131128 Practical byteman sample 20131128 Presentation Transcript

  • 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