From 9508171b157d82298bd9b4c3eb7eab505e42c6e2 Mon Sep 17 00:00:00 2001 From: Albert Flaig Date: Thu, 23 Mar 2017 15:24:31 +0100 Subject: [PATCH 1/3] Replace Spring framework with org.Reflections --- diagnoseIT/dependencies.gradle | 7 +++++-- .../engine/rule/ConditionMethod.java | 3 +-- .../engine/util/ReflectionUtils.java | 9 +++++---- .../diagnoseit.rules/diagnoseit.rules.gradle | 5 +---- .../timeseries/impl/InfluxDBConnector.java | 6 +++--- .../org/diagnoseit/standalone/DiagnoseIT.java | 17 +++++------------ .../standalone/DiagnoseITTimeseries.java | 18 +++++------------- 7 files changed, 25 insertions(+), 40 deletions(-) diff --git a/diagnoseIT/dependencies.gradle b/diagnoseIT/dependencies.gradle index ab14af0..844aea3 100644 --- a/diagnoseIT/dependencies.gradle +++ b/diagnoseIT/dependencies.gradle @@ -49,8 +49,11 @@ subprojects { 'org.objenesis:objenesis:2.1', 'com.google.guava:guava-jdk5:13.0', - 'org.springframework:spring-core:4.3.0.RELEASE', - 'org.springframework:spring-context:4.3.0.RELEASE' + + 'org.reflections:reflections:0.9.11', + + 'org.spec.research:open.xtrace.default.impl:0.2.0', + 'org.spec.research:open.xtrace.api:0.2.0' } } \ No newline at end of file diff --git a/diagnoseIT/diagnoseit.ruleengine/src/main/java/org/diagnoseit/engine/rule/ConditionMethod.java b/diagnoseIT/diagnoseit.ruleengine/src/main/java/org/diagnoseit/engine/rule/ConditionMethod.java index 3e96359..2bd7375 100644 --- a/diagnoseIT/diagnoseit.ruleengine/src/main/java/org/diagnoseit/engine/rule/ConditionMethod.java +++ b/diagnoseIT/diagnoseit.ruleengine/src/main/java/org/diagnoseit/engine/rule/ConditionMethod.java @@ -7,7 +7,6 @@ import org.apache.commons.lang3.StringUtils; import org.diagnoseit.engine.rule.annotation.Condition; import org.diagnoseit.engine.rule.exception.RuleExecutionException; -import org.springframework.util.ReflectionUtils; /** * Defines a condition method of a rule implementation. A ConditionMethod reflects the @@ -76,7 +75,7 @@ public ConditionMethod(String name, String hint, Method method) { */ public ConditionFailure execute(ExecutionContext context) { try { - boolean valid = (boolean) ReflectionUtils.invokeMethod(getMethod(), context.getInstance()); + boolean valid = (boolean) getMethod().invoke(context.getInstance()); if (!valid) { // Store information about the failed condition for later usage return new ConditionFailure(getName(), getHint()); diff --git a/diagnoseIT/diagnoseit.ruleengine/src/main/java/org/diagnoseit/engine/util/ReflectionUtils.java b/diagnoseIT/diagnoseit.ruleengine/src/main/java/org/diagnoseit/engine/util/ReflectionUtils.java index d7c8371..e81e649 100644 --- a/diagnoseIT/diagnoseit.ruleengine/src/main/java/org/diagnoseit/engine/util/ReflectionUtils.java +++ b/diagnoseIT/diagnoseit.ruleengine/src/main/java/org/diagnoseit/engine/util/ReflectionUtils.java @@ -10,8 +10,6 @@ import java.util.ArrayList; import java.util.List; -import org.springframework.core.annotation.AnnotationUtils; - /** * Class contains utility methods to work with reflection API. * @@ -93,10 +91,13 @@ public static boolean hasNoArgsConstructor(Class clazz) { * The annotation to be looked up. * @param * The type of annotation - * @return true if annotation is present, false otherwise. + * @return the Annotation if found, else null */ public static T findAnnotation(Class clazz, Class annotationClass) { - return AnnotationUtils.findAnnotation(clazz, annotationClass); + T[] annotationsByType = clazz.getAnnotationsByType(annotationClass); + if(annotationsByType.length > 0) + return annotationsByType[0]; + return null; } /** diff --git a/diagnoseIT/diagnoseit.rules/diagnoseit.rules.gradle b/diagnoseIT/diagnoseit.rules/diagnoseit.rules.gradle index 8189a88..b344324 100644 --- a/diagnoseIT/diagnoseit.rules/diagnoseit.rules.gradle +++ b/diagnoseIT/diagnoseit.rules/diagnoseit.rules.gradle @@ -1,7 +1,4 @@ dependencies { compile project(':diagnoseit.ruleengine') - compile files('libs/influxdb-java.jar') - compile files('libs/open.xtrace.jar') - compile group: 'com.squareup.retrofit', name: 'retrofit', version: '1.9.0' - compile group: 'com.squareup.okhttp', name: 'okhttp', version: '2.7.5' + compile 'org.influxdb:influxdb-java:2.0' } \ No newline at end of file diff --git a/diagnoseIT/diagnoseit.rules/src/main/java/org/diagnoseit/rules/timeseries/impl/InfluxDBConnector.java b/diagnoseIT/diagnoseit.rules/src/main/java/org/diagnoseit/rules/timeseries/impl/InfluxDBConnector.java index 65d28a7..ee75893 100644 --- a/diagnoseIT/diagnoseit.rules/src/main/java/org/diagnoseit/rules/timeseries/impl/InfluxDBConnector.java +++ b/diagnoseIT/diagnoseit.rules/src/main/java/org/diagnoseit/rules/timeseries/impl/InfluxDBConnector.java @@ -567,9 +567,9 @@ public void writeData(double responseTime, double cpuTime, double gcTime, Point point1 = Point.measurement(TABLE_TIMING_INFORMATION) .tag(INFLUXDB_TAG_TRACE, String.valueOf(traceId)) .time(traceTimestamp, TimeUnit.MILLISECONDS) - .addField(COLUMN_RESPONSE_TIME, responseTime) - .addField(COLUMN_CPU_TIME, cpuTime) - .addField(COLUMN_GC_TIME, gcTime).build(); + .field(COLUMN_RESPONSE_TIME, responseTime) + .field(COLUMN_CPU_TIME, cpuTime) + .field(COLUMN_GC_TIME, gcTime).build(); influxDB.write(DATABASE_NAME, RETENTION_POLICY, point1); } diff --git a/diagnoseIT/diagnoseit.standalone/src/main/java/org/diagnoseit/standalone/DiagnoseIT.java b/diagnoseIT/diagnoseit.standalone/src/main/java/org/diagnoseit/standalone/DiagnoseIT.java index 24f39d0..3d9329f 100644 --- a/diagnoseIT/diagnoseit.standalone/src/main/java/org/diagnoseit/standalone/DiagnoseIT.java +++ b/diagnoseIT/diagnoseit.standalone/src/main/java/org/diagnoseit/standalone/DiagnoseIT.java @@ -20,13 +20,10 @@ import org.diagnoseit.rules.RuleConstants; import org.diagnoseit.rules.result.ProblemInstanceResultCollector; import org.diagnoseit.rules.result.ProblemOccurrence; +import org.reflections.Reflections; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spec.research.open.xtrace.api.core.Trace; -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; -import org.springframework.core.type.filter.AnnotationTypeFilter; - public class DiagnoseIT implements Runnable{ @@ -92,16 +89,12 @@ public void run() { } public void init(ISessionCallback> resultHandler) throws ClassNotFoundException { - - ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false); - - scanner.addIncludeFilter(new AnnotationTypeFilter(Rule.class)); + Set> ruleClasses = new HashSet<>(); for (String packageName : rulesPackages) { - for (BeanDefinition bd : scanner.findCandidateComponents(packageName)) { - Class clazz = Class.forName(bd.getBeanClassName()); - ruleClasses.add(clazz); - } + Reflections reflections = new Reflections(packageName); + Set> subTypesOf = reflections.getTypesAnnotatedWith(Rule.class); + ruleClasses.addAll(subTypesOf); } DiagnosisEngineConfiguration> configuration = new DiagnosisEngineConfiguration>(); diff --git a/diagnoseIT/diagnoseit.standalone/src/main/java/org/diagnoseit/standalone/DiagnoseITTimeseries.java b/diagnoseIT/diagnoseit.standalone/src/main/java/org/diagnoseit/standalone/DiagnoseITTimeseries.java index 08b41ee..b333222 100644 --- a/diagnoseIT/diagnoseit.standalone/src/main/java/org/diagnoseit/standalone/DiagnoseITTimeseries.java +++ b/diagnoseIT/diagnoseit.standalone/src/main/java/org/diagnoseit/standalone/DiagnoseITTimeseries.java @@ -17,11 +17,9 @@ import org.diagnoseit.rules.result.ProblemInstanceResultCollector; import org.diagnoseit.rules.result.ProblemOccurrence; import org.diagnoseit.rules.timeseries.impl.InfluxDBConnector; +import org.reflections.Reflections; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; -import org.springframework.core.type.filter.AnnotationTypeFilter; public class DiagnoseITTimeseries implements Runnable { private static final long TIMEOUT = 50; @@ -88,18 +86,12 @@ public void run() { public void init(ISessionCallback> resultHandler) throws ClassNotFoundException { - - ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider( - false); - - scanner.addIncludeFilter(new AnnotationTypeFilter(Rule.class)); + Set> ruleClasses = new HashSet<>(); for (String packageName : rulesPackages) { - for (BeanDefinition bd : scanner - .findCandidateComponents(packageName)) { - Class clazz = Class.forName(bd.getBeanClassName()); - ruleClasses.add(clazz); - } + Reflections reflections = new Reflections(packageName); + Set> subTypesOf = reflections.getTypesAnnotatedWith(Rule.class); + ruleClasses.addAll(subTypesOf); } DiagnosisEngineConfiguration> configuration = new DiagnosisEngineConfiguration>(); From 6e5bed035cddae5a43b1f3c3d400eb0c062fe9a4 Mon Sep 17 00:00:00 2001 From: Manuel Palenga Date: Thu, 23 Mar 2017 15:26:55 +0100 Subject: [PATCH 2/3] Remove dependencies and set example traces. --- .../src/main/java/org/diagnoseit/standalone/Launcher.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/diagnoseIT/diagnoseit.standalone/src/main/java/org/diagnoseit/standalone/Launcher.java b/diagnoseIT/diagnoseit.standalone/src/main/java/org/diagnoseit/standalone/Launcher.java index 5cff97e..c8ae545 100644 --- a/diagnoseIT/diagnoseit.standalone/src/main/java/org/diagnoseit/standalone/Launcher.java +++ b/diagnoseIT/diagnoseit.standalone/src/main/java/org/diagnoseit/standalone/Launcher.java @@ -7,9 +7,7 @@ import org.diagnoseit.rules.result.ProblemOccurrence; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.spec.research.open.xtrace.adapters.introscope.source.IntroscopeTraceConverter; import org.spec.research.open.xtrace.api.core.Trace; -import org.spec.research.open.xtrace.shared.TraceConverter; /** * Launcher for rules that analyze a single trace. @@ -27,7 +25,7 @@ public class Launcher { /** * Path to traces that should be analyzed. */ - private static final String INTROSCOPE_FILE = "C:/Users/Alper Hi/Desktop/Universität/Bachelorarbeit/Traces_CA/CA_Trace_Problematic.xml"; + private static final String INTROSCOPE_FILE = "C:/Users/Alper Hi/Desktop/Universit�t/Bachelorarbeit/Traces_CA/CA_Trace_Problematic.xml"; private static final String DYNATRACE_FILE = "path to dynatrace trace file"; @@ -36,9 +34,7 @@ public class Launcher { private static final String KIEKER_FILE = "path to kieker file"; public static void main(String[] args) throws ClassNotFoundException { - TraceConverter converter = new IntroscopeTraceConverter(); - Trace trace = converter.convertTraces(INTROSCOPE_FILE).get(0); - startLauncher(trace); + startLauncher(new TraceCreatorForTesting().createTrace()); } /** From fe0e6167345965b6328acf8800f3a44cdb500c3a Mon Sep 17 00:00:00 2001 From: Albert Flaig Date: Thu, 23 Mar 2017 16:59:43 +0100 Subject: [PATCH 3/3] Renamed diagnoseit.*.gradle to default build.gradle format. Allows external references to this gradle project. --- .../{diagnoseit.root.gradle => build.gradle} | 17 ++++++++++++++--- .../{diagnoseit.rules.gradle => build.gradle} | 0 ...iagnoseit.standalone.gradle => build.gradle} | 3 ++- diagnoseIT/settings.gradle | 13 ------------- 4 files changed, 16 insertions(+), 17 deletions(-) rename diagnoseIT/{diagnoseit.root.gradle => build.gradle} (54%) rename diagnoseIT/diagnoseit.rules/{diagnoseit.rules.gradle => build.gradle} (100%) rename diagnoseIT/diagnoseit.standalone/{diagnoseit.standalone.gradle => build.gradle} (77%) diff --git a/diagnoseIT/diagnoseit.root.gradle b/diagnoseIT/build.gradle similarity index 54% rename from diagnoseIT/diagnoseit.root.gradle rename to diagnoseIT/build.gradle index 49f64b4..43ad581 100644 --- a/diagnoseIT/diagnoseit.root.gradle +++ b/diagnoseIT/build.gradle @@ -1,11 +1,22 @@ -subprojects { +allprojects { apply plugin: 'java' + apply plugin: 'maven' apply plugin: 'eclipse' - version = '0.1' - +} + +subprojects { sourceCompatibility = 1.8 targetCompatibility = 1.8 + + dependencies { + testCompile 'junit:junit:4.8.2' + testCompile 'net.sourceforge.cobertura:cobertura:2.1.1' + } + + version = '0.1.0-SNAPSHOT' + group = 'diagnoseit' + } diff --git a/diagnoseIT/diagnoseit.rules/diagnoseit.rules.gradle b/diagnoseIT/diagnoseit.rules/build.gradle similarity index 100% rename from diagnoseIT/diagnoseit.rules/diagnoseit.rules.gradle rename to diagnoseIT/diagnoseit.rules/build.gradle diff --git a/diagnoseIT/diagnoseit.standalone/diagnoseit.standalone.gradle b/diagnoseIT/diagnoseit.standalone/build.gradle similarity index 77% rename from diagnoseIT/diagnoseit.standalone/diagnoseit.standalone.gradle rename to diagnoseIT/diagnoseit.standalone/build.gradle index dc0a30f..364a457 100644 --- a/diagnoseIT/diagnoseit.standalone/diagnoseit.standalone.gradle +++ b/diagnoseIT/diagnoseit.standalone/build.gradle @@ -1,5 +1,6 @@ dependencies { - compile project(':diagnoseit.ruleengine'), project(':diagnoseit.rules') + compile project(':diagnoseit.ruleengine') + compile project(':diagnoseit.rules') compile files('libs/shared.jar') compile files('libs/adapters.appdynamics.jar') compile files('libs/adapters.dynatrace.jar') diff --git a/diagnoseIT/settings.gradle b/diagnoseIT/settings.gradle index 1722987..2ec9885 100644 --- a/diagnoseIT/settings.gradle +++ b/diagnoseIT/settings.gradle @@ -1,15 +1,2 @@ rootProject.name = "diagnoseit.root" include "diagnoseit.ruleengine","diagnoseit.rules","diagnoseit.standalone" - -/** - * Sets the name of the project build file (and all of its sub-projects) to be "${project.name}.gradle" pattern. - * This is done as the Gradle expects build file to be named build.gradle. - */ -def renameBuildFiles(project){ - project.buildFileName = "${project.name}.gradle" - project.children.each{ childProject -> - renameBuildFiles(childProject) - } -} -renameBuildFiles(rootProject) -