private void initLogstash(String testName) { initLogstashHost(); String pathToLogstash = SGTestHelper.getSGTestRootDir().replace("\\", "/") + "/src/main/resources/logstash"; String confFilePath = pathToLogstash + "/logstash-shipper-client.conf"; String fixedTestName = testName.substring(0, testName.length() - 2); String backupFilePath = pathToLogstash + "/logstash-shipper-client-" + fixedTestName + ".conf"; if (process == null) { try { LogUtils.log("copying file " + confFilePath + " to " + backupFilePath); IOUtils.copyFile(confFilePath, backupFilePath); // backupFilePath = IOUtils.backupFile(confFilePath); IOUtils.replaceTextInFile( backupFilePath, "<path_to_test_folder>", SGTestHelper.getSGTestRootDir().replace("\\", "/") + "/../" + suiteName + "/" + testName); IOUtils.replaceTextInFile(backupFilePath, "<suite_name>", suiteName); IOUtils.replaceTextInFile(backupFilePath, "<test_name>", testName); IOUtils.replaceTextInFile(backupFilePath, "<build_number>", buildNumber); IOUtils.replaceTextInFile(backupFilePath, "<version>", version); IOUtils.replaceTextInFile(backupFilePath, "<host>", logstashHost); String logstashJarPath = DeploymentUtils.getLocalRepository() + "net/logstash/1.2.2/logstash-1.2.2.jar"; logstashLogPath = pathToLogstash + "/logstash-" + fixedTestName + ".txt"; String cmdLine = "java -jar " + logstashJarPath + " agent -f " + backupFilePath + " -l " + logstashLogPath; final String[] parts = cmdLine.split(" "); final ProcessBuilder pb = new ProcessBuilder(parts); LogUtils.log("Executing Command line: " + cmdLine); TimeUnit.SECONDS.sleep(1); process = pb.start(); } catch (Exception e) { e.printStackTrace(); } } }
private void initLogstash2(ITestResult tr) { initLogstashHost(); String simpleClassName = tr.getTestClass().getRealClass().getSimpleName(); String pathToLogstash = SGTestHelper.getSGTestRootDir().replace("\\", "/") + "/src/main/resources/logstash"; String confFilePath2 = pathToLogstash + "/logstash-shipper-client-2.conf"; String backupFilePath2 = pathToLogstash + "/logstash-shipper-client-2-" + simpleClassName + ".conf"; File backupFile2 = new File(backupFilePath2); LogUtils.log( "trying to start logstash agent number 2. simple class name is " + simpleClassName); if (backupFile2.exists()) { LogUtils.log("the file " + backupFilePath2 + " already exists. not starting logstash"); } if (!isAfter(tr) && !backupFile2.exists()) { try { // backupFilePath2 = IOUtils.backupFile(confFilePath2); LogUtils.log("copying file " + confFilePath2 + " to " + backupFilePath2); IOUtils.copyFile(confFilePath2, backupFilePath2); IOUtils.replaceTextInFile(backupFilePath2, "<path_to_build>", SGTestHelper.getBuildDir()); IOUtils.replaceTextInFile( backupFilePath2, "<suite_number>", "suite_" + System.getProperty("iTests.suiteId", "0")); IOUtils.replaceTextInFile( backupFilePath2, "<path_to_test_class_folder>", SGTestHelper.getSGTestRootDir().replace("\\", "/") + "/../" + suiteName + "/" + tr.getTestClass().getName()); IOUtils.replaceTextInFile(backupFilePath2, "<suite_name>", suiteName); IOUtils.replaceTextInFile(backupFilePath2, "<test_name>", simpleClassName); IOUtils.replaceTextInFile(backupFilePath2, "<build_number>", buildNumber); IOUtils.replaceTextInFile(backupFilePath2, "<version>", version); IOUtils.replaceTextInFile(backupFilePath2, "<host>", logstashHost); String logstashJarPath = DeploymentUtils.getLocalRepository() + "net/logstash/1.2.2/logstash-1.2.2.jar"; logstashLogPath2 = pathToLogstash + "/logstash-" + simpleClassName + "-2.txt"; String cmdLine = "java -jar " + logstashJarPath + " agent -f " + backupFilePath2 + " -l " + logstashLogPath2; final String[] parts = cmdLine.split(" "); final ProcessBuilder pb = new ProcessBuilder(parts); LogUtils.log("Executing Command line: " + cmdLine); process2 = pb.start(); } catch (IOException e) { e.printStackTrace(); } } }