Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ops
/
monitor-ui
·
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
Plain Diff
Browse Files
Authored by
fu
7 years ago
Commit
353a7d95f4d2d9b3b1cbd9a8ce26d74269dc4489
2 parents
1a65cb29
ae84fc26
Merge branch 'master' into monitor-ui-fyzh
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
289 additions
and
242 deletions
monitor-ui-common/pom.xml
monitor-ui-common/src/main/java/com/ui/project/ProjectEnvironment.java
monitor-ui-ctrl/src/main/java/com/ui/ctrl/OuterIntfCtrl.java
monitor-ui-ctrl/src/main/java/com/ui/ctrl/ProjectBuildCtrl.java
monitor-ui-web/src/main/webapp/jsp/bigdata/dashboardinfo.jsp
monitor-ui-web/src/main/webapp/jsp/project/project_build.jsp
monitor-ui-common/pom.xml
View file @
353a7d9
...
...
@@ -71,6 +71,13 @@
<artifactId>
commons-lang
</artifactId>
<version>
2.6
</version>
</dependency>
<dependency>
<groupId>
commons-io
</groupId>
<artifactId>
commons-io
</artifactId>
<version>
2.2
</version>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
...
...
monitor-ui-common/src/main/java/com/ui/project/ProjectEnvironment.java
View file @
353a7d9
...
...
@@ -19,6 +19,7 @@ public class ProjectEnvironment {
dockerProjectTypeMap
.
put
(
"media"
,
"media"
);
dockerProjectTypeMap
.
put
(
"ci"
,
"核心系统ci"
);
dockerProjectTypeMap
.
put
(
"ops"
,
"ops"
);
dockerProjectTypeMap
.
put
(
"erp"
,
"erp"
);
}
public
static
Set
<
String
>
getEnviroments
(){
...
...
monitor-ui-ctrl/src/main/java/com/ui/ctrl/OuterIntfCtrl.java
View file @
353a7d9
package
com
.
ui
.
ctrl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.collect.Sets
;
...
...
@@ -7,6 +8,7 @@ import com.ui.http.HttpRestClient;
import
com.ui.model.BaseResponse
;
import
com.ui.model.MonitAlarmInfo
;
import
com.ui.model.WebHooksReleaseBO
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.math.NumberUtils
;
import
org.slf4j.Logger
;
...
...
@@ -17,6 +19,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.IOException
;
import
java.util.*
;
/**
...
...
@@ -141,5 +145,67 @@ public class OuterIntfCtrl {
}
/**
*
* Grafana alert webhook. refer to:http://docs.grafana.org/alerting/notifications/
*
* <pre>
*
* {
"title": "My alert",
"ruleId": 1,
"ruleName": "Load peaking!",
"ruleUrl": "http://url.to.grafana/db/dashboard/my_dashboard?panelId=2",
"state": "alerting",
"imageUrl": "http://s3.image.url",
"message": "Load is peaking. Make sure the traffic is real and spin up more webfronts",
"evalMatches": [
{
"metric": "requests",
"tags": {},
"value": 122
}
]
}
* </pre>
*
* Created by chunhua.zhang on 2017/5/26.
*/
/**
* 接口:grafana报警提示
* @param request
* @return
*/
@RequestMapping
(
value
=
"/grafanaWebHook"
)
@ResponseBody
public
BaseResponse
grafanaWebHook
(
HttpServletRequest
request
)
{
try
{
String
jsonBody
=
IOUtils
.
toString
(
request
.
getInputStream
(),
"utf-8"
);
log
.
info
(
"receive grafana webhook message:{}"
,
jsonBody
);
JSONObject
alert
=
(
JSONObject
)
JSON
.
parse
(
jsonBody
);
String
title
=
""
;
String
state
=
""
;
String
imgUrl
=
""
;
String
message
=
""
;
if
(
alert
!=
null
){
title
=
alert
.
getString
(
"title"
);
state
=
alert
.
getString
(
"state"
);
imgUrl
=
alert
.
get
(
"imageUrl"
)==
null
?
""
:
alert
.
getString
(
"imageUrl"
);
message
=
alert
.
get
(
"message"
)==
null
?
""
:
alert
.
getString
(
"message"
);
}
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"title"
,
title
);
map
.
put
(
"state"
,
state
);
map
.
put
(
"imgUrl"
,
imgUrl
);
map
.
put
(
"message"
,
message
);
return
httpClient
.
defaultGet
(
"/grafanaAlert/sendDing"
,
BaseResponse
.
class
,
map
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
new
BaseResponse
(
201
);
}
}
...
...
monitor-ui-ctrl/src/main/java/com/ui/ctrl/ProjectBuildCtrl.java
View file @
353a7d9
...
...
@@ -33,7 +33,11 @@ import java.util.*;
public
class
ProjectBuildCtrl
{
Logger
log
=
LoggerFactory
.
getLogger
(
ProjectBuildCtrl
.
class
);
//需要特殊处理的项目
private
final
String
PROJECT_NAME_YOHO_SEARCH_SERVICE
=
"yoho-search-service"
;
//private final String PROJECT_NAME_YOHO_SEARCH_SERVICE="yoho-search-service";
private
final
List
<
String
>
lb_proejct_list
=
new
ArrayList
<
String
>()
{{
add
(
"yoho-search-service"
);
add
(
"uic"
);
}};
@Autowired
private
HttpRestClient
httpRestClient
;
...
...
@@ -196,146 +200,65 @@ public class ProjectBuildCtrl {
}
}
List
<
BuildMessage
>
list
=
new
ArrayList
<>();
BuildRequest
buildRequest
=
new
BuildRequest
();
//分支名称
buildRequest
.
setBranch
(
branch_name
);
//登陆用户
buildRequest
.
setUser
(
user
.
getName
());
//发布环境
buildRequest
.
setEnvironment
(
environment_name
);
//回滚文件名称
buildRequest
.
setRollbackfile
(
rollbackfile_name
);
//操作类型
buildRequest
.
setOperate
(
operate_name
);
//关联工单
buildRequest
.
setWorkid
(
workid_name
);
String
messageids
=
""
;
boolean
containsSpecialProject
=
false
;
List
<
String
>
projectList
=
Arrays
.
asList
(
project_name
.
split
(
","
));
if
(
projectList
.
contains
(
PROJECT_NAME_YOHO_SEARCH_SERVICE
)
&&(
"aws"
.
equals
(
environment_name
)||
"qcloud"
.
equals
(
environment_name
))){
containsSpecialProject
=
true
;
//把要发布的项目重新组合,其中特殊情况的项目,先拿出来传递到前台,其余的普通项目直接发布
List
<
String
>
specialProjectLb
=
new
ArrayList
<>();
if
((
"aws"
.
equals
(
environment_name
)||
"qcloud"
.
equals
(
environment_name
))){
project_name
=
""
;
for
(
String
str:
projectList
){
if
(
str
.
equals
(
PROJECT_NAME_YOHO_SEARCH_SERVICE
)){
continue
;
}
if
(
project_name
.
length
()>
0
){
project_name
+=
","
;
if
(
StringUtils
.
isNotBlank
(
str
)){
if
(
lb_proejct_list
.
contains
(
str
)){
specialProjectLb
.
add
(
str
);
continue
;
}
if
(
project_name
.
length
()>
0
){
project_name
+=
","
;
}
project_name
+=
str
;
}
project_name
+=
str
;
}
}
if
(
"Deploy"
.
equals
(
operate_name
))
{
if
(
containsSpecialProject
){
//包含特殊的项目,再检查是否含其他类型的项目
//特殊项目的操作
LbResult
lbResult
=
buildYohoSearchService
(
environment_name
);
lbResult
.
setEnvironmentName
(
environment_name
);
lbResult
.
setBranch
(
branch_name
);
lbResult
.
setWorkIdName
(
workid_name
);
lbResult
.
setOperateName
(
operate_name
);
lbResult
.
setRollbackfileName
(
rollbackfile_name
);
if
(
lbResult
.
errorFlag
){
model
.
addAttribute
(
"existSpecialYohoSearchService"
,
"error"
);
}
else
{
if
(
lbResult
.
getDeployOrDeregister
().
equals
(
"1"
)){
model
.
addAttribute
(
"existSpecialYohoSearchService"
,
"old"
);
//负载均衡只有一台机器,则走原来的发布
if
(
project_name
.
length
()>
0
){
project_name
+=
(
","
+
PROJECT_NAME_YOHO_SEARCH_SERVICE
);
}
else
{
project_name
=
PROJECT_NAME_YOHO_SEARCH_SERVICE
;
}
messageids
=
deploy
(
project_name
,
environment_name
,
buildRequest
,
list
,
messageids
);
}
else
{
//从负载均衡卸载
BaseResponse
deregisterResponse
=
deregisterHostYohoSearchService
(
environment_name
,
lbResult
.
getChangeIds
());
if
(
deregisterResponse
==
null
||
deregisterResponse
.
getCode
()!=
200
){
model
.
addAttribute
(
"existSpecialYohoSearchService"
,
"error"
);
lbResult
.
setMsg
(
"负载均衡卸载机器出现错误!本项目发布终止"
);
}
else
{
//负载均衡有多个机器,保留一台,卸载其余的,然后发布其余的,然后挂载其余的,然后卸载第一台,发布第一台,挂载第一台。
model
.
addAttribute
(
"existSpecialYohoSearchService"
,
"deregister"
);
}
//其他项目的操作
if
(
project_name
.
length
()>
0
){
messageids
=
deploy
(
project_name
,
environment_name
,
buildRequest
,
list
,
messageids
);
}
}
}
model
.
addAttribute
(
"specialYohoSearchServiceResult"
,
JSON
.
toJSONString
(
lbResult
));
}
else
{
model
.
addAttribute
(
"specialProjectLbList"
,
JSONArray
.
parseArray
(
JSON
.
toJSONString
(
specialProjectLb
)));
String
messageids
=
""
;
List
<
BuildMessage
>
list
=
new
ArrayList
<>();
if
(
StringUtils
.
isNotBlank
(
project_name
)){
BuildRequest
buildRequest
=
new
BuildRequest
();
//分支名称
buildRequest
.
setBranch
(
branch_name
);
//登陆用户
buildRequest
.
setUser
(
user
.
getName
());
//发布环境
buildRequest
.
setEnvironment
(
environment_name
);
//回滚文件名称
buildRequest
.
setRollbackfile
(
rollbackfile_name
);
//操作类型
buildRequest
.
setOperate
(
operate_name
);
//关联工单
buildRequest
.
setWorkid
(
workid_name
);
if
(
"Deploy"
.
equals
(
operate_name
))
{
//不包含特殊项目,直接走原来的发布
messageids
=
deploy
(
project_name
,
environment_name
,
buildRequest
,
list
,
messageids
);
}
}
else
{
if
(
containsSpecialProject
){
//包含特殊的项目,再检查是否含其他类型的项目
//特殊项目的操作
LbResult
lbResult
=
buildYohoSearchService
(
environment_name
);
lbResult
.
setEnvironmentName
(
environment_name
);
lbResult
.
setBranch
(
branch_name
);
lbResult
.
setWorkIdName
(
workid_name
);
lbResult
.
setOperateName
(
operate_name
);
lbResult
.
setRollbackfileName
(
rollbackfile_name
);
if
(
lbResult
.
errorFlag
){
model
.
addAttribute
(
"existSpecialYohoSearchService"
,
"error"
);
}
else
{
if
(
lbResult
.
getDeployOrDeregister
().
equals
(
"1"
)){
model
.
addAttribute
(
"existSpecialYohoSearchService"
,
"old"
);
//负载均衡只有一台机器,则走原来的发布
if
(
project_name
.
length
()>
0
){
project_name
+=
(
","
+
PROJECT_NAME_YOHO_SEARCH_SERVICE
);
}
else
{
project_name
=
PROJECT_NAME_YOHO_SEARCH_SERVICE
;
}
buildRequest
.
setProject
(
project_name
);
messageids
=
rollback
(
environment_name
,
buildRequest
,
list
,
messageids
);
}
else
{
//从负载均衡卸载
BaseResponse
deregisterResponse
=
deregisterHostYohoSearchService
(
environment_name
,
lbResult
.
getChangeIds
());
if
(
deregisterResponse
==
null
||
deregisterResponse
.
getCode
()!=
200
){
model
.
addAttribute
(
"existSpecialYohoSearchService"
,
"error"
);
lbResult
.
setMsg
(
"负载均衡卸载机器出现错误!本项目发布终止"
);
}
else
{
//负载均衡有多个机器,保留一台,卸载其余的,然后发布其余的,然后挂载其余的,然后卸载第一台,发布第一台,挂载第一台。
model
.
addAttribute
(
"existSpecialYohoSearchService"
,
"deregister"
);
}
//其他项目的操作
if
(
project_name
.
length
()>
0
){
buildRequest
.
setProject
(
project_name
);
messageids
=
rollback
(
environment_name
,
buildRequest
,
list
,
messageids
);
}
}
}
model
.
addAttribute
(
"specialYohoSearchServiceResult"
,
JSON
.
toJSONString
(
lbResult
));
}
else
{
}
else
{
buildRequest
.
setProject
(
project_name
);
messageids
=
rollback
(
environment_name
,
buildRequest
,
list
,
messageids
);
}
}
model
.
addAttribute
(
"environment_name"
,
environment_name
);
model
.
addAttribute
(
"operate_name"
,
operate_name
);
model
.
addAttribute
(
"branch_name"
,
branch_name
);
model
.
addAttribute
(
"rollbackfile_name"
,
rollbackfile_name
);
model
.
addAttribute
(
"messageids"
,
messageids
);
model
.
addAttribute
(
"messageList"
,
list
);
model
.
addAttribute
(
"workid_name"
,
workid_name
);
}
catch
(
Exception
ex
)
{
}
return
new
ModelAndView
(
"project/project_build"
);
}
@RequestMapping
(
"/buildProjectWithIPs"
)
@RequestMapping
(
value
=
"/buildProjectWithIPs"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
BaseResponse
<?>
buildProjectWithIPs
(
HttpSession
session
,
String
project_name
,
String
ips
,
String
environment_name
,
String
operate_name
,
String
branch_name
,
String
rollbackfile_name
,
String
workid_name
){
BaseResponse
response
=
new
BaseResponse
();
...
...
@@ -390,44 +313,59 @@ public class ProjectBuildCtrl {
@RequestMapping
(
value
=
"/deregisterHostYohoSearchService"
)
@ResponseBody
public
BaseResponse
deregisterHostYohoSearchService
(
String
environment_name
,
String
instIds
){
public
BaseResponse
deregisterHostYohoSearchService
(
String
project
,
String
environment_name
,
String
instIds
){
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"cloudType"
,
environment_name
);
map
.
put
(
"instIds"
,
instIds
);
map
.
put
(
"project"
,
project
);
return
httpRestClient
.
defaultGet
(
"/lb/deregisterHostFromLb/yohoSearchService"
,
BaseResponse
.
class
,
map
);
}
@RequestMapping
(
value
=
"/registerHostYohoSearchService"
)
@ResponseBody
public
BaseResponse
registerHostYohoSearchService
(
String
environment_name
,
String
instIds
){
public
BaseResponse
registerHostYohoSearchService
(
String
project
,
String
environment_name
,
String
instIds
){
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"cloudType"
,
environment_name
);
map
.
put
(
"instIds"
,
instIds
);
map
.
put
(
"project"
,
project
);
return
httpRestClient
.
defaultGet
(
"/lb/registerHostFromLb/yohoSearchService"
,
BaseResponse
.
class
,
map
);
}
@RequestMapping
(
value
=
"/getLbInfoYohoSearchService"
)
@ResponseBody
public
BaseResponse
getLbInfoYohoSearchService
(
String
environment_name
){
public
BaseResponse
getLbInfoYohoSearchService
(
String
project
,
String
environment_name
){
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"cloudType"
,
environment_name
);
map
.
put
(
"project"
,
project
);
return
httpRestClient
.
defaultGet
(
"/lb/getLb/yohoSearchService"
,
BaseResponse
.
class
,
map
);
}
//特殊项目的处理yoho-search-service
//1.卸载 挂载
private
LbResult
buildYohoSearchService
(
String
environment_name
){
/**
* 特殊项目发布之前检查lb的情况
* @param project
* @param environment_name
* @return
*/
@RequestMapping
(
value
=
"/checkSpecialProjectLbInfoBeforeBuild"
)
@ResponseBody
public
BaseResponse
checkSpecialProjectLbInfoBeforeBuild
(
String
project
,
String
environment_name
,
String
branch_name
,
String
workid_name
,
String
operate_name
,
String
rollbackfile_name
){
LbResult
lbResult
=
new
LbResult
();
lbResult
.
setCurrentProject
(
PROJECT_NAME_YOHO_SEARCH_SERVICE
);
BaseResponse
response
=
httpRestClient
.
defaultGet
(
"/lb/getLb/yohoSearchService?cloudType="
+
environment_name
,
BaseResponse
.
class
);
lbResult
.
setCurrentProject
(
project
);
lbResult
.
setEnvironmentName
(
environment_name
);
lbResult
.
setBranch
(
branch_name
);
lbResult
.
setWorkIdName
(
workid_name
);
lbResult
.
setOperateName
(
operate_name
);
lbResult
.
setRollbackfileName
(
rollbackfile_name
);
BaseResponse
response
=
this
.
getLbInfoYohoSearchService
(
project
,
environment_name
);
if
(
response
!=
null
&&
response
.
getCode
()==
200
){
Map
<
String
,
String
>
hostIdAndIpMap
=(
Map
<
String
,
String
>)
response
.
getData
();
//负载均衡只有一台机器的情况,就不拿掉了 ,直接发布吧
if
(
hostIdAndIpMap
.
size
()<=
1
){
lbResult
.
setDeployOrDeregister
(
"1"
);
lbResult
.
setMsg
(
"负载均衡只有一台机器,直接发布!"
);
lbResult
.
setOnlyOneHost
(
"1"
);
lbResult
.
setMsg
(
"负载均衡最多只有一台机器,直接发布!"
);
}
else
{
lbResult
.
set
DeployOrDeregister
(
"2"
);
lbResult
.
set
OnlyOneHost
(
"2"
);
//保留的机器和需要卸载(挂载)的机器
lbResult
.
setMsg
(
"负载均衡有多个机器,走特殊发布流程!"
);
int
index
=
0
;
...
...
@@ -452,11 +390,10 @@ public class ProjectBuildCtrl {
lbResult
.
setHostNum
(
index
);
lbResult
.
setChangeNum
(
index
-
1
);
}
}
else
{
lbResult
.
setErrorFlag
(
true
);
lbResult
.
setMsg
(
"查询负载均衡信息出错,该项目的发布终止,请检查再重新发布!"
);
response
.
setData
(
lbResult
);
}
return
lbResult
;
return
response
;
}
...
...
@@ -471,7 +408,7 @@ public class ProjectBuildCtrl {
String
rollbackfileName
=
""
;
boolean
errorFlag
=
false
;
String
deployOrDeregister
=
""
;
String
onlyOneHost
=
""
;
String
msg
=
""
;
//保留的机器和需要卸载(挂载)的机器
...
...
monitor-ui-web/src/main/webapp/jsp/bigdata/dashboardinfo.jsp
View file @
353a7d9
...
...
@@ -13,50 +13,13 @@
<head>
<meta
http-equiv=
"Content-Type"
content=
"text/html; charset=UTF-8"
>
<link
rel=
"stylesheet"
href=
"<%=basePath %>css/bootstrap.min.css"
/>
<link
rel=
"stylesheet"
href=
"<%=basePath %>css/bootstrap-datetimepicker.css"
/>
<link
href=
"<%=basePath %>js/bootstrap-plugin/css/bootstrap.table.css"
rel=
"stylesheet"
media=
"screen"
/>
<link
rel=
"stylesheet"
href=
"<%=basePath %>css/bootstrap-responsive.min.css"
/>
<link
rel=
"stylesheet"
href=
"<%=basePath %>css/fullcalendar.css"
/>
<link
rel=
"stylesheet"
href=
"<%=basePath %>css/unicorn.main.css"
/>
<link
rel=
"stylesheet"
href=
"<%=basePath %>css/unicorn.grey.css"
/>
<link
rel=
"stylesheet"
href=
"<%=basePath %>css/jquery-ui.css"
/>
<link
rel=
"stylesheet"
href=
"<%=basePath %>css/uniform.css"
/>
<link
rel=
"stylesheet"
href=
"<%=basePath %>css/select2.css"
/>
<link
rel=
"stylesheet"
href=
"<%=basePath %>js/jstree/themes/proton/style.css"
/>
<link
rel=
"stylesheet"
href=
"<%=basePath %>css/select2.css"
/>
<link
rel=
"stylesheet"
href=
"<%=basePath %>css/yoho.css"
/>
<script
src=
"<%=basePath %>js/excanvas.min.js"
charset=
"UTF-8"
type=
"text/javascript"
></script>
<script
src=
"<%=basePath %>js/jquery-1.12.0.min.js"
charset=
"UTF-8"
type=
"text/javascript"
></script>
<script
src=
"<%=basePath %>js/jquery-ui.custom.js"
charset=
"UTF-8"
type=
"text/javascript"
></script>
<script
src=
"<%=basePath %>/js/bootstrap.min.js"
></script>
<script
src=
"<%=basePath %>/js/unicorn.js"
></script>
<script
src=
"<%=basePath %>js/bootstrap-plugin/datetimepicker/moment-with-locales.js"
charset=
"UTF-8"
type=
"text/javascript"
></script>
<script
src=
"<%=basePath %>js/bootstrap-plugin/datetimepicker/bootstrap-datetimepicker.js"
charset=
"UTF-8"
type=
"text/javascript"
></script>
<script
src=
"<%=basePath %>js/global.js"
charset=
"UTF-8"
type=
"text/javascript"
></script>
<script
src=
"<%=basePath %>js/bootstrap-plugin/bootstrap.pagination.js"
charset=
"UTF-8"
type=
"text/javascript"
></script>
<script
src=
"<%=basePath %>js/bootstrap-plugin/bootstrap.table.js"
charset=
"UTF-8"
type=
"text/javascript"
></script>
<script
src=
"<%=basePath %>js/bootstrap-plugin/bootstrap.dialog.js"
charset=
"UTF-8"
type=
"text/javascript"
></script>
<script
src=
"<%=basePath %>js/bootstrap-plugin/bootstrap.form.js"
charset=
"UTF-8"
type=
"text/javascript"
></script>
<script
src=
"<%=basePath %>js/bootstrap-plugin/bootstrap.panel.js"
charset=
"UTF-8"
type=
"text/javascript"
></script>
<script
src=
"<%=basePath %>js/bootstrap-plugin/bootstrap.alerts.js"
charset=
"UTF-8"
type=
"text/javascript"
></script>
<script
src=
"<%=basePath %>js/bootstrap-plugin/bootstrap.accordion.js"
charset=
"UTF-8"
type=
"text/javascript"
></script>
<script
src=
"<%=basePath %>js/bootstrap-plugin/bootstrap.breadcrumb.js"
charset=
"UTF-8"
type=
"text/javascript"
></script>
<script
src=
"<%=basePath %>js/bootstrap-plugin/bootstrap.validate.js"
charset=
"UTF-8"
type=
"text/javascript"
></script>
<script
src=
"<%=basePath %>js/bootstrap-plugin/bootstrap.form.js"
charset=
"UTF-8"
type=
"text/javascript"
></script>
<script
src=
"<%=basePath %>js/layer/layer.js"
charset=
"UTF-8"
type=
"text/javascript"
></script>
<script
src=
"<%=basePath %>js/bootstrap-plugin/bootstrap.select.js"
charset=
"UTF-8"
type=
"text/javascript"
></script>
<script
src=
"<%=basePath %>js/jstree/jstree.min.js"
></script>
<script
src=
"<%=basePath %>js/jquery.toaster.js"
></script>
<script
src=
"<%=basePath %>js/jquery-plugin/jquery.cookies.js"
charset=
"UTF-8"
type=
"text/javascript"
></script>
<script>
var
contextPath
=
'<%=basePath %>'
;
</script>
<title></title>
</head>
<body>
...
...
monitor-ui-web/src/main/webapp/jsp/project/project_build.jsp
View file @
353a7d9
...
...
@@ -102,6 +102,7 @@
<span
class=
"input-group-addon"
>
回滚:
</span>
<input
type=
"text"
id=
"rollbackfile_name"
name=
"rollbackfile_name"
class=
"form-control"
readonly=
"readonly"
value=
"${rollbackfile_name}"
/>
<input
type=
"hidden"
id=
"workid_name"
name=
"workid_name"
readonly=
"readonly"
value=
"${workid_name}"
/>
</div>
</div>
</div>
...
...
@@ -136,19 +137,19 @@
</div>
</c:forEach>
<c:
if
test=
"${existSpecialYohoSearchService=='error' or existSpecialYohoSearchService=='deregister'}
"
>
<c:
forEach
items=
"${specialProjectLbList }"
var=
"specialProject
"
>
<div
style=
"float: left;height: 600px;"
>
<hr>
<div>
当前项目:
<input
type=
"text"
value=
"
yoho-search-service
"
readonly=
"readonly"
>
<div>
当前项目:
<input
type=
"text"
value=
"
${specialProject}
"
readonly=
"readonly"
>
</div>
<div
style=
"height: 50px"
class=
"alert alert-warning"
id=
"task-info-div_
yoho-search-service
"
>
<div
style=
"height: 50px"
class=
"alert alert-warning"
id=
"task-info-div_
${specialProject}
"
>
</div>
<textarea
id=
"resultArea_
yoho-search-service
"
rows=
"25"
cols=
"100"
<textarea
id=
"resultArea_
${specialProject}
"
rows=
"25"
cols=
"100"
style=
"background-color: black; color: white"
readonly=
"readonly"
></textarea>
</div>
</c:
if
>
</c:
forEach
>
</div>
</div>
...
...
@@ -166,6 +167,8 @@
var
myArray
;
var
removeArray
=
new
Array
();
var
specialProjectLbList
=
$
{
specialProjectLbList
};
$
(
function
()
{
var
messageListHidden
=
$
(
"#messageListHidden"
).
val
();
myArray
=
messageListHidden
.
split
(
","
);
...
...
@@ -217,32 +220,92 @@
});
},
3000
);
specialBuildYohoSearchService
();
//特殊项目的发布
specialLbProject
();
});
//特殊项目的发布
var
yoho_search_service_resultAreaId
=
"resultArea_yoho-search-service"
;
function
specialBuildYohoSearchService
(){
var
existSpecialYohoSearchService
=
"${existSpecialYohoSearchService}"
;
if
(
"error"
!=
existSpecialYohoSearchService
&&
"deregister"
!=
existSpecialYohoSearchService
){
return
;
function
specialLbProject
(){
for
(
var
i
=
0
;
i
<
specialProjectLbList
.
length
;
i
++
){
var
projectName
=
specialProjectLbList
[
i
];
var
resultAreaId
=
"resultArea_"
+
projectName
;
$
.
ajax
({
url
:
contextPath
+
'project/checkSpecialProjectLbInfoBeforeBuild'
,
type
:
'POST'
,
data
:{
project
:
projectName
,
operate_name
:
$
(
"#operate_name"
).
val
(),
environment_name
:
$
(
"#environment_name"
).
val
(),
branch_name
:
$
(
"#branch_name"
).
val
(),
workid_name
:
$
(
"#workid_name"
).
val
(),
rollbackfile_name
:
$
(
"#rollbackfile_name"
).
val
()
},
dataType
:
'json'
,
success
:
function
(
reps
)
{
if
(
reps
!=
null
&&
reps
.
code
==
200
){
var
jsonLbResult
=
reps
.
data
;
console
.
log
(
jsonLbResult
);
if
(
jsonLbResult
.
onlyOneHost
==
"2"
){
textAreaAppend
(
resultAreaId
,
"lb存在多台主机,特殊流程发布!"
);
singleSpecialLbProjectBuild
(
resultAreaId
,
jsonLbResult
);
}
else
{
var
dialog
=
$
(
"<div>"
).
appendTo
(
$
(
"body"
));
dialog
.
dialog
({
title
:
"提示"
,
backdrop
:
"static"
,
content
:
"负载均衡查询到一台或者没有机器实例,通过原流程发布"
,
buttons
:
[{
text
:
"否"
,
className
:
"btn-info"
,
onclick
:
function
()
{
textAreaAppend
(
resultAreaId
,
"发布取消!!"
);
document
.
getElementById
(
"task-info-div_"
+
projectName
).
innerHTML
=
"<strong>发布取消</strong>"
;
dialog
.
dialog
(
"hide"
);
}
},
{
text
:
"是"
,
className
:
"btn-danger"
,
onclick
:
function
()
{
dialog
.
dialog
(
"hide"
);
textAreaAppend
(
resultAreaId
,
"lb最多只有一台主机,原流程直接发布!"
);
jsonLbResult
.
deployIps
=
""
;
//要发布ip为空,则根据配置文件查找全部机器
var
d
=
deployYohoSearchService
(
resultAreaId
,
jsonLbResult
);
d
.
then
(
function
()
{
textAreaAppend
(
resultAreaId
,
"发布成功,完成!!"
);
document
.
getElementById
(
"task-info-div_"
+
projectName
).
innerHTML
=
"<strong>发布成功</strong>"
;
return
;
});
}
}]
});
}
}
else
{
if
(
reps
!=
null
){
textAreaAppend
(
resultAreaId
,
"lb检查出错,"
+
projectName
+
"项目发布终止!"
+
reps
.
message
);
}
else
{
textAreaAppend
(
resultAreaId
,
"lb检查出错,"
+
projectName
+
"项目发布终止!"
);
}
}
},
error
:
function
(
e
)
{
textAreaAppend
(
resultAreaId
,
"lb检查出错,"
+
projectName
+
"项目发布终止!"
);
}
});
}
}
var
jsonLbResult
=
JSON
.
parse
(
'${specialYohoSearchServiceResult}'
);
console
.
log
(
jsonLbResult
);
if
(
"error"
==
"${existSpecialYohoSearchService}"
){
textAreaAppendYohoSearchService
(
jsonLbResult
.
msg
);
}
else
{
textAreaAppendYohoSearchService
(
jsonLbResult
.
msg
);
function
singleSpecialLbProjectBuild
(
resultAreaId
,
jsonLbResult
)
{
textAreaAppend
(
resultAreaId
,
jsonLbResult
.
msg
);
//开始执行
textAreaAppend
YohoSearchService
(
">>>>>开始执行>>>>>"
);
textAreaAppend
(
resultAreaId
,
">>>>>开始执行>>>>>"
);
//1.保留,卸载
textAreaAppendYohoSearchService
(
"保留机器id is "
+
jsonLbResult
.
keepId
);
textAreaAppendYohoSearchService
(
"保留机器ip is "
+
jsonLbResult
.
keepIp
);
textAreaAppendYohoSearchService
(
"卸载机器id包含 "
+
jsonLbResult
.
changeIds
);
textAreaAppendYohoSearchService
(
"卸载机器ip包含 "
+
jsonLbResult
.
changeIps
);
//2.查询卸载结果,等待卸载完成
//3.发布本次卸载的机器
//4.查询发布结果,发布完成之后,再挂载
...
...
@@ -251,68 +314,77 @@
//7.发布本次卸载的机器
//8.查询发布结果,发布完成之后,再挂载
//流程结束
textAreaAppend
(
resultAreaId
,
"保留机器id is "
+
jsonLbResult
.
keepId
);
textAreaAppend
(
resultAreaId
,
"保留机器ip is "
+
jsonLbResult
.
keepIp
);
textAreaAppend
(
resultAreaId
,
"卸载机器id包含 "
+
jsonLbResult
.
changeIds
);
textAreaAppend
(
resultAreaId
,
"卸载机器ip包含 "
+
jsonLbResult
.
changeIps
);
jsonLbResult
.
next_moveIds
=
jsonLbResult
.
changeIds
;
var
d
=
deregisterFromLb
(
resultAreaId
,
jsonLbResult
);
jsonLbResult
.
deployIps
=
jsonLbResult
.
changeIps
;
jsonLbResult
.
next_registerIds
=
jsonLbResult
.
changeIds
;
jsonLbResult
.
next_moveIds
=
jsonLbResult
.
keepId
;
jsonLbResult
.
lbHostNum
=
jsonLbResult
.
keepNum
;
var
d
=
checkDeregister
(
jsonLbResult
);
d
=
d
.
then
(
function
(){
jsonLbResult
.
deployIps
=
jsonLbResult
.
changeIps
;
jsonLbResult
.
next_registerIds
=
jsonLbResult
.
changeIds
;
jsonLbResult
.
next_moveIds
=
jsonLbResult
.
keepId
;
jsonLbResult
.
lbHostNum
=
jsonLbResult
.
keepNum
;
return
checkDeregister
(
resultAreaId
,
jsonLbResult
);
});
d
=
d
.
then
(
function
(){
return
deployYohoSearchService
(
jsonLbResult
);
return
deployYohoSearchService
(
resultAreaId
,
jsonLbResult
);
});
d
=
d
.
then
(
function
(){
//开始挂载到负载均衡
registerToLb
(
jsonLbResult
.
environmentName
,
jsonLbResult
.
next_registerIds
);
registerToLb
(
resultAreaId
,
jsonLbResult
,
jsonLbResult
.
next_registerIds
);
//挂载完成之后,负载均衡机器恢复卸载之前的状态,检查
jsonLbResult
.
lbHostNum
=
jsonLbResult
.
hostNum
;
return
checkDeregister
(
jsonLbResult
);
return
checkDeregister
(
resultAreaId
,
jsonLbResult
);
});
d
=
d
.
then
(
function
(){
deregisterFromLb
(
jsonLbResult
);
deregisterFromLb
(
resultAreaId
,
jsonLbResult
);
//卸载完成之后,再检查
jsonLbResult
.
deployIps
=
jsonLbResult
.
keepIp
;
jsonLbResult
.
next_registerIds
=
jsonLbResult
.
next_moveIds
;
jsonLbResult
.
next_moveIds
=
""
;
jsonLbResult
.
lbHostNum
=
jsonLbResult
.
changeNum
;
return
checkDeregister
(
jsonLbResult
);
return
checkDeregister
(
resultAreaId
,
jsonLbResult
);
});
d
=
d
.
then
(
function
()
{
return
deployYohoSearchService
(
jsonLbResult
);
return
deployYohoSearchService
(
resultAreaId
,
jsonLbResult
);
});
d
=
d
.
then
(
function
(){
//开始挂载到负载均衡
registerToLb
(
jsonLbResult
.
environmentName
,
jsonLbResult
.
next_registerIds
);
registerToLb
(
resultAreaId
,
jsonLbResult
,
jsonLbResult
.
next_registerIds
);
//挂载完成之后,负载均衡机器恢复卸载之前的状态,检查
jsonLbResult
.
lbHostNum
=
jsonLbResult
.
hostNum
;
return
checkDeregister
(
jsonLbResult
);
return
checkDeregister
(
resultAreaId
,
jsonLbResult
);
});
d
.
then
(
function
()
{
textAreaAppendYohoSearchService
(
"发布成功,完成!!"
);
document
.
getElementById
(
"task-info-div_yoho-search-service"
).
innerHTML
=
"<strong>发布成功</strong>"
;
textAreaAppend
(
resultAreaId
,
"发布成功,完成!!"
);
document
.
getElementById
(
"task-info-div_"
+
jsonLbResult
.
currentProject
).
innerHTML
=
"<strong>发布成功</strong>"
;
return
;
});
}
}
//发布
function
deployYohoSearchService
(
paramBackJson
){
textAreaAppendYohoSearchService
(
"*** 已经从负载均衡卸载下来的机器 : "
+
paramBackJson
.
deployIps
);
var
messageId
=
deployProject
(
paramBackJson
);
textAreaAppendYohoSearchService
(
"项目正在部署!messageId is "
+
messageId
);
return
deployProjectGetMsg
(
messageId
,
paramBackJson
);
function
deployYohoSearchService
(
resultAreaId
,
paramBackJson
){
textAreaAppend
(
resultAreaId
,
"*** 即将发布的机器是 : "
+
paramBackJson
.
deployIps
);
var
messageId
=
deployProject
(
resultAreaId
,
paramBackJson
);
textAreaAppend
(
resultAreaId
,
"项目正在部署!messageId is "
+
messageId
);
return
deployProjectGetMsg
(
resultAreaId
,
messageId
,
paramBackJson
);
}
function
deployProject
(
paramBackJson
){
textAreaAppendYohoSearchService
(
"开始部署项目"
);
function
deployProject
(
resultAreaId
,
paramBackJson
){
textAreaAppend
(
resultAreaId
,
"开始部署项目"
);
var
returnMessageId
=
""
;
var
url
=
contextPath
+
'project/buildProjectWithIPs'
;
var
paramFront
=
{};
...
...
@@ -331,7 +403,7 @@
async
:
false
,
success
:
function
(
data
)
{
if
(
!
data
||
data
.
code
!=
200
)
{
textAreaAppend
YohoSearchService
(
"发布失败"
);
textAreaAppend
(
resultAreaId
,
"发布失败"
);
}
else
{
//console.log("buildProjectWithIPs data is "+data.data);
returnMessageId
=
data
.
data
.
split
(
','
)[
0
];
...
...
@@ -339,16 +411,16 @@
},
error
:
function
(
e
)
{
console
.
log
(
e
);
textAreaAppend
YohoSearchService
(
"发布失败,error"
+
e
);
textAreaAppend
(
resultAreaId
,
"发布失败,error"
+
e
);
}
});
return
returnMessageId
;
}
//3.1:发布项目的同时获取发布的消息
function
deployProjectGetMsg
(
msgId
,
paramBackJson
){
function
deployProjectGetMsg
(
resultAreaId
,
msgId
,
paramBackJson
){
var
def
=
$
.
Deferred
();
textAreaAppend
YohoSearchService
(
"检查项目部署进度"
);
textAreaAppend
(
resultAreaId
,
"检查项目部署进度"
);
var
intervalIndexMsg
=
setInterval
(
function
()
{
$
.
ajax
({
url
:
contextPath
+
'project/getbuildmsg?messageid='
+
msgId
+
"&project="
+
paramBackJson
.
currentProject
,
...
...
@@ -359,7 +431,7 @@
var
obj2
=
eval
(
"("
+
data3
+
")"
);
var
messagedata
=
obj2
.
data
;
if
((
messagedata
.
message
!=
""
)
&&
(
messagedata
.
message
!=
null
)
&&
(
messagedata
.
message
!=
undefined
))
{
textAreaAppend
YohoSearchService
(
messagedata
.
message
);
textAreaAppend
(
resultAreaId
,
messagedata
.
message
);
}
//code为2 ,则结束
...
...
@@ -367,7 +439,7 @@
//只有状态2,3,4才表示系统部署成功与否
if
(
code
==
2
||
code
==
3
||
code
==
4
)
{
clearInterval
(
intervalIndexMsg
);
textAreaAppend
YohoSearchService
(
"项目部署完成,状态 is "
+
code
);
textAreaAppend
(
resultAreaId
,
"项目部署完成,状态 is "
+
code
);
if
(
code
==
2
){
//任务执行正常结束,只有这种情况,才能执行下一步操作。
def
.
resolve
();
...
...
@@ -382,12 +454,13 @@
}
//卸载
function
deregisterFromLb
(
paramBackJson
)
{
textAreaAppendYohoSearchService
(
"卸载机器到elb"
+
paramBackJson
.
next_moveIds
);
$
.
ajax
({
function
deregisterFromLb
(
resultAreaId
,
paramBackJson
)
{
textAreaAppend
(
resultAreaId
,
"从elb卸载机器 "
+
paramBackJson
.
next_moveIds
);
return
$
.
ajax
({
url
:
contextPath
+
"/project/deregisterHostYohoSearchService"
,
type
:
"post"
,
data
:{
project
:
paramBackJson
.
currentProject
,
environment_name
:
paramBackJson
.
environmentName
,
instIds
:
paramBackJson
.
next_moveIds
},
...
...
@@ -403,13 +476,14 @@
}
//挂载到负载均衡
function
registerToLb
(
environment_name
,
instIds
){
textAreaAppendYohoSearchService
(
"挂载机器到elb "
+
instIds
);
function
registerToLb
(
resultAreaId
,
jsonLbResult
,
instIds
){
textAreaAppend
(
resultAreaId
,
"挂载机器到elb "
+
instIds
);
$
.
ajax
({
url
:
contextPath
+
"/project/registerHostYohoSearchService"
,
type
:
"post"
,
data
:{
environment_name
:
environment_name
,
project
:
jsonLbResult
.
currentProject
,
environment_name
:
jsonLbResult
.
environmentName
,
instIds
:
instIds
},
dataType
:
"json"
,
...
...
@@ -426,27 +500,30 @@
//卸载检查
function
checkDeregister
(
cbfParam
){
function
checkDeregister
(
resultAreaId
,
cbfParam
){
var
keepHostNum
=
cbfParam
.
lbHostNum
;
var
df
=
$
.
Deferred
();
textAreaAppend
YohoSearchService
(
"**** 负载均衡实例数量检查 ***"
);
textAreaAppend
(
resultAreaId
,
"**** 负载均衡实例数量检查 ***"
);
var
count
=
0
;
var
intervalIndex
=
setInterval
(
function
()
{
$
.
ajax
({
url
:
contextPath
+
"/project/getLbInfoYohoSearchService
?environment_name="
+
cbfParam
.
environmentName
,
url
:
contextPath
+
"/project/getLbInfoYohoSearchService
"
,
type
:
"post"
,
dataType
:
"json"
,
//async: false,
//timeout:120000, //超时时间:120秒
data
:
{},
data
:
{
project
:
cbfParam
.
currentProject
,
environment_name
:
cbfParam
.
environmentName
},
success
:
function
(
checkResponse
)
{
count
++
;
if
(
count
>
5
){
textAreaAppend
YohoSearchService
(
"..........检查次数......"
+
(
count
-
5
));
textAreaAppend
(
resultAreaId
,
"..........检查次数......"
+
(
count
-
5
));
}
if
(
count
>
105
){
clearInterval
(
intervalIndex
);
textAreaAppend
YohoSearchService
(
"**** 超过规定的次数,任务终止 ****"
);
textAreaAppend
(
resultAreaId
,
"**** 超过规定的次数,任务终止 ****"
);
}
else
if
(
checkResponse
!=
null
&&
checkResponse
.
code
==
200
){
var
currentHosts
=
0
;
for
(
var
hostid
in
checkResponse
.
data
){
...
...
@@ -454,7 +531,7 @@
}
if
(
currentHosts
==
keepHostNum
){
clearInterval
(
intervalIndex
);
textAreaAppend
YohoSearchService
(
"**** 检查通过,负载均衡现有实例数量为: "
+
keepHostNum
);
textAreaAppend
(
resultAreaId
,
"**** 检查通过,负载均衡现有实例数量为: "
+
keepHostNum
);
df
.
resolve
();
}
}
...
...
@@ -530,10 +607,6 @@
});
}
function
textAreaAppendYohoSearchService
(
content
)
{
textAreaAppend
(
yoho_search_service_resultAreaId
,
content
);
}
function
textAreaAppend
(
textId
,
content
)
{
var
d
=
$
(
"#"
+
textId
).
val
();
if
(
d
!=
null
&&
d
.
length
>
0
){
...
...
Please
register
or
login
to post a comment