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
51e7bc07
Commit
51e7bc07
authored
Aug 01, 2016
by
Jason Song
Committed by
GitHub
Aug 01, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #362 from nobodyiam/client-no-appid
Client no appid
parents
0a5424ed
e540d883
Show whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
137 additions
and
18 deletions
+137
-18
pom.xml
apollo-adminservice/pom.xml
+1
-1
pom.xml
apollo-assembly/pom.xml
+1
-1
pom.xml
apollo-biz/pom.xml
+1
-1
pom.xml
apollo-buildtools/pom.xml
+1
-1
pom.xml
apollo-client/pom.xml
+1
-1
ConfigUtil.java
...main/java/com/ctrip/framework/apollo/util/ConfigUtil.java
+8
-4
pom.xml
apollo-common/pom.xml
+1
-1
pom.xml
apollo-configservice/pom.xml
+1
-1
ConfigController.java
...ork/apollo/configservice/controller/ConfigController.java
+8
-2
WatchKeysUtil.java
...ip/framework/apollo/configservice/util/WatchKeysUtil.java
+7
-1
ConfigControllerTest.java
...apollo/configservice/controller/ConfigControllerTest.java
+45
-0
ConfigControllerIntegrationTest.java
...gservice/integration/ConfigControllerIntegrationTest.java
+33
-0
WatchKeysUtilTest.java
...ramework/apollo/configservice/util/WatchKeysUtilTest.java
+24
-0
pom.xml
apollo-core/pom.xml
+1
-1
ConfigConsts.java
...in/java/com/ctrip/framework/apollo/core/ConfigConsts.java
+1
-0
pom.xml
apollo-demo/pom.xml
+1
-1
pom.xml
apollo-portal/pom.xml
+1
-1
pom.xml
pom.xml
+1
-1
No files found.
apollo-adminservice/pom.xml
View file @
51e7bc07
...
...
@@ -4,7 +4,7 @@
<parent>
<groupId>
com.ctrip.framework.apollo
</groupId>
<artifactId>
apollo
</artifactId>
<version>
0.0.
7
</version>
<version>
0.0.
8-SNAPSHOT
</version>
<relativePath>
../pom.xml
</relativePath>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
apollo-assembly/pom.xml
View file @
51e7bc07
...
...
@@ -4,7 +4,7 @@
<parent>
<groupId>
com.ctrip.framework.apollo
</groupId>
<artifactId>
apollo
</artifactId>
<version>
0.0.
7
</version>
<version>
0.0.
8-SNAPSHOT
</version>
<relativePath>
../pom.xml
</relativePath>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
apollo-biz/pom.xml
View file @
51e7bc07
...
...
@@ -4,7 +4,7 @@
<parent>
<artifactId>
apollo
</artifactId>
<groupId>
com.ctrip.framework.apollo
</groupId>
<version>
0.0.
7
</version>
<version>
0.0.
8-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
apollo-biz
</artifactId>
...
...
apollo-buildtools/pom.xml
View file @
51e7bc07
...
...
@@ -4,7 +4,7 @@
<parent>
<groupId>
com.ctrip.framework.apollo
</groupId>
<artifactId>
apollo
</artifactId>
<version>
0.0.
7
</version>
<version>
0.0.
8-SNAPSHOT
</version>
<relativePath>
../pom.xml
</relativePath>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
apollo-client/pom.xml
View file @
51e7bc07
...
...
@@ -4,7 +4,7 @@
<parent>
<groupId>
com.ctrip.framework.apollo
</groupId>
<artifactId>
apollo
</artifactId>
<version>
0.0.
7
</version>
<version>
0.0.
8-SNAPSHOT
</version>
<relativePath>
../pom.xml
</relativePath>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
apollo-client/src/main/java/com/ctrip/framework/apollo/util/ConfigUtil.java
View file @
51e7bc07
...
...
@@ -7,12 +7,13 @@ import com.ctrip.framework.apollo.core.ConfigConsts;
import
com.ctrip.framework.apollo.core.MetaDomainConsts
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.core.enums.EnvUtils
;
import
com.ctrip.framework.apollo.exceptions.ApolloConfigException
;
import
com.ctrip.framework.foundation.Foundation
;
import
com.dianping.cat.Cat
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.unidal.lookup.annotation.Named
;
import
org.unidal.net.Networks
;
import
java.util.concurrent.TimeUnit
;
...
...
@@ -41,12 +42,15 @@ public class ConfigUtil {
/**
* Get the app id for the current application.
*
* @return the app id
* @throws IllegalStateException if app id is not set
* @return the app id or ConfigConsts.NO_APPID_PLACEHOLDER if app id is not available
*/
public
String
getAppId
()
{
String
appId
=
Foundation
.
app
().
getAppId
();
Preconditions
.
checkState
(
appId
!=
null
,
"app.id is not set"
);
if
(
Strings
.
isNullOrEmpty
(
appId
))
{
appId
=
ConfigConsts
.
NO_APPID_PLACEHOLDER
;
logger
.
error
(
"app.id is not set, apollo will only load public namespace configurations!"
);
Cat
.
logError
(
new
ApolloConfigException
(
"app.id is not set"
));
}
return
appId
;
}
...
...
apollo-common/pom.xml
View file @
51e7bc07
...
...
@@ -4,7 +4,7 @@
<parent>
<groupId>
com.ctrip.framework.apollo
</groupId>
<artifactId>
apollo
</artifactId>
<version>
0.0.
7
</version>
<version>
0.0.
8-SNAPSHOT
</version>
<relativePath>
../pom.xml
</relativePath>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
apollo-configservice/pom.xml
View file @
51e7bc07
...
...
@@ -4,7 +4,7 @@
<parent>
<groupId>
com.ctrip.framework.apollo
</groupId>
<artifactId>
apollo
</artifactId>
<version>
0.0.
7
</version>
<version>
0.0.
8-SNAPSHOT
</version>
<relativePath>
../pom.xml
</relativePath>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/controller/ConfigController.java
View file @
51e7bc07
...
...
@@ -59,20 +59,21 @@ public class ConfigController {
@RequestParam
(
value
=
"ip"
,
required
=
false
)
String
clientIp
,
HttpServletResponse
response
)
throws
IOException
{
String
originalNamespace
=
namespace
;
//strip out .properties suffix
namespace
=
namespaceUtil
.
filterNamespaceName
(
namespace
);
List
<
Release
>
releases
=
Lists
.
newLinkedList
();
Release
currentAppRelease
=
loadConfig
(
appId
,
clusterName
,
namespace
,
dataCenter
);
String
appClusterNameLoaded
=
clusterName
;
if
(!
ConfigConsts
.
NO_APPID_PLACEHOLDER
.
equalsIgnoreCase
(
appId
))
{
Release
currentAppRelease
=
loadConfig
(
appId
,
clusterName
,
namespace
,
dataCenter
);
if
(
currentAppRelease
!=
null
)
{
releases
.
add
(
currentAppRelease
);
//we have cluster search process, so the cluster name might be overridden
appClusterNameLoaded
=
currentAppRelease
.
getClusterName
();
}
}
//if namespace does not belong to this appId, should check if there is a public configuration
if
(!
namespaceBelongsToAppId
(
appId
,
namespace
))
{
...
...
@@ -116,6 +117,11 @@ public class ConfigController {
return
true
;
}
//if no appId is present, then no other namespace belongs to it
if
(
ConfigConsts
.
NO_APPID_PLACEHOLDER
.
equalsIgnoreCase
(
appId
))
{
return
false
;
}
AppNamespace
appNamespace
=
appNamespaceService
.
findOne
(
appId
,
namespaceName
);
return
appNamespace
!=
null
;
...
...
apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/util/WatchKeysUtil.java
View file @
51e7bc07
...
...
@@ -40,6 +40,7 @@ public class WatchKeysUtil {
/**
* Assemble watch keys for the given appId, cluster, namespaces, dataCenter combination
*
* @return a multimap with namespace as the key and watch keys as the value
*/
public
Multimap
<
String
,
String
>
assembleAllWatchKeys
(
String
appId
,
String
clusterName
,
...
...
@@ -91,7 +92,9 @@ public class WatchKeysUtil {
private
Set
<
String
>
assembleWatchKeys
(
String
appId
,
String
clusterName
,
String
namespace
,
String
dataCenter
)
{
if
(
ConfigConsts
.
NO_APPID_PLACEHOLDER
.
equalsIgnoreCase
(
appId
))
{
return
Collections
.
emptySet
();
}
Set
<
String
>
watchedKeys
=
Sets
.
newHashSet
();
//watch specified cluster config change
...
...
@@ -124,6 +127,9 @@ public class WatchKeysUtil {
}
private
Set
<
String
>
namespacesBelongToAppId
(
String
appId
,
Set
<
String
>
namespaces
)
{
if
(
ConfigConsts
.
NO_APPID_PLACEHOLDER
.
equalsIgnoreCase
(
appId
))
{
return
Collections
.
emptySet
();
}
List
<
AppNamespace
>
appNamespaces
=
appNamespaceService
.
findByAppIdAndNamespaces
(
appId
,
namespaces
);
...
...
apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/controller/ConfigControllerTest.java
View file @
51e7bc07
...
...
@@ -30,6 +30,7 @@ import static org.junit.Assert.assertNull;
import
static
org
.
mockito
.
Matchers
.
anyString
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
never
;
import
static
org
.
mockito
.
Mockito
.
times
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
...
...
@@ -431,6 +432,50 @@ public class ConfigControllerTest {
configController
.
mergeReleaseConfigurations
(
Lists
.
newArrayList
(
someRelease
));
}
@Test
public
void
testQueryConfigForNoAppIdPlaceHolder
()
throws
Exception
{
String
someClientSideReleaseKey
=
"1"
;
HttpServletResponse
someResponse
=
mock
(
HttpServletResponse
.
class
);
String
appId
=
ConfigConsts
.
NO_APPID_PLACEHOLDER
;
ApolloConfig
result
=
configController
.
queryConfig
(
appId
,
someClusterName
,
defaultNamespaceName
,
someDataCenter
,
someClientSideReleaseKey
,
someClientIp
,
someResponse
);
verify
(
releaseService
,
never
()).
findLatestActiveRelease
(
appId
,
someClusterName
,
defaultNamespaceName
);
verify
(
appNamespaceService
,
never
()).
findPublicNamespaceByName
(
defaultNamespaceName
);
assertNull
(
result
);
verify
(
someResponse
,
times
(
1
)).
sendError
(
eq
(
HttpServletResponse
.
SC_NOT_FOUND
),
anyString
());
}
@Test
public
void
testQueryConfigForNoAppIdPlaceHolderWithPublicNamespace
()
throws
Exception
{
String
someClientSideReleaseKey
=
"1"
;
String
someServerSideReleaseKey
=
"2"
;
HttpServletResponse
someResponse
=
mock
(
HttpServletResponse
.
class
);
String
somePublicAppId
=
"somePublicAppId"
;
AppNamespace
somePublicAppNamespace
=
assemblePublicAppNamespace
(
somePublicAppId
,
somePublicNamespaceName
);
String
appId
=
ConfigConsts
.
NO_APPID_PLACEHOLDER
;
when
(
appNamespaceService
.
findPublicNamespaceByName
(
somePublicNamespaceName
))
.
thenReturn
(
somePublicAppNamespace
);
when
(
releaseService
.
findLatestActiveRelease
(
somePublicAppId
,
someDataCenter
,
somePublicNamespaceName
))
.
thenReturn
(
somePublicRelease
);
when
(
somePublicRelease
.
getReleaseKey
()).
thenReturn
(
someServerSideReleaseKey
);
ApolloConfig
result
=
configController
.
queryConfig
(
appId
,
someClusterName
,
somePublicNamespaceName
,
someDataCenter
,
someClientSideReleaseKey
,
someClientIp
,
someResponse
);
verify
(
releaseService
,
never
()).
findLatestActiveRelease
(
appId
,
someClusterName
,
somePublicNamespaceName
);
assertEquals
(
someServerSideReleaseKey
,
result
.
getReleaseKey
());
assertEquals
(
appId
,
result
.
getAppId
());
assertEquals
(
someClusterName
,
result
.
getCluster
());
assertEquals
(
somePublicNamespaceName
,
result
.
getNamespaceName
());
assertEquals
(
"foo"
,
result
.
getConfigurations
().
get
(
"apollo.public.bar"
));
}
private
AppNamespace
assemblePublicAppNamespace
(
String
appId
,
String
namespace
)
{
return
assembleAppNamespace
(
appId
,
namespace
,
true
);
}
...
...
apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/integration/ConfigControllerIntegrationTest.java
View file @
51e7bc07
...
...
@@ -217,4 +217,37 @@ public class ConfigControllerIntegrationTest extends AbstractBaseIntegrationTest
assertEquals
(
"v1-file"
,
result
.
getConfigurations
().
get
(
"k1"
));
assertEquals
(
null
,
result
.
getConfigurations
().
get
(
"k2"
));
}
@Test
public
void
testQueryConfigForNoAppIdPlaceHolderWithPrivateNamespace
()
throws
Exception
{
HttpStatusCodeException
httpException
=
null
;
try
{
ResponseEntity
<
ApolloConfig
>
response
=
restTemplate
.
getForEntity
(
"{baseurl}/configs/{appId}/{clusterName}/{namespace}"
,
ApolloConfig
.
class
,
getHostUrl
(),
ConfigConsts
.
NO_APPID_PLACEHOLDER
,
someCluster
,
ConfigConsts
.
NAMESPACE_APPLICATION
);
}
catch
(
HttpStatusCodeException
ex
)
{
httpException
=
ex
;
}
assertEquals
(
HttpStatus
.
NOT_FOUND
,
httpException
.
getStatusCode
());
}
@Test
@Sql
(
scripts
=
"/integration-test/test-release.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
BEFORE_TEST_METHOD
)
@Sql
(
scripts
=
"/integration-test/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
public
void
testQueryPublicConfigForNoAppIdPlaceHolder
()
throws
Exception
{
ResponseEntity
<
ApolloConfig
>
response
=
restTemplate
.
getForEntity
(
"{baseurl}/configs/{appId}/{clusterName}/{namespace}?dataCenter={dateCenter}"
,
ApolloConfig
.
class
,
getHostUrl
(),
ConfigConsts
.
NO_APPID_PLACEHOLDER
,
someCluster
,
somePublicNamespace
,
someDC
);
ApolloConfig
result
=
response
.
getBody
();
assertEquals
(
"TEST-RELEASE-KEY4"
,
result
.
getReleaseKey
());
assertEquals
(
ConfigConsts
.
NO_APPID_PLACEHOLDER
,
result
.
getAppId
());
assertEquals
(
someCluster
,
result
.
getCluster
());
assertEquals
(
somePublicNamespace
,
result
.
getNamespaceName
());
assertEquals
(
"someDC-v1"
,
result
.
getConfigurations
().
get
(
"k1"
));
assertEquals
(
"someDC-v2"
,
result
.
getConfigurations
().
get
(
"k2"
));
}
}
apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/util/WatchKeysUtilTest.java
View file @
51e7bc07
...
...
@@ -75,6 +75,8 @@ public class WatchKeysUtilTest {
when
(
somePublicAppNamespace
.
getName
()).
thenReturn
(
somePublicNamespace
);
when
(
appNamespaceService
.
findPublicNamespacesByNames
(
Sets
.
newHashSet
(
somePublicNamespace
)))
.
thenReturn
(
Lists
.
newArrayList
(
somePublicAppNamespace
));
when
(
appNamespaceService
.
findPublicNamespacesByNames
(
Sets
.
newHashSet
(
someNamespace
,
somePublicNamespace
)))
.
thenReturn
(
Lists
.
newArrayList
(
somePublicAppNamespace
));
ReflectionTestUtils
.
setField
(
watchKeysUtil
,
"appNamespaceService"
,
appNamespaceService
);
}
...
...
@@ -141,6 +143,28 @@ public class WatchKeysUtilTest {
assertWatchKeys
(
somePublicAppId
,
clusters
,
somePublicNamespace
,
watchKeysMap
.
get
(
somePublicNamespace
));
}
@Test
public
void
testAssembleWatchKeysForNoAppIdPlaceHolder
()
throws
Exception
{
Multimap
<
String
,
String
>
watchKeysMap
=
watchKeysUtil
.
assembleAllWatchKeys
(
ConfigConsts
.
NO_APPID_PLACEHOLDER
,
someCluster
,
Sets
.
newHashSet
(
someNamespace
,
anotherNamespace
),
someDC
);
assertTrue
(
watchKeysMap
.
isEmpty
());
}
@Test
public
void
testAssembleWatchKeysForNoAppIdPlaceHolderAndPublicNamespace
()
throws
Exception
{
Multimap
<
String
,
String
>
watchKeysMap
=
watchKeysUtil
.
assembleAllWatchKeys
(
ConfigConsts
.
NO_APPID_PLACEHOLDER
,
someCluster
,
Sets
.
newHashSet
(
someNamespace
,
somePublicNamespace
),
someDC
);
Set
<
String
>
clusters
=
Sets
.
newHashSet
(
defaultCluster
,
someCluster
,
someDC
);
assertEquals
(
clusters
.
size
(),
watchKeysMap
.
size
());
assertWatchKeys
(
somePublicAppId
,
clusters
,
somePublicNamespace
,
watchKeysMap
.
get
(
somePublicNamespace
));
}
private
void
assertWatchKeys
(
String
appId
,
Set
<
String
>
clusters
,
String
namespaceName
,
Collection
<
String
>
watchedKeys
)
{
for
(
String
cluster
:
clusters
)
{
...
...
apollo-core/pom.xml
View file @
51e7bc07
...
...
@@ -4,7 +4,7 @@
<parent>
<groupId>
com.ctrip.framework.apollo
</groupId>
<artifactId>
apollo
</artifactId>
<version>
0.0.
7
</version>
<version>
0.0.
8-SNAPSHOT
</version>
<relativePath>
../pom.xml
</relativePath>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
apollo-core/src/main/java/com/ctrip/framework/apollo/core/ConfigConsts.java
View file @
51e7bc07
...
...
@@ -6,4 +6,5 @@ public interface ConfigConsts {
String
CLUSTER_NAMESPACE_SEPARATOR
=
"+"
;
String
APOLLO_CLUSTER_KEY
=
"apollo.cluster"
;
String
CONFIG_FILE_CONTENT_KEY
=
"content"
;
String
NO_APPID_PLACEHOLDER
=
"ApolloNoAppIdPlaceHolder"
;
}
apollo-demo/pom.xml
View file @
51e7bc07
...
...
@@ -4,7 +4,7 @@
<parent>
<artifactId>
apollo
</artifactId>
<groupId>
com.ctrip.framework.apollo
</groupId>
<version>
0.0.
7
</version>
<version>
0.0.
8-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
apollo-demo
</artifactId>
...
...
apollo-portal/pom.xml
View file @
51e7bc07
...
...
@@ -4,7 +4,7 @@
<parent>
<groupId>
com.ctrip.framework.apollo
</groupId>
<artifactId>
apollo
</artifactId>
<version>
0.0.
7
</version>
<version>
0.0.
8-SNAPSHOT
</version>
<relativePath>
../pom.xml
</relativePath>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
pom.xml
View file @
51e7bc07
...
...
@@ -4,7 +4,7 @@
<modelVersion>
4.0.0
</modelVersion>
<groupId>
com.ctrip.framework.apollo
</groupId>
<artifactId>
apollo
</artifactId>
<version>
0.0.
7
</version>
<version>
0.0.
8-SNAPSHOT
</version>
<name>
Apollo
</name>
<packaging>
pom
</packaging>
<description>
Ctrip Configuration Center
</description>
...
...
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