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
cf7feb30
Commit
cf7feb30
authored
Apr 21, 2016
by
Yiming Liu
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #131 from nobodyiam/default-namespace-appid-merge
Change default namespace to appid itself
parents
6141e812
70a0b5f1
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
46 additions
and
24 deletions
+46
-24
ConfigService.java
...-client/src/main/java/com/ctrip/apollo/ConfigService.java
+13
-3
HttpUtil.java
...nt/src/main/java/com/ctrip/apollo/util/http/HttpUtil.java
+4
-4
ConfigServiceTest.java
...ent/src/test/java/com/ctrip/apollo/ConfigServiceTest.java
+13
-1
ConfigIntegrationTest.java
...a/com/ctrip/apollo/integration/ConfigIntegrationTest.java
+4
-5
ConfigController.java
...rip/apollo/configservice/controller/ConfigController.java
+2
-4
NotificationController.java
...ollo/configservice/controller/NotificationController.java
+10
-3
ConfigConsts.java
...ore/src/main/java/com/ctrip/apollo/core/ConfigConsts.java
+0
-4
No files found.
apollo-client/src/main/java/com/ctrip/apollo/ConfigService.java
View file @
cf7feb30
...
@@ -4,6 +4,7 @@ import com.ctrip.apollo.core.ConfigConsts;
...
@@ -4,6 +4,7 @@ import com.ctrip.apollo.core.ConfigConsts;
import
com.ctrip.apollo.internals.ConfigManager
;
import
com.ctrip.apollo.internals.ConfigManager
;
import
com.ctrip.apollo.spi.ConfigFactory
;
import
com.ctrip.apollo.spi.ConfigFactory
;
import
com.ctrip.apollo.spi.ConfigRegistry
;
import
com.ctrip.apollo.spi.ConfigRegistry
;
import
com.ctrip.apollo.util.ConfigUtil
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.Cat
;
import
org.codehaus.plexus.PlexusContainer
;
import
org.codehaus.plexus.PlexusContainer
;
...
@@ -28,7 +29,7 @@ public class ConfigService {
...
@@ -28,7 +29,7 @@ public class ConfigService {
* @return config instance
* @return config instance
*/
*/
public
static
Config
getConfig
()
{
public
static
Config
getConfig
()
{
return
getConfig
(
ConfigConsts
.
NAMESPACE_APPLICATION
);
return
getConfig
(
getDefaultNamespace
()
);
}
}
/**
/**
...
@@ -59,8 +60,17 @@ public class ConfigService {
...
@@ -59,8 +60,17 @@ public class ConfigService {
}
}
}
}
private
static
String
getDefaultNamespace
()
{
try
{
return
s_instance
.
m_container
.
lookup
(
ConfigUtil
.
class
).
getAppId
();
}
catch
(
ComponentLookupException
ex
)
{
Cat
.
logError
(
ex
);
throw
new
IllegalStateException
(
"Unable to load ConfigUtil!"
,
ex
);
}
}
public
static
void
setConfig
(
Config
config
)
{
public
static
void
setConfig
(
Config
config
)
{
setConfig
(
ConfigConsts
.
NAMESPACE_APPLICATION
,
config
);
setConfig
(
getDefaultNamespace
()
,
config
);
}
}
/**
/**
...
@@ -78,7 +88,7 @@ public class ConfigService {
...
@@ -78,7 +88,7 @@ public class ConfigService {
}
}
public
static
void
setConfigFactory
(
ConfigFactory
factory
)
{
public
static
void
setConfigFactory
(
ConfigFactory
factory
)
{
setConfigFactory
(
ConfigConsts
.
NAMESPACE_APPLICATION
,
factory
);
setConfigFactory
(
getDefaultNamespace
()
,
factory
);
}
}
/**
/**
...
...
apollo-client/src/main/java/com/ctrip/apollo/util/http/HttpUtil.java
View file @
cf7feb30
...
@@ -81,6 +81,7 @@ public class HttpUtil {
...
@@ -81,6 +81,7 @@ public class HttpUtil {
private
<
T
>
HttpResponse
<
T
>
doGetWithSerializeFunction
(
HttpRequest
httpRequest
,
private
<
T
>
HttpResponse
<
T
>
doGetWithSerializeFunction
(
HttpRequest
httpRequest
,
Function
<
String
,
T
>
serializeFunction
)
{
Function
<
String
,
T
>
serializeFunction
)
{
InputStream
is
=
null
;
InputStream
is
=
null
;
int
statusCode
;
try
{
try
{
HttpURLConnection
conn
=
(
HttpURLConnection
)
new
URL
(
httpRequest
.
getUrl
()).
openConnection
();
HttpURLConnection
conn
=
(
HttpURLConnection
)
new
URL
(
httpRequest
.
getUrl
()).
openConnection
();
...
@@ -102,7 +103,7 @@ public class HttpUtil {
...
@@ -102,7 +103,7 @@ public class HttpUtil {
conn
.
connect
();
conn
.
connect
();
int
statusCode
=
conn
.
getResponseCode
();
statusCode
=
conn
.
getResponseCode
();
if
(
statusCode
==
200
)
{
if
(
statusCode
==
200
)
{
is
=
conn
.
getInputStream
();
is
=
conn
.
getInputStream
();
...
@@ -114,9 +115,6 @@ public class HttpUtil {
...
@@ -114,9 +115,6 @@ public class HttpUtil {
return
new
HttpResponse
<>(
statusCode
,
null
);
return
new
HttpResponse
<>(
statusCode
,
null
);
}
}
throw
new
RuntimeException
(
String
.
format
(
"Get operation failed for %s, status code - %d"
,
httpRequest
.
getUrl
(),
statusCode
));
}
catch
(
Throwable
ex
)
{
}
catch
(
Throwable
ex
)
{
throw
new
RuntimeException
(
"Could not complete get operation"
,
ex
);
throw
new
RuntimeException
(
"Could not complete get operation"
,
ex
);
}
finally
{
}
finally
{
...
@@ -128,6 +126,8 @@ public class HttpUtil {
...
@@ -128,6 +126,8 @@ public class HttpUtil {
}
}
}
}
}
}
throw
new
RuntimeException
(
String
.
format
(
"Get operation failed for %s, status code - %d"
,
httpRequest
.
getUrl
(),
statusCode
));
}
}
}
}
apollo-client/src/test/java/com/ctrip/apollo/ConfigServiceTest.java
View file @
cf7feb30
...
@@ -2,6 +2,7 @@ package com.ctrip.apollo;
...
@@ -2,6 +2,7 @@ package com.ctrip.apollo;
import
com.ctrip.apollo.core.ConfigConsts
;
import
com.ctrip.apollo.core.ConfigConsts
;
import
com.ctrip.apollo.spi.ConfigFactory
;
import
com.ctrip.apollo.spi.ConfigFactory
;
import
com.ctrip.apollo.util.ConfigUtil
;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.Test
;
...
@@ -13,13 +14,16 @@ import static org.junit.Assert.assertEquals;
...
@@ -13,13 +14,16 @@ import static org.junit.Assert.assertEquals;
* @author Jason Song(song_s@ctrip.com)
* @author Jason Song(song_s@ctrip.com)
*/
*/
public
class
ConfigServiceTest
extends
ComponentTestCase
{
public
class
ConfigServiceTest
extends
ComponentTestCase
{
private
static
String
someAppId
;
@Override
@Override
@Before
@Before
public
void
setUp
()
throws
Exception
{
public
void
setUp
()
throws
Exception
{
super
.
setUp
();
super
.
setUp
();
someAppId
=
"someAppId"
;
//as ConfigService is singleton, so we must manually clear its container
//as ConfigService is singleton, so we must manually clear its container
ConfigService
.
setContainer
(
getContainer
());
ConfigService
.
setContainer
(
getContainer
());
defineComponent
(
ConfigUtil
.
class
,
MockConfigUtil
.
class
);
}
}
@Test
@Test
...
@@ -41,7 +45,7 @@ public class ConfigServiceTest extends ComponentTestCase {
...
@@ -41,7 +45,7 @@ public class ConfigServiceTest extends ComponentTestCase {
Config
config
=
ConfigService
.
getConfig
();
Config
config
=
ConfigService
.
getConfig
();
assertEquals
(
ConfigConsts
.
NAMESPACE_APPLICATION
+
":"
+
someKey
,
assertEquals
(
someAppId
+
":"
+
someKey
,
config
.
getProperty
(
someKey
,
null
));
config
.
getProperty
(
someKey
,
null
));
}
}
...
@@ -85,4 +89,12 @@ public class ConfigServiceTest extends ComponentTestCase {
...
@@ -85,4 +89,12 @@ public class ConfigServiceTest extends ComponentTestCase {
return
new
MockConfig
(
namespace
);
return
new
MockConfig
(
namespace
);
}
}
}
}
public
static
class
MockConfigUtil
extends
ConfigUtil
{
@Override
public
String
getAppId
()
{
return
someAppId
;
}
}
}
}
apollo-client/src/test/java/com/ctrip/apollo/integration/ConfigIntegrationTest.java
View file @
cf7feb30
...
@@ -7,7 +7,6 @@ import com.google.common.collect.Maps;
...
@@ -7,7 +7,6 @@ import com.google.common.collect.Maps;
import
com.ctrip.apollo.Config
;
import
com.ctrip.apollo.Config
;
import
com.ctrip.apollo.ConfigChangeListener
;
import
com.ctrip.apollo.ConfigChangeListener
;
import
com.ctrip.apollo.ConfigService
;
import
com.ctrip.apollo.ConfigService
;
import
com.ctrip.apollo.core.ConfigConsts
;
import
com.ctrip.apollo.core.dto.ApolloConfig
;
import
com.ctrip.apollo.core.dto.ApolloConfig
;
import
com.ctrip.apollo.core.dto.ApolloConfigNotification
;
import
com.ctrip.apollo.core.dto.ApolloConfigNotification
;
import
com.ctrip.apollo.core.utils.ClassLoaderUtil
;
import
com.ctrip.apollo.core.utils.ClassLoaderUtil
;
...
@@ -44,13 +43,13 @@ import static org.junit.Assert.assertThat;
...
@@ -44,13 +43,13 @@ import static org.junit.Assert.assertThat;
public
class
ConfigIntegrationTest
extends
BaseIntegrationTest
{
public
class
ConfigIntegrationTest
extends
BaseIntegrationTest
{
private
String
someReleaseId
;
private
String
someReleaseId
;
private
File
configDir
;
private
File
configDir
;
private
String
some
Namespace
;
private
String
default
Namespace
;
@Before
@Before
public
void
setUp
()
throws
Exception
{
public
void
setUp
()
throws
Exception
{
super
.
setUp
();
super
.
setUp
();
someNamespace
=
ConfigConsts
.
NAMESPACE_APPLICATION
;
defaultNamespace
=
someAppId
;
someReleaseId
=
"1"
;
someReleaseId
=
"1"
;
configDir
=
new
File
(
ClassLoaderUtil
.
getClassPath
()
+
"config-cache"
);
configDir
=
new
File
(
ClassLoaderUtil
.
getClassPath
()
+
"config-cache"
);
configDir
.
mkdirs
();
configDir
.
mkdirs
();
...
@@ -314,7 +313,7 @@ public class ConfigIntegrationTest extends BaseIntegrationTest {
...
@@ -314,7 +313,7 @@ public class ConfigIntegrationTest extends BaseIntegrationTest {
private
ApolloConfig
assembleApolloConfig
(
Map
<
String
,
String
>
configurations
)
{
private
ApolloConfig
assembleApolloConfig
(
Map
<
String
,
String
>
configurations
)
{
ApolloConfig
apolloConfig
=
ApolloConfig
apolloConfig
=
new
ApolloConfig
(
someAppId
,
someClusterName
,
some
Namespace
,
someReleaseId
);
new
ApolloConfig
(
someAppId
,
someClusterName
,
default
Namespace
,
someReleaseId
);
apolloConfig
.
setConfigurations
(
configurations
);
apolloConfig
.
setConfigurations
(
configurations
);
...
@@ -336,6 +335,6 @@ public class ConfigIntegrationTest extends BaseIntegrationTest {
...
@@ -336,6 +335,6 @@ public class ConfigIntegrationTest extends BaseIntegrationTest {
}
}
private
String
assembleLocalCacheFileName
()
{
private
String
assembleLocalCacheFileName
()
{
return
String
.
format
(
"%s-%s-%s.properties"
,
someAppId
,
someClusterName
,
some
Namespace
);
return
String
.
format
(
"%s-%s-%s.properties"
,
someAppId
,
someClusterName
,
default
Namespace
);
}
}
}
}
apollo-configservice/src/main/java/com/ctrip/apollo/configservice/controller/ConfigController.java
View file @
cf7feb30
...
@@ -2,7 +2,6 @@ package com.ctrip.apollo.configservice.controller;
...
@@ -2,7 +2,6 @@ package com.ctrip.apollo.configservice.controller;
import
com.ctrip.apollo.biz.entity.Release
;
import
com.ctrip.apollo.biz.entity.Release
;
import
com.ctrip.apollo.biz.service.ConfigService
;
import
com.ctrip.apollo.biz.service.ConfigService
;
import
com.ctrip.apollo.core.ConfigConsts
;
import
com.ctrip.apollo.core.dto.ApolloConfig
;
import
com.ctrip.apollo.core.dto.ApolloConfig
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -29,9 +28,8 @@ public class ConfigController {
...
@@ -29,9 +28,8 @@ public class ConfigController {
public
ApolloConfig
queryConfig
(
@PathVariable
String
appId
,
@PathVariable
String
clusterName
,
public
ApolloConfig
queryConfig
(
@PathVariable
String
appId
,
@PathVariable
String
clusterName
,
@RequestParam
(
value
=
"releaseId"
,
defaultValue
=
"-1"
)
String
clientSideReleaseId
,
@RequestParam
(
value
=
"releaseId"
,
defaultValue
=
"-1"
)
String
clientSideReleaseId
,
HttpServletResponse
response
)
throws
IOException
{
HttpServletResponse
response
)
throws
IOException
{
return
this
//default namespace is appId
.
queryConfig
(
appId
,
clusterName
,
ConfigConsts
.
NAMESPACE_APPLICATION
,
clientSideReleaseId
,
return
this
.
queryConfig
(
appId
,
clusterName
,
appId
,
clientSideReleaseId
,
response
);
response
);
}
}
@RequestMapping
(
value
=
"/{appId}/{clusterName}/{namespace}"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"/{appId}/{clusterName}/{namespace}"
,
method
=
RequestMethod
.
GET
)
...
...
apollo-configservice/src/main/java/com/ctrip/apollo/configservice/controller/NotificationController.java
View file @
cf7feb30
...
@@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.RequestParam;
...
@@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.context.request.async.DeferredResult
;
import
org.springframework.web.context.request.async.DeferredResult
;
import
java.util.Objects
;
import
java.util.Random
;
import
java.util.Random
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.ScheduledExecutorService
;
...
@@ -44,10 +45,15 @@ public class NotificationController {
...
@@ -44,10 +45,15 @@ public class NotificationController {
public
DeferredResult
<
ApolloConfigNotification
>
pollNotification
(
public
DeferredResult
<
ApolloConfigNotification
>
pollNotification
(
@RequestParam
(
value
=
"appId"
)
String
appId
,
@RequestParam
(
value
=
"appId"
)
String
appId
,
@RequestParam
(
value
=
"cluster"
)
String
cluster
,
@RequestParam
(
value
=
"cluster"
)
String
cluster
,
@RequestParam
(
value
=
"namespace"
,
defaultValue
=
ConfigConsts
.
NAMESPACE_APPLICATION
)
String
namespace
,
@RequestParam
(
value
=
"namespace"
,
required
=
false
)
String
namespace
,
@RequestParam
(
value
=
"datacenter"
,
required
=
false
)
String
datacenter
,
@RequestParam
(
value
=
"datacenter"
,
required
=
false
)
String
datacenter
,
@RequestParam
(
value
=
"releaseId"
,
defaultValue
=
"-1"
)
String
clientSideReleaseId
,
@RequestParam
(
value
=
"releaseId"
,
defaultValue
=
"-1"
)
String
clientSideReleaseId
,
HttpServletResponse
response
)
{
HttpServletResponse
response
)
{
//check default namespace
if
(
Objects
.
isNull
(
namespace
))
{
namespace
=
appId
;
}
DeferredResult
<
ApolloConfigNotification
>
deferredResult
=
DeferredResult
<
ApolloConfigNotification
>
deferredResult
=
new
DeferredResult
<>(
TIMEOUT
);
new
DeferredResult
<>(
TIMEOUT
);
String
key
=
assembleKey
(
appId
,
cluster
,
namespace
);
String
key
=
assembleKey
(
appId
,
cluster
,
namespace
);
...
@@ -55,13 +61,14 @@ public class NotificationController {
...
@@ -55,13 +61,14 @@ public class NotificationController {
//to record all the keys related to deferredResult
//to record all the keys related to deferredResult
this
.
deferredResultReversed
.
put
(
deferredResult
,
key
);
this
.
deferredResultReversed
.
put
(
deferredResult
,
key
);
final
String
finalNamespace
=
namespace
;
deferredResult
.
onCompletion
(()
->
{
deferredResult
.
onCompletion
(()
->
{
logger
.
info
(
"deferred result for {} {} {} completed"
,
appId
,
cluster
,
n
amespace
);
logger
.
info
(
"deferred result for {} {} {} completed"
,
appId
,
cluster
,
finalN
amespace
);
deferredResults
.
remove
(
key
,
deferredResult
);
deferredResults
.
remove
(
key
,
deferredResult
);
});
});
deferredResult
.
onTimeout
(()
->
{
deferredResult
.
onTimeout
(()
->
{
logger
.
info
(
"deferred result for {} {} {} timeout"
,
appId
,
cluster
,
n
amespace
);
logger
.
info
(
"deferred result for {} {} {} timeout"
,
appId
,
cluster
,
finalN
amespace
);
response
.
setStatus
(
HttpServletResponse
.
SC_NOT_MODIFIED
);
response
.
setStatus
(
HttpServletResponse
.
SC_NOT_MODIFIED
);
});
});
...
...
apollo-core/src/main/java/com/ctrip/apollo/core/ConfigConsts.java
View file @
cf7feb30
package
com
.
ctrip
.
apollo
.
core
;
package
com
.
ctrip
.
apollo
.
core
;
public
interface
ConfigConsts
{
public
interface
ConfigConsts
{
String
CLUSTER_NAME_DEFAULT
=
"default"
;
String
CLUSTER_NAME_DEFAULT
=
"default"
;
String
NAMESPACE_APPLICATION
=
"application"
;
}
}
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