Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wrr-cat
apollo
提交
cf7feb30
apollo
项目概览
wrr-cat
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
cf7feb30
编写于
4月 21, 2016
作者:
Y
Yiming Liu
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #131 from nobodyiam/default-namespace-appid-merge
Change default namespace to appid itself
上级
6141e812
70a0b5f1
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
46 addition
and
24 deletion
+46
-24
apollo-client/src/main/java/com/ctrip/apollo/ConfigService.java
...-client/src/main/java/com/ctrip/apollo/ConfigService.java
+13
-3
apollo-client/src/main/java/com/ctrip/apollo/util/http/HttpUtil.java
...nt/src/main/java/com/ctrip/apollo/util/http/HttpUtil.java
+4
-4
apollo-client/src/test/java/com/ctrip/apollo/ConfigServiceTest.java
...ent/src/test/java/com/ctrip/apollo/ConfigServiceTest.java
+13
-1
apollo-client/src/test/java/com/ctrip/apollo/integration/ConfigIntegrationTest.java
...a/com/ctrip/apollo/integration/ConfigIntegrationTest.java
+4
-5
apollo-configservice/src/main/java/com/ctrip/apollo/configservice/controller/ConfigController.java
...rip/apollo/configservice/controller/ConfigController.java
+2
-4
apollo-configservice/src/main/java/com/ctrip/apollo/configservice/controller/NotificationController.java
...ollo/configservice/controller/NotificationController.java
+10
-3
apollo-core/src/main/java/com/ctrip/apollo/core/ConfigConsts.java
...ore/src/main/java/com/ctrip/apollo/core/ConfigConsts.java
+0
-4
未找到文件。
apollo-client/src/main/java/com/ctrip/apollo/ConfigService.java
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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"
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录