|
@ -47,14 +47,12 @@ public class RemoteShellController extends BaseController {
|
|
public Result sendShell(
|
|
public Result sendShell(
|
|
@ApiParam(name = "command", value = "shell命令")
|
|
@ApiParam(name = "command", value = "shell命令")
|
|
@RequestParam(value = "command", required = false) String command,
|
|
@RequestParam(value = "command", required = false) String command,
|
|
// @ApiParam(name = "tenant", value = "租户名称")
|
|
|
|
// @RequestParam(value = "tenant", required = false) String tenant,
|
|
|
|
@ApiParam(name = "disCon", value = "是否断开会话连接")
|
|
@ApiParam(name = "disCon", value = "是否断开会话连接")
|
|
@RequestParam(value = "disCon", required = true) boolean disCon) {
|
|
@RequestParam(value = "disCon", required = true) boolean disCon) {
|
|
String result = "";
|
|
String result = "";
|
|
try {
|
|
try {
|
|
//TODO 发送shell命令 消息
|
|
//TODO 发送shell命令 消息
|
|
System.out.println("发送shell请求:"+command);
|
|
|
|
|
|
System.out.println("发送shell请求:" + command);
|
|
remoteShellService.sendShell(command, disCon);
|
|
remoteShellService.sendShell(command, disCon);
|
|
return Result.success("shell请求发送成功!");
|
|
return Result.success("shell请求发送成功!");
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@ -73,8 +71,18 @@ public class RemoteShellController extends BaseController {
|
|
//TODO 如何去除等待时间,目前添加sleep是因为需要等待zbus回调方法的返回结果;
|
|
//TODO 如何去除等待时间,目前添加sleep是因为需要等待zbus回调方法的返回结果;
|
|
Thread.sleep(2000);
|
|
Thread.sleep(2000);
|
|
String attachment = LocalContext.getContext().getAttachment(ContextAttributes.TENANT_NAME);
|
|
String attachment = LocalContext.getContext().getAttachment(ContextAttributes.TENANT_NAME);
|
|
result = LocalContext.getContext().getAttachment(ContextAttributes.SHELL_RESPONSE+attachment);
|
|
|
|
System.out.println("接口返回结果:"+result);
|
|
|
|
|
|
result = LocalContext.getContext().getAttachment(ContextAttributes.SHELL_RESPONSE + attachment);
|
|
|
|
int count = 0;
|
|
|
|
while (result == null) {
|
|
|
|
count++;
|
|
|
|
Thread.sleep(2000);
|
|
|
|
result = LocalContext.getContext().getAttachment(ContextAttributes.SHELL_RESPONSE + attachment);
|
|
|
|
//获取失败时,尝试再一次获取结果
|
|
|
|
if (count > 2) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
System.out.println("接口返回结果:" + result);
|
|
} catch (InterruptedException e) {
|
|
} catch (InterruptedException e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|