Skip to content
Snippets Groups Projects
Commit feb29450 authored by Jürgen Walter's avatar Jürgen Walter
Browse files

Fixed component string decomposition

Previous implementation had errors e.g. for
org.springframework.samples.petclinic.web.VetController.showVetList(java.util.Map)
parent cb9aa759
No related branches found
No related tags found
No related merge requests found
package tools.descartes.dql.connector.kieker; package tools.descartes.dql.connector.kieker;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FilenameFilter; import java.io.FilenameFilter;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.regex.Pattern;
import org.apache.log4j.Logger;
import org.eclipse.emf.common.util.EList; import org.apache.log4j.Logger;
import org.eclipse.emf.common.util.EList;
import kieker.common.configuration.Configuration;
import tools.descartes.dql.connector.kieker.structures.Component; import kieker.common.configuration.Configuration;
import tools.descartes.dql.connector.kieker.structures.Resource; import tools.descartes.dql.connector.kieker.structures.Component;
import tools.descartes.dql.connector.kieker.structures.Trace; import tools.descartes.dql.connector.kieker.structures.Resource;
import tools.descartes.dql.connector.kieker.structures.identifier.ResourceIdentifier; import tools.descartes.dql.connector.kieker.structures.Trace;
import tools.descartes.dql.connector.kieker.structures.records.EventRecord; import tools.descartes.dql.connector.kieker.structures.identifier.ResourceIdentifier;
import tools.descartes.dql.connector.kieker.structures.records.ResourceRecord; import tools.descartes.dql.connector.kieker.structures.records.EventRecord;
import tools.descartes.dql.core.engine.util.DQLLogger; import tools.descartes.dql.connector.kieker.structures.records.ResourceRecord;
import tools.descartes.dql.models.mapping.domain.ContinuousSeriesResult; import tools.descartes.dql.core.engine.util.DQLLogger;
import tools.descartes.dql.models.mapping.domain.DomainFactory; import tools.descartes.dql.models.mapping.domain.ContinuousSeriesResult;
import tools.descartes.dql.models.mapping.domain.Entity; import tools.descartes.dql.models.mapping.domain.DomainFactory;
import tools.descartes.dql.models.mapping.domain.Probe; import tools.descartes.dql.models.mapping.domain.Entity;
import tools.descartes.dql.models.mapping.domain.SeriesResultElement; import tools.descartes.dql.models.mapping.domain.Probe;
import tools.descartes.dql.models.mapping.domain.StatType; import tools.descartes.dql.models.mapping.domain.SeriesResultElement;
import tools.descartes.dql.models.mapping.mapping.EntityMapping; import tools.descartes.dql.models.mapping.domain.StatType;
import tools.descartes.dql.models.mapping.mapping.EntityMapping;
/**
* The KiekerHelper supports processing a DQL query for Kieker. /**
* It contains smaller computations or parsings like path checks or result conversion. * The KiekerHelper supports processing a DQL query for Kieker.
* Static use of this class. * It contains smaller computations or parsings like path checks or result conversion.
* * Static use of this class.
* @author Matthias Blohm <st140250@stud.uni-stuttgart.de> *
*/ * @author Matthias Blohm <st140250@stud.uni-stuttgart.de>
public class KiekerHelper { */
public class KiekerHelper {
public static final String MAX_TIMEOUT_KEY = "kieker.maxRunTimeInSeconds";
public static final String KIEKER_CONFIG_DEFAULT_KEY = "kieker.monitoring.default.properties"; public static final String MAX_TIMEOUT_KEY = "kieker.maxRunTimeInSeconds";
public static final String APPLICATION_JAR_FILE = "kieker.applicationJarFile"; public static final String KIEKER_CONFIG_DEFAULT_KEY = "kieker.monitoring.default.properties";
public static final String KIEKER_JAR_FILE = "kieker.kiekerJarFile"; public static final String APPLICATION_JAR_FILE = "kieker.applicationJarFile";
public static final String KIEKER_LOCATION = "kieker.kiekerLocation"; public static final String KIEKER_JAR_FILE = "kieker.kiekerJarFile";
public static final String APPLICATION_DIRECTORY = "kieker.modelLocation"; public static final String KIEKER_LOCATION = "kieker.kiekerLocation";
public static final String KIEKER_LOG_DIRECTORY = "kieker.log.directory"; public static final String APPLICATION_DIRECTORY = "kieker.modelLocation";
public static final String KIEKER_LOG_HOSTNAME = "kieker.log.hostname"; public static final String KIEKER_LOG_DIRECTORY = "kieker.log.directory";
public static final String KIEKER_MANIFEST_DIRECTORY = "kieker.monitoring.default.properties"; public static final String KIEKER_LOG_HOSTNAME = "kieker.log.hostname";
public static final String KIEKER_MANIFEST_DIRECTORY = "kieker.monitoring.default.properties";
public static final String METRIC_UTILIZATION = "utilization";
public static final String METRIC_RESPONSE_TIME = "responseTime"; public static final String METRIC_UTILIZATION = "utilization";
public static final String METRIC_THROUGHPUT = "throughput"; public static final String METRIC_RESPONSE_TIME = "responseTime";
public static final String METRIC_THROUGHPUT = "throughput";
private static final Logger log = DQLLogger.getLogger(KiekerHelper.class.getName());
private static final Logger log = DQLLogger.getLogger(KiekerHelper.class.getName());
/**
* This method checks whether a set of required keys are available in the properties file /**
* If not, processing is aborted and an exception is thrown. * This method checks whether a set of required keys are available in the properties file
* * If not, processing is aborted and an exception is thrown.
* @throws RuntimeException *
*/ * @throws RuntimeException
public static void checkProperties(final Properties properties, */
final String[] keys) { public static void checkProperties(final Properties properties,
for (final String key : keys) { final String[] keys) {
if (properties.get(key) == null) { for (final String key : keys) {
final String msg = "Required key in properties missing: " + key; if (properties.get(key) == null) {
final String msg = "Required key in properties missing: " + key;
log.error(msg);
throw new RuntimeException(msg); log.error(msg);
} throw new RuntimeException(msg);
} }
} }
}
public static boolean checkPropertiesFileExist(final String propertiesLocation){
String extension = ""; public static boolean checkPropertiesFileExist(final String propertiesLocation){
String extension = "";
int i = propertiesLocation.lastIndexOf('.');
if (i >= 0) { int i = propertiesLocation.lastIndexOf('.');
extension = propertiesLocation.substring(i+1); if (i >= 0) {
} extension = propertiesLocation.substring(i+1);
if (!extension.equals("properties")){ }
return false; if (!extension.equals("properties")){
} return false;
}
File file = new File(propertiesLocation);
final Properties properties = new Properties(); File file = new File(propertiesLocation);
if (file == null || !file.exists()) { final Properties properties = new Properties();
return false; if (file == null || !file.exists()) {
} return false;
try { }
properties.load(new FileInputStream(file)); try {
return true; properties.load(new FileInputStream(file));
} catch (final IOException e) { return true;
return false; } catch (final IOException e) {
} return false;
} }
}
public static Properties loadKiekerProperties(final String propertiesLocation) {
final Properties properties = new Properties(); public static Properties loadKiekerProperties(final String propertiesLocation) {
File file = new File(propertiesLocation); final Properties properties = new Properties();
File file = new File(propertiesLocation);
if (file == null || !file.exists()) {
throw new IllegalStateException( if (file == null || !file.exists()) {
"Could not find referenced .properties file"); throw new IllegalStateException(
} "Could not find referenced .properties file");
}
try {
properties.load(new FileInputStream(file)); try {
} catch (final IOException e) { properties.load(new FileInputStream(file));
throw new IllegalStateException( } catch (final IOException e) {
"Could not load properties instance"); throw new IllegalStateException(
} "Could not load properties instance");
return properties; }
} return properties;
}
public static void setMonitoringProperties(String kiekerConfigLocation, String outputPath){
Properties kiekerProperties = KiekerHelper.loadKiekerProperties(kiekerConfigLocation); public static void setMonitoringProperties(String kiekerConfigLocation, String outputPath){
Properties kiekerProperties = KiekerHelper.loadKiekerProperties(kiekerConfigLocation);
kiekerProperties.setProperty("kieker.monitoring.writer.filesystem.AsyncFsWriter.customStoragePath",
outputPath); kiekerProperties.setProperty("kieker.monitoring.writer.filesystem.AsyncFsWriter.customStoragePath",
try { outputPath);
String newConfigPath = new File(kiekerConfigLocation).getParent() + "/kieker.monitoring.properties"; try {
System.out.println(new File(kiekerConfigLocation).getParent()); String newConfigPath = new File(kiekerConfigLocation).getParent() + "/kieker.monitoring.properties";
kiekerProperties.store(new FileOutputStream(newConfigPath), ""); System.out.println(new File(kiekerConfigLocation).getParent());
} catch (FileNotFoundException e1) { kiekerProperties.store(new FileOutputStream(newConfigPath), "");
e1.printStackTrace(); } catch (FileNotFoundException e1) {
} catch (IOException e1) { e1.printStackTrace();
e1.printStackTrace(); } catch (IOException e1) {
} e1.printStackTrace();
} }
}
public static Properties getProperties(final String propertiesLocation) {
final Properties properties = new Properties(); public static Properties getProperties(final String propertiesLocation) {
File file = new File(propertiesLocation); final Properties properties = new Properties();
String propertiesFolder = new File(file.getAbsolutePath()).getParent(); File file = new File(propertiesLocation);
String propertiesFolder = new File(file.getAbsolutePath()).getParent();
if (file == null || !file.exists()) {
throw new IllegalStateException( if (file == null || !file.exists()) {
"Specified file in USING not accessible, unable to execute the query further. Aborting."); throw new IllegalStateException(
} "Specified file in USING not accessible, unable to execute the query further. Aborting.");
}
try {
properties.load(new FileInputStream(file)); try {
File dummyFile; properties.load(new FileInputStream(file));
String applicationFolder = ""; File dummyFile;
if (properties.get(APPLICATION_JAR_FILE) != null){ String applicationFolder = "";
dummyFile = new File(properties.get(APPLICATION_JAR_FILE).toString()); if (properties.get(APPLICATION_JAR_FILE) != null){
dummyFile = new File(properties.get(APPLICATION_JAR_FILE).toString());
if (!dummyFile.isAbsolute()) {
properties.setProperty(APPLICATION_JAR_FILE, propertiesFolder+File.separator+ properties.get(APPLICATION_JAR_FILE)); if (!dummyFile.isAbsolute()) {
} properties.setProperty(APPLICATION_JAR_FILE, propertiesFolder+File.separator+ properties.get(APPLICATION_JAR_FILE));
}
dummyFile = new File(properties.get(APPLICATION_JAR_FILE).toString());
if (!dummyFile.exists()){ dummyFile = new File(properties.get(APPLICATION_JAR_FILE).toString());
throw new IllegalStateException( if (!dummyFile.exists()){
"Could not find target application jar under "+dummyFile.getAbsolutePath()); throw new IllegalStateException(
} "Could not find target application jar under "+dummyFile.getAbsolutePath());
applicationFolder = new File(dummyFile.getAbsolutePath()).getParent(); }
} applicationFolder = new File(dummyFile.getAbsolutePath()).getParent();
}
if (properties.get(KIEKER_CONFIG_DEFAULT_KEY) != null){
dummyFile = new File(properties.get(KIEKER_CONFIG_DEFAULT_KEY).toString()); if (properties.get(KIEKER_CONFIG_DEFAULT_KEY) != null){
if (!dummyFile.isAbsolute()) { dummyFile = new File(properties.get(KIEKER_CONFIG_DEFAULT_KEY).toString());
properties.setProperty(KIEKER_CONFIG_DEFAULT_KEY, applicationFolder+File.separator+ properties.get(KIEKER_CONFIG_DEFAULT_KEY)); if (!dummyFile.isAbsolute()) {
} properties.setProperty(KIEKER_CONFIG_DEFAULT_KEY, applicationFolder+File.separator+ properties.get(KIEKER_CONFIG_DEFAULT_KEY));
dummyFile = new File(properties.get(KIEKER_CONFIG_DEFAULT_KEY).toString()); }
if (!dummyFile.exists()){ dummyFile = new File(properties.get(KIEKER_CONFIG_DEFAULT_KEY).toString());
throw new IllegalStateException( if (!dummyFile.exists()){
"Could not find default monitoring properties file under "+dummyFile.getAbsolutePath()); throw new IllegalStateException(
} "Could not find default monitoring properties file under "+dummyFile.getAbsolutePath());
} }
if (properties.get(KIEKER_LOG_DIRECTORY) != null){ }
dummyFile = new File(properties.get(KIEKER_LOG_DIRECTORY).toString()); if (properties.get(KIEKER_LOG_DIRECTORY) != null){
if (!dummyFile.isAbsolute()) { dummyFile = new File(properties.get(KIEKER_LOG_DIRECTORY).toString());
properties.setProperty(KIEKER_LOG_DIRECTORY, propertiesFolder+File.separator+ properties.get(KIEKER_LOG_DIRECTORY)); if (!dummyFile.isAbsolute()) {
} properties.setProperty(KIEKER_LOG_DIRECTORY, propertiesFolder+File.separator+ properties.get(KIEKER_LOG_DIRECTORY));
} }
if (properties.get(KIEKER_LOCATION) != null){ }
String kiekerLocation = properties.get(KIEKER_LOCATION).toString(); if (properties.get(KIEKER_LOCATION) != null){
dummyFile = new File(kiekerLocation); String kiekerLocation = properties.get(KIEKER_LOCATION).toString();
if (!dummyFile.exists()){ dummyFile = new File(kiekerLocation);
throw new IllegalStateException( if (!dummyFile.exists()){
"Could not find Kieker distribution under "+dummyFile.getAbsolutePath()); throw new IllegalStateException(
} "Could not find Kieker distribution under "+dummyFile.getAbsolutePath());
if (!dummyFile.isAbsolute()) { }
kiekerLocation = propertiesFolder+File.separator+ properties.get(KIEKER_LOCATION); if (!dummyFile.isAbsolute()) {
properties.setProperty(KIEKER_LOCATION, kiekerLocation); kiekerLocation = propertiesFolder+File.separator+ properties.get(KIEKER_LOCATION);
} properties.setProperty(KIEKER_LOCATION, kiekerLocation);
String aspectLocation = kiekerLocation + File.separator+"build"+File.separator+"libs"; }
String[] files = getAspectJarPath(aspectLocation); String aspectLocation = kiekerLocation + File.separator+"build"+File.separator+"libs";
if (files != null && files.length > 0){ String[] files = getAspectJarPath(aspectLocation);
properties.setProperty(KIEKER_JAR_FILE,aspectLocation+File.separator+ files[0]); if (files != null && files.length > 0){
} properties.setProperty(KIEKER_JAR_FILE,aspectLocation+File.separator+ files[0]);
}
}
properties.setProperty(APPLICATION_DIRECTORY, applicationFolder); }
} catch (final IOException e) { properties.setProperty(APPLICATION_DIRECTORY, applicationFolder);
throw new IllegalStateException( } catch (final IOException e) {
"Could not load properties instance from specified model location in USING clause"); throw new IllegalStateException(
} "Could not load properties instance from specified model location in USING clause");
}
return properties;
} return properties;
}
public static SeriesResultElement getSeriesResultElement(long timeStamp, double value, long firstTimestamp){
SeriesResultElement e = DomainFactory.eINSTANCE.createSeriesResultElement(); public static SeriesResultElement getSeriesResultElement(long timeStamp, double value, long firstTimestamp){
// convert ts to millis SeriesResultElement e = DomainFactory.eINSTANCE.createSeriesResultElement();
BigDecimal time = new BigDecimal( // convert ts to millis
((timeStamp - firstTimestamp) / 1000000.0)); BigDecimal time = new BigDecimal(
BigDecimal resVal = new BigDecimal(value); ((timeStamp - firstTimestamp) / 1000000.0));
e.setX(time); BigDecimal resVal = new BigDecimal(value);
e.setY(resVal); e.setX(time);
return e; e.setY(resVal);
} return e;
}
public static String getComponentString (String identifier){
String component = identifier; public static String getComponentString (String identifier){
if (identifier.indexOf('(')>0 && identifier.indexOf(')')>0){ String component = identifier;
String[] parts = identifier.split("\\."); if(identifier.contains("(")){
component = identifier.substring(0,(identifier.length()-parts[parts.length-1].length())-1); component = identifier.split(Pattern.quote("("))[0]; // cut off method parameters
} component = component.substring(0, component.lastIndexOf(".")); // cut off method
return component; }
} return component;
}
public static ArrayList<String> getComponentIdentifiers(EntityMapping request) {
HashSet<String> components = new HashSet<>(); public static ArrayList<String> getComponentIdentifiers(EntityMapping request) {
for (Entity service : request.getEntities()) { HashSet<String> components = new HashSet<>();
if (service.getEntityType().equals("SERVICE")){ for (Entity service : request.getEntities()) {
String identifier = service.getIdentifier(); if (service.getEntityType().equals("SERVICE")){
String component = getComponentString(identifier); String identifier = service.getIdentifier();
components.add(component); String component = getComponentString(identifier);
} components.add(component);
}
}
return new ArrayList<String>(components); }
} return new ArrayList<String>(components);
}
public static ArrayList<String> getResourceIdentifiers(EntityMapping request) {
ArrayList<String> resources = new ArrayList<>(); public static ArrayList<String> getResourceIdentifiers(EntityMapping request) {
for (Entity resource : request.getEntities()) { ArrayList<String> resources = new ArrayList<>();
if (resource.getEntityType().equals("RESOURCE")) for (Entity resource : request.getEntities()) {
resources.add(resource.getIdentifier()); if (resource.getEntityType().equals("RESOURCE"))
} resources.add(resource.getIdentifier());
return resources; }
} return resources;
}
public static Configuration createAnalysisConfig(EntityMapping request, String outputPath, String hostname){
File[] traceFolders = KiekerHelper.getTraceFolders(outputPath); public static Configuration createAnalysisConfig(EntityMapping request, String outputPath, String hostname){
Configuration readerConfig = new Configuration(); File[] traceFolders = KiekerHelper.getTraceFolders(outputPath);
Configuration readerConfig = new Configuration();
for (int i = 0; i< traceFolders.length; i++){
readerConfig.setProperty("TRACE_"+i, traceFolders[i].getAbsolutePath()); for (int i = 0; i< traceFolders.length; i++){
} readerConfig.setProperty("TRACE_"+i, traceFolders[i].getAbsolutePath());
}
for (Entity e : request.getEntities()) {
if (e.getEntityType().equals("RESOURCE")){ for (Entity e : request.getEntities()) {
String r_id = e.getIdentifier(); if (e.getEntityType().equals("RESOURCE")){
String r_value = hostname; String r_id = e.getIdentifier();
readerConfig.setProperty("RESOURCE_"+r_id, r_value); String r_value = hostname;
} readerConfig.setProperty("RESOURCE_"+r_id, r_value);
} }
}
int i = 0;
for (Entity e : request.getEntities()) { int i = 0;
if (e.getEntityType().equals("SERVICE")) { for (Entity e : request.getEntities()) {
String component = getComponentString(e.getIdentifier()); if (e.getEntityType().equals("SERVICE")) {
String identifier = hostname + " & " + component; String component = getComponentString(e.getIdentifier());
readerConfig.setProperty("COMPONENT_c" + i, identifier); String identifier = hostname + " & " + component;
i++; readerConfig.setProperty("COMPONENT_c" + i, identifier);
} i++;
} }
return readerConfig; }
} return readerConfig;
}
public static String[] getAspectJarPath(String kiekerLocation) {
File file = new File(kiekerLocation); public static String[] getAspectJarPath(String kiekerLocation) {
String[] files = file.list(new FilenameFilter() { File file = new File(kiekerLocation);
@Override String[] files = file.list(new FilenameFilter() {
public boolean accept(File current, String name) { @Override
return new File(current, name).getName().contains("aspect"); public boolean accept(File current, String name) {
} return new File(current, name).getName().contains("aspect");
}); }
return files; });
} return files;
}
public static File[] getTraceFolders(String path) {
File file = new File(path); public static File[] getTraceFolders(String path) {
File[] directories = file.listFiles(new FilenameFilter() { File file = new File(path);
@Override File[] directories = file.listFiles(new FilenameFilter() {
public boolean accept(File current, String name) { @Override
return new File(current, name).isDirectory(); public boolean accept(File current, String name) {
} return new File(current, name).isDirectory();
}); }
if (directories.length > 0){ });
return directories; if (directories.length > 0){
} return directories;
// if no folders found, files might be directly under this path and not in a subfolder }
File[] files = file.listFiles(new FilenameFilter() { // if no folders found, files might be directly under this path and not in a subfolder
@Override File[] files = file.listFiles(new FilenameFilter() {
public boolean accept(File current, String name) { @Override
return (name.endsWith(".map") || name.endsWith(".dat")); public boolean accept(File current, String name) {
} return (name.endsWith(".map") || name.endsWith(".dat"));
}); }
if (files.length > 1){ });
directories = new File[]{file}; if (files.length > 1){
} directories = new File[]{file};
return directories; }
} return directories;
}
public static String getHostName(){
String host = ""; public static String getHostName(){
try { String host = "";
host = InetAddress.getLocalHost().getHostName(); try {
} catch (UnknownHostException e) { host = InetAddress.getLocalHost().getHostName();
e.printStackTrace(); } catch (UnknownHostException e) {
} e.printStackTrace();
return host; }
} return host;
}
public static String getNewOutPutPath(String standardBatPath) {
standardBatPath += File.separator + "logs"; public static String getNewOutPutPath(String standardBatPath) {
File logFolder = new File(standardBatPath); standardBatPath += File.separator + "logs";
if (!logFolder.exists()) { File logFolder = new File(standardBatPath);
logFolder.mkdir(); if (!logFolder.exists()) {
logFolder.mkdirs(); logFolder.mkdir();
} logFolder.mkdirs();
int i = 1; }
File subLogFolder = null; int i = 1;
do { File subLogFolder = null;
subLogFolder = new File(logFolder, "run" + i); do {
i++; subLogFolder = new File(logFolder, "run" + i);
} while (subLogFolder.exists()); i++;
subLogFolder.mkdir(); } while (subLogFolder.exists());
subLogFolder.mkdirs(); subLogFolder.mkdir();
return subLogFolder.getAbsolutePath(); subLogFolder.mkdirs();
} return subLogFolder.getAbsolutePath();
}
public static void createNewOutPutPath(String newPath) {
File logFolder = new File(newPath); public static void createNewOutPutPath(String newPath) {
if (!logFolder.exists()) { File logFolder = new File(newPath);
logFolder.mkdir(); if (!logFolder.exists()) {
logFolder.mkdirs(); logFolder.mkdir();
} logFolder.mkdirs();
} }
}
public static boolean checkTraceFilesExist(String path){
File file = new File(path); public static boolean checkTraceFilesExist(String path){
if (!file.exists() || ! file.isDirectory()){ File file = new File(path);
return false; if (!file.exists() || ! file.isDirectory()){
} return false;
File[] folders = getTraceFolders(path); }
if (folders.length>0){ File[] folders = getTraceFolders(path);
return true; if (folders.length>0){
} else { return true;
return false; } else {
} return false;
} }
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment