Skip to content

Commit

Permalink
NTA-89: Add a keyword filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuan-Hu committed May 4, 2016
1 parent 82d8e76 commit 803f45f
Show file tree
Hide file tree
Showing 38 changed files with 615 additions and 242 deletions.
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,21 @@ To build the `Transaction Analyser` from source you need Maven 3.0.0+ installed

## Download and Configure WildFly

Currently the `Transaction Analyser` can work with the WildFly 8.0.0.Final:
Currently the `Transaction Analyser` can work with the WildFly 10.0.0.Final:

wget http://download.jboss.org/wildfly/8.0.0.Final/wildfly-8.0.0.Final.zip
unzip wildfly-8.0.0.Final.zip
export WILDFLY_HOME=/path/to/wildfly-8.0.0.Final
wget http://download.jboss.org/wildfly/10.0.0.Final/wildfly-10.0.0.Final.zip
unzip wildfly-10.0.0.Final.zip
export WILDFLY_HOME=/path/to/wildfly-10.0.0.Final.zip

## Run Wildfly

cd $WILDFLY_HOME/bin
./standalone.sh -c standalone-full.xml

## Deploy to WildFLy
## Deploy to WildFly
To run the `Transaction Analyzer` you just need to deploy the ear file to WildFly and visit the console. To do this:

cp nta-dist/target/nta-1.0.0.Alpha2-SNAPSHOT.ear $WILDFLY_HOME/standalone/deployments
cp nta-dist/target/nta-1.0.0.Alpha3-SNAPSHOT.ear $WILDFLY_HOME/standalone/deployments

Then visit: http://localhost:8080/nta/. By default the `Transaction Analyser` is disabled. To enable it click on the 'start' button at the top-right
of the console's home page. Similarly, you can stop it by clicking the 'stop' button.
Expand All @@ -43,7 +46,7 @@ of the console's home page. Similarly, you can stop it by clicking the 'stop' bu
## Running the Demo Application
The demo application provides a simple way to play with this tool if you don't have an application with failing transactions to hand. To deploy it:

cp demo/target/nta-demo-1.0.0.Alpha2-SNAPSHOT.war $WILDFLY_HOME/standalone/deployments
cp demo/target/nta-demo-1.0.0.Alpha3-SNAPSHOT.war $WILDFLY_HOME/standalone/deployments

The demo is now available at http://localhost:8080/txdemo. To use the demo, simply click on the button for the scenario you want to run. When the scenario
completes you will be notified of the outcome from the transaction. For most scenarios you will get an error message returned. This is to be expected
Expand Down
39 changes: 6 additions & 33 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<parent>
<artifactId>nta-all</artifactId>
<groupId>io.narayana.nta</groupId>
<version>1.0.0.Alpha2-SNAPSHOT</version>
<version>1.0.0.Alpha3-SNAPSHOT</version>
</parent>

<artifactId>core</artifactId>
Expand All @@ -50,31 +50,10 @@
</snapshotRepository>
</distributionManagement>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-bom</artifactId>
<version>2.0.0-beta-1</version>
<scope>import</scope>
<type>pom</type>
</dependency>

<dependency>
<groupId>org.jboss.bom</groupId>
<artifactId>jboss-javaee-6.0-with-tools</artifactId>
<version>1.0.0.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-api</artifactId>
<version>2.0.0-beta-1</version>
<scope>test</scope>
</dependency>

Expand All @@ -93,34 +72,31 @@
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
<version>2.0.0-beta-1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-api-maven</artifactId>
<version>2.0.0-beta-1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.6-Final</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jboss.narayana.jta</groupId>
<artifactId>narayana-jta</artifactId>
<version>5.0.0.M2</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.1_spec</artifactId>
<scope>provided</scope>
<version>1.0.1.Final</version>
</dependency>

<dependency>
Expand All @@ -145,22 +121,19 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${basedir}/../etc/lib/commons-io-2.5-SNAPSHOT.jar</systemPath>
</dependency>

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>1.0.3.Final</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -179,7 +152,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<version>${maven.plugins}</version>
<configuration>
<archive>
<manifestEntries>
Expand Down Expand Up @@ -210,7 +183,7 @@
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-arquillian-container-remote</artifactId>
<version>8.0.0.Final</version>
<version>${version.wildfly}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -233,7 +206,7 @@
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-container-remote</artifactId>
<version>7.3.0.Final-redhat-SNAPSHOT</version>
<version>${jboos.as}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
6 changes: 5 additions & 1 deletion core/src/main/java/io/narayana/nta/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@

package io.narayana.nta;

import io.narayana.nta.logparsing.as8.filters.KeywordFilter;
import io.narayana.nta.logparsing.as8.filters.PackageFilter;
import io.narayana.nta.logparsing.as8.filters.KeywordFilter;
import io.narayana.nta.logparsing.as8.handlers.*;

