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

minor path resolution fix

parent e30f8a05
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.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Properties; import java.util.Properties;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import kieker.common.configuration.Configuration; import tools.descartes.dql.connector.kieker.configgenerator.XMLGenerationManager;
import tools.descartes.dql.connector.kieker.configgenerator.XMLGenerationManager; import tools.descartes.dql.connector.kieker.filter.KiekerAnalysisController;
import tools.descartes.dql.connector.kieker.filter.KiekerAnalysisController; import tools.descartes.dql.connector.kieker.structures.Trace;
import tools.descartes.dql.connector.kieker.structures.Trace; import tools.descartes.dql.core.engine.util.DQLLogger;
import tools.descartes.dql.core.engine.util.DQLLogger; import tools.descartes.dql.models.mapping.mapping.EntityMapping;
import tools.descartes.dql.models.mapping.mapping.EntityMapping;
/**
/** * The KiekerManager processes an incoming DQL request according to its contents.
* The KiekerManager processes an incoming DQL request according to its contents. * It produces a Kieker Trace file containing the analysis results needed to answer the DQL Query.
* It produces a Kieker Trace file containing the analysis results needed to answer the DQL Query. *
* * @author Matthias Blohm <st140250@stud.uni-stuttgart.de>
* @author Matthias Blohm <st140250@stud.uni-stuttgart.de> */
*/ public class KiekerManager {
public class KiekerManager {
Logger log;
Logger log;
private final EntityMapping request;
private final EntityMapping request; private String modelLocation;
private String modelLocation; private String appDirectory;
private String appDirectory; private String appLocation;
private String appLocation; private String kiekerJarLocation;
private String kiekerJarLocation; private String kiekerConfigLocation;
private String kiekerConfigLocation; private String kiekerLocation;
private String kiekerLocation; private String traceFileOutputPath;
private String traceFileOutputPath; private String traceFileHostName;
private String traceFileHostName;
private Trace analysisResult;
private Trace analysisResult;
int monitoringTimeout = 10;
int monitoringTimeout = 10;
/**
/** * The Class must be initialized with an DQL Query that the manager takes control over.
* The Class must be initialized with an DQL Query that the manager takes control over. *
* * @param request the DQL Query to process with kieker data
* @param request the DQL Query to process with kieker data */
*/ public KiekerManager(EntityMapping request){
public KiekerManager(EntityMapping request){ this.log = DQLLogger.getLogger(KiekerManager.class.getName());
this.log = DQLLogger.getLogger(KiekerManager.class.getName()); this.request = request;
this.request = request; this.modelLocation = request.getModelLocation();
this.modelLocation = request.getModelLocation(); this.analysisResult = new Trace();
this.analysisResult = new Trace(); }
}
/**
/** * By running this method the processing of the query is initiated.
* By running this method the processing of the query is initiated. * The method tries to find a properties fiel under the modelLocation given by the query.
* The method tries to find a properties fiel under the modelLocation given by the query. * If a properties file is found that specifies a folder already containing valid kieker trace files, analysis is triggered directly.
* If a properties file is found that specifies a folder already containing valid kieker trace files, analysis is triggered directly. * Otherwise, tracefiles are searched directly under the path of the model location.
* Otherwise, tracefiles are searched directly under the path of the model location. * If still no tracefiles are found, monitoring with kieker is started first for receiving trace files.
* If still no tracefiles are found, monitoring with kieker is started first for receiving trace files. */
*/ public void run(){
public void run(){ log("Checking location for user config file...");
log("Checking location for user config file..."); if (KiekerHelper.checkPropertiesFileExist(modelLocation)){
if (KiekerHelper.checkPropertiesFileExist(modelLocation)){ log("Valid user config found, start processing...");
log("Valid user config found, start processing..."); Properties prop = KiekerHelper.getProperties(modelLocation);
Properties prop = KiekerHelper.getProperties(modelLocation); this.traceFileOutputPath= (String) prop.get(KiekerHelper.KIEKER_LOG_DIRECTORY);
this.traceFileOutputPath= (String) prop.get(KiekerHelper.KIEKER_LOG_DIRECTORY); traceFileOutputPath = traceFileOutputPath.replace("%20", " "); // fixes
if (!KiekerHelper.checkTraceFilesExist(traceFileOutputPath)){ // space
log("No traceFiles found in specified log directory"); // in
log("Start monitoring"); // path
//do monitoring first // problem
loadMonitoringConfig(prop);
startMonitoring(); if (!KiekerHelper.checkTraceFilesExist(traceFileOutputPath)){
log("Finished monitoring"); log("No traceFiles found in specified log directory");
if (!KiekerHelper.checkTraceFilesExist(traceFileOutputPath)){ log("Start monitoring");
log("Produced traceFiles cannot be found under "+traceFileOutputPath+", aborting..."); //do monitoring first
throw new IllegalStateException( loadMonitoringConfig(prop);
"Could not find any valid Kieker traceFiles under "+traceFileOutputPath); startMonitoring();
} log("Finished monitoring");
} if (!KiekerHelper.checkTraceFilesExist(traceFileOutputPath)){
this.traceFileHostName= (String) prop.get(KiekerHelper.KIEKER_LOG_HOSTNAME); log("Produced traceFiles cannot be found under "+traceFileOutputPath+", aborting...");
if (this.traceFileHostName == ""){ throw new IllegalStateException(
this.traceFileHostName = KiekerHelper.getHostName(); "Could not find any valid Kieker traceFiles under "+traceFileOutputPath);
} }
log("TraceFiles found under "+traceFileOutputPath); }
startAnalysis(); this.traceFileHostName= (String) prop.get(KiekerHelper.KIEKER_LOG_HOSTNAME);
if (this.traceFileHostName == ""){
} else { this.traceFileHostName = KiekerHelper.getHostName();
// no user config, try modelLocation as traceFile directory }
log("No user config found under "+modelLocation); log("TraceFiles found under "+traceFileOutputPath);
log("Search for existent traceFiles instead..."); startAnalysis();
if (!KiekerHelper.checkTraceFilesExist(modelLocation)){
log.error("No traceFiles found under "+modelLocation+", aborting..."); } else {
throw new IllegalStateException( // no user config, try modelLocation as traceFile directory
"Could not find any valid Kieker traceFiles under "+modelLocation); log("No user config found under "+modelLocation);
} else { log("Search for existent traceFiles instead...");
log("TraceFiles possibly found under "+modelLocation); if (!KiekerHelper.checkTraceFilesExist(modelLocation)){
this.traceFileOutputPath = modelLocation; log.error("No traceFiles found under "+modelLocation+", aborting...");
this.traceFileHostName = KiekerHelper.getHostName(); throw new IllegalStateException(
log("Try Analysis..."); "Could not find any valid Kieker traceFiles under "+modelLocation);
startAnalysis(); } else {
} log("TraceFiles possibly found under "+modelLocation);
} this.traceFileOutputPath = modelLocation;
} this.traceFileHostName = KiekerHelper.getHostName();
log("Try Analysis...");
/** startAnalysis();
* This method loads the properties found in the modelLocation into KiekerManager for further processing }
* It first checks whether all required properties can be found and then tries to parse them correctly. }
*/ }
private void loadMonitoringConfig(Properties prop){
log("Loading monitoring properties..."); /**
String[] requiredProperties = new String[]{KiekerHelper.APPLICATION_JAR_FILE,KiekerHelper.KIEKER_JAR_FILE,KiekerHelper.KIEKER_LOCATION,KiekerHelper.KIEKER_CONFIG_DEFAULT_KEY}; * This method loads the properties found in the modelLocation into KiekerManager for further processing
KiekerHelper.checkProperties(prop, requiredProperties); * It first checks whether all required properties can be found and then tries to parse them correctly.
try{ */
private void loadMonitoringConfig(Properties prop){
this.appLocation = (String) prop.get(KiekerHelper.APPLICATION_JAR_FILE); log("Loading monitoring properties...");
this.kiekerJarLocation = (String) prop.get(KiekerHelper.KIEKER_JAR_FILE); String[] requiredProperties = new String[]{KiekerHelper.APPLICATION_JAR_FILE,KiekerHelper.KIEKER_JAR_FILE,KiekerHelper.KIEKER_LOCATION,KiekerHelper.KIEKER_CONFIG_DEFAULT_KEY};
this.kiekerLocation = (String) prop.get(KiekerHelper.KIEKER_LOCATION); KiekerHelper.checkProperties(prop, requiredProperties);
this.appDirectory = (String) prop.get(KiekerHelper.APPLICATION_DIRECTORY); try{
this.monitoringTimeout = Integer.valueOf(prop.getProperty(KiekerHelper.MAX_TIMEOUT_KEY));
this.kiekerConfigLocation = prop.getProperty(KiekerHelper.KIEKER_CONFIG_DEFAULT_KEY); this.appLocation = (String) prop.get(KiekerHelper.APPLICATION_JAR_FILE);
log("Loading monitoring properties finished"); this.kiekerJarLocation = (String) prop.get(KiekerHelper.KIEKER_JAR_FILE);
} catch(Exception e){ this.kiekerLocation = (String) prop.get(KiekerHelper.KIEKER_LOCATION);
log("could not parse Properties-file. Aborting..."); this.appDirectory = (String) prop.get(KiekerHelper.APPLICATION_DIRECTORY);
throw new IllegalStateException("Could not parse properties file under "+modelLocation); this.monitoringTimeout = Integer.valueOf(prop.getProperty(KiekerHelper.MAX_TIMEOUT_KEY));
} this.kiekerConfigLocation = prop.getProperty(KiekerHelper.KIEKER_CONFIG_DEFAULT_KEY);
} log("Loading monitoring properties finished");
} catch(Exception e){
/** log("could not parse Properties-file. Aborting...");
* By calling this method, monitoring is started. throw new IllegalStateException("Could not parse properties file under "+modelLocation);
* If the monitored application does not terminate after the timeout specified in the properties file, }
* monitoring is terminated. }
* This method triggers both resource and application monitoring.
*/ /**
private void startMonitoring(){ * By calling this method, monitoring is started.
log("Creating monitoring configurations..."); * If the monitored application does not terminate after the timeout specified in the properties file,
KiekerHelper.createNewOutPutPath(traceFileOutputPath); * monitoring is terminated.
KiekerHelper.setMonitoringProperties(kiekerConfigLocation, traceFileOutputPath); * This method triggers both resource and application monitoring.
*/
ArrayList<String> services = KiekerHelper.getComponentIdentifiers(request); private void startMonitoring(){
// Config Generation log("Creating monitoring configurations...");
if (!XMLGenerationManager.generateDefaultXML(services, appDirectory+File.separator+"META-INF")) { KiekerHelper.createNewOutPutPath(traceFileOutputPath);
log("Warning: Config could not be created"); KiekerHelper.setMonitoringProperties(kiekerConfigLocation, traceFileOutputPath);
}
log("Start monitoring for "+monitoringTimeout +" seconds..."); ArrayList<String> services = KiekerHelper.getComponentIdentifiers(request);
Process p; // Config Generation
try { if (!XMLGenerationManager.generateDefaultXML(services, appDirectory+File.separator+"META-INF")) {
ResourceMonitor.startResourceMonitor(kiekerLocation,appDirectory); log("Warning: Config could not be created");
String command = "java -javaagent:" + kiekerJarLocation + " -jar " + appLocation; }
p = Runtime.getRuntime() log("Start monitoring for "+monitoringTimeout +" seconds...");
.exec(command); Process p;
String line; try {
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); ResourceMonitor.startResourceMonitor(kiekerLocation,appDirectory);
/*while ((line = in.readLine()) != null) { String command = "java -javaagent:" + kiekerJarLocation + " -jar " + appLocation;
System.out.println(line); p = Runtime.getRuntime()
}*/ .exec(command);
in.close(); String line;
} catch (Exception e) { BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
log(e.getMessage()); /*while ((line = in.readLine()) != null) {
e.printStackTrace(); System.out.println(line);
throw new IllegalStateException("Could not execute application with kieker"); }*/
} in.close();
} catch (Exception e) {
// warten bis timeout log(e.getMessage());
try { e.printStackTrace();
Thread.sleep(monitoringTimeout * 1000); throw new IllegalStateException("Could not execute application with kieker");
p.destroy(); }
ResourceMonitor.stopRessourceMonitor();
} catch (InterruptedException e) { // warten bis timeout
e.printStackTrace(); try {
} Thread.sleep(monitoringTimeout * 1000);
log("Monitoring terminated"); p.destroy();
} ResourceMonitor.stopRessourceMonitor();
} catch (InterruptedException e) {
/** e.printStackTrace();
* By calling this method, analysis is started. }
* Therefore a kieker analysis configuration is created based on the request, which is then passed to an instance of KiekerAnalysisController. log("Monitoring terminated");
*/ }
private void startAnalysis(){
log("Starting analysis..."); /**
try{ * By calling this method, analysis is started.
Configuration analysisConfiguration = KiekerHelper.createAnalysisConfig(request, traceFileOutputPath,traceFileHostName); * Therefore a kieker analysis configuration is created based on the request, which is then passed to an instance of KiekerAnalysisController.
*/
KiekerAnalysisController c = new KiekerAnalysisController(analysisConfiguration); private void startAnalysis(){
c.fillTrace(); log("Starting analysis...");
this.analysisResult = c.getTrace(); try{
this.analysisResult.sortChronological(); Configuration analysisConfiguration = KiekerHelper.createAnalysisConfig(request, traceFileOutputPath,traceFileHostName);
} catch(Exception e){
log("Unable to analyze traceFiles!"); KiekerAnalysisController c = new KiekerAnalysisController(analysisConfiguration);
throw new IllegalStateException("Analyzing Kieker traceFiles failed"); c.fillTrace();
} this.analysisResult = c.getTrace();
log("Analysis finished"); this.analysisResult.sortChronological();
} } catch(Exception e){
log("Unable to analyze traceFiles!");
/** throw new IllegalStateException("Analyzing Kieker traceFiles failed");
* Gives back the analysis result as a Kieker Trace containing the relevant data passed through the filters. }
* Only call after the run() method has been executed, otherwise the result will be empty. log("Analysis finished");
* }
* @return the analysis result as a filtered Kieker Trace
*/ /**
public Trace getAnalysisResult(){ * Gives back the analysis result as a Kieker Trace containing the relevant data passed through the filters.
return this.analysisResult; * Only call after the run() method has been executed, otherwise the result will be empty.
} *
* @return the analysis result as a filtered Kieker Trace
/** */
* Gives back the timestamp of the first event occuring in the trace files. public Trace getAnalysisResult(){
* It is used for displaying any following records relatively to the first one. return this.analysisResult;
* This way Pavo's timeline can start at zero. }
*
* @return the timestamp of the first captured event in ns /**
*/ * Gives back the timestamp of the first event occuring in the trace files.
public long getStartingTime(){ * It is used for displaying any following records relatively to the first one.
long firstEvent = Long.MAX_VALUE; * This way Pavo's timeline can start at zero.
long firstResource = Long.MAX_VALUE; *
if (this.analysisResult.getEvents() != null && this.analysisResult.getEvents().size()>0){ * @return the timestamp of the first captured event in ns
firstEvent = this.analysisResult.getEvents().get(0).getTimestamp(); */
} public long getStartingTime(){
if (this.analysisResult.getResources() != null && this.analysisResult.getResources().size()>0){ long firstEvent = Long.MAX_VALUE;
firstResource = this.analysisResult.getResources().get(0).getTimestamp(); long firstResource = Long.MAX_VALUE;
} if (this.analysisResult.getEvents() != null && this.analysisResult.getEvents().size()>0){
return Math.min(firstEvent, firstResource); firstEvent = this.analysisResult.getEvents().get(0).getTimestamp();
} }
if (this.analysisResult.getResources() != null && this.analysisResult.getResources().size()>0){
/** firstResource = this.analysisResult.getResources().get(0).getTimestamp();
* private method for logging events happening in KiekerManager }
*/ return Math.min(firstEvent, firstResource);
private void log(String msg){ }
log.info(msg);
} /**
* private method for logging events happening in KiekerManager
*/
} private void log(String msg){
log.info(msg);
}
}
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