From: davidplunkett Date: Thu, 28 Mar 2019 23:47:05 +0000 (+0000) Subject: fix blocking output on exec processes X-Git-Tag: 1.0.0~2 X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F19%2F519%2F1;p=camunda_workflow.git fix blocking output on exec processes Change-Id: Ica49d4574b1c66e26abbe3ab1f5bd91548496a53 Signed-off-by: davidplunkett --- diff --git a/akraino/src/main/java/com/akraino/bpm/service/impl/BashScriptExecutionServiceImpl.java b/akraino/src/main/java/com/akraino/bpm/service/impl/BashScriptExecutionServiceImpl.java index c6cea57..2990768 100644 --- a/akraino/src/main/java/com/akraino/bpm/service/impl/BashScriptExecutionServiceImpl.java +++ b/akraino/src/main/java/com/akraino/bpm/service/impl/BashScriptExecutionServiceImpl.java @@ -31,31 +31,28 @@ import com.akraino.bpm.service.BashScriptExecutionService; @Service("bashscriptExecutionService") public class BashScriptExecutionServiceImpl implements BashScriptExecutionService{ - private static Logger logger = LoggerFactory.getLogger(BashScriptExecutionServiceImpl.class); - - public void executeScript(String filepatch) { - - try { - logger.debug("Executing the script............."); - Process p = Runtime.getRuntime().exec(filepatch); - p.waitFor(); - BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); - String line = ""; - while ((line = input.readLine()) != null) { - logger.debug(line); - if(line.contains("Error:")) { - throw new TaskExecutorException("problem while executing the Bash script. "+line); - } - - } - - } catch (IOException e) { - throw new TaskExecutorException(filepatch + " not found."); - } catch (InterruptedException e) { - throw new TaskExecutorException("problem while executing the script "+filepatch); - } - - - } - + private static Logger logger = LoggerFactory.getLogger(BashScriptExecutionServiceImpl.class); + + public void executeScript(String filepatch) { + + try { + logger.debug("Executing the script............."); + Process p = Runtime.getRuntime().exec(filepatch); + BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); + String line = ""; + while ((line = input.readLine()) != null) { + logger.debug(line); + } + p.waitFor(); + logger.debug("Script exit code :"+p.exitValue()); + if(p.exitValue()!=0) { + throw new TaskExecutorException("problem while executing the script. exit code :"+p.exitValue()); + } + } catch (IOException e) { + throw new TaskExecutorException(filepatch + " not found."); + } catch (InterruptedException e) { + throw new TaskExecutorException("problem while executing the script "+filepatch); + } + } } + diff --git a/akraino/src/main/java/com/akraino/bpm/service/impl/DeploymentverificationServiceImpl.java b/akraino/src/main/java/com/akraino/bpm/service/impl/DeploymentverificationServiceImpl.java index f17ea47..957455a 100644 --- a/akraino/src/main/java/com/akraino/bpm/service/impl/DeploymentverificationServiceImpl.java +++ b/akraino/src/main/java/com/akraino/bpm/service/impl/DeploymentverificationServiceImpl.java @@ -30,48 +30,47 @@ import com.akraino.bpm.service.DeploymentVerificationService; @Service("deploymentVerificationService") public class DeploymentverificationServiceImpl implements DeploymentVerificationService{ - private static Logger logger = LoggerFactory.getLogger(DeploymentverificationServiceImpl.class); + private static Logger logger = LoggerFactory.getLogger(DeploymentverificationServiceImpl.class); - /** - * Execute a script. potentially several times. - * @param filepatch the file to execute - * @param waitttime how long to wait (in seconds) between executions - * @param iterations the maximum number of iterations - */ - public void executeScript(String filepatch, int waitttime, int iterations) { + /** + * Execute a script. potentially several times. + * @param filepatch the file to execute + * @param waitttime how long to wait (in seconds) between executions + * @param iterations the maximum number of iterations + */ + public void executeScript(String filepatch, int waitttime, int iterations) { - boolean issuccess=false; - for( int i=0;i<=iterations;i++) { - try { - logger.debug("Executing the deployment verification script.............iteration : {}",i); - Thread.sleep(waitttime*1000); - Process p = Runtime.getRuntime().exec(filepatch); - p.waitFor(); - BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); - String line = ""; - while ((line = input.readLine()) != null) { - if (line.equals("0")) { - issuccess=true; - } - } + boolean issuccess=false; + for( int i=0;i<=iterations;i++) { + try { + logger.debug("Executing the deployment verification script.............iteration : {}",i); + Thread.sleep(waitttime*1000); + Process p = Runtime.getRuntime().exec(filepatch); + BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); + String line = ""; + while ((line = input.readLine()) != null) { + logger.debug(line); + } + p.waitFor(); + issuccess = (p.exitValue() == 0); + logger.debug("Script exit code :"+p.exitValue()); + if(p.exitValue()!=0) { + throw new TaskExecutorException("problem while executing the script. exit code :"+p.exitValue()); + } + } catch (IOException e) { + throw new TaskExecutorException(filepatch + " not found."); + } catch (InterruptedException e) { + throw new TaskExecutorException("problem while executing the script "+filepatch); + } + if(issuccess) { + break; + } + } - logger.debug("Script exit code :"+p.exitValue()); - if(p.exitValue()!=0) { - throw new TaskExecutorException("problem while executing the script. exit code :"+p.exitValue()); - } - } catch (IOException e) { - throw new TaskExecutorException(filepatch + " not found."); - } catch (InterruptedException e) { - throw new TaskExecutorException("problem while executing the script "+filepatch); - } - if(issuccess) { - break; - } - } - - if(!issuccess) { - logger.debug("verification script returned 1 "); - throw new TaskExecutorException("1"); - } - } + if(!issuccess) { + logger.debug("verification script returned 1 "); + throw new TaskExecutorException("1"); + } + } } + diff --git a/akraino/src/main/java/com/akraino/bpm/service/impl/ScriptExecutionServiceImpl.java b/akraino/src/main/java/com/akraino/bpm/service/impl/ScriptExecutionServiceImpl.java index e545a84..b763680 100644 --- a/akraino/src/main/java/com/akraino/bpm/service/impl/ScriptExecutionServiceImpl.java +++ b/akraino/src/main/java/com/akraino/bpm/service/impl/ScriptExecutionServiceImpl.java @@ -31,117 +31,91 @@ import com.akraino.bpm.service.ScriptExecutionService; @Service("scriptExecutionService") public class ScriptExecutionServiceImpl implements ScriptExecutionService{ - private static Logger logger = LoggerFactory.getLogger(ScriptExecutionServiceImpl.class); - - /** - * Execute a script - * @param filepatch the script to execute - */ - public void executeScript(String filepatch) { - - try { - logger.debug("Executing the script............."); - Process p = Runtime.getRuntime().exec(filepatch); - BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); - String line = ""; - while ((line = input.readLine()) != null) { - logger.debug(line); - } - p.waitFor(); - logger.debug("Script exit code :"+p.exitValue()); - if(p.exitValue()!=0) { - throw new TaskExecutorException("problem while executing the script. exit code :"+p.exitValue()); - } - - } catch (IOException e) { - throw new TaskExecutorException(filepatch + " not found."); - } catch (InterruptedException e) { - throw new TaskExecutorException("problem while executing the script "+filepatch); - } - - } - - /** - * Execute a command in a directory - * @param dir the directory to execute in - * @param cmd the command to execute - */ - public void executeCDScript(String dir,String cmd) { - - try { - logger.debug("Executing the script.............dir:{},command:{}",dir,cmd); - - String[] command = { "/bin/bash", "-c", "bash "+cmd }; - Process p = Runtime.getRuntime().exec(command, null, new File(dir)); - p.waitFor(); - BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); - String line = ""; - while ((line = input.readLine()) != null) { - logger.debug(line); - } - logger.debug("Script exit code :"+p.exitValue()); - if(p.exitValue()!=0) { - throw new TaskExecutorException("problem while executing the script. exit code :"+p.exitValue()); - } - } catch (IOException e) { - throw new TaskExecutorException(cmd + " not found."); - } catch (InterruptedException e) { - throw new TaskExecutorException("problem while executing the script "+cmd); - } - } - - /** - * Execute a command in a directory - * @param dir the directory to execute in - * @param cmd the command to execute - */ - public void executeCDBashScript(String dir,String cmd) { - - try { - logger.debug("Executing the script.............dir:{},command:{}",dir,cmd); - - String[] command = { "/bin/bash", "-c", "bash "+cmd }; - Process p = Runtime.getRuntime().exec(command, null, new File(dir)); - p.waitFor(); - BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); - String line = ""; - while ((line = input.readLine()) != null) { - logger.debug(line); - } - logger.debug("Script exit code :"+p.exitValue()); - if(p.exitValue()!=0) { - throw new TaskExecutorException("problem while executing the script . exit code :"+p.exitValue()); - } - } catch (IOException e) { - throw new TaskExecutorException(cmd + " not found."); - } catch (InterruptedException e) { - throw new TaskExecutorException("problem while executing the script "+cmd); - } - } - - /*public void executeAirshipScript(String cmd) { - - try { - logger.debug("Executing the script.............{}",cmd); - ProcessBuilder pb = new ProcessBuilder(cmd); - Process shellProcess = pb.start(); - - shellProcess.waitFor(); - BufferedReader input = new BufferedReader(new InputStreamReader(shellProcess.getInputStream())); - String line = ""; - while ((line = input.readLine()) != null) { - logger.debug(line); - } - logger.debug("Script exit code :"+shellProcess.exitValue()); - if(shellProcess.exitValue()!=0) { - throw new TaskExecutorException("problem while executing the script. exit code :"+shellProcess.exitValue()); - } - - - } catch (IOException e) { - throw new TaskExecutorException(cmd + " not found."); - } catch (InterruptedException e) { - throw new TaskExecutorException("problem while executing the script "+cmd); - } - }*/ + private static Logger logger = LoggerFactory.getLogger(ScriptExecutionServiceImpl.class); + + /** + * Execute a script + * @param filepatch the script to execute + */ + public void executeScript(String filepatch) { + + try { + logger.debug("Executing the script............."); + Process p = Runtime.getRuntime().exec(filepatch); + BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); + String line = ""; + while ((line = input.readLine()) != null) { + logger.debug(line); + } + p.waitFor(); + logger.debug("Script exit code :"+p.exitValue()); + if(p.exitValue()!=0) { + throw new TaskExecutorException("problem while executing the script. exit code :"+p.exitValue()); + } + } catch (IOException e) { + throw new TaskExecutorException(filepatch + " not found."); + } catch (InterruptedException e) { + throw new TaskExecutorException("problem while executing the script "+filepatch); + } + + } + + /** + * Execute a command in a directory + * @param dir the directory to execute in + * @param cmd the command to execute + */ + public void executeCDScript(String dir,String cmd) { + + try { + logger.debug("Executing the script.............dir:{}, command:{}",dir,cmd); + + String[] command = { "/bin/bash", "-c", "bash "+cmd }; + Process p = Runtime.getRuntime().exec(command, null, new File(dir)); + BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); + String line = ""; + while ((line = input.readLine()) != null) { + logger.debug(line); + } + p.waitFor(); + logger.debug("Script exit code :"+p.exitValue()); + if(p.exitValue()!=0) { + throw new TaskExecutorException("problem while executing the script. exit code :"+p.exitValue()); + } + } catch (IOException e) { + throw new TaskExecutorException(cmd + " not found."); + } catch (InterruptedException e) { + throw new TaskExecutorException("problem while executing the script "+cmd); + } + } + + /** + * Execute a command in a directory + * @param dir the directory to execute in + * @param cmd the command to execute + */ + public void executeCDBashScript(String dir,String cmd) { + + try { + logger.debug("Executing the script.............dir:{}, command:{}",dir,cmd); + + String[] command = { "/bin/bash", "-c", "bash "+cmd }; + Process p = Runtime.getRuntime().exec(command, null, new File(dir)); + BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); + String line = ""; + while ((line = input.readLine()) != null) { + logger.debug(line); + } + p.waitFor(); + logger.debug("Script exit code :"+p.exitValue()); + if(p.exitValue()!=0) { + throw new TaskExecutorException("problem while executing the script . exit code :"+p.exitValue()); + } + } catch (IOException e) { + throw new TaskExecutorException(cmd + " not found."); + } catch (InterruptedException e) { + throw new TaskExecutorException("problem while executing the script "+cmd); + } + } } +