List of usage examples for org.apache.commons.io IOUtils readLines
public static List readLines(Reader input) throws IOException
Reader
as a list of Strings, one entry per line. From source file:edu.ucsd.crbs.cws.cluster.submission.TestJobCmdScriptCreatorImpl.java
@Test public void testCreateAndRunScriptWithFakeFailingKeplerWithOnlyErrorEmailIsSet() throws Exception { assumeTrue(SystemUtils.IS_OS_UNIX);// w ww. jav a 2 s . c om File baseDirectory = Folder.newFolder(); File tempDirectory = new File(baseDirectory + File.separator + "subdir"); File outputsDir = new File(tempDirectory + File.separator + Constants.OUTPUTS_DIR_NAME); assertTrue(outputsDir.mkdirs()); FileWriter fw = new FileWriter(outputsDir.getAbsoluteFile() + File.separator + "WORKFLOW.FAILED.txt.tmp"); fw.write("simple.error.message=simple\n"); fw.write("detailed.error.message=detailed\n"); fw.flush(); fw.close(); JobEmailNotificationData emailNotifyData = createJobEmailNotificationData(); emailNotifyData.setErrorEmail("error@error.com"); File stderrFile = new File(outputsDir.getAbsolutePath() + File.separator + "stderr"); assertTrue(stderrFile.createNewFile()); JobBinaries jb = new JobBinaries(); jb.setKeplerScript("/bin/mv WORKFLOW.FAILED.txt.tmp WORKFLOW.FAILED.txt;#"); jb.setRegisterUpdateJar("register.jar"); jb.setJavaCommand("/bin/echo"); jb.setEchoCommand("/bin/echo"); jb.setMailCommand("cat >> email.${finishedMessage};/bin/echo "); jb.setRetryCount(1); JobCmdScriptCreatorImpl scriptCreator = new JobCmdScriptCreatorImpl("/workflowsdir", jb, emailNotifyData); Job j = new Job(); Workflow w = new Workflow(); w.setId(new Long(5)); w.setName("worky"); j.setWorkflow(w); j.setId(2345L); j.setName("myjoby"); j.setOwner("bob"); String jobCmd = scriptCreator.create(tempDirectory.getAbsolutePath(), j, new Long(2345)); assertTrue(jobCmd != null); RunCommandLineProcessImpl rclpi = new RunCommandLineProcessImpl(); rclpi.setWorkingDirectory(outputsDir.getAbsolutePath()); String result; try { result = rclpi.runCommandLineProcess(jobCmd); fail("Expected exception"); } catch (Exception ex) { assertTrue(ex.getMessage().startsWith("Non zero exit code (101)")); } File emailStartFile = new File(outputsDir.getAbsolutePath() + File.separator + "email."); assertTrue(!emailStartFile.exists()); File emailFailedFile = new File(outputsDir.getAbsolutePath() + File.separator + "email.failed"); List<String> lines = IOUtils.readLines(new FileReader(emailFailedFile)); for (String line : lines) { if (line.startsWith("Dear")) { assertTrue(line.contains("Dear bob,")); } } }
From source file:edu.ucsd.crbs.cws.cluster.submission.TestJobCmdScriptCreatorImpl.java
@Test public void testCreateAndRunScriptWithFakeKeplerThatSucceedsWithPreExistingWorkflowFailedFile() throws Exception { assumeTrue(SystemUtils.IS_OS_UNIX);// www . j a va2 s. com File baseDirectory = Folder.newFolder(); File tempDirectory = new File(baseDirectory + File.separator + "subdir"); File outputsDir = new File(tempDirectory + File.separator + Constants.OUTPUTS_DIR_NAME); assertTrue(outputsDir.mkdirs()); JobEmailNotificationData emailNotifyData = createJobEmailNotificationData(); JobBinaries jb = new JobBinaries(); jb.setKeplerScript(getAndCheckForTrueBinaryFile().getAbsolutePath()); jb.setRegisterUpdateJar("register.jar"); jb.setJavaCommand("/bin/echo"); jb.setRetryCount(1); JobCmdScriptCreatorImpl scriptCreator = new JobCmdScriptCreatorImpl("/workflowsdir", jb, emailNotifyData); Job j = new Job(); Workflow w = new Workflow(); w.setId(new Long(5)); j.setWorkflow(w); FileWriter fw = new FileWriter(outputsDir.getAbsoluteFile() + File.separator + "WORKFLOW.FAILED.txt"); fw.write("simple.error.message=simple\n"); fw.write("detailed.error.message=detailed\n"); fw.flush(); fw.close(); String jobCmd = scriptCreator.create(tempDirectory.getAbsolutePath(), j, new Long(2345)); assertTrue(jobCmd != null); assertTrue( jobCmd.equals(outputsDir.getAbsolutePath() + File.separator + JobCmdScriptCreatorImpl.JOB_CMD_SH)); File checkCmdFile = new File(jobCmd); assertTrue(checkCmdFile.canExecute()); RunCommandLineProcessImpl rclpi = new RunCommandLineProcessImpl(); rclpi.setWorkingDirectory(tempDirectory.getAbsolutePath()); String result = rclpi.runCommandLineProcess(jobCmd); List<String> yos = IOUtils.readLines(new FileReader(jobCmd)); String logFile = baseDirectory.getAbsoluteFile() + File.separator + "job...log"; File checkLogFile = new File(logFile); assertTrue(logFile + " and we ran " + jobCmd, checkLogFile.exists()); List<String> lines = IOUtils.readLines(new FileReader(logFile)); for (String line : lines) { if (line.startsWith("exitcode: ")) { assertTrue(line, line.equals("exitcode: 0")); } } String updateFile = tempDirectory.getAbsoluteFile() + File.separator + "updateworkspacefile.out"; lines = IOUtils.readLines(new FileReader(updateFile)); for (String line : lines) { if (line.startsWith("-jar")) { assertTrue(line, line.startsWith( "-jar register.jar --updatepath 2345 --path " + outputsDir.getAbsolutePath() + " --size ")); assertTrue(line, line.endsWith(" --workspacefilefailed false")); } } }
From source file:edu.ucsd.crbs.cws.cluster.submission.TestJobCmdScriptCreatorImpl.java
@Test public void testCreateAndRunScriptWithFakeKeplerThatGeneratesWorkflowFailedFile() throws Exception { assumeTrue(SystemUtils.IS_OS_UNIX);// ww w .j a v a 2 s.co m File baseDirectory = Folder.newFolder(); File tempDirectory = new File(baseDirectory + File.separator + "subdir"); File outputsDir = new File(tempDirectory + File.separator + Constants.OUTPUTS_DIR_NAME); assertTrue(outputsDir.mkdirs()); JobEmailNotificationData emailNotifyData = createJobEmailNotificationData(); JobBinaries jb = new JobBinaries(); jb.setKeplerScript( "/bin/echo -e \"simple.error.message=fake fail\\\\n" + "detailed.error.message=fake fail detailed" + "\\\\n\" > " + outputsDir.getAbsolutePath() + File.separator + "WORKFLOW.FAILED.txt"); jb.setRegisterUpdateJar("register.jar"); jb.setJavaCommand("/bin/echo"); jb.setRetryCount(1); JobCmdScriptCreatorImpl scriptCreator = new JobCmdScriptCreatorImpl("/workflowsdir", jb, emailNotifyData); Job j = new Job(); Workflow w = new Workflow(); w.setId(new Long(5)); j.setWorkflow(w); String jobCmd = scriptCreator.create(tempDirectory.getAbsolutePath(), j, new Long(10)); assertTrue(jobCmd != null); assertTrue( jobCmd.equals(outputsDir.getAbsolutePath() + File.separator + JobCmdScriptCreatorImpl.JOB_CMD_SH)); File checkCmdFile = new File(jobCmd); assertTrue(checkCmdFile.canExecute()); RunCommandLineProcessImpl rclpi = new RunCommandLineProcessImpl(); rclpi.setWorkingDirectory(outputsDir.getAbsolutePath()); String result; try { result = rclpi.runCommandLineProcess(jobCmd); } catch (Exception ex) { assertTrue(ex.getMessage().startsWith("Non zero exit code (101)")); } String logFile = tempDirectory.getAbsoluteFile() + File.separator + "job...log"; File checkLogFile = new File(logFile); assertTrue(logFile + " and we ran " + jobCmd, checkLogFile.exists()); List<String> lines = IOUtils.readLines(new FileReader(logFile)); for (String line : lines) { if (line.startsWith("exitcode: ")) { assertTrue(line, line.equals("exitcode: 101")); } } String updateFile = tempDirectory.getAbsoluteFile() + File.separator + "updateworkspacefile.out"; lines = IOUtils.readLines(new FileReader(updateFile)); for (String line : lines) { if (line.startsWith("-jar")) { assertTrue(line, line.startsWith( "-jar register.jar --updatepath 10 --path " + outputsDir.getAbsolutePath() + " --size ")); assertTrue(line, line.endsWith(" --workspacefilefailed true")); } } }
From source file:edu.ucsd.crbs.cws.cluster.submission.TestJobCmdScriptCreatorImpl.java
@Test public void testCreateAndRunScriptWithFakeKeplerThatSimulatesUSR2Signal() throws Exception { assumeTrue(SystemUtils.IS_OS_UNIX);//from w w w .j ava 2 s . co m File baseDirectory = Folder.newFolder(); File tempDirectory = new File(baseDirectory + File.separator + "subdir"); File outputsDir = new File(tempDirectory + File.separator + Constants.OUTPUTS_DIR_NAME); assertTrue(outputsDir.mkdirs()); JobEmailNotificationData emailNotifyData = createJobEmailNotificationData(); JobBinaries jb = new JobBinaries(); jb.setKeplerScript("kill -s USR2 $$;sleep 100"); jb.setRegisterUpdateJar("register.jar"); jb.setJavaCommand("/bin/echo"); jb.setRetryCount(1); JobCmdScriptCreatorImpl scriptCreator = new JobCmdScriptCreatorImpl("/workflowsdir", jb, emailNotifyData); Job j = new Job(); Workflow w = new Workflow(); w.setId(new Long(5)); j.setWorkflow(w); String jobCmd = scriptCreator.create(tempDirectory.getAbsolutePath(), j, new Long(10)); assertTrue(jobCmd != null); assertTrue( jobCmd.equals(outputsDir.getAbsolutePath() + File.separator + JobCmdScriptCreatorImpl.JOB_CMD_SH)); File checkCmdFile = new File(jobCmd); assertTrue(checkCmdFile.canExecute()); RunCommandLineProcessImpl rclpi = new RunCommandLineProcessImpl(); rclpi.setWorkingDirectory(outputsDir.getAbsolutePath()); String result; try { result = rclpi.runCommandLineProcess(jobCmd); } catch (Exception ex) { assertTrue(ex.getMessage(), ex.getMessage().startsWith("Non zero exit code (100)")); } String logFile = tempDirectory.getAbsoluteFile() + File.separator + "job...log"; File checkLogFile = new File(logFile); assertTrue(logFile + " and we ran " + jobCmd, checkLogFile.exists()); List<String> lines = IOUtils.readLines(new FileReader(logFile)); for (String line : lines) { if (line.startsWith("exitcode: ")) { assertTrue(line, line.equals("exitcode: 100")); } } checkWorkflowFailed(outputsDir.getAbsolutePath(), "Job killed by scheduler", "Job received USR2 signal which is the signal to exit"); }
From source file:com.jaspersoft.studio.statistics.UsageManager.java
/** * Check on the server if there is a newer version of Jaspersoft Studio * /*from w w w . j av a 2s . com*/ * @return a not null VersionCheckResult that contains information on the new version and if there is a new version */ public VersionCheckResult checkVersion() { String uuid = getAppDataFolder().getName(); String versionKnownByTheStats = getInstallationInfoContainer().getProperty(VERSION_INFO); int newInstallation = 0; // Read if there is an UUID in the preferences used to track the older versions PropertiesHelper ph = PropertiesHelper.getInstance(); String backward_uuid = ph.getString(BACKWARD_UUID_PROPERTY, null); if (backward_uuid == null) { // If the backward value is null then i'm already using the new system, check if it // is a new installation or an update if (versionKnownByTheStats == null) { // Since the last version was not yet initialized it is a new installation newInstallation = 1; } else if (!versionKnownByTheStats.equals(getVersion())) { // There is a version stored in the file, that is the last version known by the server, if it is // different from the real version then there were an update newInstallation = 2; } } else { // If the backward value is != null then it isn't for sure a new installation, maybe there were // but since i'm inside the new code then it should be an update. newInstallation = 2; setInstallationInfo(VERSION_INFO, getVersion()); } StringBuilder urlBuilder = new StringBuilder(); urlBuilder.append(HEARTBEAT_SERVER_URL); urlBuilder.append("?version=");//$NON-NLS-1$ urlBuilder.append(getVersion()); urlBuilder.append("&uuid=");//$NON-NLS-1$ urlBuilder.append(uuid); urlBuilder.append("&new=");//$NON-NLS-1$ urlBuilder.append(newInstallation); urlBuilder.append("&isRCP=");//$NON-NLS-1$ urlBuilder.append(String.valueOf(isRCP())); String urlstr = urlBuilder.toString(); System.out.println("Invoking URL: " + urlstr); //$NON-NLS-1$ VersionCheckResult result = new VersionCheckResult(); try { Executor exec = Executor.newInstance(); URI fullURI = new URI(urlstr); HttpUtils.setupProxy(exec, fullURI); HttpHost proxy = HttpUtils.getUnauthProxy(exec, fullURI); Request req = Request.Get(urlstr); if (proxy != null) req.viaProxy(proxy); String response = exec.execute(req).returnContent().asString(); String serverVersion = null; String optmsg = ""; //$NON-NLS-1$ for (String inputLine : IOUtils.readLines(new StringReader(response))) { if (serverVersion == null) { serverVersion = inputLine.trim(); } else { optmsg += inputLine; } } // Update the installation info only if the informations was given correctly to the server setInstallationInfo(VERSION_INFO, getVersion()); // Remove the old backward compatibility value if present to switch to the new system if (backward_uuid != null) { ph.removeString(BACKWARD_UUID_PROPERTY, InstanceScope.SCOPE); } result = new VersionCheckResult(serverVersion, optmsg, getVersion()); } catch (Exception ex) { ex.printStackTrace(); JaspersoftStudioPlugin.getInstance().logError(Messages.UsageManager_errorUpdateCheck, ex); } return result; }
From source file:edu.ucsd.crbs.cws.cluster.submission.TestJobCmdScriptCreatorImpl.java
@Test public void testCreateAndRunScriptWithFakeKeplerThatSimulatesUSR2SignalButAlreadyHasWorkFlowFailedFile() throws Exception { assumeTrue(SystemUtils.IS_OS_UNIX);//from w ww .j a va 2s . co m File baseDirectory = Folder.newFolder(); File tempDirectory = new File(baseDirectory + File.separator + "subdir"); File outputsDir = new File(tempDirectory + File.separator + Constants.OUTPUTS_DIR_NAME); assertTrue(outputsDir.mkdirs()); JobEmailNotificationData emailNotifyData = createJobEmailNotificationData(); JobBinaries jb = new JobBinaries(); jb.setKeplerScript("mv " + outputsDir.getAbsoluteFile() + File.separator + "WORKFLOW.FAILED.txt2 " + outputsDir.getAbsoluteFile() + File.separator + "WORKFLOW.FAILED.txt; kill -s USR2 $$;sleep 100"); jb.setRegisterUpdateJar("register.jar"); jb.setJavaCommand("/bin/echo"); jb.setRetryCount(1); JobCmdScriptCreatorImpl scriptCreator = new JobCmdScriptCreatorImpl("/workflowsdir", jb, emailNotifyData); Job j = new Job(); Workflow w = new Workflow(); w.setId(new Long(5)); j.setWorkflow(w); FileWriter fw = new FileWriter(outputsDir.getAbsoluteFile() + File.separator + "WORKFLOW.FAILED.txt2"); fw.write("simple.error.message=simple\n"); fw.write("detailed.error.message=detailed\n"); fw.flush(); fw.close(); String jobCmd = scriptCreator.create(tempDirectory.getAbsolutePath(), j, new Long(10)); assertTrue(jobCmd != null); assertTrue( jobCmd.equals(outputsDir.getAbsolutePath() + File.separator + JobCmdScriptCreatorImpl.JOB_CMD_SH)); File checkCmdFile = new File(jobCmd); assertTrue(checkCmdFile.canExecute()); RunCommandLineProcessImpl rclpi = new RunCommandLineProcessImpl(); rclpi.setWorkingDirectory(outputsDir.getAbsolutePath()); String result; try { result = rclpi.runCommandLineProcess(jobCmd); } catch (Exception ex) { assertTrue(ex.getMessage(), ex.getMessage().startsWith("Non zero exit code (100)")); } String logFile = tempDirectory.getAbsoluteFile() + File.separator + "job...log"; File checkLogFile = new File(logFile); assertTrue(logFile + " and we ran " + jobCmd, checkLogFile.exists()); List<String> lines = IOUtils.readLines(new FileReader(logFile)); for (String line : lines) { if (line.startsWith("exitcode: ")) { assertTrue(line, line.equals("exitcode: 100")); } } File failedFile = checkWorkflowFailed(outputsDir.getAbsolutePath(), "simple", "detailed"); lines = IOUtils.readLines(new FileReader(failedFile)); boolean jobFound = false; for (String line : lines) { if (line.startsWith(" Job received")) { assertTrue(line, line.equals(" Job received USR2 signal which in SGE meant it is about to be killed")); jobFound = true; } } assertTrue(jobFound); }
From source file:edu.ucsd.crbs.cws.cluster.submission.TestJobCmdScriptCreatorImpl.java
@Test public void testCreateAndRunScriptWithKeplerThatHasExceptionInStdErrFile() throws Exception { assumeTrue(SystemUtils.IS_OS_UNIX);//from w ww . ja v a 2 s. co m File baseDirectory = Folder.newFolder(); File tempDirectory = new File(baseDirectory + File.separator + "subdir"); File outputsDir = new File(tempDirectory + File.separator + Constants.OUTPUTS_DIR_NAME); assertTrue(outputsDir.mkdirs()); JobEmailNotificationData emailNotifyData = createJobEmailNotificationData(); JobBinaries jb = new JobBinaries(); jb.setKeplerScript(getAndCheckForTrueBinaryFile().getAbsolutePath()); jb.setRegisterUpdateJar("register.jar"); jb.setJavaCommand("/bin/echo"); jb.setRetryCount(1); JobCmdScriptCreatorImpl scriptCreator = new JobCmdScriptCreatorImpl("/workflowsdir", jb, emailNotifyData); Job j = new Job(); Workflow w = new Workflow(); w.setId(new Long(5)); j.setWorkflow(w); FileWriter fw = new FileWriter(outputsDir.getAbsoluteFile() + File.separator + "stderr"); fw.write("Exception in thread \"main\" Java returned: 1\n" + " at org.kepler.build.modules.ModulesTask.execute(ModulesTask.java:106)\n" + " at org.kepler.build.runner.Kepler.main(Kepler.java:109)\n" + "Caused by: Java returned: 1\n" + " at org.kepler.build.modules.ModulesTask.execute(ModulesTask.java:106)\n" + " at org.kepler.build.runner.Kepler.run(Kepler.java:266)\n" + " at org.kepler.build.modules.ModulesTask.execute(ModulesTask.java:102)\n" + " ... 1 more\n" + "Caused by: Java returned: 1\n" + " at org.apache.tools.ant.taskdefs.Java.execute(Java.java:111)\n" + " at org.kepler.build.Run.runSuite(Run.java:379)\n" + " at org.kepler.build.Run.run(Run.java:240)\n" + " at org.kepler.build.modules.ModulesTask.execute(ModulesTask.java:102)\n" + " ... 3 more"); fw.flush(); fw.close(); String jobCmd = scriptCreator.create(tempDirectory.getAbsolutePath(), j, new Long(10)); assertTrue(jobCmd != null); assertTrue( jobCmd.equals(outputsDir.getAbsolutePath() + File.separator + JobCmdScriptCreatorImpl.JOB_CMD_SH)); File checkCmdFile = new File(jobCmd); assertTrue(checkCmdFile.canExecute()); RunCommandLineProcessImpl rclpi = new RunCommandLineProcessImpl(); rclpi.setWorkingDirectory(outputsDir.getAbsolutePath()); String result; try { result = rclpi.runCommandLineProcess(jobCmd); } catch (Exception ex) { assertTrue(ex.getMessage(), ex.getMessage().startsWith("Non zero exit code (101)")); } String logFile = tempDirectory.getAbsoluteFile() + File.separator + "job...log"; File checkLogFile = new File(logFile); assertTrue(logFile + " and we ran " + jobCmd, checkLogFile.exists()); List<String> lines = IOUtils.readLines(new FileReader(logFile)); for (String line : lines) { if (line.startsWith("exitcode: ")) { assertTrue(line, line.equals("exitcode: 101")); } } checkWorkflowFailed(outputsDir.getAbsolutePath(), "Error running Kepler", "Found Exception in thread main Java returned: 1 in the stderr file for Kepler"); }
From source file:com.logiware.accounting.domain.EdiInvoice.java
private void createMaerskLineInvoice(File file) throws Exception { InputStream inputStream = null; try {/* www . j a va 2 s.co m*/ TradingPartnerDAO tradingPartnerDAO = new TradingPartnerDAO(); vendorNumber = "MAEINC0001"; vendorName = tradingPartnerDAO.getAccountName(this.vendorNumber); status = ConstantsInterface.STATUS_EDI_OPEN; company = Company.MAERSK_LINE; CompanyModel companyModel = new SystemRulesDAO().getCompanyDetails(); this.billToParty = companyModel.getName() + "\n" + companyModel.getAddress(); inputStream = new FileInputStream(file); List<String> lines = IOUtils.readLines(inputStream); ediInvoiceContainers = new ArrayList<EdiInvoiceContainer>(); ediInvoiceDetails = new ArrayList<EdiInvoiceDetail>(); for (String line : lines) { if (CommonUtils.isStartsWith(line, "B3")) { String[] values = line.split("\\*"); invoiceNumber = values[2]; //Invoice Number searchInvoiceNumber = invoiceNumber.replaceAll("[^\\p{Alpha}\\p{Digit}]+", ""); etd = DateUtils.parseDate(values[6], "yyyyMMdd"); //ETD invoiceAmount = (Double.parseDouble(values[7].replaceAll("[^0-9.]", "")) / 100); //Invoice Amount eta = DateUtils.parseDate(values[9], "yyyyMMdd"); //ETA invoiceDate = DateUtils.parseDate(values[12], "yyyyMMdd"); //Invoice Date Vendor vendor = tradingPartnerDAO.getVendor(vendorNumber); Integer termValue = 0; String termDesc = "Due Upon Receipt"; if (null != vendor && null != vendor.getCterms()) { termValue = Integer.parseInt(vendor.getCterms().getCode()); termDesc = vendor.getCterms().getCodedesc(); } dueDate = DateUtils.addDays(invoiceDate, termValue); paymentTerms = termDesc; } else if (CommonUtils.isStartsWith(line, "N9")) { String[] values = line.split("\\*"); if (StringUtils.equalsIgnoreCase(values[1], "BN")) { bookingNumber = values[2]; //Booking Number } else if (StringUtils.equalsIgnoreCase(values[1], "MB")) { masterBl = values[2]; //Master BL } else if (StringUtils.equalsIgnoreCase(values[1], "SI")) { yourReference1 = values[2]; // Your Reference } } else if (CommonUtils.isStartsWith(line, "V1")) { String[] values = line.split("\\*"); vesselName = values[2]; //Vessel Name voyageNumber = values[4]; //Voyage Number } else if (CommonUtils.isStartsWith(line, "L11")) { String[] values = line.split("\\*"); if (StringUtils.equalsIgnoreCase(values[2], "BM")) { blNumber = values[1]; //Bl Number } } else if (CommonUtils.isStartsWith(line, "C3")) { String[] values = line.split("\\*"); currency = values[1]; //Currency } else if (CommonUtils.isStartsWith(line, "R4")) { String[] values = line.split("\\*"); if (StringUtils.equalsIgnoreCase(values[1], "D")) { portOfDischarge = values[4]; //Port of Discharge } else if (StringUtils.equalsIgnoreCase(values[1], "E")) { placeOfDelivery = values[4]; //Place of Delivery } else if (StringUtils.equalsIgnoreCase(values[1], "L")) { portOfLoading = values[4]; //Port of Loading } else if (StringUtils.equalsIgnoreCase(values[1], "R")) { placeOfReceipt = values[4]; //Place of Receipt } } else if (CommonUtils.isStartsWith(line, "L1")) { String[] values = line.split("\\*"); EdiInvoiceDetail ediInvoiceDetail = new EdiInvoiceDetail(); ediInvoiceDetail.setEdiInvoice(this); ediInvoiceDetail.setCurrency(currency); ediInvoiceDetail.setDescription(values[12]); //Description of Charges ediInvoiceDetail.setQuantity(values[17]); //Qty ediInvoiceDetail.setUom(values[8]); //UoM ediInvoiceDetail.setPrice(values[2]); //Unit Price ediInvoiceDetails.add(ediInvoiceDetail); } else if (CommonUtils.isStartsWith(line, "N7")) { String[] values = line.split("\\*"); ediInvoiceContainers .add(new EdiInvoiceContainer(values[1] + "-" + values[2] + "-" + values[3], this)); //Container No } } } catch (Exception e) { log.info("createMaerskLineInvoice failed on " + new Date(), e); } finally { if (null != inputStream) { inputStream.close(); } } }
From source file:edu.ucsd.crbs.cws.cluster.submission.TestJobCmdScriptCreatorImpl.java
@Test public void testCreateAndRunScriptWithKeplerThatHasSQLExceptionInStdOutFile() throws Exception { assumeTrue(SystemUtils.IS_OS_UNIX);// w w w . j a v a2 s . c o m File baseDirectory = Folder.newFolder(); File tempDirectory = new File(baseDirectory + File.separator + "subdir"); File outputsDir = new File(tempDirectory + File.separator + Constants.OUTPUTS_DIR_NAME); assertTrue(outputsDir.mkdirs()); JobEmailNotificationData emailNotifyData = createJobEmailNotificationData(); JobBinaries jb = new JobBinaries(); jb.setKeplerScript(getAndCheckForTrueBinaryFile().getAbsolutePath()); jb.setRegisterUpdateJar("register.jar"); jb.setJavaCommand("/bin/echo"); jb.setRetryCount(1); JobCmdScriptCreatorImpl scriptCreator = new JobCmdScriptCreatorImpl("/workflowsdir", jb, emailNotifyData); Job j = new Job(); Workflow w = new Workflow(); w.setId(new Long(5)); j.setWorkflow(w); FileWriter fw = new FileWriter(outputsDir.getAbsoluteFile() + File.separator + "stdout"); fw.write(" [null]\n" + " [null] ... 4 more\n" + " [null] Caused by: java.lang.Exception: Failed to call application initializer class \"org.kepler.gui.KeplerInitializer\". Perhaps the configuration file \"file:/sharktopus/megashark/cws/bin/Kepler-20141020.103034/common/configs/ptolemy/configs/kepler/ConfigRedirectGUIWithCache.xml\" has a problem?\n" + " [null] Caused by: java.sql.SQLException: Unable to start HSQL server for jdbc:hsqldb:hsql://localhost:26343/hsqldb;filepath=hsqldb:file:/home/churas/.kepler/cache-2.4/cachedata/hsqldb\n" + " [null] at ptolemy.actor.gui.ConfigurationApplication.readConfiguration(ConfigurationApplication.java:716) at org.kepler.util.sql.HSQL._getConnection(HSQL.java:683)\n" + " [null]\n"); fw.flush(); fw.close(); String jobCmd = scriptCreator.create(tempDirectory.getAbsolutePath(), j, new Long(10)); assertTrue(jobCmd != null); assertTrue( jobCmd.equals(outputsDir.getAbsolutePath() + File.separator + JobCmdScriptCreatorImpl.JOB_CMD_SH)); File checkCmdFile = new File(jobCmd); assertTrue(checkCmdFile.canExecute()); RunCommandLineProcessImpl rclpi = new RunCommandLineProcessImpl(); rclpi.setWorkingDirectory(outputsDir.getAbsolutePath()); String result; try { result = rclpi.runCommandLineProcess(jobCmd); } catch (Exception ex) { assertTrue(ex.getMessage(), ex.getMessage().startsWith("Non zero exit code (101)")); } String logFile = tempDirectory.getAbsoluteFile() + File.separator + "job...log"; File checkLogFile = new File(logFile); assertTrue(logFile + " and we ran " + jobCmd, checkLogFile.exists()); List<String> lines = IOUtils.readLines(new FileReader(logFile)); boolean exitFound = false; for (String line : lines) { if (line.startsWith("exitcode: ")) { assertTrue(line, line.equals("exitcode: 101")); exitFound = true; } } assertTrue(exitFound); checkWorkflowFailed(outputsDir.getAbsolutePath(), "Error running Kepler due to internal database", "SQLException was found in stdout file"); }
From source file:edu.ucsd.crbs.cws.cluster.submission.TestJobCmdScriptCreatorImpl.java
@Test public void testCreateAndRunScriptWhereUpdateFailsWithThreeRetries() throws Exception { assumeTrue(SystemUtils.IS_OS_UNIX);//from w w w . ja v a 2 s .c o m File baseDirectory = Folder.newFolder(); File tempDirectory = new File(baseDirectory + File.separator + "subdir"); File outputsDir = new File(tempDirectory + File.separator + Constants.OUTPUTS_DIR_NAME); assertTrue(outputsDir.mkdirs()); JobEmailNotificationData emailNotifyData = createJobEmailNotificationData(); emailNotifyData.setErrorEmail("error@error.com > emailargs"); JobBinaries jb = new JobBinaries(); jb.setKeplerScript(getAndCheckForTrueBinaryFile().getAbsolutePath()); jb.setRegisterUpdateJar("register.jar"); jb.setMailCommand("cat > email.${finishedMessage};/bin/echo"); jb.setJavaCommand(getAndCheckForFalseBinaryFile().getAbsolutePath()); jb.setRetryCount(3); JobCmdScriptCreatorImpl scriptCreator = new JobCmdScriptCreatorImpl("/workflowsdir", jb, emailNotifyData); Job j = new Job(); Workflow w = new Workflow(); w.setId(new Long(5)); j.setWorkflow(w); String jobCmd = scriptCreator.create(tempDirectory.getAbsolutePath(), j, new Long(10)); assertTrue(jobCmd != null); assertTrue( jobCmd.equals(outputsDir.getAbsolutePath() + File.separator + JobCmdScriptCreatorImpl.JOB_CMD_SH)); File checkCmdFile = new File(jobCmd); assertTrue(checkCmdFile.canExecute()); RunCommandLineProcessImpl rclpi = new RunCommandLineProcessImpl(); rclpi.setWorkingDirectory(outputsDir.getAbsolutePath()); String result; try { result = rclpi.runCommandLineProcess(jobCmd); } catch (Exception ex) { assertTrue(ex.getMessage(), ex.getMessage().startsWith("Non zero exit code (102)")); } String logFile = tempDirectory.getAbsoluteFile() + File.separator + "job...log"; File checkLogFile = new File(logFile); assertTrue(logFile + " and we ran " + jobCmd, checkLogFile.exists()); List<String> lines = IOUtils.readLines(new FileReader(logFile)); for (String line : lines) { if (line.startsWith("exitcode: ")) { assertTrue(line, line.equals("exitcode: 102")); } } lines = IOUtils .readLines(new FileReader(outputsDir.getAbsoluteFile() + File.separator + "WORKFLOW.FAILED.txt")); for (String line : lines) { if (line.startsWith("simple.error.message")) { assertTrue(line, line.equals("simple.error.message=Unable to update WorkspaceFile")); } if (line.startsWith("detailed.error.message")) { assertTrue(line, line.equals( "detailed.error.message=Received non zero exit code (1) when trying to update WorkspaceFile")); } } File emailFailedFile = new File(outputsDir.getAbsolutePath() + File.separator + "email.failed"); assertTrue(emailFailedFile.exists()); lines = IOUtils.readLines(new FileReader(emailFailedFile)); boolean yourFound = false; boolean unableFound = false; for (String line : lines) { if (line.startsWith("Your Unknown job: ")) { assertTrue(line.contains(" has failed")); yourFound = true; } if (line.contains("WORKFLOW.FAILED.txt:")) { assertTrue(line.contains("Unable to update WorkspaceFile")); unableFound = true; } } assertTrue(yourFound); assertTrue(unableFound); }