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
dc493792
Commit
dc493792
authored
May 12, 2016
by
Yiming Liu
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #185 from nobodyiam/performance-tuning-merge
Performance tunning and misc improvement.
parents
94d583d9
f6e69aca
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
118 additions
and
14 deletions
+118
-14
AdminServiceApplication.java
...c/main/java/com/ctrip/apollo/AdminServiceApplication.java
+2
-0
AdminServiceTestConfiguration.java
.../java/com/ctrip/apollo/AdminServiceTestConfiguration.java
+4
-3
AbstractControllerTest.java
...pollo/adminservice/controller/AbstractControllerTest.java
+2
-2
ReleaseControllerTest.java
...apollo/adminservice/controller/ReleaseControllerTest.java
+5
-1
RepositoryAspect.java
.../main/java/com/ctrip/apollo/biz/aop/RepositoryAspect.java
+41
-0
RestTemplateFactory.java
...ava/com/ctrip/apollo/common/auth/RestTemplateFactory.java
+6
-1
HttpMessageConverterConfiguration.java
.../common/controller/HttpMessageConverterConfiguration.java
+37
-0
WebMvcConfig.java
...java/com/ctrip/apollo/common/controller/WebMvcConfig.java
+4
-3
ConfigServiceApplication.java
.../main/java/com/ctrip/apollo/ConfigServiceApplication.java
+2
-0
AbstractBaseIntegrationTest.java
...onfigservice/integration/AbstractBaseIntegrationTest.java
+1
-0
AdminServiceAPI.java
...ain/java/com/ctrip/apollo/portal/api/AdminServiceAPI.java
+5
-1
ServiceLocator.java
.../java/com/ctrip/apollo/portal/service/ServiceLocator.java
+7
-1
AbstractPortalTest.java
...test/java/com/ctrip/apollo/portal/AbstractPortalTest.java
+2
-2
No files found.
apollo-adminservice/src/main/java/com/ctrip/apollo/AdminServiceApplication.java
View file @
dc493792
...
...
@@ -6,10 +6,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.cloud.netflix.eureka.EnableEurekaClient
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.EnableAspectJAutoProxy
;
@SpringBootApplication
@EnableEurekaClient
@EnableAspectJAutoProxy
public
class
AdminServiceApplication
{
public
static
void
main
(
String
[]
args
)
{
ConfigurableApplicationContext
context
=
new
SpringApplicationBuilder
(
AdminServiceApplication
.
class
).
run
(
args
);
...
...
apollo-adminservice/src/test/java/com/ctrip/apollo/AdminServiceTestConfiguration.java
View file @
dc493792
package
com
.
ctrip
.
apollo
;
import
com.ctrip.apollo.common.controller.HttpMessageConverterConfiguration
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.ComponentScan.Filter
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.FilterType
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
@Configuration
@ComponentScan
(
excludeFilters
=
{
@Filter
(
type
=
FilterType
.
ASSIGNABLE_TYPE
,
value
=
{
SampleAdminServiceApplication
.
class
,
AdminServiceApplication
.
class
})})
SampleAdminServiceApplication
.
class
,
AdminServiceApplication
.
class
,
HttpMessageConverterConfiguration
.
class
})})
@EnableAutoConfiguration
public
class
AdminServiceTestConfiguration
{
...
...
apollo-adminservice/src/test/java/com/ctrip/apollo/adminservice/controller/AbstractControllerTest.java
View file @
dc493792
package
com
.
ctrip
.
apollo
.
adminservice
.
controller
;
import
javax.annotation.PostConstruct
;
import
com.ctrip.apollo.AdminServiceTestConfiguration
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Value
;
...
...
@@ -11,7 +11,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import
org.springframework.web.client.DefaultResponseErrorHandler
;
import
org.springframework.web.client.RestTemplate
;
import
com.ctrip.apollo.AdminServiceTestConfiguration
;
import
javax.annotation.PostConstruct
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
AdminServiceTestConfiguration
.
class
)
...
...
apollo-adminservice/src/test/java/com/ctrip/apollo/adminservice/controller/ReleaseControllerTest.java
View file @
dc493792
...
...
@@ -20,7 +20,9 @@ import org.junit.Assert;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.test.context.jdbc.Sql
;
...
...
@@ -69,11 +71,13 @@ public class ReleaseControllerTest extends AbstractControllerTest {
ItemDTO
[].
class
);
Assert
.
assertEquals
(
3
,
items
.
length
);
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
);
MultiValueMap
<
String
,
String
>
parameters
=
new
LinkedMultiValueMap
<
String
,
String
>();
parameters
.
add
(
"name"
,
"someReleaseName"
);
parameters
.
add
(
"comment"
,
"someComment"
);
HttpEntity
<
MultiValueMap
<
String
,
String
>>
entity
=
new
HttpEntity
<
MultiValueMap
<
String
,
String
>>(
parameters
,
null
);
new
HttpEntity
<
MultiValueMap
<
String
,
String
>>(
parameters
,
headers
);
ResponseEntity
<
ReleaseDTO
>
response
=
restTemplate
.
postForEntity
(
"http://localhost:"
+
port
+
"/apps/"
+
app
.
getAppId
()
+
"/clusters/"
+
cluster
.
getName
()
+
"/namespaces/"
+
namespace
.
getNamespaceName
()
+
"/releases"
,
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/aop/RepositoryAspect.java
0 → 100644
View file @
dc493792
package
com
.
ctrip
.
apollo
.
biz
.
aop
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.message.Message
;
import
com.dianping.cat.message.Transaction
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.springframework.stereotype.Component
;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@Aspect
@Component
public
class
RepositoryAspect
{
@Pointcut
(
"execution(public * org.springframework.data.repository.Repository+.*(..))"
)
public
void
anyRepositoryMethod
()
{
}
@Around
(
"anyRepositoryMethod()"
)
public
Object
invokeWithCatTransaction
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
String
name
=
joinPoint
.
getSignature
().
getDeclaringType
().
getSimpleName
()
+
"."
+
joinPoint
.
getSignature
()
.
getName
();
Transaction
catTransaction
=
Cat
.
newTransaction
(
"SQL"
,
name
);
try
{
Object
result
=
joinPoint
.
proceed
();
catTransaction
.
setStatus
(
Message
.
SUCCESS
);
return
result
;
}
catch
(
Throwable
ex
)
{
catTransaction
.
setStatus
(
ex
);
throw
ex
;
}
finally
{
catTransaction
.
complete
();
}
}
}
apollo-common/src/main/java/com/ctrip/apollo/common/auth/RestTemplateFactory.java
View file @
dc493792
...
...
@@ -13,6 +13,8 @@ import org.apache.http.impl.client.HttpClientBuilder;
import
org.apache.http.message.BasicHeader
;
import
org.springframework.beans.factory.FactoryBean
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.web.HttpMessageConverters
;
import
org.springframework.http.client.HttpComponentsClientHttpRequestFactory
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.client.RestTemplate
;
...
...
@@ -21,6 +23,8 @@ import com.google.common.io.BaseEncoding;
@Component
public
class
RestTemplateFactory
implements
FactoryBean
<
RestTemplate
>,
InitializingBean
{
@Autowired
private
HttpMessageConverters
httpMessageConverters
;
private
RestTemplate
restTemplate
;
...
...
@@ -49,7 +53,8 @@ public class RestTemplateFactory implements FactoryBean<RestTemplate>, Initializ
HttpClientBuilder
.
create
().
setDefaultCredentialsProvider
(
credentialsProvider
)
.
setDefaultHeaders
(
defaultHeaders
).
build
();
restTemplate
=
new
RestTemplate
(
new
HttpComponentsClientHttpRequestFactory
(
httpClient
));
restTemplate
=
new
RestTemplate
(
httpMessageConverters
.
getConverters
());
restTemplate
.
setRequestFactory
(
new
HttpComponentsClientHttpRequestFactory
(
httpClient
));
}
}
apollo-common/src/main/java/com/ctrip/apollo/common/controller/HttpMessageConverterConfiguration.java
0 → 100644
View file @
dc493792
package
com
.
ctrip
.
apollo
.
common
.
controller
;
import
com.google.common.collect.Lists
;
import
com.google.gson.GsonBuilder
;
import
org.springframework.boot.autoconfigure.web.HttpMessageConverters
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.converter.ByteArrayHttpMessageConverter
;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.http.converter.StringHttpMessageConverter
;
import
org.springframework.http.converter.json.GsonHttpMessageConverter
;
import
org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter
;
import
java.util.List
;
/**
* Created by Jason on 5/11/16.
*/
@Configuration
public
class
HttpMessageConverterConfiguration
{
@Bean
public
HttpMessageConverters
messageConverters
()
{
GsonHttpMessageConverter
gsonHttpMessageConverter
=
new
GsonHttpMessageConverter
();
gsonHttpMessageConverter
.
setGson
(
new
GsonBuilder
().
setDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss.SSSZ"
).
create
());
final
List
<
HttpMessageConverter
<?>>
converters
=
Lists
.
newArrayList
(
new
ByteArrayHttpMessageConverter
(),
new
StringHttpMessageConverter
(),
new
AllEncompassingFormHttpMessageConverter
(),
gsonHttpMessageConverter
);
return
new
HttpMessageConverters
()
{
@Override
public
List
<
HttpMessageConverter
<?>>
getConverters
()
{
return
converters
;
}
};
}
}
apollo-common/src/main/java/com/ctrip/apollo/common/controller/WebMvcConfig.java
View file @
dc493792
package
com
.
ctrip
.
apollo
.
common
.
controller
;
import
java.util.List
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.data.web.PageableHandlerMethodArgumentResolver
;
...
...
@@ -10,13 +8,15 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import
org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
import
java.util.List
;
@Configuration
public
class
WebMvcConfig
extends
WebMvcConfigurerAdapter
{
@Override
public
void
addArgumentResolvers
(
List
<
HandlerMethodArgumentResolver
>
argumentResolvers
)
{
PageableHandlerMethodArgumentResolver
pageResolver
=
new
PageableHandlerMethodArgumentResolver
();
new
PageableHandlerMethodArgumentResolver
();
pageResolver
.
setFallbackPageable
(
new
PageRequest
(
0
,
10
));
argumentResolvers
.
add
(
pageResolver
);
...
...
@@ -26,4 +26,5 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter {
public
void
configureContentNegotiation
(
ContentNegotiationConfigurer
configurer
)
{
configurer
.
ignoreAcceptHeader
(
true
).
defaultContentType
(
MediaType
.
APPLICATION_JSON
);
}
}
apollo-configservice/src/main/java/com/ctrip/apollo/ConfigServiceApplication.java
View file @
dc493792
...
...
@@ -6,6 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.cloud.netflix.eureka.server.EnableEurekaServer
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.EnableAspectJAutoProxy
;
/**
* Spring boot application entry point
...
...
@@ -14,6 +15,7 @@ import org.springframework.context.ConfigurableApplicationContext;
*/
@SpringBootApplication
@EnableEurekaServer
@EnableAspectJAutoProxy
public
class
ConfigServiceApplication
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
...
...
apollo-configservice/src/test/java/com/ctrip/apollo/configservice/integration/AbstractBaseIntegrationTest.java
View file @
dc493792
...
...
@@ -22,6 +22,7 @@ import javax.annotation.PostConstruct;
@SpringApplicationConfiguration
(
classes
=
AbstractBaseIntegrationTest
.
TestConfiguration
.
class
)
@WebIntegrationTest
(
randomPort
=
true
)
public
abstract
class
AbstractBaseIntegrationTest
{
RestTemplate
restTemplate
=
new
TestRestTemplate
(
"user"
,
""
);
@PostConstruct
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/api/AdminServiceAPI.java
View file @
dc493792
...
...
@@ -11,6 +11,8 @@ import com.ctrip.apollo.core.dto.NamespaceDTO;
import
com.ctrip.apollo.core.dto.ReleaseDTO
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.LinkedMultiValueMap
;
...
...
@@ -130,11 +132,13 @@ public class AdminServiceAPI {
public
ReleaseDTO
release
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespace
,
String
releaseBy
,
String
comment
)
{
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
);
MultiValueMap
<
String
,
String
>
parameters
=
new
LinkedMultiValueMap
<
String
,
String
>();
parameters
.
add
(
"name"
,
releaseBy
);
parameters
.
add
(
"comment"
,
comment
);
HttpEntity
<
MultiValueMap
<
String
,
String
>>
entity
=
new
HttpEntity
<
MultiValueMap
<
String
,
String
>>(
parameters
,
null
);
new
HttpEntity
<
MultiValueMap
<
String
,
String
>>(
parameters
,
headers
);
ResponseEntity
<
ReleaseDTO
>
response
=
restTemplate
.
postForEntity
(
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ServiceLocator.java
View file @
dc493792
...
...
@@ -11,6 +11,8 @@ import javax.annotation.PostConstruct;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.web.HttpMessageConverters
;
import
org.springframework.http.client.HttpComponentsClientHttpRequestFactory
;
import
org.springframework.http.client.SimpleClientHttpRequestFactory
;
import
org.springframework.stereotype.Service
;
...
...
@@ -31,7 +33,10 @@ public class ServiceLocator {
private
static
final
int
DEFAULT_TIMEOUT_MS
=
1000
;
private
RestTemplate
restTemplate
=
new
RestTemplate
();
private
RestTemplate
restTemplate
;
@Autowired
private
HttpMessageConverters
httpMessageConverters
;
private
Map
<
Env
,
List
<
ServiceDTO
>>
serviceCaches
=
new
ConcurrentHashMap
<
Env
,
List
<
ServiceDTO
>>();
...
...
@@ -81,6 +86,7 @@ public class ServiceLocator {
@PostConstruct
private
void
postConstruct
()
{
restTemplate
=
new
RestTemplate
(
httpMessageConverters
.
getConverters
());
if
(
restTemplate
.
getRequestFactory
()
instanceof
SimpleClientHttpRequestFactory
)
{
SimpleClientHttpRequestFactory
rf
=
(
SimpleClientHttpRequestFactory
)
restTemplate
.
getRequestFactory
();
...
...
apollo-portal/src/test/java/com/ctrip/apollo/portal/AbstractPortalTest.java
View file @
dc493792
package
com
.
ctrip
.
apollo
.
portal
;
import
javax.annotation.PostConstruct
;
import
com.ctrip.apollo.PortalApplication
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Value
;
...
...
@@ -11,7 +11,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import
org.springframework.web.client.DefaultResponseErrorHandler
;
import
org.springframework.web.client.RestTemplate
;
import
com.ctrip.apollo.PortalApplication
;
import
javax.annotation.PostConstruct
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
PortalApplication
.
class
)
...
...
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