parallec icon indicating copy to clipboard operation
parallec copied to clipboard

multiple hosts execute different ssh command concurrently

Open snecker opened this issue 5 years ago • 0 comments

Hi,I want to login in multiple hosts with different password and excute different command concurrently, so I tried the following groovy code

String vmIp = "host1 host2 host3 host4"
ParallelClient pc = new ParallelClient()
pc.prepareSsh().setConcurrency(10)
	.setSshLoginType(SshLoginType.PASSWORD)
	.setReplacementVarMapNodeSpecific([
	    "host1": new StrStrMap(["cmd": "echo 1", "userName": "user", "password": "pwd"]),
	    "host2": new StrStrMap(["cmd": "echo 2", "userName": "user", "password": "pwd"]),
	    "host3": new StrStrMap(["cmd": "echo 3", "userName": "user", "password": "pwd"]),
	    "host4": new StrStrMap(["cmd": "echo 4", "userName": "user", "password": "pwd"])])
	.setTargetHostsFromString(vmIp)
	.setSshCommandLine("\$cmd")
	.setSshUserName("\$userName")
	.setSshPassword("\$password")
	.setSshPort(22)
	.execute(new ParallecResponseHandler() {
	@Override
	public void onCompleted(ResponseOnSingleTask res, Map<String, Object> responseContext) {
		System.out.println("Responose:" + res.toString() + " host: "
				+ res.getHost() + " errmsg: "
				+ res.getErrorMessage());
	}
});
pc.prepareSsh()
pc.releaseExternalResources();

but it doesnt work,the log is

