List of usage examples for java.io File canExecute
public boolean canExecute()
From source file:eu.scape_project.tool.toolwrapper.toolwrapper_bash_debian_generator.DebianBashWrapperGenerator.java
private void verifyExecutionPermissionsOfFilesBeingInstalled(File file) { String absolutePath = file.getAbsolutePath(); String relativePath = absolutePath .replaceFirst(new File(inputDir, Constants.BASHGENERATOR_INSTALL_OUTDIRNAME).getAbsolutePath(), ""); if (file.isFile()) { // if the original has execution permission, then add the same // permission to the copied version if (file.canExecute()) { new File(tempDebianDir, relativePath).setExecutable(true); }//from w w w.j a v a2s . c om } else if (file.isDirectory()) { for (File f : file.listFiles()) { verifyExecutionPermissionsOfFilesBeingInstalled(f); } } }
From source file:com.cws.esolutions.agent.processors.impl.ServiceCheckProcessorImpl.java
public ServiceCheckResponse runSystemCheck(final ServiceCheckRequest request) throws ServiceCheckException { final String methodName = IServiceCheckProcessor.CNAME + "#runSystemCheck(final ServiceCheckRequest request) throws ServiceCheckException"; if (DEBUG) {/*from ww w. j a v a2s . c o m*/ DEBUGGER.debug(methodName); DEBUGGER.debug("ServiceCheckRequest: {}", request); } int exitCode = -1; Socket socket = null; File sourceFile = null; CommandLine command = null; BufferedWriter writer = null; ExecuteStreamHandler streamHandler = null; ByteArrayOutputStream outputStream = null; ServiceCheckResponse response = new ServiceCheckResponse(); final DefaultExecutor executor = new DefaultExecutor(); final ExecuteWatchdog watchdog = new ExecuteWatchdog(CONNECT_TIMEOUT * 1000); final DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler(); try { switch (request.getRequestType()) { case NETSTAT: sourceFile = scriptConfig.getScripts().get("netstat"); if (DEBUG) { DEBUGGER.debug("sourceFile: {}", sourceFile); } if (!(sourceFile.canExecute())) { throw new ServiceCheckException( "Script file either does not exist or cannot be executed. Cannot continue."); } command = CommandLine.parse(sourceFile.getAbsolutePath()); if (request.getPortNumber() != 0) { command.addArgument(String.valueOf(request.getPortNumber()), true); } if (DEBUG) { DEBUGGER.debug("CommandLine: {}", command); } outputStream = new ByteArrayOutputStream(); streamHandler = new PumpStreamHandler(outputStream); executor.setWatchdog(watchdog); executor.setStreamHandler(streamHandler); if (DEBUG) { DEBUGGER.debug("ExecuteStreamHandler: {}", streamHandler); DEBUGGER.debug("ExecuteWatchdog: {}", watchdog); DEBUGGER.debug("DefaultExecuteResultHandler: {}", resultHandler); DEBUGGER.debug("DefaultExecutor: {}", executor); } executor.execute(command, resultHandler); resultHandler.waitFor(); exitCode = resultHandler.getExitValue(); if (DEBUG) { DEBUGGER.debug("exitCode: {}", exitCode); } writer = new BufferedWriter(new FileWriter(LOGS_DIRECTORY + "/" + sourceFile.getName() + ".log")); writer.write(outputStream.toString()); writer.flush(); response.setResponseData(outputStream.toString()); if (executor.isFailure(exitCode)) { response.setRequestStatus(AgentStatus.FAILURE); } else { response.setRequestStatus(AgentStatus.SUCCESS); } break; case REMOTEDATE: response.setRequestStatus(AgentStatus.SUCCESS); response.setResponseData(System.currentTimeMillis()); break; case TELNET: response = new ServiceCheckResponse(); int targetPort = request.getPortNumber(); String targetServer = request.getTargetHost(); if (DEBUG) { DEBUGGER.debug("Target port: {}", targetPort); DEBUGGER.debug("Target server: {}", targetServer); } if (targetPort == 0) { throw new ServiceCheckException("Target port number was not assigned. Cannot action request."); } final String CRLF = "\r\n"; final String TERMINATE_TELNET = "^]"; synchronized (new Object()) { InetSocketAddress socketAddress = new InetSocketAddress(targetServer, targetPort); socket = new Socket(); socket.setSoTimeout(IServiceCheckProcessor.CONNECT_TIMEOUT); socket.setSoLinger(false, 0); socket.setKeepAlive(false); try { socket.connect(socketAddress, IServiceCheckProcessor.CONNECT_TIMEOUT); if (!(socket.isConnected())) { throw new ConnectException("Failed to connect to host " + targetServer + " on port " + request.getPortNumber()); } PrintWriter pWriter = new PrintWriter(socket.getOutputStream(), true); pWriter.println(TERMINATE_TELNET + CRLF); pWriter.flush(); pWriter.close(); response.setRequestStatus(AgentStatus.SUCCESS); response.setResponseData("Telnet connection to " + targetServer + " on port " + request.getPortNumber() + " successful."); } catch (ConnectException cx) { response.setRequestStatus(AgentStatus.FAILURE); response.setResponseData("Telnet connection to " + targetServer + " on port " + request.getPortNumber() + " failed with message: " + cx.getMessage()); } } break; case PROCESSLIST: sourceFile = scriptConfig.getScripts().get("processList"); if (DEBUG) { DEBUGGER.debug("sourceFile: {}", sourceFile); } if (!(sourceFile.canExecute())) { throw new ServiceCheckException( "Script file either does not exist or cannot be executed. Cannot continue."); } command = CommandLine.parse(sourceFile.getAbsolutePath()); if (request.getPortNumber() != 0) { command.addArgument(String.valueOf(request.getPortNumber()), true); } if (DEBUG) { DEBUGGER.debug("CommandLine: {}", command); } outputStream = new ByteArrayOutputStream(); streamHandler = new PumpStreamHandler(outputStream); executor.setWatchdog(watchdog); executor.setStreamHandler(streamHandler); if (DEBUG) { DEBUGGER.debug("ExecuteStreamHandler: {}", streamHandler); DEBUGGER.debug("ExecuteWatchdog: {}", watchdog); DEBUGGER.debug("DefaultExecuteResultHandler: {}", resultHandler); DEBUGGER.debug("DefaultExecutor: {}", executor); } executor.execute(command, resultHandler); resultHandler.waitFor(); exitCode = resultHandler.getExitValue(); if (DEBUG) { DEBUGGER.debug("exitCode: {}", exitCode); } writer = new BufferedWriter(new FileWriter(LOGS_DIRECTORY + "/" + sourceFile.getName() + ".log")); writer.write(outputStream.toString()); writer.flush(); response.setResponseData(outputStream.toString()); if (executor.isFailure(exitCode)) { response.setRequestStatus(AgentStatus.FAILURE); } else { response.setRequestStatus(AgentStatus.SUCCESS); } break; default: // unknown operation throw new ServiceCheckException("No valid operation was specified"); } } catch (UnknownHostException uhx) { ERROR_RECORDER.error(uhx.getMessage(), uhx); throw new ServiceCheckException(uhx.getMessage(), uhx); } catch (SocketException sx) { ERROR_RECORDER.error(sx.getMessage(), sx); throw new ServiceCheckException(sx.getMessage(), sx); } catch (IOException iox) { ERROR_RECORDER.error(iox.getMessage(), iox); throw new ServiceCheckException(iox.getMessage(), iox); } catch (InterruptedException ix) { ERROR_RECORDER.error(ix.getMessage(), ix); throw new ServiceCheckException(ix.getMessage(), ix); } finally { try { if (writer != null) { writer.close(); } if ((socket != null) && (!(socket.isClosed()))) { socket.close(); } } catch (IOException iox) { ERROR_RECORDER.error(iox.getMessage(), iox); } } return response; }
From source file:edu.ucsd.crbs.cws.cluster.submission.TestJobCmdScriptCreatorImpl.java
@Test public void testCreateWithErrorEmailsSet() throws Exception { File tempDirectory = Folder.newFolder(); File outputsDir = new File(tempDirectory + File.separator + Constants.OUTPUTS_DIR_NAME); assertTrue(outputsDir.mkdirs());/* w w w . j a v a 2 s.c o m*/ JobEmailNotificationData emailNotifyData = createJobEmailNotificationData(); emailNotifyData.setErrorEmail("error@error.com"); JobBinaries jb = new JobBinaries(); jb.setKeplerScript("kepler.sh"); jb.setRegisterUpdateJar("register.jar"); 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); Parameter emailParam = new Parameter(); emailParam.setName(Constants.CWS_NOTIFYEMAIL); emailParam.setValue("bob@bob.com"); ArrayList<Parameter> params = new ArrayList<>(); params.add(emailParam); j.setParameters(params); 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()); List<String> lines = IOUtils.readLines(new FileReader(jobCmd)); assertTrue(lines != null); boolean emailFound = false; boolean errorEmailFound = false; for (String line : lines) { if (line.startsWith("EMAIL_ADDR=")) { assertTrue(line.equals("EMAIL_ADDR=\"bob@bob.com\"")); emailFound = true; } if (line.startsWith("ERROR_EMAIL_ADDR")) { assertTrue(line.equals("ERROR_EMAIL_ADDR=\"error@error.com\"")); errorEmailFound = true; } } assertTrue(emailFound); assertTrue(errorEmailFound); }
From source file:edu.ucsd.crbs.cws.cluster.submission.TestJobCmdScriptCreatorImpl.java
@Test public void testCreateAndRunScriptWhereUpdateFailsOnceAndThenWorks() throws Exception { assumeTrue(SystemUtils.IS_OS_UNIX);//from w w w . java2s. 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.setMailCommand("cat > email.${finishedMessage};/bin/echo"); jb.setJavaCommand("if [ $cntr -eq 0 ] ; then " + getAndCheckForFalseBinaryFile().getAbsolutePath() + "; else " + getAndCheckForTrueBinaryFile().getAbsolutePath() + "; fi #"); 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 = rclpi.runCommandLineProcess(jobCmd); assertTrue(result.contains("Update of workspace path try 1 of 3 failed. Sleeping 0 seconds and retrying")); 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: 0")); exitFound = true; } } assertTrue(exitFound); }
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 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("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:edu.ucsd.crbs.cws.cluster.submission.TestJobCmdScriptCreatorImpl.java
@Test public void testCreateAndRunScriptWithFakeKeplerThatFailsAndNoEmailsSet() throws Exception { assumeTrue(SystemUtils.IS_OS_UNIX);//from w ww . j a 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(); JobBinaries jb = new JobBinaries(); jb.setKeplerScript(getAndCheckForFalseBinaryFile().getAbsolutePath()); jb.setRegisterUpdateJar("register.jar"); jb.setJavaCommand("/bin/echo"); jb.setRetryCount(1); JobCmdScriptCreatorImpl scriptCreator = new JobCmdScriptCreatorImpl("/workflowsdir", jb, emailNotifyData); File checkForTrue = getAndCheckForTrueBinaryFile(); scriptCreator.setJavaBinaryPath(checkForTrue.getAbsolutePath()); 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(tempDirectory.getAbsolutePath()); try { String result = rclpi.runCommandLineProcess(jobCmd); } catch (Exception ex) { assertTrue(ex.getMessage().startsWith("Non zero exit code (1)")); } 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: 1")); } } }
From source file:edu.ucsd.crbs.cws.cluster.submission.TestJobCmdScriptCreatorImpl.java
@Test public void testCreateWithJobWithNoArgs() throws Exception { File tempDirectory = Folder.newFolder(); File outputsDir = new File(tempDirectory + File.separator + Constants.OUTPUTS_DIR_NAME); assertTrue(outputsDir.mkdirs());/* w ww . ja v a 2s . c o m*/ JobEmailNotificationData emailNotifyData = createJobEmailNotificationData(); JobBinaries jb = new JobBinaries(); jb.setKeplerScript("kepler.sh"); jb.setRegisterUpdateJar("register.jar"); 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()); List<String> lines = IOUtils.readLines(new FileReader(jobCmd)); assertTrue(lines != null); boolean emailFound = false; boolean errorEmailFound = false; boolean javaFound = false; boolean keplerFound = false; for (String line : lines) { if (line.startsWith("kepler.sh")) { assertTrue(":" + line + ":", line.equals("kepler.sh -runwf -redirectgui " + outputsDir.getAbsolutePath() + " /workflowsdir/5/5.kar &")); keplerFound = true; } if (line.startsWith("EMAIL_ADDR=")) { assertTrue(line.equals("EMAIL_ADDR=\"\"")); emailFound = true; } if (line.startsWith("ERROR_EMAIL_ADDR")) { assertTrue(line.equals("ERROR_EMAIL_ADDR=\"\"")); errorEmailFound = true; } if (line.startsWith(" java")) { assertTrue(line, line.equals(" java -jar register.jar --updatepath \"10\" --path \"" + outputsDir.getAbsolutePath() + "\" --size `du " + outputsDir.getAbsolutePath() + " -bs | sed \"s/\\W*\\/.*//\"` $workspaceStatusFlag >> " + tempDirectory.getAbsolutePath() + "/updateworkspacefile.out 2>&1")); javaFound = true; } } assertTrue(emailFound); assertTrue(errorEmailFound); assertTrue(javaFound); assertTrue(keplerFound); }
From source file:edu.ucsd.crbs.cws.cluster.submission.TestJobCmdScriptCreatorImpl.java
@Test public void testCreateAndRunScriptWithFakeKeplerThatSucceedsWithNoEmailSet() throws Exception { assumeTrue(SystemUtils.IS_OS_UNIX);/*ww w . j a va 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(); File stderrFile = new File(outputsDir.getAbsolutePath() + File.separator + "stderr"); assertTrue(stderrFile.createNewFile()); 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); 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); 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);//from ww w . j a 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(); 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 testCreateAndRunScriptWithKeplerThatHasSQLExceptionInStdOutFile() throws Exception { assumeTrue(SystemUtils.IS_OS_UNIX);//from w ww. ja v a2s. 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 + "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"); }