Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
apollo
Commits
561ad088
Commit
561ad088
authored
Dec 23, 2016
by
lepdou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add cat restapi transaction & fix email windows outlook bug
parent
66c20025
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
226 additions
and
126 deletions
+226
-126
PortalSettings.java
...ip/framework/apollo/portal/components/PortalSettings.java
+5
-0
RetryableRestTemplate.java
...ework/apollo/portal/components/RetryableRestTemplate.java
+2
-0
PortalConfig.java
...amework/apollo/portal/components/config/PortalConfig.java
+31
-4
ConfigPublishEmailBuilder.java
...al/components/emailbuilder/ConfigPublishEmailBuilder.java
+82
-71
GrayPublishEmailBuilder.java
...rtal/components/emailbuilder/GrayPublishEmailBuilder.java
+23
-11
MergeEmailBuilder.java
...llo/portal/components/emailbuilder/MergeEmailBuilder.java
+11
-2
NormalPublishEmailBuilder.java
...al/components/emailbuilder/NormalPublishEmailBuilder.java
+11
-2
RollbackEmailBuilder.java
.../portal/components/emailbuilder/RollbackEmailBuilder.java
+11
-2
NamespaceService.java
...rip/framework/apollo/portal/service/NamespaceService.java
+10
-8
CtripEmailRequestBuilder.java
...ork/apollo/portal/spi/ctrip/CtripEmailRequestBuilder.java
+4
-1
CtripEmailService.java
.../framework/apollo/portal/spi/ctrip/CtripEmailService.java
+10
-4
WebContextConfiguration.java
...work/apollo/portal/spi/ctrip/WebContextConfiguration.java
+4
-4
UserAccessFilter.java
...ork/apollo/portal/spi/ctrip/filters/UserAccessFilter.java
+17
-12
PageCommon.js
...lo-portal/src/main/resources/static/scripts/PageCommon.js
+4
-4
pom.xml
pom.xml
+1
-1
No files found.
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/components/PortalSettings.java
View file @
561ad088
...
...
@@ -76,6 +76,11 @@ public class PortalSettings {
return
activeEnvs
;
}
public
boolean
isEnvActive
(
Env
env
)
{
Boolean
mark
=
envStatusMark
.
get
(
env
);
return
mark
==
null
?
false
:
mark
;
}
private
class
HealthCheckTask
implements
Runnable
{
private
static
final
int
ENV_DOWN_THRESHOLD
=
2
;
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/components/RetryableRestTemplate.java
View file @
561ad088
...
...
@@ -85,6 +85,7 @@ public class RetryableRestTemplate {
String
uri
=
uriTemplateHandler
.
expand
(
path
,
uriVariables
).
getPath
();
Transaction
ct
=
Tracer
.
newTransaction
(
"AdminAPI"
,
uri
);
ct
.
addData
(
"Env"
,
env
);
List
<
ServiceDTO
>
services
=
getAdminServices
(
env
,
ct
);
...
...
@@ -126,6 +127,7 @@ public class RetryableRestTemplate {
String
uri
=
uriTemplateHandler
.
expand
(
path
,
uriVariables
).
getPath
();
Transaction
ct
=
Tracer
.
newTransaction
(
"AdminAPI"
,
uri
);
ct
.
addData
(
"Env"
,
env
);
List
<
ServiceDTO
>
services
=
getAdminServices
(
env
,
ct
);
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/components/config/PortalConfig.java
View file @
561ad088
...
...
@@ -101,6 +101,21 @@ public class PortalConfig extends RefreshableConfig {
/***
* Level: low
**/
public
Set
<
Env
>
publishTipsSupportedEnvs
()
{
String
[]
configurations
=
getArrayProperty
(
"namespace.publish.tips.supported.envs"
,
null
);
Set
<
Env
>
result
=
Sets
.
newHashSet
();
if
(
configurations
==
null
||
configurations
.
length
==
0
)
{
return
result
;
}
for
(
String
env
:
configurations
)
{
result
.
add
(
Env
.
fromString
(
env
));
}
return
result
;
}
public
String
consumerTokenSalt
()
{
return
getValue
(
"consumer.token.salt"
,
"apollo-portal"
);
}
...
...
@@ -109,12 +124,20 @@ public class PortalConfig extends RefreshableConfig {
return
getValue
(
"email.sender"
);
}
public
String
publishEmailBodyTemplate
()
{
return
getValue
(
"email.template.release.v2"
,
""
);
public
String
emailTemplateFramework
()
{
return
getValue
(
"email.template.framework"
,
""
);
}
public
String
emailReleaseDiffModuleTemplate
()
{
return
getValue
(
"email.template.release.module.diff"
,
""
);
}
public
String
rollbackEmailBodyTemplate
()
{
return
getValue
(
"email.template.rollback.v2"
,
""
);
public
String
emailRollbackDiffModuleTemplate
()
{
return
getValue
(
"email.template.rollback.module.diff"
,
""
);
}
public
String
emailGrayRulesModuleTemplate
()
{
return
getValue
(
"email.template.release.module.rules"
,
""
);
}
/***
...
...
@@ -139,6 +162,10 @@ public class PortalConfig extends RefreshableConfig {
return
getIntProperty
(
"ctrip.email.survival.duration"
,
5
);
}
public
boolean
isSendEmailAsync
()
{
return
getBooleanProperty
(
"email.send.async"
,
true
);
}
public
String
portalServerName
()
{
return
getValue
(
"serverName"
);
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/components/emailbuilder/ConfigPublishEmailBuilder.java
View file @
561ad088
...
...
@@ -47,15 +47,13 @@ public abstract class ConfigPublishEmailBuilder {
private
static
final
String
EMAIL_CONTENT_FIELD_RELEASE_TITLE
=
"#\\{releaseTitle}"
;
private
static
final
String
EMAIL_CONTENT_FIELD_RELEASE_COMMENT
=
"#\\{releaseComment}"
;
private
static
final
String
EMAIL_CONTENT_FIELD_APOLLO_SERVER_ADDRESS
=
"#\\{apollo.portal.address}"
;
private
static
final
String
EMAIL_CONTENT_FIELD_DIFF
=
"#\\{diff
}"
;
private
static
final
String
EMAIL_CONTENT_FIELD_DIFF
_CONTENT
=
"#\\{diffContent
}"
;
//email content special field placeholder
protected
static
final
String
EMAIL_CONTENT_
FIELD_RULE
=
"#\\{rules
}"
;
private
static
final
String
EMAIL_CONTENT_DIFF_MODULE
=
"#\\{diffModule}"
;
protected
static
final
String
EMAIL_CONTENT_
GRAY_RULES_MODULE
=
"#\\{rulesModule
}"
;
//email content module switch
private
static
final
String
EMAIL_CONTENT_DIFF_HAS_CONTENT_SWITCH
=
"diff-hidden"
;
private
static
final
String
EMAIL_CONTENT_DIFF_HAS_NOT_CONTENT_SWITCH
=
"diff-empty-hidden"
;
protected
static
final
String
EMAIL_CONTENT_RULE_SWITCH
=
"rule-hidden"
;
//email content special field placeholder
protected
static
final
String
EMAIL_CONTENT_GRAY_RULES_CONTENT
=
"#\\{rulesContent}"
;
//set config's value max length to protect email.
protected
static
final
int
VALUE_MAX_LENGTH
=
100
;
...
...
@@ -72,65 +70,50 @@ public abstract class ConfigPublishEmailBuilder {
@Autowired
private
UserService
userService
;
@Autowired
private
PortalConfig
portalConfig
;
public
Email
build
(
Env
env
,
ReleaseHistoryBO
releaseHistory
)
{
Email
email
=
new
Email
();
email
.
setSubject
(
subject
());
email
.
setSenderEmailAddress
(
portalConfig
.
emailSender
());
email
.
setBody
(
emailContent
(
env
,
releaseHistory
));
email
.
setRecipients
(
recipients
(
releaseHistory
.
getAppId
(),
releaseHistory
.
getNamespaceName
()));
return
email
;
}
protected
PortalConfig
portalConfig
;
/**
* email subject
*/
protected
abstract
String
subject
();
/**
* email body content
*/
protected
abstract
String
emailContent
(
Env
env
,
ReleaseHistoryBO
releaseHistory
);
private
List
<
String
>
recipients
(
String
appId
,
String
namespaceName
)
{
Set
<
UserInfo
>
modifyRoleUsers
=
rolePermissionService
.
queryUsersWithRole
(
RoleUtils
.
buildNamespaceRoleName
(
appId
,
namespaceName
,
RoleType
.
MODIFY_NAMESPACE
));
Set
<
UserInfo
>
releaseRoleUsers
=
rolePermissionService
.
queryUsersWithRole
(
RoleUtils
.
buildNamespaceRoleName
(
appId
,
namespaceName
,
RoleType
.
RELEASE_NAMESPACE
));
Set
<
UserInfo
>
owners
=
rolePermissionService
.
queryUsersWithRole
(
RoleUtils
.
buildAppMasterRoleName
(
appId
));
/**
* email body template framework
*/
protected
abstract
String
getTemplateFramework
();
Set
<
String
>
userIds
=
new
HashSet
<>(
modifyRoleUsers
.
size
()
+
releaseRoleUsers
.
size
()
+
owners
.
size
());
/**
* email body diff module template
*/
protected
abstract
String
getDiffModuleTemplate
();
for
(
UserInfo
userInfo
:
modifyRoleUsers
)
{
userIds
.
add
(
userInfo
.
getUserId
());
}
for
(
UserInfo
userInfo
:
releaseRoleUsers
)
{
userIds
.
add
(
userInfo
.
getUserId
());
}
for
(
UserInfo
userInfo
:
owners
)
{
userIds
.
add
(
userInfo
.
getUserId
());
}
public
Email
build
(
Env
env
,
ReleaseHistoryBO
releaseHistory
)
{
List
<
UserInfo
>
userInfos
=
userService
.
findByUserIds
(
Lists
.
newArrayList
(
userIds
)
);
Email
email
=
new
Email
(
);
if
(
CollectionUtils
.
isEmpty
(
userInfos
)){
return
Collections
.
emptyList
(
);
}
email
.
setSubject
(
subject
());
email
.
setSenderEmailAddress
(
portalConfig
.
emailSender
()
);
email
.
setRecipients
(
recipients
(
releaseHistory
.
getAppId
(),
releaseHistory
.
getNamespaceName
()));
List
<
String
>
recipients
=
new
ArrayList
<>(
userInfos
.
size
());
for
(
UserInfo
userInfo:
userInfos
){
recipients
.
add
(
userInfo
.
getEmail
());
}
String
emailBody
=
emailContent
(
env
,
releaseHistory
);
//clear not used module
emailBody
=
emailBody
.
replaceAll
(
EMAIL_CONTENT_DIFF_MODULE
,
""
);
emailBody
=
emailBody
.
replaceAll
(
EMAIL_CONTENT_GRAY_RULES_MODULE
,
""
);
email
.
setBody
(
emailBody
);
return
recipients
;
return
email
;
}
protected
String
renderEmailCommonContent
(
String
template
,
Env
env
,
ReleaseHistoryBO
releaseHistory
)
{
protected
String
renderEmailCommonContent
(
Env
env
,
ReleaseHistoryBO
releaseHistory
)
{
String
template
=
getTemplateFramework
();
String
renderResult
=
renderReleaseBasicInfo
(
template
,
env
,
releaseHistory
);
renderResult
=
renderDiff
Content
(
renderResult
,
env
,
releaseHistory
);
renderResult
=
renderDiff
Module
(
renderResult
,
env
,
releaseHistory
);
return
renderResult
;
}
...
...
@@ -142,16 +125,16 @@ public abstract class ConfigPublishEmailBuilder {
renderResult
=
renderResult
.
replaceAll
(
EMAIL_CONTENT_FIELD_OPERATOR
,
Matcher
.
quoteReplacement
(
releaseHistory
.
getOperator
()));
renderResult
=
renderResult
.
replaceAll
(
EMAIL_CONTENT_FIELD_RELEASE_TITLE
,
Matcher
.
quoteReplacement
(
releaseHistory
.
getReleaseTitle
()));
renderResult
=
renderResult
.
replaceAll
(
EMAIL_CONTENT_FIELD_RELEASE_ID
,
String
.
valueOf
(
releaseHistory
.
getReleaseId
()));
renderResult
.
replaceAll
(
EMAIL_CONTENT_FIELD_RELEASE_ID
,
String
.
valueOf
(
releaseHistory
.
getReleaseId
()));
renderResult
=
renderResult
.
replaceAll
(
EMAIL_CONTENT_FIELD_RELEASE_HISTORY_ID
,
String
.
valueOf
(
releaseHistory
.
getId
()));
renderResult
.
replaceAll
(
EMAIL_CONTENT_FIELD_RELEASE_HISTORY_ID
,
String
.
valueOf
(
releaseHistory
.
getId
()));
renderResult
=
renderResult
.
replaceAll
(
EMAIL_CONTENT_FIELD_RELEASE_COMMENT
,
Matcher
.
quoteReplacement
(
releaseHistory
.
getReleaseComment
()));
renderResult
=
renderResult
.
replaceAll
(
EMAIL_CONTENT_FIELD_APOLLO_SERVER_ADDRESS
,
getApolloPortalAddress
());
return
renderResult
.
replaceAll
(
EMAIL_CONTENT_FIELD_RELEASE_TIME
,
dateFormat
.
format
(
releaseHistory
.
getReleaseTime
()));
.
replaceAll
(
EMAIL_CONTENT_FIELD_RELEASE_TIME
,
dateFormat
.
format
(
releaseHistory
.
getReleaseTime
()));
}
private
String
renderDiff
Content
(
String
t
emplate
,
Env
env
,
ReleaseHistoryBO
releaseHistory
)
{
private
String
renderDiff
Module
(
String
bodyT
emplate
,
Env
env
,
ReleaseHistoryBO
releaseHistory
)
{
String
appId
=
releaseHistory
.
getAppId
();
String
namespaceName
=
releaseHistory
.
getNamespaceName
();
...
...
@@ -162,16 +145,15 @@ public abstract class ConfigPublishEmailBuilder {
//don't show diff content if namespace's format is file
if
(
appNamespace
==
null
||
!
appNamespace
.
getFormat
().
equals
(
ConfigFileFormat
.
Properties
.
getValue
()))
{
!
appNamespace
.
getFormat
().
equals
(
ConfigFileFormat
.
Properties
.
getValue
()))
{
return
template
.
replaceAll
(
EMAIL_CONTENT_FIELD_DIFF
,
"请点击链接到Apollo上查看
"
);
return
bodyTemplate
.
replaceAll
(
EMAIL_CONTENT_DIFF_MODULE
,
"<br><h4>变更内容请点击链接到Apollo上查看</h4>
"
);
}
ReleaseCompareResult
result
=
getReleaseCompareResult
(
env
,
releaseHistory
);
if
(!
result
.
hasContent
())
{
String
renderResult
=
template
.
replaceAll
(
EMAIL_CONTENT_DIFF_HAS_NOT_CONTENT_SWITCH
,
""
);
return
renderResult
.
replaceAll
(
EMAIL_CONTENT_FIELD_DIFF
,
""
);
return
bodyTemplate
.
replaceAll
(
EMAIL_CONTENT_DIFF_MODULE
,
"<br><h4>无配置变更</h4>"
);
}
List
<
Change
>
changes
=
result
.
getChanges
();
...
...
@@ -184,23 +166,24 @@ public abstract class ConfigPublishEmailBuilder {
changesHtmlBuilder
.
append
(
"<tr>"
);
changesHtmlBuilder
.
append
(
"<td width=\"10%\">"
).
append
(
change
.
getType
().
toString
()).
append
(
"</td>"
);
changesHtmlBuilder
.
append
(
"<td width=\"
1
0%\">"
).
append
(
cutOffString
(
key
)).
append
(
"</td>"
);
changesHtmlBuilder
.
append
(
"<td width=\"
10
%\">"
).
append
(
cutOffString
(
oldValue
)).
append
(
"</td>"
);
changesHtmlBuilder
.
append
(
"<td width=\"
10
%\">"
).
append
(
cutOffString
(
newValue
)).
append
(
"</td>"
);
changesHtmlBuilder
.
append
(
"<td width=\"
2
0%\">"
).
append
(
cutOffString
(
key
)).
append
(
"</td>"
);
changesHtmlBuilder
.
append
(
"<td width=\"
35
%\">"
).
append
(
cutOffString
(
oldValue
)).
append
(
"</td>"
);
changesHtmlBuilder
.
append
(
"<td width=\"
35
%\">"
).
append
(
cutOffString
(
newValue
)).
append
(
"</td>"
);
changesHtmlBuilder
.
append
(
"</tr>"
);
}
String
diffContent
=
Matcher
.
quoteReplacement
(
changesHtmlBuilder
.
toString
());
String
renderResult
=
template
.
replaceAll
(
EMAIL_CONTENT_FIELD_DIFF
,
diffContent
);
return
renderResult
.
replaceAll
(
EMAIL_CONTENT_DIFF_HAS_CONTENT_SWITCH
,
""
);
String
diffModuleTemplate
=
getDiffModuleTemplate
();
String
diffModuleRenderResult
=
diffModuleTemplate
.
replaceAll
(
EMAIL_CONTENT_FIELD_DIFF_CONTENT
,
diffContent
);
return
bodyTemplate
.
replaceAll
(
EMAIL_CONTENT_DIFF_MODULE
,
diffModuleRenderResult
);
}
private
ReleaseCompareResult
getReleaseCompareResult
(
Env
env
,
ReleaseHistoryBO
releaseHistory
)
{
if
(
releaseHistory
.
getOperation
()
==
ReleaseOperation
.
GRAY_RELEASE
&&
releaseHistory
.
getPreviousReleaseId
()
==
0
)
{
&&
releaseHistory
.
getPreviousReleaseId
()
==
0
)
{
ReleaseDTO
masterLatestActiveRelease
=
releaseService
.
loadLatestRelease
(
releaseHistory
.
getAppId
(),
env
,
releaseHistory
.
getClusterName
(),
releaseHistory
.
getNamespaceName
());
releaseHistory
.
getAppId
(),
env
,
releaseHistory
.
getClusterName
(),
releaseHistory
.
getNamespaceName
());
ReleaseDTO
branchLatestActiveRelease
=
releaseService
.
findReleaseById
(
env
,
releaseHistory
.
getReleaseId
());
return
releaseService
.
compare
(
masterLatestActiveRelease
,
branchLatestActiveRelease
);
...
...
@@ -209,13 +192,41 @@ public abstract class ConfigPublishEmailBuilder {
return
releaseService
.
compare
(
env
,
releaseHistory
.
getPreviousReleaseId
(),
releaseHistory
.
getReleaseId
());
}
private
List
<
String
>
recipients
(
String
appId
,
String
namespaceName
)
{
Set
<
UserInfo
>
modifyRoleUsers
=
rolePermissionService
.
queryUsersWithRole
(
RoleUtils
.
buildNamespaceRoleName
(
appId
,
namespaceName
,
RoleType
.
MODIFY_NAMESPACE
));
Set
<
UserInfo
>
releaseRoleUsers
=
rolePermissionService
.
queryUsersWithRole
(
RoleUtils
.
buildNamespaceRoleName
(
appId
,
namespaceName
,
RoleType
.
RELEASE_NAMESPACE
));
Set
<
UserInfo
>
owners
=
rolePermissionService
.
queryUsersWithRole
(
RoleUtils
.
buildAppMasterRoleName
(
appId
));
Set
<
String
>
userIds
=
new
HashSet
<>(
modifyRoleUsers
.
size
()
+
releaseRoleUsers
.
size
()
+
owners
.
size
());
protected
String
getReleaseTemplate
(
)
{
return
portalConfig
.
publishEmailBodyTemplate
(
);
}
for
(
UserInfo
userInfo
:
modifyRoleUsers
)
{
userIds
.
add
(
userInfo
.
getUserId
()
);
}
protected
String
getRollbackTemplate
()
{
return
portalConfig
.
rollbackEmailBodyTemplate
();
for
(
UserInfo
userInfo
:
releaseRoleUsers
)
{
userIds
.
add
(
userInfo
.
getUserId
());
}
for
(
UserInfo
userInfo
:
owners
)
{
userIds
.
add
(
userInfo
.
getUserId
());
}
List
<
UserInfo
>
userInfos
=
userService
.
findByUserIds
(
Lists
.
newArrayList
(
userIds
));
if
(
CollectionUtils
.
isEmpty
(
userInfos
))
{
return
Collections
.
emptyList
();
}
List
<
String
>
recipients
=
new
ArrayList
<>(
userInfos
.
size
());
for
(
UserInfo
userInfo
:
userInfos
)
{
recipients
.
add
(
userInfo
.
getEmail
());
}
return
recipients
;
}
protected
String
getApolloPortalAddress
()
{
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/components/emailbuilder/GrayPublishEmailBuilder.java
View file @
561ad088
...
...
@@ -31,36 +31,48 @@ public class GrayPublishEmailBuilder extends ConfigPublishEmailBuilder {
@Override
public
String
emailContent
(
Env
env
,
ReleaseHistoryBO
releaseHistory
)
{
String
result
=
renderEmailCommonContent
(
getReleaseTemplate
(),
env
,
releaseHistory
);
String
result
=
renderEmailCommonContent
(
env
,
releaseHistory
);
return
renderGrayReleaseRuleContent
(
result
,
releaseHistory
);
}
private
String
renderGrayReleaseRuleContent
(
String
template
,
ReleaseHistoryBO
releaseHistory
)
{
String
result
=
template
.
replaceAll
(
EMAIL_CONTENT_RULE_SWITCH
,
""
);
@Override
protected
String
getTemplateFramework
()
{
return
portalConfig
.
emailTemplateFramework
();
}
@Override
protected
String
getDiffModuleTemplate
()
{
return
portalConfig
.
emailReleaseDiffModuleTemplate
();
}
private
String
renderGrayReleaseRuleContent
(
String
bodyTemplate
,
ReleaseHistoryBO
releaseHistory
)
{
Map
<
String
,
Object
>
context
=
releaseHistory
.
getOperationContext
();
Object
rules
=
context
.
get
(
"rules"
);
List
<
GrayReleaseRuleItemDTO
>
ruleItems
=
rules
==
null
?
null
:
gson
.
fromJson
(
rules
.
toString
(),
GsonType
.
RULE_ITEMS
);
ruleItems
=
rules
==
null
?
null
:
gson
.
fromJson
(
rules
.
toString
(),
GsonType
.
RULE_ITEMS
);
StringBuilder
rulesHtmlBuilder
=
new
StringBuilder
();
if
(
CollectionUtils
.
isEmpty
(
ruleItems
))
{
r
ulesHtmlBuilder
.
append
(
"无灰度规则
"
);
r
eturn
bodyTemplate
.
replaceAll
(
EMAIL_CONTENT_GRAY_RULES_MODULE
,
"<br><h4>无灰度规则</h4>
"
);
}
else
{
StringBuilder
rulesHtmlBuilder
=
new
StringBuilder
();
for
(
GrayReleaseRuleItemDTO
ruleItem
:
ruleItems
)
{
String
clientAppId
=
ruleItem
.
getClientAppId
();
Set
<
String
>
ips
=
ruleItem
.
getClientIpList
();
rulesHtmlBuilder
.
append
(
"<b>AppId: </b>"
)
.
append
(
clientAppId
)
.
append
(
" <b>IP: </b>"
);
.
append
(
clientAppId
)
.
append
(
" <b>IP: </b>"
);
IP_JOINER
.
appendTo
(
rulesHtmlBuilder
,
ips
);
}
}
String
grayRulesModuleContent
=
portalConfig
.
emailGrayRulesModuleTemplate
().
replaceAll
(
EMAIL_CONTENT_GRAY_RULES_CONTENT
,
Matcher
.
quoteReplacement
(
rulesHtmlBuilder
.
toString
()));
return
result
.
replaceAll
(
EMAIL_CONTENT_FIELD_RULE
,
Matcher
.
quoteReplacement
(
rulesHtmlBuilder
.
toString
()));
return
bodyTemplate
.
replaceAll
(
EMAIL_CONTENT_GRAY_RULES_MODULE
,
Matcher
.
quoteReplacement
(
grayRulesModuleContent
));
}
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/components/emailbuilder/MergeEmailBuilder.java
View file @
561ad088
...
...
@@ -20,7 +20,16 @@ public class MergeEmailBuilder extends ConfigPublishEmailBuilder {
@Override
protected
String
emailContent
(
Env
env
,
ReleaseHistoryBO
releaseHistory
)
{
String
template
=
getReleaseTemplate
();
return
renderEmailCommonContent
(
template
,
env
,
releaseHistory
);
return
renderEmailCommonContent
(
env
,
releaseHistory
);
}
@Override
protected
String
getTemplateFramework
()
{
return
portalConfig
.
emailTemplateFramework
();
}
@Override
protected
String
getDiffModuleTemplate
()
{
return
portalConfig
.
emailReleaseDiffModuleTemplate
();
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/components/emailbuilder/NormalPublishEmailBuilder.java
View file @
561ad088
...
...
@@ -20,7 +20,16 @@ public class NormalPublishEmailBuilder extends ConfigPublishEmailBuilder {
@Override
protected
String
emailContent
(
Env
env
,
ReleaseHistoryBO
releaseHistory
)
{
String
template
=
getReleaseTemplate
();
return
renderEmailCommonContent
(
template
,
env
,
releaseHistory
);
return
renderEmailCommonContent
(
env
,
releaseHistory
);
}
@Override
protected
String
getTemplateFramework
()
{
return
portalConfig
.
emailTemplateFramework
();
}
@Override
protected
String
getDiffModuleTemplate
()
{
return
portalConfig
.
emailReleaseDiffModuleTemplate
();
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/components/emailbuilder/RollbackEmailBuilder.java
View file @
561ad088
...
...
@@ -20,7 +20,16 @@ public class RollbackEmailBuilder extends ConfigPublishEmailBuilder {
@Override
protected
String
emailContent
(
Env
env
,
ReleaseHistoryBO
releaseHistory
)
{
String
template
=
getRollbackTemplate
();
return
renderEmailCommonContent
(
template
,
env
,
releaseHistory
);
return
renderEmailCommonContent
(
env
,
releaseHistory
);
}
@Override
protected
String
getTemplateFramework
()
{
return
portalConfig
.
emailTemplateFramework
();
}
@Override
protected
String
getDiffModuleTemplate
()
{
return
portalConfig
.
emailRollbackDiffModuleTemplate
();
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java
View file @
561ad088
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
service
;
import
com.ctrip.framework.apollo.portal.components.config.PortalConfig
;
import
com.google.common.collect.Maps
;
import
com.google.gson.Gson
;
...
...
@@ -30,10 +31,7 @@ import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.client.HttpClientErrorException
;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.*
;
@Service
public
class
NamespaceService
{
...
...
@@ -42,8 +40,6 @@ public class NamespaceService {
private
Gson
gson
=
new
Gson
();
@Autowired
private
PortalSettings
portalSettings
;
@Autowired
private
UserInfoHolder
userInfoHolder
;
@Autowired
private
ItemService
itemService
;
...
...
@@ -53,6 +49,10 @@ public class NamespaceService {
private
AdminServiceAPI
.
NamespaceAPI
namespaceAPI
;
@Autowired
private
AppNamespaceService
appNamespaceService
;
@Autowired
private
PortalConfig
portalConfig
;
@Autowired
private
PortalSettings
portalSettings
;
public
NamespaceDTO
createNamespace
(
Env
env
,
NamespaceDTO
namespace
)
{
...
...
@@ -138,9 +138,11 @@ public class NamespaceService {
public
Map
<
String
,
Map
<
String
,
Boolean
>>
getNamespacesPublishInfo
(
String
appId
)
{
Map
<
String
,
Map
<
String
,
Boolean
>>
result
=
Maps
.
newHashMap
();
List
<
Env
>
envs
=
portalSettings
.
getActive
Envs
();
Set
<
Env
>
envs
=
portalConfig
.
publishTipsSupported
Envs
();
for
(
Env
env:
envs
)
{
result
.
put
(
env
.
toString
(),
namespaceAPI
.
getNamespacePublishInfo
(
env
,
appId
));
if
(
portalSettings
.
isEnvActive
(
env
))
{
result
.
put
(
env
.
toString
(),
namespaceAPI
.
getNamespacePublishInfo
(
env
,
appId
));
}
}
return
result
;
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/CtripEmailRequestBuilder.java
View file @
561ad088
...
...
@@ -66,7 +66,10 @@ public class CtripEmailRequestBuilder {
setSender
.
invoke
(
emailRequest
,
email
.
getSenderEmailAddress
());
setSubject
.
invoke
(
emailRequest
,
email
.
getSubject
());
setBodyContent
.
invoke
(
emailRequest
,
email
.
getBody
());
String
emailBodyBuilder
=
"<entry><content><![CDATA[<!DOCTYPE html>"
+
email
.
getBody
()
+
"]]></content></entry>"
;
setBodyContent
.
invoke
(
emailRequest
,
emailBodyBuilder
);
setRecipient
.
invoke
(
emailRequest
,
email
.
getRecipients
());
return
emailRequest
;
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/CtripEmailService.java
View file @
561ad088
...
...
@@ -21,6 +21,7 @@ public class CtripEmailService implements EmailService {
private
Object
emailServiceClient
;
private
Method
sendEmailAsync
;
private
Method
sendEmail
;
@Autowired
private
CtripEmailRequestBuilder
emailRequestBuilder
;
...
...
@@ -33,13 +34,15 @@ public class CtripEmailService implements EmailService {
initServiceClientConfig
();
Class
emailServiceClientClazz
=
Class
.
forName
(
"com.ctrip.framework.apolloctripservice.emailservice.EmailServiceClient"
);
Class
.
forName
(
"com.ctrip.framework.apolloctripservice.emailservice.EmailServiceClient"
);
Method
getInstanceMethod
=
emailServiceClientClazz
.
getMethod
(
"getInstance"
);
emailServiceClient
=
getInstanceMethod
.
invoke
(
null
);
Class
sendEmailRequestClazz
=
Class
.
forName
(
"com.ctrip.framework.apolloctripservice.emailservice.SendEmailRequest"
);
Class
.
forName
(
"com.ctrip.framework.apolloctripservice.emailservice.SendEmailRequest"
);
sendEmailAsync
=
emailServiceClientClazz
.
getMethod
(
"sendEmailAsync"
,
sendEmailRequestClazz
);
sendEmail
=
emailServiceClientClazz
.
getMethod
(
"sendEmail"
,
sendEmailRequestClazz
);
}
catch
(
Throwable
e
)
{
logger
.
error
(
"init ctrip email service failed"
,
e
);
Tracer
.
logError
(
"init ctrip email service failed"
,
e
);
...
...
@@ -64,9 +67,12 @@ public class CtripEmailService implements EmailService {
try
{
Object
emailRequest
=
emailRequestBuilder
.
buildEmailRequest
(
email
);
Object
sendResponse
=
sendEmailAsync
.
invoke
(
emailServiceClient
,
emailRequest
);
logger
.
info
(
"Email sender response:"
+
sendResponse
);
Object
sendResponse
=
portalConfig
.
isSendEmailAsync
()
?
sendEmailAsync
.
invoke
(
emailServiceClient
,
emailRequest
)
:
sendEmail
.
invoke
(
emailServiceClient
,
emailRequest
);
logger
.
info
(
"Email server response: "
+
sendResponse
);
}
catch
(
Throwable
e
)
{
logger
.
error
(
"send email failed"
,
e
);
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/WebContextConfiguration.java
View file @
561ad088
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
spi
.
ctrip
;
import
com.ctrip.framework.apollo.portal.spi.ctrip.filters.UserAccessFilter
;
import
com.google.common.base.Strings
;
import
com.ctrip.framework.apollo.portal.components.config.PortalConfig
;
import
com.ctrip.framework.apollo.portal.spi.UserInfoHolder
;
import
com.ctrip.framework.apollo.portal.spi.ctrip.filters.RecordAccessUserFilter
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.context.embedded.FilterRegistrationBean
;
...
...
@@ -47,10 +47,10 @@ public class WebContextConfiguration {
}
@Bean
public
FilterRegistrationBean
recordAccessUser
Filter
()
{
public
FilterRegistrationBean
userAccess
Filter
()
{
FilterRegistrationBean
filter
=
new
FilterRegistrationBean
();
filter
.
setFilter
(
new
RecordAccessUser
Filter
(
userInfoHolder
));
filter
.
addUrlPatterns
(
"/
apps
"
);
filter
.
setFilter
(
new
UserAccess
Filter
(
userInfoHolder
));
filter
.
addUrlPatterns
(
"/
*
"
);
return
filter
;
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/filters/
RecordAccessUser
Filter.java
→
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/ctrip/filters/
UserAccess
Filter.java
View file @
561ad088
...
...
@@ -3,23 +3,19 @@ package com.ctrip.framework.apollo.portal.spi.ctrip.filters;
import
com.ctrip.framework.apollo.portal.constant.CatEventType
;
import
com.ctrip.framework.apollo.portal.spi.UserInfoHolder
;
import
com.ctrip.framework.apollo.tracer.Tracer
;
import
com.google.common.base.Strings
;
import
javax.servlet.*
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.IOException
;
import
javax.servlet.Filter
;
import
javax.servlet.FilterChain
;
import
javax.servlet.FilterConfig
;
import
javax.servlet.ServletException
;
import
javax.servlet.ServletRequest
;
import
javax.servlet.ServletResponse
;
public
class
RecordAccessUserFilter
implements
Filter
{
public
class
UserAccessFilter
implements
Filter
{
private
static
final
String
STATIC_RESOURCE_REGEX
=
".*\\.(js|html|htm|png|css|woff2)$"
;
private
UserInfoHolder
userInfoHolder
;
public
RecordAccessUserFilter
(
UserInfoHolder
userInfoHolder
)
{
public
UserAccessFilter
(
UserInfoHolder
userInfoHolder
)
{
this
.
userInfoHolder
=
userInfoHolder
;
}
...
...
@@ -30,9 +26,13 @@ public class RecordAccessUserFilter implements Filter {
@Override
public
void
doFilter
(
ServletRequest
request
,
ServletResponse
response
,
FilterChain
chain
)
throws
IOException
,
ServletException
{
throws
IOException
,
ServletException
{
String
requestUri
=
((
HttpServletRequest
)
request
).
getRequestURI
();
Tracer
.
logEvent
(
CatEventType
.
USER_ACCESS
,
userInfoHolder
.
getUser
().
getUserId
());
if
(!
isStaticResource
(
requestUri
))
{
Tracer
.
logEvent
(
CatEventType
.
USER_ACCESS
,
userInfoHolder
.
getUser
().
getUserId
());
}
chain
.
doFilter
(
request
,
response
);
}
...
...
@@ -41,4 +41,9 @@ public class RecordAccessUserFilter implements Filter {
public
void
destroy
()
{
}
private
boolean
isStaticResource
(
String
uri
)
{
return
!
Strings
.
isNullOrEmpty
(
uri
)
&&
uri
.
matches
(
STATIC_RESOURCE_REGEX
);
}
}
apollo-portal/src/main/resources/static/scripts/PageCommon.js
View file @
561ad088
...
...
@@ -17,12 +17,12 @@ $(document).ready(function () {
$
(
'[data-tooltip="tooltip"]'
).
tooltip
({
trigger
:
'hover'
});
},
2500
);
setTimeout
(
function
()
{
$
(
"textarea"
).
niceScroll
({
cursoropacitymax
:
0
});
$
(
"pre"
).
niceScroll
({
cursoropacitymax
:
0
});
},
1000
);
setTimeout
(
function
()
{
$
(
".release-history-list"
).
niceScroll
({
cursoropacitymax
:
0
});
},
2500
);
...
...
pom.xml
View file @
561ad088
...
...
@@ -143,7 +143,7 @@
<dependency>
<groupId>
com.dianping.cat
</groupId>
<artifactId>
cat-client
</artifactId>
<version>
2.
1.2
</version>
<version>
2.
2.1
</version>
</dependency>
<dependency>
<groupId>
org.unidal.framework
</groupId>
...
...
Write
Preview
Markdown
is supported
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