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