practical byteman sample 20131128

Download Practical byteman sample 20131128

If you can't read please download the document

Upload: jooho-lee

Post on 16-Apr-2017

1.894 views

Category:

Technology


4 download

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 EnvironmentEAP 6.1 (JBoss AS 7.2)

Byteman 2.1.3

Domain Mode

Why?

Hash Code for deployed applicationUsing 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 addContentINTERFACE ^org.jboss.as.repository.ContentRepositoryMETHOD addContentAT INVOKE createTempFileIF TRUEDO 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 addContentINTERFACE ^org.jboss.as.repository.ContentRepositoryMETHOD addContentAT INVOKE getDeploymentContentFileIF TRUEDO debug("------- " + $this + " -------"); System.out.println("sha1Bytes = " + $sha1Bytes);ENDRULE

Syntax explanation

^ Interface or Abstract or Root class(java.lang.Object)

INTERFACE or CLASS

Implementation class will be intercepted by Byteman

$0.(field param name)Field variable value

$0,$1...Local variable value

$this Class object

$METHODCalled method information

AFTER WRITE Script

Sample Script(deployment.btm)It is possible to change class like following: CLASS ^org.jboss.as.server.deployment.AbstractDeploymentUploadHandler (Abstract class)

RULE During deployment getContentInputStreamCLASS org.jboss.as.server.deployment.DeploymentUploadStreamAttachmentHandlerMETHOD getContentInputStreamAFTER WRITE $inIF TRUEDO 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 $inAfter 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 1CLASS com.arjuna.ats.arjuna.recovery.ActionStatusServiceMETHOD doWorkAT CATCH java.io.IOExceptionIF TRUEDO debug("---"+$this+"---");$^.printStackTrace()ENDRULE

RULE jbossts printStackTrace at-catch 2CLASS com.arjuna.ats.internal.arjuna.recovery.ConnectionMETHOD runAT CATCH java.io.IOExceptionIF TRUEDO debug("---"+$this+"---");$^.printStackTrace()ENDRULE