import java.io.File;
Expand Down Expand Up @@ -54,7 +56,7 @@ public final class Configuration {
/**
*
*/
public static final int DEFAULT_ITEMS_PER_PAGE = 7;
public static final int DEFAULT_ITEMS_PER_PAGE = 50;
/**
*
*/
Expand All @@ -64,6 +66,7 @@ public final class Configuration {
*/
public static final Class[] LOG_HANDLERS = new Class[]{
BasicActionHandler.class,
JCAEnlistResourceHandler.class,
JTACreateResourceRecordHandler.class,
JTAResourceExceptionHandler.class,
JTAResourceRecordHandler.class,
Expand All @@ -79,6 +82,7 @@ public final class Configuration {

public static final Class[] LOG_FILTERS = new Class[]{
PackageFilter.class,
KeywordFilter.class,
};

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package io.narayana.nta.logparsing.as8.filters;

import org.apache.log4j.Logger;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

public class GetFilterKeywords {
private List<String> filterKeywords;
private static final Logger logger = Logger.getLogger(GetFilterKeywords.class.getName());

private static class GetFilterKeywordsHolder {
private static final GetFilterKeywords INSTANCE = new GetFilterKeywords();
}

public static final GetFilterKeywords getInstance() {
return GetFilterKeywordsHolder.INSTANCE;
}

private GetFilterKeywords() {
InputStream inputStream = null;
try {
Properties prop = new Properties();
filterKeywords = new ArrayList<>();

String propFileName = "filter.properties";
logger.warn(getClass().getClassLoader().getResource());
inputStream = getClass().getClassLoader().getResourceAsStream(propFileName);
if (inputStream != null) {
prop.load(inputStream);
} else {
throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath");
}

for (String name : prop.stringPropertyNames()) {
if (name.contains("keywords"))
filterKeywords.add(prop.getProperty(name));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
inputStream.close();
} catch (IOException ignored) {
}
}
}

public List<String> getFilterKeywords() {
return filterKeywords;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2016, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package io.narayana.nta.logparsing.as8.filters;

import io.narayana.nta.logparsing.common.Filter;

import java.util.List;

/**
* @author huyuan
*/
public class KeywordFilter implements Filter {


@Override
public boolean matches(String line) throws IndexOutOfBoundsException {

List<String> keywordList = GetFilterKeywords.getInstance().getFilterKeywords();

try {
for (String s : keywordList) {
if (line.contains(s)) { // if black list use !line.contains(s)
return true;
}
}
return false;
} catch (IndexOutOfBoundsException e) {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@
public class PackageFilter implements Filter {

public static final String PACKAGE_ARJUNA = "com.arjuna";
public static final String PACKAGE_JCA = "org.jboss.jca";


@Override
public boolean matches(String line) {

try {
final int startPos = line.indexOf('[') + 1;
return !PACKAGE_ARJUNA.equals(line.substring(startPos, startPos + 10));
if(startPos == 0) {
return false;
}
return !PACKAGE_ARJUNA.equals(line.substring(startPos, startPos + PACKAGE_ARJUNA.length())) &&
!PACKAGE_JCA.equals(line.substring(startPos, startPos + PACKAGE_JCA.length()));
} catch (IndexOutOfBoundsException e) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright (c) 2011, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package io.narayana.nta.logparsing.as8.handlers;

import java.util.regex.Matcher;

/**
* @author <a href="mailto:[email protected]">Amos Feng</a>
*/
public class JCAEnlistResourceHandler extends JbossAS8AbstractHandler {
public static final String REGEX = "Enlisted resource.*?xaResource=LocalXAResourceImpl.*?" + "tx_uid=" + PATTERN_TXUID +
".*?branch_uid=" + PATTERN_BRANCHUID + ".*?eis_name=" + PATTERN_EISNAME +
".*?productName=(?<" + RM_PRODUCT_NAME + ">.*?)\\sproductVersion=(?<" + RM_PRODUCT_VERSION + ">.*?)" +
"\\sjndiName=(?<" + RM_JNDI_NAME + ">java:[\\w/]+)\\].*";

public JCAEnlistResourceHandler() {
super(REGEX);
}


@Override
public void handle(Matcher matcher, String line) {

service.enlistResourceManagerJTA(matcher.group(TXUID), matcher.group(BRANCHUID), matcher.group(RM_JNDI_NAME), matcher.group(RM_PRODUCT_NAME),
matcher.group(RM_PRODUCT_VERSION), matcher.group(EISNAME), parseTimestamp(matcher.group(TIMESTAMP)), matcher.group(TXUID) + ":" + LAST_RESOURCE_ID);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class JTACreateResourceRecordHandler extends JbossAS8AbstractHandler {
/**
*
*/
public static final String REGEX = "XAResourceRecord\\.XAResourceRecord.*?" + "tx_uid=" + PATTERN_TXUID + ".*?" + PATTERN_XARESOURCEWRAPPERIMPL + "\\] \\), record id=" + PATTERN_RESOURCE_UID;
public static final String REGEX = "XAResourceRecord\\.XAResourceRecord.*?" + "tx_uid=" + PATTERN_TXUID + ".*?branch_uid=" + PATTERN_BRANCHUID + ".*?eis_name=" + PATTERN_EISNAME + ".*?(" + PATTERN_XARESOURCEWRAPPERIMPL + ")?\\] \\), record id=" + PATTERN_RESOURCE_UID + "$";

public static final String LINE = "XAResourceRecord.XAResourceRecord ( < formatId=131077, gtrid_length=29, " +
"bqual_length=36, tx_uid=0:ffff7f000001:-3713c968:5243fb29:25, node_name=1, branch_uid=0:ffff7f000001:-3713c968:5243fb29:2c, " +
Expand All @@ -57,8 +57,8 @@ public JTACreateResourceRecordHandler() {
@Override
public void handle(Matcher matcher, String line) {

service.enlistResourceManagerJTA(matcher.group(TXUID), matcher.group(RM_JNDI_NAME), matcher.group(RM_PRODUCT_NAME),
matcher.group(RM_PRODUCT_VERSION), parseTimestamp(matcher.group(TIMESTAMP)), matcher.group(RESUID));
service.enlistResourceManagerJTA(matcher.group(TXUID), matcher.group(BRANCHUID), matcher.group(RM_JNDI_NAME), matcher.group(RM_PRODUCT_NAME),
matcher.group(RM_PRODUCT_VERSION), matcher.group(EISNAME), parseTimestamp(matcher.group(TIMESTAMP)), matcher.group(RESUID));
}

public static void main(String[] args) {
Expand Down
Loading

0 comments on commit 803f45f

Please sign in to comment.