Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ops
/
monitor-service
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
qinchao
7 years ago
Commit
d192f99aebd0baebbdb62d516a6120010ee25fe3
1 parent
6f9a71c5
优化代码
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
44 additions
and
68 deletions
monitor-service-cmdb/src/main/java/com/monitor/cloudtools/util/CommodUtil.java
monitor-service-switch/src/main/java/com/monitor/switchs/SwitchCmdUtil.java
monitor-service-switch/src/main/java/com/monitor/switchs/centerSwitch/service/SwitchService.java
monitor-service-switch/src/main/java/com/monitor/switchs/projectRestart/common/ExeIpTask.java
monitor-service-switch/src/main/java/com/monitor/switchs/projectRestart/common/ExeProjectTask.java
monitor-service-switch/src/main/java/com/monitor/switchs/projectRestart/service/impl/JavaProjectStatusLoaderTask.java
monitor-service-switch/src/main/java/com/monitor/switchs/projectRestart/service/impl/RestartServiceImpl.java
monitor-service-cmdb/src/main/java/com/monitor/cloudtools/util/CommodUtil.java
View file @
d192f99
...
...
@@ -6,6 +6,8 @@ import org.slf4j.LoggerFactory;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* Created by xh on 2017/6/13.
...
...
@@ -38,4 +40,36 @@ public class CommodUtil {
}
return
sb
.
toString
();
}
/**
* 执行远程命令
* @param commond
* @return
*/
public
static
List
<
String
>
exeReturnList
(
String
commond
)
{
Process
process
;
List
<
String
>
list
=
new
ArrayList
<>();
BufferedReader
input
=
null
;
try
{
logger
.
info
(
" - exe 1 parms - command="
+
commond
);
process
=
Runtime
.
getRuntime
().
exec
(
commond
);
input
=
new
BufferedReader
(
new
InputStreamReader
(
process
.
getInputStream
()));
String
line
;
while
((
line
=
input
.
readLine
())
!=
null
)
{
list
.
add
(
line
);
}
}
catch
(
Exception
e
)
{
logger
.
error
(
" process exe failed!"
,
e
);
}
finally
{
if
(
input
!=
null
)
{
try
{
input
.
close
();
}
catch
(
IOException
e
)
{
logger
.
error
(
" process exe failed!"
,
e
);
}
}
}
return
list
;
}
}
\ No newline at end of file
...
...
monitor-service-switch/src/main/java/com/monitor/switchs/SwitchCmdUtil.java
View file @
d192f99
...
...
@@ -128,67 +128,4 @@ public class SwitchCmdUtil {
return
mapList
;
}
/**
* 执行远程命令
* @param commond
* @return
*/
public
static
List
<
String
>
exe
(
String
commond
)
{
Process
process
;
List
<
String
>
list
=
new
ArrayList
<>();
BufferedReader
input
=
null
;
try
{
logger
.
info
(
" - exe 1 parms - command="
+
commond
);
process
=
Runtime
.
getRuntime
().
exec
(
commond
);
input
=
new
BufferedReader
(
new
InputStreamReader
(
process
.
getInputStream
()));
String
line
;
while
((
line
=
input
.
readLine
())
!=
null
)
{
list
.
add
(
line
);
}
}
catch
(
Exception
e
)
{
logger
.
error
(
" process exe failed!"
,
e
);
}
finally
{
if
(
input
!=
null
)
{
try
{
input
.
close
();
}
catch
(
IOException
e
)
{
logger
.
error
(
" process exe failed!"
,
e
);
}
}
}
return
list
;
}
/*
* dns切换查看
* @param commond
* @param param
* @return
*/
/*public static String exeDns(String commond, String param) {
Process process = null;
StringBuilder sb = new StringBuilder();
BufferedReader input = null;
try {
String command = BASE_DIR_DNS + commond + " " + param;
logger.info(" - exeDns parms - command=" + command);
process = Runtime.getRuntime().exec(command);
input = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
while ((line = input.readLine()) != null) {
sb.append(line + "\r\n");
}
} catch (Exception e) {
logger.error(" process exeDns failed!", e);
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
logger.error("process exeDns failed!", e);
}
}
}
return sb.toString();
}*/
}
\ No newline at end of file
...
...
monitor-service-switch/src/main/java/com/monitor/switchs/centerSwitch/service/SwitchService.java
View file @
d192f99
package
com
.
monitor
.
switchs
.
centerSwitch
.
service
;
import
com.contants.AlarmGroupContants
;
import
com.monitor.cloudtools.util.CommodUtil
;
import
com.monitor.common.service.AlarmMsgService
;
import
com.monitor.model.domain.CenterSwitchModel
;
import
com.monitor.switchs.SwitchCmdUtil
;
...
...
@@ -46,7 +47,7 @@ public class SwitchService {
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
logger
.
info
(
" SwitchService - doCommond - "
+
df
.
format
(
new
Date
())+
" - command="
+
commond
.
toString
());
List
<
String
>
resultList
=
SwitchCmdUtil
.
exe
(
commond
.
toString
());
List
<
String
>
resultList
=
CommodUtil
.
exeReturnList
(
commond
.
toString
());
StringBuilder
result
=
new
StringBuilder
();
for
(
String
str
:
resultList
)
{
...
...
monitor-service-switch/src/main/java/com/monitor/switchs/projectRestart/common/ExeIpTask.java
View file @
d192f99
package
com
.
monitor
.
switchs
.
projectRestart
.
common
;
import
com.monitor.cloudtools.util.CommodUtil
;
import
com.monitor.common.ProjectConstant
;
import
com.monitor.model.domain.RestartProcess
;
import
com.monitor.switchs.SwitchCmdUtil
;
...
...
@@ -53,7 +54,7 @@ public class ExeIpTask implements Runnable {
if
(
"restart"
.
equals
(
exe
)){
IpStatus
.
add
(
project
,
ip
);
}
SwitchCmdUtil
.
exe
(
commond
);
CommodUtil
.
exeReturnList
(
commond
);
if
(
"restart"
.
equals
(
exe
)){
IpStatus
.
remove
(
project
,
ip
);
}
...
...
monitor-service-switch/src/main/java/com/monitor/switchs/projectRestart/common/ExeProjectTask.java
View file @
d192f99
package
com
.
monitor
.
switchs
.
projectRestart
.
common
;
import
com.monitor.cloudtools.util.CommodUtil
;
import
com.monitor.common.ProjectConstant
;
import
com.monitor.model.domain.RestartModel
;
import
com.monitor.model.domain.RestartProcess
;
...
...
@@ -36,7 +37,7 @@ public class ExeProjectTask implements Runnable {
int
firstLength
;
if
(!
"single"
.
equals
(
restartModel
.
getCloud
()))
{
String
commond
=
"ssh master@"
+
ProjectConstant
.
DEPLOY_IP
+
" sh /home/master/.java_pm/java_restart.sh getIPs "
+
restartModel
.
getCloud
()
+
" "
+
project
;
List
<
String
>
ips
=
SwitchCmdUtil
.
exe
(
commond
);
List
<
String
>
ips
=
CommodUtil
.
exeReturnList
(
commond
);
if
(
ips
.
isEmpty
())
{
log
.
error
(
"ips is null,cloud:{},project:{}"
,
restartModel
.
getCloud
(),
project
);
restartProcess
.
setStatus
(
2
);
//结束
...
...
monitor-service-switch/src/main/java/com/monitor/switchs/projectRestart/service/impl/JavaProjectStatusLoaderTask.java
View file @
d192f99
package
com
.
monitor
.
switchs
.
projectRestart
.
service
.
impl
;
import
com.monitor.cloudtools.util.CommodUtil
;
import
com.monitor.common.ProjectConstant
;
import
com.monitor.model.domain.JavaProjectStatus
;
import
com.monitor.switchs.SwitchCmdUtil
;
...
...
@@ -67,7 +68,7 @@ public class JavaProjectStatusLoaderTask {
private
List
<
JavaProjectStatus
>
getStatusInfos
(
String
projectName
)
{
List
<
JavaProjectStatus
>
javaProjectStatusList
=
new
ArrayList
<>();
String
commond
=
"ssh master@"
+
ProjectConstant
.
DEPLOY_IP
+
" sh /home/master/.java_pm/java_restart.sh checkstatus mix "
+
projectName
;
List
<
String
>
list
=
SwitchCmdUtil
.
exe
(
commond
);
List
<
String
>
list
=
CommodUtil
.
exeReturnList
(
commond
);
for
(
String
string
:
list
)
{
String
[]
array
=
string
.
split
(
"@@"
);
if
(
array
.
length
<
3
)
{
...
...
monitor-service-switch/src/main/java/com/monitor/switchs/projectRestart/service/impl/RestartServiceImpl.java
View file @
d192f99
package
com
.
monitor
.
switchs
.
projectRestart
.
service
.
impl
;
import
com.model.HostInfo
;
import
com.monitor.cloudtools.util.CommodUtil
;
import
com.monitor.cmdb.service.IHostInfoService
;
import
com.monitor.common.ProjectConstant
;
import
com.monitor.common.contants.ProjectOnline
;
...
...
@@ -64,7 +65,7 @@ public class RestartServiceImpl implements RestartService {
String
[]
projectTag_array
=
currentProject
.
getTags
().
split
(
","
);
String
commond
=
"ssh master@"
+
ProjectConstant
.
DEPLOY_IP
+
" sh /home/master/.java_pm/java_restart.sh getIPs mix "
+
projectName
;
List
<
String
>
ips
=
SwitchCmdUtil
.
exe
(
commond
);
List
<
String
>
ips
=
CommodUtil
.
exeReturnList
(
commond
);
log
.
info
(
"RestartServiceImpl updateHostTags get host ips is {} "
,
ips
);
if
(
ips
!=
null
&&
ips
.
size
()>
0
)
{
for
(
String
string
:
ips
)
{
...
...
Please
register
or
login
to post a comment