17:51:16.673 [main] INFO  .core.task.ParallelTaskManager - Initialized ParallelTaskManager...
17:51:16.702 [main] INFO  es.AsyncHttpClientFactoryEmbed - FastClient: ningFastClientConnectionTimeoutMillis: 4000
17:51:16.710 [main] INFO  es.AsyncHttpClientFactoryEmbed - FastClient: ningFastClientRequestTimeoutMillis: 14000
17:51:16.888 [main] INFO  s.netty.NettyAsyncHttpProvider - Number of application's worked threads is 0
17:51:16.893 [main] INFO  s.netty.NettyAsyncHttpProvider - Number of application's worked threads is 0
17:51:16.902 [main] INFO  s.netty.NettyAsyncHttpProvider - Number of application's worked threads is 0
17:51:16.902 [main] INFO  s.netty.NettyAsyncHttpProvider - Number of application's worked threads is 0
17:51:17.685 [main] INFO  o.parallec.core.ParallelClient - Initialing Parallel Client Resources: actor system, HttpClientStore, Task Manager ....
17:51:18.572 [main] INFO  es.AsyncHttpClientFactoryEmbed - FastClient: ningFastClientConnectionTimeoutMillis: 4000
17:51:18.573 [main] INFO  es.AsyncHttpClientFactoryEmbed - FastClient: ningFastClientRequestTimeoutMillis: 14000
17:51:18.574 [main] INFO  s.netty.NettyAsyncHttpProvider - Number of application's worked threads is 0
17:51:18.574 [main] INFO  s.netty.NettyAsyncHttpProvider - Number of application's worked threads is 0
17:51:18.574 [main] INFO  s.netty.NettyAsyncHttpProvider - Number of application's worked threads is 0
17:51:18.575 [main] INFO  s.netty.NettyAsyncHttpProvider - Number of application's worked threads is 0
17:51:18.577 [main] INFO  o.parallec.core.ParallelClient - Parallel Client Resources has been initialized.
17:51:18.624 [main] INFO  allec.core.ParallelTaskBuilder - Initialized task builder with default config
17:51:18.689 [main] INFO  allec.core.ParallelTaskBuilder - Set requestReplacementType as {}TARGET_HOST_SPECIFIC_VAR_REPLACEMENT
17:51:18.690 [main] INFO  c.core.util.PcTargetHostsUtils - Target hosts size : 4
17:51:18.702 [main] INFO  allec.core.ParallelTaskBuilder - ***********START_PARALLEL_HTTP_TASK_PT_4_20180720175118702_00b7c4ae-701***********
17:51:18.705 [main] INFO  allec.core.ParallelTaskBuilder - Disabled CapacityAwareTaskScheduler. Immediately execute task PT_4_20180720175118702_00b7c4ae-701 
17:51:18.706 [main] INFO  allec.core.ParallelTaskBuilder - Executing task PT_4_20180720175118702_00b7c4ae-701 in SYNC mode...  
17:51:18.707 [Thread-1] INFO  .core.task.ParallelTaskManager - Added task PT_4_20180720175118702_00b7c4ae-701 to the running inprogress map...
17:51:18.711 [Thread-1] INFO  .core.task.ParallelTaskManager - !!STARTED sendAgentCommandToManager : PT_4_20180720175118702_00b7c4ae-701 at 2018-07-20 17:51:18.711+0800
17:51:18.718 [default-dispatcher-4] INFO  ec.core.actor.ExecutionManager - parallec task state : IN_PROGRESS
17:51:18.719 [default-dispatcher-4] INFO  ec.core.actor.ExecutionManager - Before Safety Check: total entry count: 4
17:51:18.719 [default-dispatcher-4] INFO  ec.core.actor.ExecutionManager - After Safety Check: total entry count in nodeDataMapValidSafe: 4
17:51:18.719 [default-dispatcher-4] INFO  ec.core.actor.ExecutionManager - !Obtain command request for target host meta id THM_4_20180720175118702_423897a9-f3f  with count: 4
17:51:18.739 [default-dispatcher-2] INFO  ctor.AssistantExecutionManager - Now finished sending all needed messages. Done job of ASST Manager at 2018.07.20.17.51.18.739+0800
17:51:23.772 [pool-5-thread-1] ERROR ander.workflow.ssh.SshProvider - error in exec SSH. 
If exection is JSchException: Auth cancel and using public key. 
Make sure 1. private key full path is right (try sshMeta.getPrivKeyAbsPath()). 
2. the user name and key matches  com.jcraft.jsch.JSchException: timeout: socket is not established
17:51:23.772 [pool-5-thread-4] ERROR ander.workflow.ssh.SshProvider - error in exec SSH. 
If exection is JSchException: Auth cancel and using public key. 
Make sure 1. private key full path is right (try sshMeta.getPrivKeyAbsPath()). 
2. the user name and key matches  com.jcraft.jsch.JSchException: timeout: socket is not established
17:51:23.772 [pool-5-thread-2] ERROR ander.workflow.ssh.SshProvider - error in exec SSH. 
If exection is JSchException: Auth cancel and using public key. 
Make sure 1. private key full path is right (try sshMeta.getPrivKeyAbsPath()). 
2. the user name and key matches  com.jcraft.jsch.JSchException: timeout: socket is not established
17:51:23.772 [pool-5-thread-3] ERROR ander.workflow.ssh.SshProvider - error in exec SSH. 
If exection is JSchException: Auth cancel and using public key. 
Make sure 1. private key full path is right (try sshMeta.getPrivKeyAbsPath()). 
2. the user name and key matches  com.jcraft.jsch.JSchException: timeout: socket is not established
17:51:23.894 [default-dispatcher-3] INFO  ec.core.actor.ExecutionManager - 
[1]__RESP_RECV_IN_MGR 1 (+3) / 4 (25.000%)  AFT 5.175 S @ host2 @ 2018.07.20.17.51.23.892+0800 , TaskID : 00b7c4ae-701 , CODE: null, RESP_BRIEF: EMPTY , ERR: com.jcraft.jsch.JSchException: timeout: socket is not established
Responose:ResponseOnSingleTask [request=TaskRequest [actorMaxOperationTimeoutSec=15, resourcePath=, requestContent=, httpMethod=NA, pollable=false, httpHeaderMap={}, protocol=ssh, host=host2, hostUniform=null, port=0, sshMeta=io.parallec.core.bean.ssh.SshMeta@69b0315a, tcpMeta=null, udpMeta=null, pingMeta=null, handler=null, responseContext=null, responseHeaderMeta=null], responseContent=null, receiveTime=2018.07.20.17.51.23.888+0800, receiveTimeInManager=2018.07.20.17.51.23.889+0800, error=true, errorMessage=com.jcraft.jsch.JSchException: timeout: socket is not established, stackTrace=null, statusCode=null, statusCodeInt=-1, operationTimeMillis=5150, pollingHistoryMap={}, responseHeaders=null] host: host2 errmsg: com.jcraft.jsch.JSchException: timeout: socket is not established
17:51:23.924 [default-dispatcher-3] INFO  ec.core.actor.ExecutionManager - 
[2]__RESP_RECV_IN_MGR 2 (+2) / 4 (50.000%)  AFT 5.206 S @ host4 @ 2018.07.20.17.51.23.923+0800 , TaskID : 00b7c4ae-701 , CODE: null, RESP_BRIEF: EMPTY , ERR: com.jcraft.jsch.JSchException: timeout: socket is not established
Responose:ResponseOnSingleTask [request=TaskRequest [actorMaxOperationTimeoutSec=15, resourcePath=, requestContent=, httpMethod=NA, pollable=false, httpHeaderMap={}, protocol=ssh, host=host4, hostUniform=null, port=0, sshMeta=io.parallec.core.bean.ssh.SshMeta@69b0315a, tcpMeta=null, udpMeta=null, pingMeta=null, handler=null, responseContext=null, responseHeaderMeta=null], responseContent=null, receiveTime=2018.07.20.17.51.23.888+0800, receiveTimeInManager=2018.07.20.17.51.23.889+0800, error=true, errorMessage=com.jcraft.jsch.JSchException: timeout: socket is not established, stackTrace=null, statusCode=null, statusCodeInt=-1, operationTimeMillis=5153, pollingHistoryMap={}, responseHeaders=null] host: host4 errmsg: com.jcraft.jsch.JSchException: timeout: socket is not established
17:51:23.924 [default-dispatcher-3] INFO  ec.core.actor.ExecutionManager - 
[3]__RESP_RECV_IN_MGR 3 (+1) / 4 (75.000%)  AFT 5.207 S @ host1 @ 2018.07.20.17.51.23.924+0800 , TaskID : 00b7c4ae-701 , CODE: null, RESP_BRIEF: EMPTY , ERR: com.jcraft.jsch.JSchException: timeout: socket is not established
Responose:ResponseOnSingleTask [request=TaskRequest [actorMaxOperationTimeoutSec=15, resourcePath=, requestContent=, httpMethod=NA, pollable=false, httpHeaderMap={}, protocol=ssh, host=host1, hostUniform=null, port=0, sshMeta=io.parallec.core.bean.ssh.SshMeta@69b0315a, tcpMeta=null, udpMeta=null, pingMeta=null, handler=null, responseContext=null, responseHeaderMeta=null], responseContent=null, receiveTime=2018.07.20.17.51.23.888+0800, receiveTimeInManager=2018.07.20.17.51.23.889+0800, error=true, errorMessage=com.jcraft.jsch.JSchException: timeout: socket is not established, stackTrace=null, statusCode=null, statusCodeInt=-1, operationTimeMillis=5153, pollingHistoryMap={}, responseHeaders=null] host: host1 errmsg: com.jcraft.jsch.JSchException: timeout: socket is not established
17:51:23.925 [default-dispatcher-3] INFO  ec.core.actor.ExecutionManager - 
[4]__RESP_RECV_IN_MGR 4 (+0) / 4 (100.00%)  AFT 5.208 S @ host3 @ 2018.07.20.17.51.23.925+0800 , TaskID : 00b7c4ae-701 , CODE: null, RESP_BRIEF: EMPTY , ERR: com.jcraft.jsch.JSchException: timeout: socket is not established
Responose:ResponseOnSingleTask [request=TaskRequest [actorMaxOperationTimeoutSec=15, resourcePath=, requestContent=, httpMethod=NA, pollable=false, httpHeaderMap={}, protocol=ssh, host=host3, hostUniform=null, port=0, sshMeta=io.parallec.core.bean.ssh.SshMeta@69b0315a, tcpMeta=null, udpMeta=null, pingMeta=null, handler=null, responseContext=null, responseHeaderMeta=null], responseContent=null, receiveTime=2018.07.20.17.51.23.912+0800, receiveTimeInManager=2018.07.20.17.51.23.912+0800, error=true, errorMessage=com.jcraft.jsch.JSchException: timeout: socket is not established, stackTrace=null, statusCode=null, statusCodeInt=-1, operationTimeMillis=5175, pollingHistoryMap={}, responseHeaders=null] host: host3 errmsg: com.jcraft.jsch.JSchException: timeout: socket is not established
17:51:23.925 [default-dispatcher-3] INFO  ec.core.actor.ExecutionManager - task.state : COMPLETED_WITHOUT_ERROR
17:51:23.926 [default-dispatcher-3] INFO  ec.core.actor.ExecutionManager - task.totalJobNumActual : 4 InitCount: 4
17:51:23.926 [default-dispatcher-3] INFO  ec.core.actor.ExecutionManager - task.response received Num 4 
17:51:23.926 [default-dispatcher-3] INFO  ec.core.actor.ExecutionManager - SUCCESSFUL GOT ON ALL RESPONSES: Received all the expected messages. Count matches: 4 at time: 2018.07.20.17.51.23.926+0800
17:51:23.927 [default-dispatcher-3] INFO  ec.core.actor.ExecutionManager - 
Time taken to get all responses back : 5.21 secs
17:51:23.927 [Thread-1] INFO  .core.task.ParallelTaskManager - !!COMPLETED sendTaskToExecutionManager : PT_4_20180720175118702_00b7c4ae-701 at 2018-07-20 17:51:23.927+0800  		  GenericResponseMap in future size: 4
17:51:23.928 [Thread-1] INFO  .core.task.ParallelTaskManager - Removed task PT_4_20180720175118702_00b7c4ae-701 from the running inprogress map... . This task should be garbage collected if there are no other pointers.
17:51:24.212 [main] INFO  allec.core.ParallelTaskBuilder - ***********FINISH_PARALLEL_HTTP_TASK_PT_4_20180720175118702_00b7c4ae-701***********
17:51:24.212 [main] INFO  o.parallec.core.ParallelClient - Releasing all ParallelClient resources... 
17:51:24.212 [main] INFO  arallec.core.actor.ActorConfig - shutting down actor system...
17:51:24.235 [main] INFO  arallec.core.actor.ActorConfig - Actor system has been shut down.
17:51:24.238 [main] INFO  o.parallec.core.ParallelClient - Have released all ParallelClient resources (actor system + async+sync http client + task queue)

how to achieve my goal? Thank you!

snecker avatar Jul 20 '18 09:07 snecker