Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 61729 Details for
Bug 172064
Automate the Stand-alone GLA testsuites
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
patch for org.eclipse.tptp.monitoring.auto.tests.util
org.eclipse.tptp.monitoring.auto.tests.util_patch.txt (text/plain), 35.71 KB, created by
Rohit Shetty
on 2007-03-22 15:23:01 EDT
(
hide
)
Description:
patch for org.eclipse.tptp.monitoring.auto.tests.util
Filename:
MIME Type:
Creator:
Rohit Shetty
Created:
2007-03-22 15:23:01 EDT
Size:
35.71 KB
patch
obsolete
>Index: src/org/eclipse/tptp/monitoring/auto/tests/utils/TestJUtils.java >=================================================================== >RCS file: /cvsroot/tptp/test-results/monitor/org.eclipse.tptp.monitoring.auto.tests.util/src/org/eclipse/tptp/monitoring/auto/tests/utils/TestJUtils.java,v >retrieving revision 1.5 >diff -u -r1.5 TestJUtils.java >--- src/org/eclipse/tptp/monitoring/auto/tests/utils/TestJUtils.java 13 Oct 2006 16:44:54 -0000 1.5 >+++ src/org/eclipse/tptp/monitoring/auto/tests/utils/TestJUtils.java 22 Mar 2007 19:21:59 -0000 >@@ -116,11 +116,23 @@ > > public static void testBenchMarkCBEComparison(String benchMarkFile, String outputFile,boolean compareCreationTime) > { >+ testBenchMarkCBEComparison(benchMarkFile,outputFile,compareCreationTime,false); >+ } >+ >+ public static void testBenchMarkCBEComparison(String benchMarkFile, String outputFile,boolean compareCreationTime,boolean GLAAsBenchmarkFolder) >+ { >+ testBenchMarkCBEComparison(benchMarkFile,outputFile,compareCreationTime,GLAAsBenchmarkFolder,false); >+ } >+ >+ public static void testBenchMarkCBEComparison(String benchMarkFile, String outputFile,boolean compareCreationTime,boolean GLAAsBenchmarkFolder,boolean narmalizeSapce) >+ { > try > { > System.out.println("Comparing..."); > CbeFileComparator comparator = new CbeFileComparator(); > comparator.setCompareCreationTime(compareCreationTime); >+ comparator.setGLAAsBenchMarkFolder(GLAAsBenchmarkFolder); >+ comparator.setNormalizeSpace(narmalizeSapce); > comparator.compare(benchMarkFile,outputFile); > String report = comparator.getReport(); > assertNull(report,report); >@@ -143,6 +155,7 @@ > assertNull(report,report); > } catch (Exception e) > { >+ e.printStackTrace(); > fail(e.toString()); > } > } >@@ -265,5 +278,22 @@ > fail(e.toString()); > } > } >+ >+ public static void testRunNoLogStandaloneAdapters(String adapter) >+ { >+ try >+ { >+ RunAdapter runAdap = new RunAdapter(); >+ runAdap.setNoLog(true); >+ runAdap.run(adapter); >+ String report = runAdap.getReport(); >+ assertNull(report,report); >+ >+ } >+ catch(Exception e) >+ { >+ fail(e.toString()); >+ } >+ } > > } >\ No newline at end of file >Index: src/org/eclipse/tptp/monitoring/auto/tests/utils/RunAdapter.java >=================================================================== >RCS file: /cvsroot/tptp/test-results/monitor/org.eclipse.tptp.monitoring.auto.tests.util/src/org/eclipse/tptp/monitoring/auto/tests/utils/RunAdapter.java,v >retrieving revision 1.7 >diff -u -r1.7 RunAdapter.java >--- src/org/eclipse/tptp/monitoring/auto/tests/utils/RunAdapter.java 13 Oct 2006 16:44:54 -0000 1.7 >+++ src/org/eclipse/tptp/monitoring/auto/tests/utils/RunAdapter.java 22 Mar 2007 19:21:59 -0000 >@@ -66,6 +66,7 @@ > > private boolean simulateContOpp = false; > private boolean noScript = false; >+ private boolean noLog = false; > private boolean filterTest = false; > > private String componentName =""; >@@ -255,10 +256,11 @@ > > junitReport = ex.runAdapter(); > checkHGLALog(dir,adapterFile.getAbsolutePath()); >- String genOutFileName = adapterDir.getAbsolutePath() + FILE_SEPARATOR + outputFileName; >+ String outFile = ((outputFileName == null || outputFileName.equals(""))?"example.out":outputFileName); >+ String genOutFileName = adapterDir.getAbsolutePath() + FILE_SEPARATOR + outFile; > File genOutFile = new File(genOutFileName); > String toDelFileName = adapterFile.getName().substring(0,adapterFile.getName().lastIndexOf(".")) + ".out"; >- if(genOutFile.isFile() && !outputFileName.equals(toDelFileName) ) >+ if(genOutFile.isFile() && !outFile.equals(toDelFileName) ) > { > File toDelFile = new File(adapterDir.getAbsolutePath() + FILE_SEPARATOR + toDelFileName); > if(toDelFile.exists()) >@@ -356,7 +358,10 @@ > } > if(isAdapter) > { >- runAdapterFile(dir); >+ if(noLog) >+ runNoLogAdapter(dir); >+ else >+ runAdapterFile(dir); > } > else > { >@@ -424,6 +429,44 @@ > //removeEditedAdapter(adapter); > } > >+ private void runNoLogAdapter(File adapter) >+ throws Exception >+ { >+ File dir = new File(USER_HOME); >+ markExistingHGLALogs(dir); >+ String fileName = adapter.getName().substring(0,adapter.getName().lastIndexOf(".")); >+ String adapterDir = adapter.getParent(); >+ String scriptKey = null; >+ >+ >+ if((scriptKey = (String)adapterScripts.get(fileName))!= null) >+ { >+ File execFile = editAdapterScriptFile(adapter,adapterDir,scriptKey) ; >+ if(execFile != null) >+ { >+ buildAdapterBasedCmdString(execFile) ; >+ if(simulateContOpp) >+ editAdapter(adapter); >+ } >+ else >+ { >+ writeErrorLog(adapter.getAbsolutePath(),"Could not find the adapter script file.Running the adapter with the GLA script.",30,true); >+ editAdapter(adapter); >+ buildGLABasedCmdString(adapter.getAbsolutePath()); >+ } >+ } >+ else >+ { >+ editAdapter(adapter); >+ buildGLABasedCmdString(adapter.getAbsolutePath()); >+ } >+ >+ timeAndRun(adapter,fileName,"example.log"); >+ >+ checkHGLALog(dir,adapter.getAbsolutePath()); >+ //removeEditedAdapter(adapter); >+ } >+ > private void buildGLABasedCmdString(String filePath) > { > if(!(OPERATING_SYSTEM.indexOf("Win") >= 0)) >@@ -796,6 +839,11 @@ > noScript = b; > } > >+ public void setNoLog(boolean b) throws Exception >+ { >+ noLog = b; >+ } >+ > public void editAdapter(File adapter) > throws Exception > { >Index: src/org/eclipse/tptp/monitoring/auto/tests/utils/CbeFileComparator.java >=================================================================== >RCS file: /cvsroot/tptp/test-results/monitor/org.eclipse.tptp.monitoring.auto.tests.util/src/org/eclipse/tptp/monitoring/auto/tests/utils/CbeFileComparator.java,v >retrieving revision 1.6 >diff -u -r1.6 CbeFileComparator.java >--- src/org/eclipse/tptp/monitoring/auto/tests/utils/CbeFileComparator.java 29 Jan 2007 16:06:28 -0000 1.6 >+++ src/org/eclipse/tptp/monitoring/auto/tests/utils/CbeFileComparator.java 22 Mar 2007 19:21:57 -0000 >@@ -13,8 +13,13 @@ > > package org.eclipse.tptp.monitoring.auto.tests.utils; > >+import java.io.BufferedReader; > import java.io.File; >+import java.io.FileOutputStream; >+import java.io.FileReader; > import java.io.IOException; >+import java.io.OutputStreamWriter; >+import java.io.Writer; > import java.util.Iterator; > import java.util.LinkedList; > >@@ -37,6 +42,8 @@ > public final static String LINE_SEPARATOR; > public final static String FILE_SEPARATOR; > private boolean compareCreationTime = false; >+ private boolean compareGLALogs = false; >+ private boolean replaceSpaceChars = false; > > static > { >@@ -54,56 +61,35 @@ > { > simulateContOpp = contOppVal; > } >+ /** >+ * Required when the comparison needs to be done against an out file >+ * that is also generated by the GLA >+ */ >+ public void setGLAAsBenchMarkFolder(boolean b) >+ { >+ compareGLALogs = b; >+ } >+ >+ public void setNormalizeSpace(boolean b) >+ { >+ replaceSpaceChars = b; >+ } > > public CbeFileComparator() throws IOException > { > fileSuffix = PropertiesWrapper.get("comparator.filesuffix"); >- if(fileSuffix == null) fileSuffix = ".out"; >+ if(fileSuffix == null || fileSuffix.trim().equals("")) fileSuffix = ".out"; > } > > > public boolean compare(String firstFileName) > throws Exception > { >- if(firstFileName.endsWith(".adapter")) firstFileName = firstFileName.substring(0,firstFileName.lastIndexOf(".")) + fileSuffix; >- >- String ADAPTER_HOME= PropertiesWrapper.getProperty("ADAPTER_CONFIG_HOME"); >- if(ADAPTER_HOME == null || !(new File(ADAPTER_HOME)).isDirectory()) >- { >- ADAPTER_HOME = PropertiesWrapper.getProperty("GLA_HOME") + FILE_SEPARATOR + "config"; >- } >- String secondFileName = ADAPTER_HOME + FILE_SEPARATOR + firstFileName; >- if(simulateContOpp) >- { >- firstFileName = ADAPTER_HOME + FILE_SEPARATOR + firstFileName; >- } >- else >- { >- String BENCHMARK_HOME = PropertiesWrapper.getProperty("BENCHMARK_HOME"); >- firstFileName = BENCHMARK_HOME + FILE_SEPARATOR + firstFileName; >- } >- >- >- File dir1 = new File(firstFileName); >- File dir2 = new File(secondFileName); >- >- if(dir1.isDirectory() && dir2.isDirectory()) >- { >- frstDir = firstFileName; >- scndDir = secondFileName; >- list(dir1); >- } >- else if(dir2.isFile() && dir1.isFile()) >- { >- compareXmlFiles(firstFileName,secondFileName); >- } >- else >+ if(firstFileName.endsWith(".adapter")) > { >- System.out.println("The files \"" + firstFileName + "\" and \"" + secondFileName + "\" seem to have a problem and comparison cannot be carried out."); >- throw new Exception("The files \"" + firstFileName + "\" and \"" + secondFileName + "\" seem to have a problem and comparison cannot be carried out."); >- } >- return true; >- >+ firstFileName = firstFileName.substring(0,firstFileName.lastIndexOf(".")) + fileSuffix; >+ } >+ return compare(firstFileName,firstFileName); > } > > public boolean compare(String benchMarkFileName, String outputFileName) >@@ -117,10 +103,12 @@ > { > ADAPTER_HOME = PropertiesWrapper.getProperty("GLA_HOME") + FILE_SEPARATOR + "config"; > } >+ if(compareGLALogs || simulateContOpp) >+ { >+ BENCHMARK_HOME = ADAPTER_HOME; >+ } > String secondFileName = ADAPTER_HOME + FILE_SEPARATOR + outputFileName; > String firstFileName = BENCHMARK_HOME + FILE_SEPARATOR + benchMarkFileName; >- >- > > File dir1 = new File(firstFileName); > File dir2 = new File(secondFileName); >@@ -133,7 +121,7 @@ > } > else if(dir2.isFile() && dir1.isFile()) > { >- compareXmlFiles(firstFileName,secondFileName); >+ compareXmlFiles(dir1.getAbsolutePath(),dir2.getAbsolutePath()); > } > else > { >@@ -143,6 +131,35 @@ > return true; > > } >+ >+ private String convertToAscii(String file) throws IOException >+ { >+ String newFile = file + "_ascii"; >+ File nFile = new File(newFile); >+ if(nFile.exists()) nFile.delete(); >+ >+ BufferedReader source = new BufferedReader(new FileReader(file)); >+ FileOutputStream fos = new FileOutputStream(newFile); >+ Writer out = new OutputStreamWriter(fos, "ascii"); >+ int len; >+ char[] buffer = new char[2 * 1024 * 1024]; >+ while ((len = source.read(buffer)) >= 0) >+ out.write(buffer, 0, len); >+ out.close(); >+ >+ //nFile.deleteOnExit(); >+ return newFile; >+ } >+ >+ /* >+ * The outfiles on zOS are generated in the local encoding and comparison fails >+ * To avoid this the files can be converted to ascii and then compared. >+ */ >+ private String noramlizeOutFileOnZOS(String file,boolean isBenchmark) throws IOException >+ { >+ if(!PropertiesWrapper.OPERATING_SYSTEM.startsWith("z/OS") || (isBenchmark && !(compareGLALogs || simulateContOpp))) return file; >+ return convertToAscii(file); >+ } > private boolean compareXmlFiles(String firstFileName,String secondFileName) > throws Exception > { >@@ -160,8 +177,8 @@ > secondFileName = firstFileName.substring(0,firstFileName.lastIndexOf(FILE_SEPARATOR)) + FILE_SEPARATOR + "CON_" + firstFileName.substring(firstFileName.lastIndexOf(FILE_SEPARATOR) + 1,firstFileName.length()); > } > } >- XMLFileReader fileOne = new XMLFileReader(firstFileName,"CommonBaseEvent"); >- XMLFileReader fileTwo = new XMLFileReader(secondFileName,"CommonBaseEvent"); >+ XMLFileReader fileOne = new XMLFileReader(noramlizeOutFileOnZOS(firstFileName,true),"CommonBaseEvent"); >+ XMLFileReader fileTwo = new XMLFileReader(noramlizeOutFileOnZOS(secondFileName,false),"CommonBaseEvent"); > LinkedList fileOneList = new LinkedList(); > LinkedList fileTwoList = new LinkedList(); > long fileOne_lastIndex = fileOne.createIndexes(); >@@ -332,6 +349,8 @@ > > private String cleanStrings(String vals) > { >+ if(replaceSpaceChars) >+ vals = vals.replaceAll("\\s+", " "); > return vals.replaceAll("&#x[DA9];","").trim(); > } > >Index: src/org/eclipse/tptp/monitoring/auto/tests/utils/DeploymentUtil.java >=================================================================== >RCS file: src/org/eclipse/tptp/monitoring/auto/tests/utils/DeploymentUtil.java >diff -N src/org/eclipse/tptp/monitoring/auto/tests/utils/DeploymentUtil.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/tptp/monitoring/auto/tests/utils/DeploymentUtil.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,238 @@ >+package org.eclipse.tptp.monitoring.auto.tests.utils; >+/********************************************************************** >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * $Id: DeploymentUtil.java,v 1.1 2007/02/14 07:15:40 roshetty Exp $ >+ * >+ * Contributors: >+ * IBM - Initial API and implementation >+ **********************************************************************/ >+ >+import java.io.BufferedInputStream; >+import java.io.BufferedOutputStream; >+import java.io.BufferedWriter; >+import java.io.File; >+import java.io.FileInputStream; >+import java.io.FileOutputStream; >+import java.io.FileWriter; >+import java.io.IOException; >+import java.io.InputStream; >+import java.io.OutputStream; >+import java.lang.reflect.Method; >+import java.net.URL; >+import java.net.URLClassLoader; >+import java.util.zip.ZipEntry; >+import java.util.zip.ZipInputStream; >+ >+public class DeploymentUtil >+{ >+ private static boolean _deployed = false; >+ >+ public static void InstallGLA() >+ { >+ if(!_deployed) >+ { >+ _deployed = true; >+ try { >+ deploy(); >+ // Add the GLA jars to the classpath dynamically >+ addAllFilesToClasspath(new File(PropertiesWrapper.GLA_HOME + PropertiesWrapper.FILE_SEPARATOR + "lib")); >+ } catch (Throwable e) { >+ // TODO Auto-generated catch block >+ System.err.println(e); >+ } >+ } >+ } >+ >+ public static void deploy(String deploymentHome, String imageFolder) throws IOException >+ { >+ File depRoot = new File(imageFolder); >+ File[] files = depRoot.listFiles(); >+ >+ Processor processor = new Processor(); >+ String zOSScript = createZOSUnzipScript(processor); >+ >+ for(int i = 0; i < files.length; i ++) >+ { >+ String depFile = files[i].getAbsolutePath(); >+ >+ if(isZipFile(depFile)) >+ { >+ System.out.println("Deploying file: " + depFile); >+ if(PropertiesWrapper.OPERATING_SYSTEM.startsWith("z/OS")) >+ { >+ try >+ { >+ //On zOS there are specific commands that need to be run, use the generated script for this >+ processor.executeProcess("/bin/sh " + zOSScript + " " + depFile,deploymentHome); >+ } >+ catch (Throwable e) >+ { >+ // TODO Auto-generated catch block >+ System.err.println(e.getMessage()); >+ } >+ } >+ else >+ { >+ // GLA Install guide says - Extract the zip file, So we have code here to unzip. >+ extractZipFile(depFile,deploymentHome); >+ } >+ } >+ } >+ } >+ >+ //Create the shell script in the local encoding to unzip the GLA >+ private static String createZOSUnzipScript(Processor processor) throws IOException >+ { >+ if(PropertiesWrapper.OPERATING_SYSTEM.startsWith("z/OS")) >+ { >+ File newFileName = new File(PropertiesWrapper.DEPLOYMENT_HOME + "/unzipzos.sh"); >+ if(newFileName.exists()) newFileName.delete(); >+ BufferedWriter newExecFile = new BufferedWriter(new FileWriter(newFileName)) ; >+ newExecFile.write("#!/bin/sh" >+ + PropertiesWrapper.LINE_SEPARATOR + "/c390/build/bin/unzip -aoq $1" >+ + PropertiesWrapper.LINE_SEPARATOR + "/c390/build/bin/unzip -oq $1 *.adapter" >+ + PropertiesWrapper.LINE_SEPARATOR + "/c390/build/bin/unzip -oq $1 *.xsd" >+ + PropertiesWrapper.LINE_SEPARATOR + "/c390/build/bin/unzip -aaoq $1 *.sh" >+ + PropertiesWrapper.LINE_SEPARATOR + "/c390/build/bin/unzip -aaoq $1 *.log" >+ + PropertiesWrapper.LINE_SEPARATOR); >+ newExecFile.close(); >+ newFileName.deleteOnExit(); >+ processor.executeProcess("/bin/chmod 777 " + newFileName.getAbsolutePath(),PropertiesWrapper.DEPLOYMENT_HOME); >+ return newFileName.getAbsolutePath(); >+ } >+ return null; >+ } >+ >+ public static void deploy(String imageFolder) throws IOException >+ { >+ deploy(PropertiesWrapper.DEPLOYMENT_HOME,imageFolder); >+ } >+ >+ public static void deploy() throws IOException >+ { >+ deploy(PropertiesWrapper.DEPLOYMENT_HOME + PropertiesWrapper.FILE_SEPARATOR + "ZipFiles"); >+ } >+ >+ private static final Class[] parameters = new Class[]{URL.class}; >+ >+ public static void addAllFilesToClasspath(File root) throws IOException >+ { >+ File[] files = root.listFiles(); >+ for(int i = 0; i < files.length; i ++) >+ { >+ addFileToClasspath(files[i]); >+ } >+ } >+ >+ public static void addFileToClasspath(File f) throws IOException { >+ addURL(f.toURL()); >+ } >+ >+ private static void addURL(URL u) throws IOException >+ { >+ URLClassLoader sysloader = (URLClassLoader)ClassLoader.getSystemClassLoader(); >+ Class sysclass = URLClassLoader.class; >+ try >+ { >+ Method method = sysclass.getDeclaredMethod("addURL",parameters); >+ method.setAccessible(true); >+ method.invoke(sysloader,new Object[]{ u }); >+ } >+ catch (Throwable t) >+ { >+ throw new IOException("Error, could not add URL to system classloader"); >+ } >+ } >+ >+ /** >+ * Check if a file is a zip file >+ * @param file >+ * @return >+ * @throws IOException >+ */ >+ public static boolean isZipFile(String file) throws IOException >+ { >+ if(!(new File(file)).isFile()) return false; >+ InputStream inputStream = new BufferedInputStream(new FileInputStream(file), 64*1024); >+ inputStream.mark(5); >+ return isZipFile(inputStream); >+ } >+ >+ /** >+ * Check if a stream is from a zip file >+ * @param inputStream >+ * @return >+ * @throws IOException >+ */ >+ public static boolean isZipFile(InputStream inputStream) throws IOException{ >+ byte[] headerSignature = new byte[4]; >+ >+ if (inputStream.read(headerSignature) > 1) { >+ if (headerSignature[0] == 0x50 && >+ headerSignature[1] == 0x4b && >+ headerSignature[2] == 0x03 && >+ headerSignature[3] == 0x04) { >+ return true; >+ } >+ } >+ return false; >+ } >+ >+ public static String extractZipFile(String file,String parentDir) throws IOException >+ { >+ return extractZipFile(new BufferedInputStream(new FileInputStream(file), 64*1024),parentDir); >+ } >+ >+ public static String extractZipFile(InputStream inputStream,String parentDir) throws IOException >+ { >+ File parent = new File(parentDir); >+ >+ if (parent != null && !parent.exists()) >+ parent.mkdirs(); >+ >+ ZipInputStream zipInputStream = new ZipInputStream(inputStream); >+ String fileName; >+ >+ while (zipInputStream.available() > -1) >+ { >+ ZipEntry entry = (ZipEntry) zipInputStream.getNextEntry(); >+ if (entry == null) >+ { >+ break; >+ } >+ >+ fileName = entry.getName(); >+ >+ File file = new File(parentDir + "/" + fileName); >+ >+ if(file.exists() && file.isFile()) file.delete(); >+ if (entry.isDirectory()) { >+ if(!file.exists()) >+ file.mkdir(); >+ continue; >+ } >+ file.deleteOnExit(); >+ >+ copyInputStream(zipInputStream, new BufferedOutputStream(new FileOutputStream(file))); >+ >+ zipInputStream.closeEntry(); >+ } >+ >+ zipInputStream.close(); >+ return parent+"/"; >+ } >+ >+ public static void copyInputStream(InputStream in, OutputStream out) throws IOException >+ { >+ int len; >+ byte[] buffer = new byte[2 * 1024 * 1024]; >+ >+ while ((len = in.read(buffer)) >= 0) >+ out.write(buffer, 0, len); >+ out.close(); >+ } >+} >Index: src/org/eclipse/tptp/monitoring/auto/tests/utils/WindowsLogParser.java >=================================================================== >RCS file: src/org/eclipse/tptp/monitoring/auto/tests/utils/WindowsLogParser.java >diff -N src/org/eclipse/tptp/monitoring/auto/tests/utils/WindowsLogParser.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/tptp/monitoring/auto/tests/utils/WindowsLogParser.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,420 @@ >+/********************************************************************** >+ * Copyright (c) 2006 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * $Id: WindowsLogParser.java,v 1.1 2006/02/14 07:15:40 roshetty Exp $ >+ * >+ * Contributors: >+ * IBM - Initial API and implementation >+ **********************************************************************/ >+package org.eclipse.tptp.monitoring.auto.tests.utils; >+//org.eclipse.tptp.monitoring.auto.tests.utils; >+ >+import java.text.ParsePosition; >+import java.text.SimpleDateFormat; >+import java.util.Calendar; >+import java.util.Hashtable; >+ >+import org.eclipse.hyades.logging.core.Guid; >+import org.eclipse.hyades.logging.events.cbe.CommonBaseEvent; >+import org.eclipse.hyades.logging.events.cbe.ComponentIdentification; >+import org.eclipse.hyades.logging.events.cbe.ReportSituation; >+import org.eclipse.hyades.logging.events.cbe.Situation; >+import org.eclipse.hyades.logging.parsers.LogParserException; >+import org.eclipse.hyades.logging.parsers.MonitoringParser; >+import org.eclipse.hyades.logging.parsers.ParserConstants; >+ >+public class WindowsLogParser extends MonitoringParser >+{ >+ //Variable to hold the system timezone value >+ private String timezone; >+ >+ public static final String WINDOWS_DATE_FORMAT_1 = "dd/MM/yyyy,hh:mm:ss aa"; >+ public static final String WINDOWS_DATE_FORMAT_2 = "dd/MM/yyyy,HH:mm:ss"; >+ >+ // protected static Locale parseLocale = new Locale("en", "US"); >+ // protected static SimpleDateFormat dateFormat = new SimpleDateFormat(LogParserConstants.WAS_INSTALL_LOG_DATE_FORMAT1,parseLocale); >+ //protected static SimpleDateFormat cbeDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss",parseLocale); >+ >+ protected static SimpleDateFormat dateFormat_1 = new SimpleDateFormat(WINDOWS_DATE_FORMAT_1); >+ protected static SimpleDateFormat dateFormat_2 = new SimpleDateFormat(WINDOWS_DATE_FORMAT_2); >+ protected static SimpleDateFormat cbeDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); >+ >+ // Default Constructor, also used to initialize all member variables >+ public WindowsLogParser() { >+ //intialize the other variables >+ timezone = ""; >+ inittimezone(); >+ } >+ >+ /* >+ * this is an renamed function of setUserInput, (non-Javadoc) >+ * @see org.eclipse.hyades.logging.parsers.IParser#setConfiguration(java.util.Hashtable) >+ */ >+ public void setConfiguration(Hashtable table) throws LogParserException { >+ super.setConfiguration(table); >+ } >+ >+ >+ /** >+ * Determine the situation based on the situation code value >+ */ >+ private Situation createSituation() >+ { >+ Situation cbeSituation = eventFactory.createSituation(); >+ ReportSituation cbeReportSituation = eventFactory.createReportSituation(); >+ cbeReportSituation.setReasoningScope(ParserConstants.INTERNAL_REASONING_SCOPE); >+ cbeReportSituation.setReportCategory(ParserConstants.LOG_REPORT_CATEGORY); >+ cbeSituation.setCategoryName(ParserConstants.REPORT_SITUATION_CATEGORY_NAME); >+ cbeSituation.setSituationType(cbeReportSituation); >+ return cbeSituation; >+ } >+ >+ private void parseRecord(String line,CommonBaseEvent cbe) throws LogParserException >+ { >+ // Initialize the CBE >+ cbe.init(); >+ >+ // Set the event's globalInstanceId property with a new GUID >+ cbe.setGlobalInstanceId(Guid.generate()); >+ >+ // Set the ExtensionName >+ cbe.setExtensionName("CommonBaseEvent"); >+ >+ //Set the Situation value >+ cbe.setSituation(createSituation()); >+ >+ for(int i=0;i<=7;i++) >+ { >+ int idx = line.indexOf(','); >+ String snippet = (idx >-1 && i < 7)?line.substring(0,idx):line; >+ line = line.substring(idx+1); >+ switch(i) >+ { >+ case 0: >+ //parse time >+ idx = line.indexOf(','); >+ snippet = snippet + "," + line.substring(0,idx); >+ line = line.substring(idx+1); >+ String cbetime = getCBEDate(snippet,(snippet.endsWith("M")?dateFormat_1:dateFormat_2)); >+ cbetime = cbetime.concat(".000"); >+ cbetime = cbetime.concat(timezone); >+ cbe.setCreationTime(cbetime); >+ break; >+ case 1: >+ //Create source component id and set the values >+ ComponentIdentification srcComponent = eventFactory.createComponentIdentification() ; >+ srcComponent.init(); >+ srcComponent.setComponent("Windows"); >+ srcComponent.setComponentIdType("ProductName"); >+ srcComponent.setSubComponent(snippet); >+ srcComponent.setComponentType("WindowsOperatingSystem"); >+ cbe.setSourceComponentId(srcComponent); >+ break; >+ case 2: >+ //Set the severity value >+ cbe.setSeverity(getSeverity(snippet)); >+ break; >+ case 3: >+ break; >+ case 4: >+ // code to conver to Hexadecimal as the eventReader.exe displays this is hex >+ // Remove the below try-catch if the exe is change to output decimal >+ /*try >+ { >+ snippet = Long.toHexString(Long.parseLong(snippet)); >+ snippet = snippet.toUpperCase(); >+ >+ for(int len = snippet.length();len < 8; len ++) >+ { >+ snippet = 0 + snippet; >+ } >+ } >+ catch(Exception e){}*/ >+ //Uncomment the above code and comment the line below once bugzilla 176476 has been fixed. >+ snippet = (recordCount + 1) + ""; >+ cbe.setMsgDataElement(eventFactory.createMsgDataElement()); >+ cbe.getMsgDataElement().init(); >+ cbe.getMsgDataElement().setMsgId(snippet); >+ cbe.getMsgDataElement().setMsgIdType("UNKNOWN"); >+ break; >+ case 5: >+ if(!(snippet.trim().equals(""))) >+ { >+ cbe.addExtendedDataElement(createStringEDE("Username",snippet.substring(snippet.indexOf('\\')+1))); >+ } >+ break; >+ case 6: >+ // Set the ReporterComponent values >+ ComponentIdentification reporterComponent = eventFactory.createComponentIdentification() ; >+ reporterComponent.init(); >+ reporterComponent.setLocationType("Hostname"); >+ reporterComponent.setComponent("ACAdapter"); >+ reporterComponent.setComponentType("WindowsOperatingSystem"); >+ reporterComponent.setComponentIdType("APPLICATION"); >+ reporterComponent.setSubComponent("NTEventLogSensor"); >+ cbe.setReporterComponentId(reporterComponent); >+ >+ if(!(snippet.trim().equals(""))) >+ { >+ cbe.getReporterComponentId().setLocation(snippet); >+ cbe.getReporterComponentId().setLocationType("Hostname"); >+ cbe.getSourceComponentId().setLocation(snippet); >+ cbe.getSourceComponentId().setLocationType("Hostname"); >+ } >+ else >+ { >+ cbe.getReporterComponentId().setLocation(localHostId); >+ cbe.getReporterComponentId().setLocationType(localHostIdFormat); >+ cbe.getSourceComponentId().setLocation(localHostId); >+ cbe.getSourceComponentId().setLocationType(localHostIdFormat); >+ } >+ break; >+ case 7: >+ ////System.out.println("*****messageString****** "+snippet); >+ String messageString = undoCVSFormating(snippet); >+ ////System.out.println("*****messageString****** "+messageString); >+ if(messageString.equals("")) break; >+ >+ if (messageString.length() > 1024) >+ { >+ cbe.setMsg(messageString.substring(0, 1024)); >+ cbe.addExtendedDataElement(createStringEDE(ParserConstants.MESSAGE_EXTENDED_DATA_ELEMENT,messageString.toString())); >+ } >+ else >+ { >+ cbe.setMsg(messageString.toString()); >+ } >+ break; >+ default: >+ break; >+ } >+ } >+ } >+ >+ private String undoCVSFormating(String msgString) >+ { >+ msgString = msgString.replaceAll("\"\"", "\""); >+ msgString = msgString.replaceAll("\n", " "); >+ msgString = msgString.replaceAll("\r", " "); >+ >+ if(msgString.startsWith("\"") && msgString.endsWith("\"")) >+ { >+ msgString = msgString.substring(1,msgString.length()-1); >+ } >+ if(msgString.matches("The description for Event ID .* in Source .* cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the .* flag to retrieve this description; see Help and Support for details. The following information is part of the event:.*")) >+ { >+ msgString = msgString.replaceAll("The description for Event ID .* in Source .* cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event:", ""); >+ msgString = msgString.trim(); >+ msgString = msgString.substring(0, msgString.length()-1); >+ } >+ if(msgString.equals("The event log file is corrupt.")) >+ { >+ msgString = ""; >+ } >+ return msgString.trim(); >+ } >+ >+ private String nextLine = null; >+ >+ private String getLogRecord() throws LogParserException >+ { >+ String record = nextLine; >+ nextLine = null; >+ String line=null; >+ >+ while ((line=readALine()) != null) >+ { >+ if(line.length() == 0) line = " "; >+ >+ try >+ { >+ if(line.matches("\\d{2}/\\d{2}/\\d{4},\\d{2}:\\d{2}:\\d{2}[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,.*")) >+ { >+ if(record == null) >+ { >+ record = line; >+ } >+ else >+ { >+ nextLine = line; >+ break; >+ } >+ } >+ else if(record != null) >+ { >+ record = record + ParserConstants.LINE_SEPARATOR + line; >+ } >+ } >+ catch(Exception e) >+ { >+ if(record != null) >+ { >+ record = record + ParserConstants.LINE_SEPARATOR + line; >+ } >+ } >+ } >+ >+ return record; >+ } >+ /** >+ * to parse Severity of the record >+ * @param message id >+ * @return >+ */ >+ private short getSeverity(String severString) >+ { >+ if(severString.endsWith("Success Audit")) >+ return 15; >+ else if(severString.endsWith("Failure Audit")) >+ return 16; >+ else if(severString.endsWith("Information")) >+ return 20; >+ else if(severString.endsWith("Warning")) >+ return 30; >+ else if(severString.endsWith("Error")) >+ return 40; >+ else >+ return 17; >+ } >+ >+ /* >+ * Intialize the timezone value to the system default timezone value >+ */ >+ private void inittimezone() >+ { >+ //intialize the timezone value >+ Calendar localCalendar = Calendar.getInstance(); >+ int utcOffset = ((localCalendar.get(Calendar.ZONE_OFFSET) + localCalendar.get(Calendar.DST_OFFSET)) / 60000); >+ if (utcOffset < 0) { >+ timezone = timezone.concat("-"); >+ } >+ else { >+ timezone = timezone.concat("+"); >+ } >+ utcOffset = Math.abs(utcOffset); >+ // Compute the Time Zone value (+/-hh:mm) >+ String numberHours = String.valueOf(utcOffset / 60); >+ if (numberHours.length() == 1) { >+ timezone = timezone.concat("0"); >+ } >+ timezone = timezone.concat(numberHours); >+ timezone = timezone.concat(":"); >+ String numberMinutes = String.valueOf(utcOffset % 60); >+ if (numberMinutes.length() == 1) { >+ timezone = timezone.concat("0"); >+ } >+ timezone = timezone.concat(numberMinutes); >+ } >+ >+ >+ /** >+ * Parses the log file, generates a CBE for each parsed log record and >+ * returns the array of CBE's. >+ * @return CommonBaseEvent[] The array of generated CBE objects. >+ * @exception LogParserException thrown if an exception is encountered during parsing >+ */ >+ public CommonBaseEvent[] parseNext() throws LogParserException >+ { >+ try >+ { >+ // counter for the number of CBE events converted >+ arrayIndex = 0; >+ String currentLine = null; >+ while((currentLine = getLogRecord()) != null) >+ { >+ currentLine = currentLine.trim(); >+ //System.out.println("*****currentLine**** "+currentLine); >+ if(messages[arrayIndex] == null) >+ { >+ messages[arrayIndex] = eventFactory.createCommonBaseEvent(); >+ } >+ >+ if(currentLine.length() == 0) { >+ continue; >+ } >+ if (currentLine.length()> 0) >+ { >+ parseRecord(currentLine,messages[arrayIndex]); >+ >+ arrayIndex++; >+ recordCount++; >+ } //if condition block >+ if(arrayIndex == MessageArraySize) >+ { >+ arrayIndex = 0; >+ return messages; >+ } >+ } >+ if (arrayIndex == 0) { >+ setEndOfFile(); >+ return null; >+ } >+ else { >+ for (int index = arrayIndex; index < MessageArraySize; index++) >+ { >+ messages[index] = null; >+ } >+ } >+ } >+ catch(Exception e) { >+ throw new LogParserException("Internal Error occurred in Windows CSV parser - " + e.getMessage()); >+ } >+ if(recordCount == 0) { >+ throw new LogParserException("The Windows CSV log does not have any records"); >+ } >+ return messages; >+ } >+ >+ /** >+ * This method converts the given date into CBE Date format >+ * @param dateString >+ * @param dateFormat >+ * @return >+ */ >+ private String getCBEDate(String dateString,SimpleDateFormat dateFormat) >+ { >+ try >+ { >+ //Date creationDateObj = dateFormat.parse(dateString); >+ ParsePosition parseLoc = new ParsePosition(0); >+ java.util.Date creationDateObj = dateFormat.parse(dateString, parseLoc); >+ if(creationDateObj != null) >+ { >+ StringBuffer cbeCreationDate = new StringBuffer(cbeDateFormat.format(creationDateObj)); >+ return cbeCreationDate.toString(); >+ } >+ } >+ catch(Exception pe) >+ { >+ //pe.printStackTrace(); >+ // do nothing >+ } >+ return null; >+ } >+ >+ /** >+ * Initialize this parser. >+ */ >+ public void preParse() throws LogParserException { >+ super.preParse(); >+ } >+ >+ /** >+ * Returns the name of the parser (non-Javadoc) >+ * @see org.eclipse.hyades.logging.parsers.Parser#getName() >+ */ >+ public String getName() { >+ return "Windows application log"; >+ } >+ >+ /** >+ * Returns current Version >+ */ >+ public String getVersion() { >+ return "windows"; >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 172064
:
61727
| 61729 |
61731