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
12f05863
Commit
12f05863
authored
Apr 25, 2016
by
Yiming Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix service caches bugs
parent
3d0186e1
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
43 additions
and
15 deletions
+43
-15
pom.xml
apollo-buildtools/pom.xml
+1
-0
ConfigService.java
...-client/src/main/java/com/ctrip/apollo/ConfigService.java
+0
-1
DefaultConfigManagerTest.java
.../com/ctrip/apollo/internals/DefaultConfigManagerTest.java
+0
-1
ConfigServiceTestConfiguration.java
...java/com/ctrip/apollo/ConfigServiceTestConfiguration.java
+0
-2
NotificationControllerIntegrationTest.java
...ce/integration/NotificationControllerIntegrationTest.java
+0
-1
ApolloConfig.java
...src/main/java/com/ctrip/apollo/core/dto/ApolloConfig.java
+0
-2
AppService.java
...main/java/com/ctrip/apollo/portal/service/AppService.java
+0
-1
ServiceLocator.java
.../java/com/ctrip/apollo/portal/service/ServiceLocator.java
+42
-7
No files found.
apollo-buildtools/pom.xml
View file @
12f05863
...
...
@@ -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
View file @
12f05863
...
...
@@ -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
View file @
12f05863
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/test/java/com/ctrip/apollo/ConfigServiceTestConfiguration.java
View file @
12f05863
...
...
@@ -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
View file @
12f05863
...
...
@@ -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/src/main/java/com/ctrip/apollo/core/dto/ApolloConfig.java
View file @
12f05863
...
...
@@ -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-portal/src/main/java/com/ctrip/apollo/portal/service/AppService.java
View file @
12f05863
...
...
@@ -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
View file @
12f05863
...
...
@@ -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
);
}
}
}
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