Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wrr-cat
apollo
提交
17fdc911
apollo
项目概览
wrr-cat
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
提交
17fdc911
编写于
4月 26, 2016
作者:
J
Jason Song
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #142 from yiming187/service_refactor
Service refactor
上级
3d0186e1
e355e6ac
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
74 addition
and
17 deletion
+74
-17
.gitignore
.gitignore
+0
-1
apollo-biz/src/main/java/com/ctrip/apollo/biz/datasource/TitanEntityManager.java
...a/com/ctrip/apollo/biz/datasource/TitanEntityManager.java
+5
-1
apollo-buildtools/pom.xml
apollo-buildtools/pom.xml
+1
-0
apollo-client/src/main/java/com/ctrip/apollo/ConfigService.java
...-client/src/main/java/com/ctrip/apollo/ConfigService.java
+0
-1
apollo-client/src/test/java/com/ctrip/apollo/internals/DefaultConfigManagerTest.java
.../com/ctrip/apollo/internals/DefaultConfigManagerTest.java
+0
-1
apollo-configservice/src/main/java/com/ctrip/apollo/metaservice/service/DiscoveryService.java
...om/ctrip/apollo/metaservice/service/DiscoveryService.java
+10
-0
apollo-configservice/src/test/java/com/ctrip/apollo/ConfigServiceTestConfiguration.java
...java/com/ctrip/apollo/ConfigServiceTestConfiguration.java
+0
-2
apollo-configservice/src/test/java/com/ctrip/apollo/configservice/integration/NotificationControllerIntegrationTest.java
...ce/integration/NotificationControllerIntegrationTest.java
+0
-1
apollo-core/pom.xml
apollo-core/pom.xml
+8
-0
apollo-core/src/main/java/com/ctrip/apollo/core/dto/ApolloConfig.java
...src/main/java/com/ctrip/apollo/core/dto/ApolloConfig.java
+0
-2
apollo-core/src/main/resources/apollo-env.properties
apollo-core/src/main/resources/apollo-env.properties
+8
-0
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/AppService.java
...main/java/com/ctrip/apollo/portal/service/AppService.java
+0
-1
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ServiceLocator.java
.../java/com/ctrip/apollo/portal/service/ServiceLocator.java
+42
-7
未找到文件。
.gitignore
浏览文件 @
17fdc911
...
...
@@ -28,4 +28,3 @@ dev
fat
uat
prd
apollo-env.properties
apollo-biz/src/main/java/com/ctrip/apollo/biz/datasource/TitanEntityManager.java
浏览文件 @
17fdc911
...
...
@@ -9,6 +9,8 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Conditional
;
import
org.springframework.stereotype.Component
;
import
com.dianping.cat.Cat
;
@Component
@Conditional
(
TitanCondition
.
class
)
public
class
TitanEntityManager
{
...
...
@@ -22,8 +24,10 @@ public class TitanEntityManager {
Class
clazz
=
Class
.
forName
(
"com.ctrip.datasource.configure.DalDataSourceFactory"
);
Object
obj
=
clazz
.
newInstance
();
Method
method
=
clazz
.
getMethod
(
"createDataSource"
,
new
Class
[]
{
String
.
class
,
String
.
class
});
return
((
DataSource
)
method
.
invoke
(
obj
,
DataSource
ds
=
((
DataSource
)
method
.
invoke
(
obj
,
new
Object
[]
{
settings
.
getTitanDbname
(),
settings
.
getTitanUrl
()}));
Cat
.
logEvent
(
"Apollo.Datasource.Titan"
,
settings
.
getTitanDbname
());
return
ds
;
}
}
apollo-buildtools/pom.xml
浏览文件 @
17fdc911
...
...
@@ -11,6 +11,7 @@
<artifactId>
apollo-buildtools
</artifactId>
<name>
Apollo BuildTools
</name>
<properties>
<java.version>
1.7
</java.version>
<github.path>
${project.artifactId}
</github.path>
</properties>
<dependencies>
...
...
apollo-client/src/main/java/com/ctrip/apollo/ConfigService.java
浏览文件 @
17fdc911
...
...
@@ -4,7 +4,6 @@ import com.ctrip.apollo.core.ConfigConsts;
import
com.ctrip.apollo.internals.ConfigManager
;
import
com.ctrip.apollo.spi.ConfigFactory
;
import
com.ctrip.apollo.spi.ConfigRegistry
;
import
com.ctrip.apollo.util.ConfigUtil
;
import
com.dianping.cat.Cat
;
import
org.codehaus.plexus.PlexusContainer
;
...
...
apollo-client/src/test/java/com/ctrip/apollo/internals/DefaultConfigManagerTest.java
浏览文件 @
17fdc911
package
com.ctrip.apollo.internals
;
import
com.ctrip.apollo.Config
;
import
com.ctrip.apollo.ConfigChangeListener
;
import
com.ctrip.apollo.spi.ConfigFactory
;
import
com.ctrip.apollo.spi.ConfigFactoryManager
;
...
...
apollo-configservice/src/main/java/com/ctrip/apollo/metaservice/service/DiscoveryService.java
浏览文件 @
17fdc911
package
com.ctrip.apollo.metaservice.service
;
import
com.ctrip.apollo.core.ServiceNameConsts
;
import
com.dianping.cat.Cat
;
import
com.netflix.appinfo.InstanceInfo
;
import
com.netflix.discovery.EurekaClient
;
import
com.netflix.discovery.shared.Application
;
...
...
@@ -19,16 +20,25 @@ public class DiscoveryService {
public
List
<
InstanceInfo
>
getConfigServiceInstances
()
{
Application
application
=
eurekaClient
.
getApplication
(
ServiceNameConsts
.
APOLLO_CONFIGSERVICE
);
if
(
application
==
null
)
{
Cat
.
logEvent
(
"Apollo.EurekaDiscovery.NotFound"
,
ServiceNameConsts
.
APOLLO_CONFIGSERVICE
);
}
return
application
!=
null
?
application
.
getInstances
()
:
new
ArrayList
<>();
}
public
List
<
InstanceInfo
>
getMetaServiceInstances
()
{
Application
application
=
eurekaClient
.
getApplication
(
ServiceNameConsts
.
APOLLO_METASERVICE
);
if
(
application
==
null
)
{
Cat
.
logEvent
(
"Apollo.EurekaDiscovery.NotFound"
,
ServiceNameConsts
.
APOLLO_METASERVICE
);
}
return
application
!=
null
?
application
.
getInstances
()
:
new
ArrayList
<>();
}
public
List
<
InstanceInfo
>
getAdminServiceInstances
()
{
Application
application
=
eurekaClient
.
getApplication
(
ServiceNameConsts
.
APOLLO_ADMINSERVICE
);
if
(
application
==
null
)
{
Cat
.
logEvent
(
"Apollo.EurekaDiscovery.NotFound"
,
ServiceNameConsts
.
APOLLO_ADMINSERVICE
);
}
return
application
!=
null
?
application
.
getInstances
()
:
new
ArrayList
<>();
}
}
apollo-configservice/src/test/java/com/ctrip/apollo/ConfigServiceTestConfiguration.java
浏览文件 @
17fdc911
...
...
@@ -6,8 +6,6 @@ import org.springframework.context.annotation.ComponentScan.Filter;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.FilterType
;
import
com.ctrip.apollo.common.controller.WebSecurityConfig
;
@Configuration
@ComponentScan
(
excludeFilters
=
{
@Filter
(
type
=
FilterType
.
ASSIGNABLE_TYPE
,
value
=
{
SampleConfigServiceApplication
.
class
,
ConfigServiceApplication
.
class
})})
...
...
apollo-configservice/src/test/java/com/ctrip/apollo/configservice/integration/NotificationControllerIntegrationTest.java
浏览文件 @
17fdc911
...
...
@@ -10,7 +10,6 @@ import org.junit.Test;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.client.HttpComponentsClientHttpRequestFactory
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
...
...
apollo-core/pom.xml
浏览文件 @
17fdc911
...
...
@@ -41,4 +41,12 @@
</dependency>
<!-- end of log -->
</dependencies>
<build>
<resources>
<resource>
<directory>
src/main/resources
</directory>
<filtering>
true
</filtering>
</resource>
</resources>
</build>
</project>
apollo-core/src/main/java/com/ctrip/apollo/core/dto/ApolloConfig.java
浏览文件 @
17fdc911
...
...
@@ -2,8 +2,6 @@ package com.ctrip.apollo.core.dto;
import
com.google.common.base.MoreObjects
;
import
com.ctrip.apollo.Apollo
;
import
java.util.Map
;
/**
...
...
apollo-core/src/main/resources/apollo-env.properties
0 → 100644
浏览文件 @
17fdc911
local.meta
=
http://localhost:8080
dev.meta
=
${dev};
fat.meta
=
${fat};
fws.meta
=
${fws};
uat.meta
=
${uat};
lpt.meta
=
${lpt};
tools.meta
=
${tools};
pro.meta
=
${pro};
\ No newline at end of file
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/AppService.java
浏览文件 @
17fdc911
...
...
@@ -15,7 +15,6 @@ import com.ctrip.apollo.core.dto.AppDTO;
import
com.ctrip.apollo.core.enums.Env
;
import
com.ctrip.apollo.core.exception.BadRequestException
;
import
com.ctrip.apollo.core.exception.ServiceException
;
import
com.ctrip.apollo.core.utils.StringUtils
;
import
com.ctrip.apollo.portal.PortalSettings
;
import
com.ctrip.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.apollo.portal.entity.ClusterNavTree
;
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ServiceLocator.java
浏览文件 @
17fdc911
...
...
@@ -3,15 +3,22 @@ package com.ctrip.apollo.portal.service;
import
java.net.URI
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
javax.annotation.PostConstruct
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.http.client.HttpComponentsClientHttpRequestFactory
;
import
org.springframework.http.client.SimpleClientHttpRequestFactory
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.client.RestTemplate
;
import
com.ctrip.apollo.core.enums.Env
;
import
com.ctrip.apollo.core.MetaDomainConsts
;
import
com.ctrip.apollo.core.dto.ServiceDTO
;
import
com.ctrip.apollo.core.enums.Env
;
import
com.ctrip.apollo.core.exception.ServiceException
;
/**
...
...
@@ -22,16 +29,22 @@ public class ServiceLocator {
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ServiceLocator
.
class
);
private
static
final
int
DEFAULT_TIMEOUT_MS
=
1000
;
private
RestTemplate
restTemplate
=
new
RestTemplate
();
private
List
<
ServiceDTO
>
serviceCaches
=
new
ArrayList
<>();
private
Map
<
Env
,
List
<
ServiceDTO
>>
serviceCaches
=
new
ConcurrentHashMap
<
Env
,
List
<
ServiceDTO
>>();
private
final
AtomicInteger
adminCallCounts
=
new
AtomicInteger
(
0
);
private
final
AtomicInteger
configCallCounts
=
new
AtomicInteger
(
0
);
public
ServiceDTO
getAdminService
(
Env
env
)
throws
ServiceException
{
List
<
ServiceDTO
>
services
=
getServices
(
env
,
"admin"
);
if
(
services
.
size
()
==
0
)
{
throw
new
ServiceException
(
"No available admin service"
);
}
return
services
.
get
(
0
);
return
services
.
get
(
adminCallCounts
.
getAndIncrement
()
%
services
.
size
()
);
}
public
ServiceDTO
getConfigService
(
Env
env
)
throws
ServiceException
{
...
...
@@ -39,23 +52,45 @@ public class ServiceLocator {
if
(
services
.
size
()
==
0
)
{
throw
new
ServiceException
(
"No available config service"
);
}
return
services
.
get
(
0
);
return
services
.
get
(
configCallCounts
.
getAndIncrement
()
%
services
.
size
()
);
}
private
List
<
ServiceDTO
>
getServices
(
Env
env
,
String
serviceUrl
)
{
String
domainName
=
MetaDomainConsts
.
getDomain
(
env
);
String
url
=
domainName
+
"/services/"
+
serviceUrl
;
List
<
ServiceDTO
>
serviceDtos
=
null
;
try
{
ServiceDTO
[]
services
=
restTemplate
.
getForObject
(
new
URI
(
url
),
ServiceDTO
[].
class
);
if
(
services
!=
null
&&
services
.
length
>
0
)
{
serviceCaches
.
clear
();
if
(!
serviceCaches
.
containsKey
(
env
))
{
serviceDtos
=
new
ArrayList
<
ServiceDTO
>();
serviceCaches
.
put
(
env
,
serviceDtos
);
}
else
{
serviceDtos
=
serviceCaches
.
get
(
env
);
serviceDtos
.
clear
();
}
for
(
ServiceDTO
service
:
services
)
{
service
Cache
s
.
add
(
service
);
service
Dto
s
.
add
(
service
);
}
}
}
catch
(
Exception
ex
)
{
logger
.
warn
(
ex
.
getMessage
());
}
return
serviceCaches
;
return
serviceDtos
;
}
@PostConstruct
private
void
postConstruct
()
{
if
(
restTemplate
.
getRequestFactory
()
instanceof
SimpleClientHttpRequestFactory
)
{
SimpleClientHttpRequestFactory
rf
=
(
SimpleClientHttpRequestFactory
)
restTemplate
.
getRequestFactory
();
rf
.
setReadTimeout
(
DEFAULT_TIMEOUT_MS
);
rf
.
setConnectTimeout
(
DEFAULT_TIMEOUT_MS
);
}
else
if
(
restTemplate
.
getRequestFactory
()
instanceof
HttpComponentsClientHttpRequestFactory
)
{
HttpComponentsClientHttpRequestFactory
rf
=
(
HttpComponentsClientHttpRequestFactory
)
restTemplate
.
getRequestFactory
();
rf
.
setReadTimeout
(
DEFAULT_TIMEOUT_MS
);
rf
.
setConnectTimeout
(
DEFAULT_TIMEOUT_MS
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录