From: Eby, Robert (re2429) Date: Wed, 6 Feb 2019 01:31:02 +0000 (-0500) Subject: Use bash rather than sh X-Git-Tag: 1.0.0~20 X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F71%2F371%2F1;p=camunda_workflow.git Use bash rather than sh Added missing deploy parameter Change-Id: I04233cfff797a4d9b106f463c6688b57c7d74406 Signed-off-by: Eby, Robert (re2429) --- diff --git a/.gitignore b/.gitignore index cd9ded1..32fc3bb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ /akraino/.project /akraino/Servers /config/.application.yaml.swp - +/akraino/target diff --git a/akraino/pom.xml b/akraino/pom.xml index 515f0bd..68264ec 100644 --- a/akraino/pom.xml +++ b/akraino/pom.xml @@ -62,7 +62,7 @@ org.springframework.boot spring-boot-starter-tertifartifactId> test - 1.5.8.RE + 1.5.8.RE --> diff --git a/akraino/src/main/java/com/akraino/bpm/delegate/DeployPostVerficationRemoteScriptExecutor.java b/akraino/src/main/java/com/akraino/bpm/delegate/DeployPostVerficationRemoteScriptExecutor.java index cca42b0..569936c 100644 --- a/akraino/src/main/java/com/akraino/bpm/delegate/DeployPostVerficationRemoteScriptExecutor.java +++ b/akraino/src/main/java/com/akraino/bpm/delegate/DeployPostVerficationRemoteScriptExecutor.java @@ -32,16 +32,14 @@ import com.akraino.bpm.service.RemoteScriptExecutionService; @Component public class DeployPostVerficationRemoteScriptExecutor implements JavaDelegate { - - - private static Logger logger = LoggerFactory.getLogger(DeployPostVerficationRemoteScriptExecutor.class); - + private static Logger logger = LoggerFactory.getLogger(DeployPostVerficationRemoteScriptExecutor.class); + @Autowired RemoteScriptExecutionService remoteScriptExecutionService; - - @Autowired + + @Autowired DeployResponseSenderService deployResponseSenderService; - + public void execute(DelegateExecution ctx) throws Exception { String remotserver=(String)ctx.getVariable("remotserver"); int portnumner=(Integer)ctx.getVariable("port"); @@ -57,11 +55,8 @@ public class DeployPostVerficationRemoteScriptExecutor implements JavaDelegate { logger.debug("task execution started remotserver {} , portnumner {},username {}, password {},filename : {} ,fileparams={},src dir={},dest dir={}", remotserver,portnumner,username,password,filename,fileparams,srcdir,destdir); - String command="sh " +destdir+"/"+filename+" "+(fileparams!=null?fileparams.replaceAll(",", " "):" "); + String command = String.format("/bin/bash %s/%s %s", destdir, filename, (fileparams!=null?fileparams.replaceAll(",", " "):"")); logger.debug("Execution command {}",command); remoteScriptExecutionService.executeRemoteScript(remotserver,username,password,portnumner,filename,fileparams,srcdir,destdir,command); - - } - } diff --git a/akraino/src/main/java/com/akraino/bpm/delegate/DeployRemoteDeploymentVerificationDelegate.java b/akraino/src/main/java/com/akraino/bpm/delegate/DeployRemoteDeploymentVerificationDelegate.java index 49f98b4..c46b71f 100644 --- a/akraino/src/main/java/com/akraino/bpm/delegate/DeployRemoteDeploymentVerificationDelegate.java +++ b/akraino/src/main/java/com/akraino/bpm/delegate/DeployRemoteDeploymentVerificationDelegate.java @@ -16,7 +16,6 @@ package com.akraino.bpm.delegate; - import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.engine.delegate.JavaDelegate; import org.slf4j.Logger; @@ -29,8 +28,6 @@ import com.akraino.bpm.model.BuildResponse; import com.akraino.bpm.service.DeployResponseSenderService; import com.akraino.bpm.service.RemoteDeploymentVerificationService; - - @Component public class DeployRemoteDeploymentVerificationDelegate implements JavaDelegate { @@ -39,11 +36,10 @@ public class DeployRemoteDeploymentVerificationDelegate implements JavaDelegate @Autowired RemoteDeploymentVerificationService remotedeploymentVerificationService; - @Autowired + @Autowired DeployResponseSenderService deployResponseSenderService; - - public void execute(DelegateExecution ctx) throws Exception { + public void execute(DelegateExecution ctx) throws Exception { try { String verifierFilename=(String)ctx.getVariable("verifier"); @@ -63,15 +59,11 @@ public class DeployRemoteDeploymentVerificationDelegate implements JavaDelegate logger.debug("task execution started remotserver {} , portnumner {},username {}, password {},filename : {} , waittime : {},No of iterations :{}", remotserver,portnumner,username,password,verifierFilename,srcdir,destdir,waittime,iterations); - String command="sh " +destdir+"/"+verifierFilename+" "+(filepparams!=null?filepparams.replaceAll(",", " "):" "); + String command = String.format("/bin/bash %s/%s %s", destdir, verifierFilename, (filepparams!=null?filepparams.replaceAll(",", " "):"")); logger.debug("Execution command {}",command); remotedeploymentVerificationService.executeScript(remotserver,username,password,portnumner,verifierFilename,filepparams,srcdir,destdir,waittime,iterations,command); - }catch(TaskExecutorException ex) { + } catch(TaskExecutorException ex) { throw ex; - } - - + } } - } - diff --git a/akraino/src/main/java/com/akraino/bpm/delegate/DeployRemoteScriptExecutorTaskDelegate.java b/akraino/src/main/java/com/akraino/bpm/delegate/DeployRemoteScriptExecutorTaskDelegate.java index e68ae98..247be64 100644 --- a/akraino/src/main/java/com/akraino/bpm/delegate/DeployRemoteScriptExecutorTaskDelegate.java +++ b/akraino/src/main/java/com/akraino/bpm/delegate/DeployRemoteScriptExecutorTaskDelegate.java @@ -27,19 +27,15 @@ import com.akraino.bpm.model.BuildResponse; import com.akraino.bpm.service.DeployResponseSenderService; import com.akraino.bpm.service.RemoteScriptExecutionService; - - @Component public class DeployRemoteScriptExecutorTaskDelegate implements JavaDelegate { - - - private static Logger logger = LoggerFactory.getLogger(DeployRemoteScriptExecutorTaskDelegate.class); + private static Logger logger = LoggerFactory.getLogger(DeployRemoteScriptExecutorTaskDelegate.class); @Autowired RemoteScriptExecutionService remoteScriptExecutionService; - @Autowired + @Autowired DeployResponseSenderService deployResponseSenderService; public void execute(DelegateExecution ctx) throws Exception { @@ -57,9 +53,8 @@ public class DeployRemoteScriptExecutorTaskDelegate implements JavaDelegate { logger.debug("task execution started remotserver {} , portnumner {},username {}, password {},filename : {} ,fileparams={},src dir={},dest dir={}", remotserver,portnumner,username,password,filename,fileparams,srcdir,destdir); - String command="sh " +destdir+"/"+filename+" "+(fileparams!=null?fileparams.replaceAll(",", " "):" "); + String command = String.format("/bin/bash %s/%s %s", destdir, filename, (fileparams!=null?fileparams.replaceAll(",", " "):"")); logger.debug("Execution command {}",command); remoteScriptExecutionService.executeRemoteScript(remotserver,username,password,portnumner,filename,fileparams,srcdir,destdir,command); } - } diff --git a/akraino/src/main/java/com/akraino/bpm/delegate/RemoteDeploymentVerificationDelegate.java b/akraino/src/main/java/com/akraino/bpm/delegate/RemoteDeploymentVerificationDelegate.java index 30204bb..80d4670 100644 --- a/akraino/src/main/java/com/akraino/bpm/delegate/RemoteDeploymentVerificationDelegate.java +++ b/akraino/src/main/java/com/akraino/bpm/delegate/RemoteDeploymentVerificationDelegate.java @@ -38,7 +38,7 @@ public class RemoteDeploymentVerificationDelegate implements JavaDelegate { RemoteDeploymentVerificationService remotedeploymentVerificationService; - public void execute(DelegateExecution ctx) throws Exception { + public void execute(DelegateExecution ctx) throws Exception { try { String verifierFilename=(String)ctx.getVariable("verifier"); @@ -55,15 +55,12 @@ public class RemoteDeploymentVerificationDelegate implements JavaDelegate { logger.debug("task execution started remotserver {} , portnumner {},username {}, password {},filename : {} , waittime : {},No of iterations :{}", remotserver,portnumner,username,password,verifierFilename,srcdir,destdir,waittime,iterations); - String command="sh " +destdir+"/"+(verifierFilename!=null?verifierFilename:" ")+" "+(filepparams!=null?filepparams.replaceAll(",", " "):" "); + // This looks wrong! + String command = "/bin/bash " +destdir+"/"+(verifierFilename!=null?verifierFilename:" ")+" "+(filepparams!=null?filepparams.replaceAll(",", " "):" "); logger.debug("Execution command {}",command); remotedeploymentVerificationService.executeScript(remotserver,username,password,portnumner,verifierFilename,filepparams,srcdir,destdir,waittime,iterations,command); - }catch(TaskExecutorException ex) { + } catch(TaskExecutorException ex) { throw ex; - } - - + } } - -} - +} \ No newline at end of file diff --git a/akraino/src/main/java/com/akraino/bpm/delegate/RemoteScriptExecutorTaskDelegate.java b/akraino/src/main/java/com/akraino/bpm/delegate/RemoteScriptExecutorTaskDelegate.java index d5db4f6..5008925 100644 --- a/akraino/src/main/java/com/akraino/bpm/delegate/RemoteScriptExecutorTaskDelegate.java +++ b/akraino/src/main/java/com/akraino/bpm/delegate/RemoteScriptExecutorTaskDelegate.java @@ -25,14 +25,10 @@ import org.springframework.stereotype.Component; import com.akraino.bpm.service.RemoteScriptExecutionService; - - @Component public class RemoteScriptExecutorTaskDelegate implements JavaDelegate { - - - private static Logger logger = LoggerFactory.getLogger(RemoteScriptExecutorTaskDelegate.class); + private static Logger logger = LoggerFactory.getLogger(RemoteScriptExecutorTaskDelegate.class); @Autowired RemoteScriptExecutionService remoteScriptExecutionService; @@ -46,13 +42,11 @@ public class RemoteScriptExecutorTaskDelegate implements JavaDelegate { String fileparams=(String)ctx.getVariable("fileparams"); String srcdir=(String)ctx.getVariable("srcdir"); String destdir=(String)ctx.getVariable("destdir"); - - + logger.debug("task execution started remotserver {} , portnumner {},username {}, password {},filename : {} ,fileparams={},src dir={},dest dir={}", remotserver,portnumner,username,password,filename,fileparams,srcdir,destdir); - String command="cd "+destdir+ ";"+"sh "+filename+" "+(fileparams!=null?fileparams.replaceAll(",", " "):" "); + String command = String.format("cd %s; /bin/bash %s %s", destdir, filename, (fileparams!=null?fileparams.replaceAll(",", " "):"")); logger.debug("Execution command {}",command); remoteScriptExecutionService.executeRemoteScript(remotserver,username,password,portnumner,filename,fileparams,srcdir,destdir,command); } - } diff --git a/akraino/src/main/java/com/akraino/bpm/service/impl/AsyncProcessExecutorServiceImpl.java b/akraino/src/main/java/com/akraino/bpm/service/impl/AsyncProcessExecutorServiceImpl.java index 695606e..0b79327 100644 --- a/akraino/src/main/java/com/akraino/bpm/service/impl/AsyncProcessExecutorServiceImpl.java +++ b/akraino/src/main/java/com/akraino/bpm/service/impl/AsyncProcessExecutorServiceImpl.java @@ -136,6 +136,7 @@ public class AsyncProcessExecutorServiceImpl implements AsyncProcessExecutorServ .putValue("port", deploy.getPort()) .putValue("destdir",deploy.getDestdir()) .putValue("remotefilename", deploy.getRemotefilename()) + .putValue("filename", deploy.getRemotefilename()) // Needed by DeployRemoteScriptExecutorTaskDelegate.execute() .putValue("fileparams", deploy.getFileparams()) .putValue("verifier", deploy.getDeploymentverifier()) .putValue("verifierfileparams", deploy.getDeploymentverifierfileparams()) 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 36842d3..1745792 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 @@ -32,9 +32,9 @@ import com.akraino.bpm.service.ScriptExecutionService; public class ScriptExecutionServiceImpl implements ScriptExecutionService{ private static Logger logger = LoggerFactory.getLogger(ScriptExecutionServiceImpl.class); - + public void executeScript(String filepatch) { - + try { logger.debug("Executing the script............."); Process p = Runtime.getRuntime().exec(filepatch); @@ -48,21 +48,20 @@ public class ScriptExecutionServiceImpl implements ScriptExecutionService{ 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); } - + } public void executeCDScript(String dir,String cmd) { - + try { logger.debug("Executing the script.............dir:{},command:{}",dir,cmd); - - String[] command = { "/bin/sh", "-c", "sh "+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())); @@ -74,22 +73,22 @@ public class ScriptExecutionServiceImpl implements ScriptExecutionService{ if(p.exitValue()!=0) { throw new TaskExecutorException("problem while executing the script . exist 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 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(); @@ -102,27 +101,27 @@ public class ScriptExecutionServiceImpl implements ScriptExecutionService{ 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); + ProcessBuilder pb = new ProcessBuilder(cmd); Process shellProcess = pb.start(); - - shellProcess.waitFor(); + + shellProcess.waitFor(); BufferedReader input = new BufferedReader(new InputStreamReader(shellProcess.getInputStream())); String line = ""; while ((line = input.readLine()) != null) { @@ -132,14 +131,13 @@ public class ScriptExecutionServiceImpl implements ScriptExecutionService{ if(shellProcess.exitValue()!=0) { throw new TaskExecutorException("problem while executing the script . exist code :"+shellProcess.exitValue()); } - - + + } catch (IOException e) { throw new TaskExecutorException(cmd + " not found."); } catch (InterruptedException e) { throw new TaskExecutorException("problem while executing the script "+cmd); } - - }*/ + }*/ } diff --git a/pom.xml b/pom.xml index 515f0bd..68264ec 100644 --- a/pom.xml +++ b/pom.xml @@ -62,7 +62,7 @@ org.springframework.boot spring-boot-starter-tertifartifactId> test - 1.5.8.RE + 1.5.8.RE -->