From feb2945090a17039ca0b084838896954b1c3f03c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Walter?= <juergen.walter@uni-wuerzburg.de> Date: Tue, 3 Jan 2017 15:26:21 +0100 Subject: [PATCH] Fixed component string decomposition Previous implementation had errors e.g. for org.springframework.samples.petclinic.web.VetController.showVetList(java.util.Map) --- .../dql/connector/kieker/KiekerHelper.java | 769 +++++++++--------- 1 file changed, 385 insertions(+), 384 deletions(-) diff --git a/tools.descartes.dql.connector.kieker/src/tools/descartes/dql/connector/kieker/KiekerHelper.java b/tools.descartes.dql.connector.kieker/src/tools/descartes/dql/connector/kieker/KiekerHelper.java index 89de58d..7470b5d 100644 --- a/tools.descartes.dql.connector.kieker/src/tools/descartes/dql/connector/kieker/KiekerHelper.java +++ b/tools.descartes.dql.connector.kieker/src/tools/descartes/dql/connector/kieker/KiekerHelper.java @@ -1,384 +1,385 @@ -package tools.descartes.dql.connector.kieker; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.FilenameFilter; -import java.io.IOException; -import java.math.BigDecimal; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -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 tools.descartes.dql.connector.kieker.structures.Resource; -import tools.descartes.dql.connector.kieker.structures.Trace; -import tools.descartes.dql.connector.kieker.structures.identifier.ResourceIdentifier; -import tools.descartes.dql.connector.kieker.structures.records.EventRecord; -import tools.descartes.dql.connector.kieker.structures.records.ResourceRecord; -import tools.descartes.dql.core.engine.util.DQLLogger; -import tools.descartes.dql.models.mapping.domain.ContinuousSeriesResult; -import tools.descartes.dql.models.mapping.domain.DomainFactory; -import tools.descartes.dql.models.mapping.domain.Entity; -import tools.descartes.dql.models.mapping.domain.Probe; -import tools.descartes.dql.models.mapping.domain.SeriesResultElement; -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. - * Static use of this class. - * - * @author Matthias Blohm <st140250@stud.uni-stuttgart.de> - */ -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 APPLICATION_JAR_FILE = "kieker.applicationJarFile"; - public static final String KIEKER_JAR_FILE = "kieker.kiekerJarFile"; - public static final String KIEKER_LOCATION = "kieker.kiekerLocation"; - public static final String APPLICATION_DIRECTORY = "kieker.modelLocation"; - public static final String KIEKER_LOG_DIRECTORY = "kieker.log.directory"; - 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_THROUGHPUT = "throughput"; - - 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. - * - * @throws RuntimeException - */ - public static void checkProperties(final Properties properties, - final String[] keys) { - for (final String key : keys) { - if (properties.get(key) == null) { - final String msg = "Required key in properties missing: " + key; - - log.error(msg); - throw new RuntimeException(msg); - } - } - } - - public static boolean checkPropertiesFileExist(final String propertiesLocation){ - String extension = ""; - - int i = propertiesLocation.lastIndexOf('.'); - if (i >= 0) { - extension = propertiesLocation.substring(i+1); - } - if (!extension.equals("properties")){ - return false; - } - - File file = new File(propertiesLocation); - final Properties properties = new Properties(); - if (file == null || !file.exists()) { - return false; - } - try { - properties.load(new FileInputStream(file)); - return true; - } catch (final IOException e) { - return false; - } - } - - - public static Properties loadKiekerProperties(final String propertiesLocation) { - final Properties properties = new Properties(); - File file = new File(propertiesLocation); - - if (file == null || !file.exists()) { - throw new IllegalStateException( - "Could not find referenced .properties file"); - } - - try { - properties.load(new FileInputStream(file)); - } catch (final IOException e) { - throw new IllegalStateException( - "Could not load properties instance"); - } - return properties; - } - - public static void setMonitoringProperties(String kiekerConfigLocation, String outputPath){ - Properties kiekerProperties = KiekerHelper.loadKiekerProperties(kiekerConfigLocation); - - kiekerProperties.setProperty("kieker.monitoring.writer.filesystem.AsyncFsWriter.customStoragePath", - outputPath); - try { - String newConfigPath = new File(kiekerConfigLocation).getParent() + "/kieker.monitoring.properties"; - System.out.println(new File(kiekerConfigLocation).getParent()); - kiekerProperties.store(new FileOutputStream(newConfigPath), ""); - } catch (FileNotFoundException e1) { - e1.printStackTrace(); - } catch (IOException e1) { - e1.printStackTrace(); - } - } - - - public static Properties getProperties(final String propertiesLocation) { - final Properties properties = new Properties(); - File file = new File(propertiesLocation); - String propertiesFolder = new File(file.getAbsolutePath()).getParent(); - - if (file == null || !file.exists()) { - throw new IllegalStateException( - "Specified file in USING not accessible, unable to execute the query further. Aborting."); - } - - try { - properties.load(new FileInputStream(file)); - File dummyFile; - String applicationFolder = ""; - 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)); - } - - dummyFile = new File(properties.get(APPLICATION_JAR_FILE).toString()); - if (!dummyFile.exists()){ - throw new IllegalStateException( - "Could not find target application jar under "+dummyFile.getAbsolutePath()); - } - 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 (!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()){ - 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 (!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(); - dummyFile = new File(kiekerLocation); - if (!dummyFile.exists()){ - throw new IllegalStateException( - "Could not find Kieker distribution under "+dummyFile.getAbsolutePath()); - } - if (!dummyFile.isAbsolute()) { - 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); - 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) { - throw new IllegalStateException( - "Could not load properties instance from specified model location in USING clause"); - } - - - return properties; - } - - - - - - public static SeriesResultElement getSeriesResultElement(long timeStamp, double value, long firstTimestamp){ - SeriesResultElement e = DomainFactory.eINSTANCE.createSeriesResultElement(); - // convert ts to millis - BigDecimal time = new BigDecimal( - ((timeStamp - firstTimestamp) / 1000000.0)); - BigDecimal resVal = new BigDecimal(value); - e.setX(time); - e.setY(resVal); - return e; - } - - public static String getComponentString (String identifier){ - String component = identifier; - if (identifier.indexOf('(')>0 && identifier.indexOf(')')>0){ - String[] parts = identifier.split("\\."); - component = identifier.substring(0,(identifier.length()-parts[parts.length-1].length())-1); - } - return component; - } - - public static ArrayList<String> getComponentIdentifiers(EntityMapping request) { - HashSet<String> components = new HashSet<>(); - for (Entity service : request.getEntities()) { - if (service.getEntityType().equals("SERVICE")){ - String identifier = service.getIdentifier(); - String component = getComponentString(identifier); - components.add(component); - } - - } - return new ArrayList<String>(components); - } - - public static ArrayList<String> getResourceIdentifiers(EntityMapping request) { - ArrayList<String> resources = new ArrayList<>(); - for (Entity resource : request.getEntities()) { - if (resource.getEntityType().equals("RESOURCE")) - resources.add(resource.getIdentifier()); - } - return resources; - } - - - public static Configuration createAnalysisConfig(EntityMapping request, String outputPath, String hostname){ - 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 (Entity e : request.getEntities()) { - if (e.getEntityType().equals("RESOURCE")){ - String r_id = e.getIdentifier(); - String r_value = hostname; - readerConfig.setProperty("RESOURCE_"+r_id, r_value); - } - } - - int i = 0; - for (Entity e : request.getEntities()) { - if (e.getEntityType().equals("SERVICE")) { - String component = getComponentString(e.getIdentifier()); - String identifier = hostname + " & " + component; - readerConfig.setProperty("COMPONENT_c" + i, identifier); - i++; - } - } - return readerConfig; - } - - - - public static String[] getAspectJarPath(String kiekerLocation) { - File file = new File(kiekerLocation); - String[] files = file.list(new FilenameFilter() { - @Override - public boolean accept(File current, String name) { - return new File(current, name).getName().contains("aspect"); - } - }); - return files; - } - - - - public static File[] getTraceFolders(String path) { - File file = new File(path); - File[] directories = file.listFiles(new FilenameFilter() { - @Override - public boolean accept(File current, String name) { - return new File(current, name).isDirectory(); - } - }); - 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() { - @Override - public boolean accept(File current, String name) { - return (name.endsWith(".map") || name.endsWith(".dat")); - } - }); - if (files.length > 1){ - directories = new File[]{file}; - } - return directories; - } - - - - - public static String getHostName(){ - String host = ""; - try { - host = InetAddress.getLocalHost().getHostName(); - } catch (UnknownHostException e) { - e.printStackTrace(); - } - return host; - } - - public static String getNewOutPutPath(String standardBatPath) { - standardBatPath += File.separator + "logs"; - File logFolder = new File(standardBatPath); - if (!logFolder.exists()) { - logFolder.mkdir(); - logFolder.mkdirs(); - } - int i = 1; - File subLogFolder = null; - do { - subLogFolder = new File(logFolder, "run" + i); - i++; - } while (subLogFolder.exists()); - subLogFolder.mkdir(); - subLogFolder.mkdirs(); - return subLogFolder.getAbsolutePath(); - } - - public static void createNewOutPutPath(String newPath) { - File logFolder = new File(newPath); - if (!logFolder.exists()) { - logFolder.mkdir(); - logFolder.mkdirs(); - } - } - - public static boolean checkTraceFilesExist(String path){ - File file = new File(path); - if (!file.exists() || ! file.isDirectory()){ - return false; - } - File[] folders = getTraceFolders(path); - if (folders.length>0){ - return true; - } else { - return false; - } - } - -} +package tools.descartes.dql.connector.kieker; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FilenameFilter; +import java.io.IOException; +import java.math.BigDecimal; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.regex.Pattern; + +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 tools.descartes.dql.connector.kieker.structures.Resource; +import tools.descartes.dql.connector.kieker.structures.Trace; +import tools.descartes.dql.connector.kieker.structures.identifier.ResourceIdentifier; +import tools.descartes.dql.connector.kieker.structures.records.EventRecord; +import tools.descartes.dql.connector.kieker.structures.records.ResourceRecord; +import tools.descartes.dql.core.engine.util.DQLLogger; +import tools.descartes.dql.models.mapping.domain.ContinuousSeriesResult; +import tools.descartes.dql.models.mapping.domain.DomainFactory; +import tools.descartes.dql.models.mapping.domain.Entity; +import tools.descartes.dql.models.mapping.domain.Probe; +import tools.descartes.dql.models.mapping.domain.SeriesResultElement; +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. + * Static use of this class. + * + * @author Matthias Blohm <st140250@stud.uni-stuttgart.de> + */ +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 APPLICATION_JAR_FILE = "kieker.applicationJarFile"; + public static final String KIEKER_JAR_FILE = "kieker.kiekerJarFile"; + public static final String KIEKER_LOCATION = "kieker.kiekerLocation"; + public static final String APPLICATION_DIRECTORY = "kieker.modelLocation"; + public static final String KIEKER_LOG_DIRECTORY = "kieker.log.directory"; + 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_THROUGHPUT = "throughput"; + + 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. + * + * @throws RuntimeException + */ + public static void checkProperties(final Properties properties, + final String[] keys) { + for (final String key : keys) { + if (properties.get(key) == null) { + final String msg = "Required key in properties missing: " + key; + + log.error(msg); + throw new RuntimeException(msg); + } + } + } + + public static boolean checkPropertiesFileExist(final String propertiesLocation){ + String extension = ""; + + int i = propertiesLocation.lastIndexOf('.'); + if (i >= 0) { + extension = propertiesLocation.substring(i+1); + } + if (!extension.equals("properties")){ + return false; + } + + File file = new File(propertiesLocation); + final Properties properties = new Properties(); + if (file == null || !file.exists()) { + return false; + } + try { + properties.load(new FileInputStream(file)); + return true; + } catch (final IOException e) { + return false; + } + } + + + public static Properties loadKiekerProperties(final String propertiesLocation) { + final Properties properties = new Properties(); + File file = new File(propertiesLocation); + + if (file == null || !file.exists()) { + throw new IllegalStateException( + "Could not find referenced .properties file"); + } + + try { + properties.load(new FileInputStream(file)); + } catch (final IOException e) { + throw new IllegalStateException( + "Could not load properties instance"); + } + return properties; + } + + public static void setMonitoringProperties(String kiekerConfigLocation, String outputPath){ + Properties kiekerProperties = KiekerHelper.loadKiekerProperties(kiekerConfigLocation); + + kiekerProperties.setProperty("kieker.monitoring.writer.filesystem.AsyncFsWriter.customStoragePath", + outputPath); + try { + String newConfigPath = new File(kiekerConfigLocation).getParent() + "/kieker.monitoring.properties"; + System.out.println(new File(kiekerConfigLocation).getParent()); + kiekerProperties.store(new FileOutputStream(newConfigPath), ""); + } catch (FileNotFoundException e1) { + e1.printStackTrace(); + } catch (IOException e1) { + e1.printStackTrace(); + } + } + + + public static Properties getProperties(final String propertiesLocation) { + final Properties properties = new Properties(); + File file = new File(propertiesLocation); + String propertiesFolder = new File(file.getAbsolutePath()).getParent(); + + if (file == null || !file.exists()) { + throw new IllegalStateException( + "Specified file in USING not accessible, unable to execute the query further. Aborting."); + } + + try { + properties.load(new FileInputStream(file)); + File dummyFile; + String applicationFolder = ""; + 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)); + } + + dummyFile = new File(properties.get(APPLICATION_JAR_FILE).toString()); + if (!dummyFile.exists()){ + throw new IllegalStateException( + "Could not find target application jar under "+dummyFile.getAbsolutePath()); + } + 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 (!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()){ + 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 (!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(); + dummyFile = new File(kiekerLocation); + if (!dummyFile.exists()){ + throw new IllegalStateException( + "Could not find Kieker distribution under "+dummyFile.getAbsolutePath()); + } + if (!dummyFile.isAbsolute()) { + 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); + 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) { + throw new IllegalStateException( + "Could not load properties instance from specified model location in USING clause"); + } + + + return properties; + } + + + + + + public static SeriesResultElement getSeriesResultElement(long timeStamp, double value, long firstTimestamp){ + SeriesResultElement e = DomainFactory.eINSTANCE.createSeriesResultElement(); + // convert ts to millis + BigDecimal time = new BigDecimal( + ((timeStamp - firstTimestamp) / 1000000.0)); + BigDecimal resVal = new BigDecimal(value); + e.setX(time); + e.setY(resVal); + return e; + } + + public static String getComponentString (String identifier){ + String component = identifier; + if(identifier.contains("(")){ + component = identifier.split(Pattern.quote("("))[0]; // cut off method parameters + component = component.substring(0, component.lastIndexOf(".")); // cut off method + } + return component; + } + + public static ArrayList<String> getComponentIdentifiers(EntityMapping request) { + HashSet<String> components = new HashSet<>(); + for (Entity service : request.getEntities()) { + if (service.getEntityType().equals("SERVICE")){ + String identifier = service.getIdentifier(); + String component = getComponentString(identifier); + components.add(component); + } + + } + return new ArrayList<String>(components); + } + + public static ArrayList<String> getResourceIdentifiers(EntityMapping request) { + ArrayList<String> resources = new ArrayList<>(); + for (Entity resource : request.getEntities()) { + if (resource.getEntityType().equals("RESOURCE")) + resources.add(resource.getIdentifier()); + } + return resources; + } + + + public static Configuration createAnalysisConfig(EntityMapping request, String outputPath, String hostname){ + 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 (Entity e : request.getEntities()) { + if (e.getEntityType().equals("RESOURCE")){ + String r_id = e.getIdentifier(); + String r_value = hostname; + readerConfig.setProperty("RESOURCE_"+r_id, r_value); + } + } + + int i = 0; + for (Entity e : request.getEntities()) { + if (e.getEntityType().equals("SERVICE")) { + String component = getComponentString(e.getIdentifier()); + String identifier = hostname + " & " + component; + readerConfig.setProperty("COMPONENT_c" + i, identifier); + i++; + } + } + return readerConfig; + } + + + + public static String[] getAspectJarPath(String kiekerLocation) { + File file = new File(kiekerLocation); + String[] files = file.list(new FilenameFilter() { + @Override + public boolean accept(File current, String name) { + return new File(current, name).getName().contains("aspect"); + } + }); + return files; + } + + + + public static File[] getTraceFolders(String path) { + File file = new File(path); + File[] directories = file.listFiles(new FilenameFilter() { + @Override + public boolean accept(File current, String name) { + return new File(current, name).isDirectory(); + } + }); + 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() { + @Override + public boolean accept(File current, String name) { + return (name.endsWith(".map") || name.endsWith(".dat")); + } + }); + if (files.length > 1){ + directories = new File[]{file}; + } + return directories; + } + + + + + public static String getHostName(){ + String host = ""; + try { + host = InetAddress.getLocalHost().getHostName(); + } catch (UnknownHostException e) { + e.printStackTrace(); + } + return host; + } + + public static String getNewOutPutPath(String standardBatPath) { + standardBatPath += File.separator + "logs"; + File logFolder = new File(standardBatPath); + if (!logFolder.exists()) { + logFolder.mkdir(); + logFolder.mkdirs(); + } + int i = 1; + File subLogFolder = null; + do { + subLogFolder = new File(logFolder, "run" + i); + i++; + } while (subLogFolder.exists()); + subLogFolder.mkdir(); + subLogFolder.mkdirs(); + return subLogFolder.getAbsolutePath(); + } + + public static void createNewOutPutPath(String newPath) { + File logFolder = new File(newPath); + if (!logFolder.exists()) { + logFolder.mkdir(); + logFolder.mkdirs(); + } + } + + public static boolean checkTraceFilesExist(String path){ + File file = new File(path); + if (!file.exists() || ! file.isDirectory()){ + return false; + } + File[] folders = getTraceFolders(path); + if (folders.length>0){ + return true; + } else { + return false; + } + } + +} -- GitLab