Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Eladmin
Commits
175a2eb6
Commit
175a2eb6
authored
Nov 27, 2019
by
zhanghouying
Browse files
连接服务器使用用户设置的端口,提供测试连接按钮,测试配置信息是否正确
parent
53583b20
Changes
5
Hide whitespace changes
Inline
Side-by-side
eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/ServerDeployController.java
View file @
175a2eb6
...
@@ -61,4 +61,13 @@ public class ServerDeployController {
...
@@ -61,4 +61,13 @@ public class ServerDeployController {
serverDeployService
.
delete
(
id
);
serverDeployService
.
delete
(
id
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
}
@Log
(
"测试连接服务器"
)
@ApiOperation
(
value
=
"测试连接服务器"
)
@PostMapping
(
"/testConnect"
)
@PreAuthorize
(
"@el.check('serverDeploy:add')"
)
public
ResponseEntity
testConnect
(
@Validated
@RequestBody
ServerDeploy
resources
){
return
new
ResponseEntity
<>(
serverDeployService
.
testConnect
(
resources
),
HttpStatus
.
CREATED
);
}
}
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/ServerDeployService.java
View file @
175a2eb6
...
@@ -58,4 +58,11 @@ public interface ServerDeployService {
...
@@ -58,4 +58,11 @@ public interface ServerDeployService {
* @return /
* @return /
*/
*/
ServerDeployDto
findByIp
(
String
ip
);
ServerDeployDto
findByIp
(
String
ip
);
/**
* 测试登录服务器
* @param resources
* @return
*/
Boolean
testConnect
(
ServerDeploy
resources
);
}
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/DeployServiceImpl.java
View file @
175a2eb6
...
@@ -379,7 +379,7 @@ public class DeployServiceImpl implements DeployService {
...
@@ -379,7 +379,7 @@ public class DeployServiceImpl implements DeployService {
sendMsg
(
"IP对应服务器信息不存在:"
+
ip
,
MsgType
.
ERROR
);
sendMsg
(
"IP对应服务器信息不存在:"
+
ip
,
MsgType
.
ERROR
);
throw
new
BadRequestException
(
"IP对应服务器信息不存在:"
+
ip
);
throw
new
BadRequestException
(
"IP对应服务器信息不存在:"
+
ip
);
}
}
return
new
ExecuteShellUtil
(
ip
,
serverDeployDTO
.
getAccount
(),
serverDeployDTO
.
getPassword
());
return
new
ExecuteShellUtil
(
ip
,
serverDeployDTO
.
getAccount
(),
serverDeployDTO
.
getPassword
()
,
serverDeployDTO
.
getPort
()
);
}
}
private
ScpClientUtil
getScpClientUtil
(
String
ip
)
{
private
ScpClientUtil
getScpClientUtil
(
String
ip
)
{
...
...
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/ServerDeployServiceImpl.java
View file @
175a2eb6
...
@@ -6,6 +6,7 @@ import me.zhengjie.modules.mnt.service.ServerDeployService;
...
@@ -6,6 +6,7 @@ import me.zhengjie.modules.mnt.service.ServerDeployService;
import
me.zhengjie.modules.mnt.service.dto.ServerDeployDto
;
import
me.zhengjie.modules.mnt.service.dto.ServerDeployDto
;
import
me.zhengjie.modules.mnt.service.dto.ServerDeployQueryCriteria
;
import
me.zhengjie.modules.mnt.service.dto.ServerDeployQueryCriteria
;
import
me.zhengjie.modules.mnt.service.mapper.ServerDeployMapper
;
import
me.zhengjie.modules.mnt.service.mapper.ServerDeployMapper
;
import
me.zhengjie.modules.mnt.util.ExecuteShellUtil
;
import
me.zhengjie.utils.PageUtil
;
import
me.zhengjie.utils.PageUtil
;
import
me.zhengjie.utils.QueryHelp
;
import
me.zhengjie.utils.QueryHelp
;
import
me.zhengjie.utils.ValidationUtil
;
import
me.zhengjie.utils.ValidationUtil
;
...
@@ -56,7 +57,22 @@ public class ServerDeployServiceImpl implements ServerDeployService {
...
@@ -56,7 +57,22 @@ public class ServerDeployServiceImpl implements ServerDeployService {
return
serverDeployMapper
.
toDto
(
deploy
);
return
serverDeployMapper
.
toDto
(
deploy
);
}
}
@Override
@Override
public
Boolean
testConnect
(
ServerDeploy
resources
)
{
ExecuteShellUtil
executeShellUtil
=
null
;
try
{
executeShellUtil
=
new
ExecuteShellUtil
(
resources
.
getIp
(),
resources
.
getAccount
(),
resources
.
getPassword
(),
resources
.
getPort
());
return
executeShellUtil
.
execute
(
"ls"
)==
0
;
}
catch
(
Exception
e
)
{
return
false
;
}
finally
{
if
(
executeShellUtil
!=
null
)
{
executeShellUtil
.
close
();
}
}
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
ServerDeployDto
create
(
ServerDeploy
resources
)
{
public
ServerDeployDto
create
(
ServerDeploy
resources
)
{
return
serverDeployMapper
.
toDto
(
serverDeployRepository
.
save
(
resources
));
return
serverDeployMapper
.
toDto
(
serverDeployRepository
.
save
(
resources
));
...
...
eladmin-system/src/main/java/me/zhengjie/modules/mnt/util/ExecuteShellUtil.java
View file @
175a2eb6
...
@@ -18,16 +18,14 @@ import java.util.Vector;
...
@@ -18,16 +18,14 @@ import java.util.Vector;
@Slf4j
@Slf4j
public
class
ExecuteShellUtil
{
public
class
ExecuteShellUtil
{
public
final
int
DEFAULT_SSH_PORT
=
22
;
private
Vector
<
String
>
stdout
;
private
Vector
<
String
>
stdout
;
Session
session
;
Session
session
;
public
ExecuteShellUtil
(
final
String
ipAddress
,
final
String
username
,
final
String
password
)
{
public
ExecuteShellUtil
(
final
String
ipAddress
,
final
String
username
,
final
String
password
,
int
port
)
{
try
{
try
{
JSch
jsch
=
new
JSch
();
JSch
jsch
=
new
JSch
();
session
=
jsch
.
getSession
(
username
,
ipAddress
,
DEFAULT_SSH_PORT
);
session
=
jsch
.
getSession
(
username
,
ipAddress
,
port
);
session
.
setPassword
(
password
);
session
.
setPassword
(
password
);
session
.
setConfig
(
"StrictHostKeyChecking"
,
"no"
);
session
.
setConfig
(
"StrictHostKeyChecking"
,
"no"
);
session
.
connect
(
3000
);
session
.
connect
(
3000
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment