@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);
+ }
+ }
}
+
@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");
+ }
+ }
}
+
@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);
+ }
+ }
}
+