Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
apollo
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Administrator
apollo
Commits
ffc33fb8
Commit
ffc33fb8
authored
Feb 22, 2020
by
Jason Song
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make gray release rule case-insensitive
parent
62cdc90d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
14 deletions
+43
-14
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/grayReleaseRule/GrayReleaseRuleCache.java
...work/apollo/biz/grayReleaseRule/GrayReleaseRuleCache.java
+6
-1
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/grayReleaseRule/GrayReleaseRulesHolder.java
...rk/apollo/biz/grayReleaseRule/GrayReleaseRulesHolder.java
+6
-3
apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/grayReleaseRule/GrayReleaseRulesHolderTest.java
...pollo/biz/grayReleaseRule/GrayReleaseRulesHolderTest.java
+4
-0
apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/GrayReleaseRuleItemDTO.java
...p/framework/apollo/common/dto/GrayReleaseRuleItemDTO.java
+1
-1
apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/controller/NotificationControllerV2Test.java
...onfigservice/controller/NotificationControllerV2Test.java
+26
-9
No files found.
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/grayReleaseRule/GrayReleaseRuleCache.java
View file @
ffc33fb8
...
...
@@ -7,7 +7,7 @@ import java.util.Set;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public
class
GrayReleaseRuleCache
{
public
class
GrayReleaseRuleCache
implements
Comparable
<
GrayReleaseRuleCache
>
{
private
long
ruleId
;
private
String
branchName
;
private
String
namespaceName
;
...
...
@@ -67,4 +67,9 @@ public class GrayReleaseRuleCache {
}
return
false
;
}
@Override
public
int
compareTo
(
GrayReleaseRuleCache
that
)
{
return
Long
.
compare
(
this
.
ruleId
,
that
.
ruleId
);
}
}
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/grayReleaseRule/GrayReleaseRulesHolder.java
View file @
ffc33fb8
...
...
@@ -3,10 +3,10 @@ package com.ctrip.framework.apollo.biz.grayReleaseRule;
import
com.google.common.base.Joiner
;
import
com.google.common.base.Splitter
;
import
com.google.common.base.Strings
;
import
com.google.common.collect.HashMultimap
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Multimap
;
import
com.google.common.collect.Multimaps
;
import
com.google.common.collect.Ordering
;
import
com.google.common.collect.Sets
;
import
com.ctrip.framework.apollo.biz.config.BizConfig
;
...
...
@@ -23,6 +23,7 @@ import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory;
import
com.ctrip.framework.apollo.tracer.Tracer
;
import
com.ctrip.framework.apollo.tracer.spi.Transaction
;
import
com.google.common.collect.TreeMultimap
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.InitializingBean
;
...
...
@@ -61,8 +62,10 @@ public class GrayReleaseRulesHolder implements ReleaseMessageListener, Initializ
public
GrayReleaseRulesHolder
()
{
loadVersion
=
new
AtomicLong
();
grayReleaseRuleCache
=
Multimaps
.
synchronizedSetMultimap
(
HashMultimap
.
create
());
reversedGrayReleaseRuleCache
=
Multimaps
.
synchronizedSetMultimap
(
HashMultimap
.
create
());
grayReleaseRuleCache
=
Multimaps
.
synchronizedSetMultimap
(
TreeMultimap
.
create
(
String
.
CASE_INSENSITIVE_ORDER
,
Ordering
.
natural
()));
reversedGrayReleaseRuleCache
=
Multimaps
.
synchronizedSetMultimap
(
TreeMultimap
.
create
(
String
.
CASE_INSENSITIVE_ORDER
,
Ordering
.
natural
()));
executorService
=
Executors
.
newScheduledThreadPool
(
1
,
ApolloThreadFactory
.
create
(
"GrayReleaseRulesHolder"
,
true
));
}
...
...
apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/grayReleaseRule/GrayReleaseRulesHolderTest.java
View file @
ffc33fb8
...
...
@@ -84,6 +84,8 @@ public class GrayReleaseRulesHolderTest {
assertEquals
(
someReleaseId
,
grayReleaseRulesHolder
.
findReleaseIdFromGrayReleaseRule
(
someClientAppId
,
someClientIp
,
someAppId
,
someClusterName
,
someNamespaceName
));
assertEquals
(
someReleaseId
,
grayReleaseRulesHolder
.
findReleaseIdFromGrayReleaseRule
(
someClientAppId
.
toUpperCase
(),
someClientIp
,
someAppId
.
toUpperCase
(),
someClusterName
,
someNamespaceName
.
toUpperCase
()));
assertNull
(
grayReleaseRulesHolder
.
findReleaseIdFromGrayReleaseRule
(
someClientAppId
,
anotherClientIp
,
someAppId
,
someClusterName
,
someNamespaceName
));
...
...
@@ -94,6 +96,8 @@ public class GrayReleaseRulesHolderTest {
assertTrue
(
grayReleaseRulesHolder
.
hasGrayReleaseRule
(
someClientAppId
,
someClientIp
,
someNamespaceName
));
assertTrue
(
grayReleaseRulesHolder
.
hasGrayReleaseRule
(
someClientAppId
.
toUpperCase
(),
someClientIp
,
someNamespaceName
.
toUpperCase
()));
assertFalse
(
grayReleaseRulesHolder
.
hasGrayReleaseRule
(
someClientAppId
,
anotherClientIp
,
someNamespaceName
));
assertFalse
(
grayReleaseRulesHolder
.
hasGrayReleaseRule
(
someClientAppId
,
someClientIp
,
...
...
apollo-common/src/main/java/com/ctrip/framework/apollo/common/dto/GrayReleaseRuleItemDTO.java
View file @
ffc33fb8
...
...
@@ -37,7 +37,7 @@ public class GrayReleaseRuleItemDTO {
}
private
boolean
appIdMatches
(
String
clientAppId
)
{
return
this
.
clientAppId
.
equals
(
clientAppId
);
return
this
.
clientAppId
.
equals
IgnoreCase
(
clientAppId
);
}
private
boolean
ipMatches
(
String
clientIp
)
{
...
...
apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/controller/NotificationControllerV2Test.java
View file @
ffc33fb8
...
...
@@ -341,35 +341,52 @@ public class NotificationControllerV2Test {
}
@Test
public
void
testPollNotificationWithCaseInsensitiveAppId
()
throws
Exception
{
String
someWatchKey
=
Joiner
.
on
(
ConfigConsts
.
CLUSTER_NAMESPACE_SEPARATOR
)
public
void
testPollNotificationWithIncorrectCase
()
throws
Exception
{
String
appIdWithIncorrectCase
=
someAppId
.
toUpperCase
();
String
namespaceWithIncorrectCase
=
defaultNamespace
.
toUpperCase
();
String
someMessage
=
Joiner
.
on
(
ConfigConsts
.
CLUSTER_NAMESPACE_SEPARATOR
)
.
join
(
someAppId
,
someCluster
,
defaultNamespace
);
String
another
WatchKey
=
Joiner
.
on
(
ConfigConsts
.
CLUSTER_NAMESPACE_SEPARATOR
)
.
join
(
"someAPPID"
,
someCluster
,
defaultNamespace
);
String
some
WatchKey
=
Joiner
.
on
(
ConfigConsts
.
CLUSTER_NAMESPACE_SEPARATOR
)
.
join
(
appIdWithIncorrectCase
,
someCluster
,
defaultNamespace
);
Multimap
<
String
,
String
>
watchKeysMap
=
assembleMultiMap
(
defaultNamespace
,
Lists
.
newArrayList
(
someWatchKey
));
String
notificationAsString
=
transformApolloConfigNotificationsToString
(
defaultNamespace
,
someNotificationId
);
transformApolloConfigNotificationsToString
(
defaultNamespace
.
toUpperCase
()
,
someNotificationId
);
when
(
namespaceUtil
.
filterNamespaceName
(
namespaceWithIncorrectCase
)).
thenReturn
(
namespaceWithIncorrectCase
);
when
(
namespaceUtil
.
normalizeNamespace
(
appIdWithIncorrectCase
,
namespaceWithIncorrectCase
)).
thenReturn
(
defaultNamespace
);
when
(
watchKeysUtil
.
assembleAllWatchKeys
(
someAppId
,
someCluster
,
Sets
.
newHashSet
(
defaultNamespace
),
.
assembleAllWatchKeys
(
appIdWithIncorrectCase
,
someCluster
,
Sets
.
newHashSet
(
defaultNamespace
),
someDataCenter
)).
thenReturn
(
watchKeysMap
);
DeferredResult
<
ResponseEntity
<
List
<
ApolloConfigNotification
>>>
deferredResult
=
controller
.
pollNotification
(
someAppId
,
someCluster
,
notificationAsString
,
someDataCenter
,
.
pollNotification
(
appIdWithIncorrectCase
,
someCluster
,
notificationAsString
,
someDataCenter
,
someClientIp
);
long
someId
=
1
;
ReleaseMessage
someReleaseMessage
=
new
ReleaseMessage
(
anotherWatchKey
);
ReleaseMessage
someReleaseMessage
=
new
ReleaseMessage
(
someMessage
);
someReleaseMessage
.
setId
(
someId
);
controller
.
handleMessage
(
someReleaseMessage
,
Topics
.
APOLLO_RELEASE_TOPIC
);
//now both of them should have result
assertTrue
(
deferredResult
.
hasResult
());
ResponseEntity
<
List
<
ApolloConfigNotification
>>
response
=
(
ResponseEntity
<
List
<
ApolloConfigNotification
>>)
deferredResult
.
getResult
();
assertEquals
(
1
,
response
.
getBody
().
size
());
ApolloConfigNotification
notification
=
response
.
getBody
().
get
(
0
);
assertEquals
(
HttpStatus
.
OK
,
response
.
getStatusCode
());
assertEquals
(
namespaceWithIncorrectCase
,
notification
.
getNamespaceName
());
assertEquals
(
someId
,
notification
.
getNotificationId
());
ApolloNotificationMessages
notificationMessages
=
notification
.
getMessages
();
assertEquals
(
1
,
notificationMessages
.
getDetails
().
size
());
assertEquals
(
someId
,
notificationMessages
.
get
(
someMessage
).
longValue
());
}
private
String
transformApolloConfigNotificationsToString
(
...
...
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