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
7692e147
Commit
7692e147
authored
Mar 29, 2016
by
Jason Song
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #54 from ctripcorp/env_update_merge
Env update merge
parents
48c3bb83
c46f561c
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
161 additions
and
103 deletions
+161
-103
ApolloBeanUtils.java
...main/java/com/ctrip/apollo/biz/utils/ApolloBeanUtils.java
+20
-6
ConverterUtils.java
.../main/java/com/ctrip/apollo/biz/utils/ConverterUtils.java
+0
-24
ConfigServiceLocator.java
.../com/ctrip/apollo/client/loader/ConfigServiceLocator.java
+5
-5
RemoteConfigLoader.java
...m/ctrip/apollo/client/loader/impl/RemoteConfigLoader.java
+2
-2
RemoteConfigLoaderTest.java
...rip/apollo/client/loader/impl/RemoteConfigLoaderTest.java
+3
-3
ServiceController.java
...trip/apollo/metaservice/controller/ServiceController.java
+10
-10
ConfigConsts.java
...ore/src/main/java/com/ctrip/apollo/core/ConfigConsts.java
+1
-1
ServiceNameConsts.java
...rc/main/java/com/ctrip/apollo/core/ServiceNameConsts.java
+5
-5
ServiceDTO.java
...e/src/main/java/com/ctrip/apollo/core/dto/ServiceDTO.java
+2
-2
ServiceException.java
...ava/com/ctrip/apollo/core/exception/ServiceException.java
+14
-0
ResourceUtils.java
.../main/java/com/ctrip/apollo/core/utils/ResourceUtils.java
+9
-3
apollo-env.properties
apollo-core/src/main/resources/apollo-env.properties
+2
-2
MetaDomainTest.java
...e/src/test/java/com/ctrip/apollo/core/MetaDomainTest.java
+5
-4
apollo-env.properties
apollo-core/src/test/resources/apollo-env.properties
+3
-2
PortalSettings.java
...src/main/java/com/ctrip/apollo/portal/PortalSettings.java
+31
-0
API.java
...portal/src/main/java/com/ctrip/apollo/portal/api/API.java
+10
-4
ConfigService.java
...n/java/com/ctrip/apollo/portal/service/ConfigService.java
+3
-3
ServiceLocator.java
.../java/com/ctrip/apollo/portal/service/ServiceLocator.java
+16
-15
application.yml
apollo-portal/src/main/resources/application.yml
+4
-0
ConfigServiceTest.java
...va/com/ctrip/apollo/portal/service/ConfigServiceTest.java
+16
-12
No files found.
apollo-biz/src/main/java/com/ctrip/apollo/biz/utils/ApolloBeanUtils.java
View file @
7692e147
package
com
.
ctrip
.
apollo
.
biz
.
utils
;
import
org.springframework.beans.BeanWrapper
;
import
org.springframework.beans.BeanWrapperImpl
;
import
org.springframework.util.CollectionUtils
;
import
java.lang.reflect.Field
;
...
...
@@ -48,11 +50,23 @@ public class ApolloBeanUtils {
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
org
.
springframework
.
beans
.
BeanUtils
.
copyProperties
(
src
,
instance
,
ConverterUtils
.
getNullPropertyNames
(
src
));
org
.
springframework
.
beans
.
BeanUtils
.
copyProperties
(
src
,
instance
,
getNullPropertyNames
(
src
));
return
instance
;
}
static
String
[]
getNullPropertyNames
(
Object
source
)
{
final
BeanWrapper
src
=
new
BeanWrapperImpl
(
source
);
java
.
beans
.
PropertyDescriptor
[]
pds
=
src
.
getPropertyDescriptors
();
Set
<
String
>
emptyNames
=
new
HashSet
<
String
>();
for
(
java
.
beans
.
PropertyDescriptor
pd
:
pds
)
{
Object
srcValue
=
src
.
getPropertyValue
(
pd
.
getName
());
if
(
srcValue
==
null
)
emptyNames
.
add
(
pd
.
getName
());
}
String
[]
result
=
new
String
[
emptyNames
.
size
()];
return
emptyNames
.
toArray
(
result
);
}
/**
* 用于将一个列表转换为列表中的对象的某个属性映射到列表中的对象
*
...
...
@@ -92,7 +106,7 @@ public class ApolloBeanUtils {
*/
public
static
<
K
,
V
>
Map
<
K
,
List
<
V
>>
aggByKeyToList
(
String
key
,
List
list
)
{
Map
<
K
,
List
<
V
>>
map
=
new
HashMap
<
K
,
List
<
V
>>();
if
(
CollectionUtils
.
isEmpty
(
list
))
{
//防止外面传入空list
if
(
CollectionUtils
.
isEmpty
(
list
))
{
//
防止外面传入空list
return
map
;
}
try
{
...
...
@@ -122,7 +136,7 @@ public class ApolloBeanUtils {
*/
public
static
Set
toPropertySet
(
String
key
,
List
list
)
{
Set
set
=
new
HashSet
();
if
(
CollectionUtils
.
isEmpty
(
list
))
{
//防止外面传入空list
if
(
CollectionUtils
.
isEmpty
(
list
))
{
//
防止外面传入空list
return
set
;
}
try
{
...
...
@@ -168,7 +182,7 @@ public class ApolloBeanUtils {
return
field
.
get
(
obj
);
}
}
catch
(
Exception
e
)
{
//ig
//
ig
}
return
null
;
}
...
...
@@ -184,7 +198,7 @@ public class ApolloBeanUtils {
field
.
set
(
obj
,
value
);
}
}
catch
(
Exception
e
)
{
//ig
//
ig
}
}
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/utils/ConverterUtils.java
deleted
100644 → 0
View file @
48c3bb83
package
com
.
ctrip
.
apollo
.
biz
.
utils
;
import
java.util.HashSet
;
import
java.util.Set
;
import
org.springframework.beans.BeanWrapper
;
import
org.springframework.beans.BeanWrapperImpl
;
public
class
ConverterUtils
{
static
String
[]
getNullPropertyNames
(
Object
source
)
{
final
BeanWrapper
src
=
new
BeanWrapperImpl
(
source
);
java
.
beans
.
PropertyDescriptor
[]
pds
=
src
.
getPropertyDescriptors
();
Set
<
String
>
emptyNames
=
new
HashSet
<
String
>();
for
(
java
.
beans
.
PropertyDescriptor
pd
:
pds
)
{
Object
srcValue
=
src
.
getPropertyValue
(
pd
.
getName
());
if
(
srcValue
==
null
)
emptyNames
.
add
(
pd
.
getName
());
}
String
[]
result
=
new
String
[
emptyNames
.
size
()];
return
emptyNames
.
toArray
(
result
);
}
}
apollo-client/src/main/java/com/ctrip/apollo/client/loader/ConfigServiceLocator.java
View file @
7692e147
package
com
.
ctrip
.
apollo
.
client
.
loader
;
import
com.ctrip.apollo.client.env.ClientEnvironment
;
import
com.ctrip.apollo.core.
serivce.ApolloService
;
import
com.ctrip.apollo.core.
dto.ServiceDTO
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -17,17 +17,17 @@ public class ConfigServiceLocator {
private
RestTemplate
restTemplate
=
new
RestTemplate
();
private
List
<
ApolloService
>
serviceCaches
=
new
ArrayList
<>();
private
List
<
ServiceDTO
>
serviceCaches
=
new
ArrayList
<>();
public
List
<
ApolloService
>
getConfigServices
()
{
public
List
<
ServiceDTO
>
getConfigServices
()
{
ClientEnvironment
env
=
ClientEnvironment
.
getInstance
();
String
domainName
=
env
.
getMetaServerDomainName
();
String
url
=
domainName
+
"/services/config"
;
try
{
ApolloService
[]
services
=
restTemplate
.
getForObject
(
new
URI
(
url
),
ApolloService
[].
class
);
ServiceDTO
[]
services
=
restTemplate
.
getForObject
(
new
URI
(
url
),
ServiceDTO
[].
class
);
if
(
services
!=
null
&&
services
.
length
>
0
)
{
serviceCaches
.
clear
();
for
(
ApolloService
service
:
services
)
{
for
(
ServiceDTO
service
:
services
)
{
serviceCaches
.
add
(
service
);
}
}
...
...
apollo-client/src/main/java/com/ctrip/apollo/client/loader/impl/RemoteConfigLoader.java
View file @
7692e147
...
...
@@ -6,7 +6,7 @@ import com.ctrip.apollo.client.loader.ConfigServiceLocator;
import
com.ctrip.apollo.client.model.ApolloRegistry
;
import
com.ctrip.apollo.client.util.ConfigUtil
;
import
com.ctrip.apollo.core.dto.ApolloConfig
;
import
com.ctrip.apollo.core.
serivce.ApolloService
;
import
com.ctrip.apollo.core.
dto.ServiceDTO
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -96,7 +96,7 @@ public class RemoteConfigLoader extends AbstractConfigLoader {
}
private
String
getConfigServiceUrl
()
{
List
<
ApolloService
>
services
=
serviceLocator
.
getConfigServices
();
List
<
ServiceDTO
>
services
=
serviceLocator
.
getConfigServices
();
if
(
services
.
size
()
==
0
)
{
throw
new
RuntimeException
(
"No available config service"
);
}
...
...
apollo-client/src/test/java/com/ctrip/apollo/client/loader/impl/RemoteConfigLoaderTest.java
View file @
7692e147
...
...
@@ -4,7 +4,7 @@ import com.ctrip.apollo.client.loader.ConfigServiceLocator;
import
com.ctrip.apollo.client.model.ApolloRegistry
;
import
com.ctrip.apollo.client.util.ConfigUtil
;
import
com.ctrip.apollo.core.dto.ApolloConfig
;
import
com.ctrip.apollo.core.
serivce.ApolloService
;
import
com.ctrip.apollo.core.
dto.ServiceDTO
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -60,9 +60,9 @@ public class RemoteConfigLoaderTest {
ApolloRegistry
apolloRegistry
=
assembleSomeApolloRegistry
(
someAppId
,
"someVersion"
);
ApolloConfig
previousConfig
=
null
;
ApolloService
someService
=
new
ApolloService
();
ServiceDTO
someService
=
new
ServiceDTO
();
someService
.
setHomepageUrl
(
someServerUrl
);
List
<
ApolloService
>
someServices
=
new
ArrayList
<>();
List
<
ServiceDTO
>
someServices
=
new
ArrayList
<>();
someServices
.
add
(
someService
);
when
(
serviceLocater
.
getConfigServices
()).
thenReturn
(
someServices
);
when
(
configUtil
.
getCluster
()).
thenReturn
(
someCluster
);
...
...
apollo-configservice/src/main/java/com/ctrip/apollo/metaservice/controller/ServiceController.java
View file @
7692e147
package
com
.
ctrip
.
apollo
.
metaservice
.
controller
;
import
com.ctrip.apollo.core.
serivce.ApolloService
;
import
com.ctrip.apollo.core.
dto.ServiceDTO
;
import
com.ctrip.apollo.metaservice.service.DiscoveryService
;
import
com.netflix.appinfo.InstanceInfo
;
...
...
@@ -20,11 +20,11 @@ public class ServiceController {
@RequestMapping
(
"/meta"
)
public
List
<
ApolloService
>
getMetaService
()
{
public
List
<
ServiceDTO
>
getMetaService
()
{
List
<
InstanceInfo
>
instances
=
discoveryService
.
getMetaServiceInstances
();
List
<
ApolloService
>
result
=
new
ArrayList
<
ApolloService
>();
List
<
ServiceDTO
>
result
=
new
ArrayList
<
ServiceDTO
>();
for
(
InstanceInfo
instance
:
instances
)
{
ApolloService
service
=
new
ApolloService
();
ServiceDTO
service
=
new
ServiceDTO
();
service
.
setAppName
(
instance
.
getAppName
());
service
.
setInstanceId
(
instance
.
getInstanceId
());
service
.
setHomepageUrl
(
instance
.
getHomePageUrl
());
...
...
@@ -34,11 +34,11 @@ public class ServiceController {
}
@RequestMapping
(
"/config"
)
public
List
<
ApolloService
>
getConfigService
()
{
public
List
<
ServiceDTO
>
getConfigService
()
{
List
<
InstanceInfo
>
instances
=
discoveryService
.
getConfigServiceInstances
();
List
<
ApolloService
>
result
=
new
ArrayList
<
ApolloService
>();
List
<
ServiceDTO
>
result
=
new
ArrayList
<
ServiceDTO
>();
for
(
InstanceInfo
instance
:
instances
)
{
ApolloService
service
=
new
ApolloService
();
ServiceDTO
service
=
new
ServiceDTO
();
service
.
setAppName
(
instance
.
getAppName
());
service
.
setInstanceId
(
instance
.
getInstanceId
());
service
.
setHomepageUrl
(
instance
.
getHomePageUrl
());
...
...
@@ -48,11 +48,11 @@ public class ServiceController {
}
@RequestMapping
(
"/admin"
)
public
List
<
ApolloService
>
getAdminService
()
{
public
List
<
ServiceDTO
>
getAdminService
()
{
List
<
InstanceInfo
>
instances
=
discoveryService
.
getAdminServiceInstances
();
List
<
ApolloService
>
result
=
new
ArrayList
<
ApolloService
>();
List
<
ServiceDTO
>
result
=
new
ArrayList
<
ServiceDTO
>();
for
(
InstanceInfo
instance
:
instances
)
{
ApolloService
service
=
new
ApolloService
();
ServiceDTO
service
=
new
ServiceDTO
();
service
.
setAppName
(
instance
.
getAppName
());
service
.
setInstanceId
(
instance
.
getInstanceId
());
service
.
setHomepageUrl
(
instance
.
getHomePageUrl
());
...
...
apollo-core/src/main/java/com/ctrip/apollo/core/Con
stan
ts.java
→
apollo-core/src/main/java/com/ctrip/apollo/core/Con
figCons
ts.java
View file @
7692e147
package
com
.
ctrip
.
apollo
.
core
;
public
interface
Con
stan
ts
{
public
interface
Con
figCons
ts
{
String
DEFAULT_CLUSTER_NAME
=
"default"
;
...
...
apollo-core/src/main/java/com/ctrip/apollo/core/ServiceNameConsts.java
View file @
7692e147
package
com
.
ctrip
.
apollo
.
core
;
public
class
ServiceNameConsts
{
public
interface
ServiceNameConsts
{
public
static
final
String
APOLLO_METASERVICE
=
"apollo-metaservice"
;
final
String
APOLLO_METASERVICE
=
"apollo-metaservice"
;
public
static
final
String
APOLLO_CONFIGSERVICE
=
"apollo-configservice"
;
final
String
APOLLO_CONFIGSERVICE
=
"apollo-configservice"
;
public
static
final
String
APOLLO_ADMINSERVICE
=
"apollo-adminservice"
;
final
String
APOLLO_ADMINSERVICE
=
"apollo-adminservice"
;
public
static
final
String
APOLLO_PORTAL
=
"apollo-portal"
;
final
String
APOLLO_PORTAL
=
"apollo-portal"
;
}
apollo-core/src/main/java/com/ctrip/apollo/core/
serivce/ApolloService
.java
→
apollo-core/src/main/java/com/ctrip/apollo/core/
dto/ServiceDTO
.java
View file @
7692e147
package
com
.
ctrip
.
apollo
.
core
.
serivce
;
package
com
.
ctrip
.
apollo
.
core
.
dto
;
public
class
ApolloService
{
public
class
ServiceDTO
{
private
String
appName
;
...
...
apollo-core/src/main/java/com/ctrip/apollo/core/exception/ServiceException.java
0 → 100644
View file @
7692e147
package
com
.
ctrip
.
apollo
.
core
.
exception
;
public
class
ServiceException
extends
Exception
{
/**
*
*/
private
static
final
long
serialVersionUID
=
1L
;
public
ServiceException
(
String
str
)
{
super
(
str
);
}
}
apollo-core/src/main/java/com/ctrip/apollo/core/utils/ResourceUtils.java
View file @
7692e147
...
...
@@ -15,7 +15,7 @@ import org.slf4j.LoggerFactory;
public
class
ResourceUtils
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ResourceUtils
.
class
);
@SuppressWarnings
(
"unchecked"
)
public
static
Properties
readConfigFile
(
String
configPath
,
Properties
defaults
)
{
InputStream
in
=
ClassLoader
.
getSystemResourceAsStream
(
configPath
);
...
...
@@ -28,6 +28,8 @@ public class ResourceUtils {
if
(
Files
.
isReadable
(
path
))
{
in
=
new
FileInputStream
(
path
.
toFile
());
logger
.
info
(
"Reading config from file {} "
,
path
);
}
else
{
logger
.
info
(
"Could not find available config file"
);
}
}
if
(
defaults
!=
null
)
{
...
...
@@ -51,12 +53,16 @@ public class ResourceUtils {
}
StringBuilder
sb
=
new
StringBuilder
();
for
(
Enumeration
<
String
>
e
=
(
Enumeration
<
String
>)
props
.
propertyNames
();
e
.
hasMoreElements
();
)
{
.
hasMoreElements
();)
{
String
key
=
e
.
nextElement
();
String
val
=
(
String
)
props
.
getProperty
(
key
);
sb
.
append
(
key
).
append
(
'='
).
append
(
val
).
append
(
'\n'
);
}
logger
.
info
(
"Reading properties: \n"
+
sb
.
toString
());
if
(
sb
.
length
()
>
0
)
{
logger
.
info
(
"Reading properties: \n"
+
sb
.
toString
());
}
else
{
logger
.
info
(
"No available properties"
);
}
return
props
;
}
}
apollo-core/src/main/resources/apollo-env.properties
View file @
7692e147
local.meta
=
http://localhost:8090
\ No newline at end of file
local.meta
=
http://localhost:8080
\ No newline at end of file
apollo-core/src/test/java/com/ctrip/apollo/core/MetaDomainTest.java
View file @
7692e147
package
com
.
ctrip
.
apollo
.
core
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.springframework.util.Assert
;
import
com.ctrip.apollo.Apollo.Env
;
public
class
MetaDomainTest
{
@Test
public
void
testDefaultDomain
()
{
Assert
.
notNull
(
MetaDomainConsts
.
getDomain
(
Env
.
LOCAL
));
Assert
.
isNull
(
MetaDomainConsts
.
getDomain
(
Env
.
PRO
));
public
void
testGetMetaDomain
()
{
Assert
.
assertEquals
(
"http://localhost:8090"
,
MetaDomainConsts
.
getDomain
(
Env
.
LOCAL
));
Assert
.
assertEquals
(
"http://dev:8080"
,
MetaDomainConsts
.
getDomain
(
Env
.
DEV
));
Assert
.
assertNull
(
MetaDomainConsts
.
getDomain
(
Env
.
PRO
));
}
}
apollo-core/src/test/resources/apollo-env.properties
View file @
7692e147
local.meta
=
http://localhost:8090
\ No newline at end of file
local.meta
=
http://localhost:8090
dev.meta
=
http://dev:8080
\ No newline at end of file
apollo-portal/src/main/java/com/ctrip/apollo/portal/PortalSettings.java
0 → 100644
View file @
7692e147
package
com
.
ctrip
.
apollo
.
portal
;
import
java.util.ArrayList
;
import
java.util.List
;
import
javax.annotation.PostConstruct
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
com.ctrip.apollo.Apollo.Env
;
@Component
public
class
PortalSettings
{
@Value
(
"#{'${apollo.portal.env}'.split(',')}"
)
private
List
<
String
>
env
;
private
List
<
Env
>
envs
=
new
ArrayList
<
Env
>();
@PostConstruct
private
void
postConstruct
()
{
for
(
String
e
:
env
)
{
envs
.
add
(
Env
.
valueOf
(
e
.
toUpperCase
()));
}
}
public
List
<
Env
>
getEnvs
()
{
return
envs
;
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/api/API.java
View file @
7692e147
package
com
.
ctrip
.
apollo
.
portal
.
api
;
import
com.ctrip.apollo.Apollo
;
import
com.ctrip.apollo.core.exception.ServiceException
;
import
com.ctrip.apollo.portal.service.ServiceLocator
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -13,9 +14,14 @@ public class API {
protected
RestTemplate
restTemplate
=
new
RestTemplate
();
public
String
getAdminServiceHost
(
Apollo
.
Env
env
){
//本地测试用
// return "http://localhost:8090";
return
serviceLocator
.
getAdminService
(
env
);
public
String
getAdminServiceHost
(
Apollo
.
Env
env
)
{
// 本地测试用
// return "http://localhost:8090";
try
{
return
serviceLocator
.
getAdminService
(
env
).
getHomepageUrl
();
}
catch
(
ServiceException
e
)
{
e
.
printStackTrace
();
}
return
""
;
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ConfigService.java
View file @
7692e147
...
...
@@ -14,7 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service
;
import
com.ctrip.apollo.Apollo.Env
;
import
com.ctrip.apollo.core.Con
stan
ts
;
import
com.ctrip.apollo.core.Con
figCons
ts
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
import
com.ctrip.apollo.core.dto.ConfigItemDTO
;
import
com.ctrip.apollo.core.dto.ReleaseSnapshotDTO
;
...
...
@@ -61,7 +61,7 @@ public class ConfigService {
for
(
ReleaseSnapshotDTO
snapShot
:
releaseSnapShots
)
{
// default cluster
if
(
Con
stan
ts
.
DEFAULT_CLUSTER_NAME
.
equals
(
snapShot
.
getClusterName
()))
{
if
(
Con
figCons
ts
.
DEFAULT_CLUSTER_NAME
.
equals
(
snapShot
.
getClusterName
()))
{
collectDefaultClusterConfigs
(
appId
,
snapShot
,
appConfigVO
);
...
...
@@ -223,7 +223,7 @@ public class ConfigService {
clusterName
=
entry
.
getKey
();
clusterConfigs
=
entry
.
getValue
();
if
(
Con
stan
ts
.
DEFAULT_CLUSTER_NAME
.
equals
(
clusterName
))
{
if
(
Con
figCons
ts
.
DEFAULT_CLUSTER_NAME
.
equals
(
clusterName
))
{
// default cluster configs
collectDefaultClusterConfigs
(
appId
,
clusterConfigs
,
defaultClusterConfigs
,
overrideAppConfigs
);
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ServiceLocator.java
View file @
7692e147
...
...
@@ -11,7 +11,8 @@ import org.springframework.web.client.RestTemplate;
import
com.ctrip.apollo.Apollo.Env
;
import
com.ctrip.apollo.core.MetaDomainConsts
;
import
com.ctrip.apollo.core.serivce.ApolloService
;
import
com.ctrip.apollo.core.dto.ServiceDTO
;
import
com.ctrip.apollo.core.exception.ServiceException
;
/**
* @author liuym
...
...
@@ -23,32 +24,32 @@ public class ServiceLocator {
private
RestTemplate
restTemplate
=
new
RestTemplate
();
private
List
<
ApolloService
>
serviceCaches
=
new
ArrayList
<>();
private
List
<
ServiceDTO
>
serviceCaches
=
new
ArrayList
<>();
public
List
<
ApolloService
>
getAdminServices
(
Env
env
)
{
return
getServices
(
env
,
"admin"
);
}
public
String
getAdminService
(
Env
env
)
{
List
<
ApolloService
>
services
=
getAdminServices
(
env
);
public
ServiceDTO
getAdminService
(
Env
env
)
throws
ServiceException
{
List
<
ServiceDTO
>
services
=
getServices
(
env
,
"admin"
);
if
(
services
.
size
()
==
0
)
{
throw
new
Runtim
eException
(
"No available admin service"
);
throw
new
Servic
eException
(
"No available admin service"
);
}
return
services
.
get
(
0
)
.
getHomepageUrl
()
;
return
services
.
get
(
0
);
}
public
List
<
ApolloService
>
getConfigServices
(
Env
env
)
{
return
getServices
(
env
,
"config"
);
public
ServiceDTO
getConfigService
(
Env
env
)
throws
ServiceException
{
List
<
ServiceDTO
>
services
=
getServices
(
env
,
"config"
);
if
(
services
.
size
()
==
0
)
{
throw
new
ServiceException
(
"No available config service"
);
}
return
services
.
get
(
0
);
}
private
List
<
ApolloService
>
getServices
(
Env
env
,
String
serviceUrl
)
{
private
List
<
ServiceDTO
>
getServices
(
Env
env
,
String
serviceUrl
)
{
String
domainName
=
MetaDomainConsts
.
getDomain
(
env
);
String
url
=
domainName
+
"/services/"
+
serviceUrl
;
try
{
ApolloService
[]
services
=
restTemplate
.
getForObject
(
new
URI
(
url
),
ApolloService
[].
class
);
ServiceDTO
[]
services
=
restTemplate
.
getForObject
(
new
URI
(
url
),
ServiceDTO
[].
class
);
if
(
services
!=
null
&&
services
.
length
>
0
)
{
serviceCaches
.
clear
();
for
(
ApolloService
service
:
services
)
{
for
(
ServiceDTO
service
:
services
)
{
serviceCaches
.
add
(
service
);
}
}
...
...
apollo-portal/src/main/resources/application.yml
View file @
7692e147
...
...
@@ -17,3 +17,7 @@ logging:
ctrip
:
appid
:
100003173
apollo
:
portal
:
env
:
dev,fws,uat
apollo-portal/src/test/java/com/ctrip/apollo/portal/service/ConfigServiceTest.java
View file @
7692e147
...
...
@@ -15,11 +15,13 @@ import org.springframework.test.util.ReflectionTestUtils;
import
org.springframework.web.client.RestTemplate
;
import
com.ctrip.apollo.Apollo.Env
;
import
com.ctrip.apollo.core.Con
stan
ts
;
import
com.ctrip.apollo.core.Con
figCons
ts
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
import
com.ctrip.apollo.core.dto.ConfigItemDTO
;
import
com.ctrip.apollo.core.dto.ReleaseSnapshotDTO
;
import
com.ctrip.apollo.core.dto.ServiceDTO
;
import
com.ctrip.apollo.core.dto.VersionDTO
;
import
com.ctrip.apollo.core.exception.ServiceException
;
import
com.ctrip.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.apollo.portal.constants.PortalConstants
;
import
com.ctrip.apollo.portal.entity.AppConfigVO
;
...
...
@@ -47,7 +49,7 @@ public class ConfigServiceTest {
@Before
public
void
setUp
()
{
public
void
setUp
()
throws
ServiceException
{
ReflectionTestUtils
.
setField
(
versionAPI
,
"restTemplate"
,
restTemplate
);
ReflectionTestUtils
.
setField
(
clusterAPI
,
"restTemplate"
,
restTemplate
);
ReflectionTestUtils
.
setField
(
configAPI
,
"restTemplate"
,
restTemplate
);
...
...
@@ -57,7 +59,9 @@ public class ConfigServiceTest {
ReflectionTestUtils
.
setField
(
configAPI
,
"serviceLocator"
,
serviceLocator
);
String
defaultAdminService
=
"http://localhost:8090"
;
Mockito
.
doReturn
(
defaultAdminService
).
when
(
serviceLocator
).
getAdminService
(
Env
.
DEV
);
ServiceDTO
service
=
new
ServiceDTO
();
service
.
setHomepageUrl
(
defaultAdminService
);
Mockito
.
doReturn
(
service
).
when
(
serviceLocator
).
getAdminService
(
Env
.
DEV
);
}
@Test
...
...
@@ -89,7 +93,7 @@ public class ConfigServiceTest {
VersionDTO
someVersion
=
assembleVersion
(
appId
,
"1.0"
,
releaseId
);
ReleaseSnapshotDTO
[]
someReleaseSnapShots
=
new
ReleaseSnapshotDTO
[
1
];
someReleaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
Con
stan
ts
.
DEFAULT_CLUSTER_NAME
,
someReleaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
Con
figCons
ts
.
DEFAULT_CLUSTER_NAME
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}"
);
when
(
versionAPI
.
getVersionById
(
Env
.
DEV
,
versionId
)).
thenReturn
(
someVersion
);
...
...
@@ -111,7 +115,7 @@ public class ConfigServiceTest {
long
releaseId
=
11111
;
VersionDTO
someVersion
=
assembleVersion
(
appId
,
"1.0"
,
releaseId
);
ReleaseSnapshotDTO
[]
someReleaseSnapShots
=
new
ReleaseSnapshotDTO
[
1
];
someReleaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
Con
stan
ts
.
DEFAULT_CLUSTER_NAME
,
someReleaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
Con
figCons
ts
.
DEFAULT_CLUSTER_NAME
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\", \"5555.bar\":\"demo2\", \"22.bar\":\"demo2\"}"
);
when
(
versionAPI
.
getVersionById
(
Env
.
DEV
,
versionId
)).
thenReturn
(
someVersion
);
...
...
@@ -133,7 +137,7 @@ public class ConfigServiceTest {
long
releaseId
=
11111
;
VersionDTO
someVersion
=
assembleVersion
(
appId
,
"1.0"
,
releaseId
);
ReleaseSnapshotDTO
[]
someReleaseSnapShots
=
new
ReleaseSnapshotDTO
[
2
];
someReleaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
Con
stan
ts
.
DEFAULT_CLUSTER_NAME
,
someReleaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
Con
figCons
ts
.
DEFAULT_CLUSTER_NAME
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}"
);
someReleaseSnapShots
[
1
]
=
assembleReleaseSnapShot
(
11112
,
"cluster1"
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}"
);
...
...
@@ -179,7 +183,7 @@ public class ConfigServiceTest {
private
ReleaseSnapshotDTO
[]
assembleReleaseSnapShots
()
{
ReleaseSnapshotDTO
[]
releaseSnapShots
=
new
ReleaseSnapshotDTO
[
3
];
releaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
Con
stan
ts
.
DEFAULT_CLUSTER_NAME
,
releaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
Con
figCons
ts
.
DEFAULT_CLUSTER_NAME
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\",\"3333.foo\":\"1008\",\"4444.bar\":\"99901\"}"
);
releaseSnapShots
[
1
]
=
assembleReleaseSnapShot
(
11111
,
"cluster1"
,
"{\"6666.foo\":\"demo1\"}"
);
releaseSnapShots
[
2
]
=
assembleReleaseSnapShot
(
11111
,
"cluster2"
,
"{\"6666.bar\":\"bar2222\"}"
);
...
...
@@ -197,7 +201,7 @@ public class ConfigServiceTest {
private
ClusterDTO
[]
assembleClusters
()
{
ClusterDTO
[]
clusters
=
new
ClusterDTO
[
2
];
clusters
[
0
]
=
assembleCluster
(
100
,
"6666"
,
Con
stan
ts
.
DEFAULT_CLUSTER_NAME
);
clusters
[
0
]
=
assembleCluster
(
100
,
"6666"
,
Con
figCons
ts
.
DEFAULT_CLUSTER_NAME
);
clusters
[
1
]
=
assembleCluster
(
101
,
"6666"
,
"cluster1"
);
return
clusters
;
}
...
...
@@ -212,10 +216,10 @@ public class ConfigServiceTest {
private
ConfigItemDTO
[]
assembleConfigItems
()
{
ConfigItemDTO
[]
configItems
=
new
ConfigItemDTO
[
5
];
configItems
[
0
]
=
assembleConfigItem
(
100
,
Con
stan
ts
.
DEFAULT_CLUSTER_NAME
,
"6666"
,
"6666.k1"
,
"6666.v1"
);
configItems
[
1
]
=
assembleConfigItem
(
100
,
Con
stan
ts
.
DEFAULT_CLUSTER_NAME
,
"6666"
,
"6666.k2"
,
"6666.v2"
);
configItems
[
2
]
=
assembleConfigItem
(
100
,
Con
stan
ts
.
DEFAULT_CLUSTER_NAME
,
"6666"
,
"6666.k3"
,
"6666.v3"
);
configItems
[
3
]
=
assembleConfigItem
(
100
,
Con
stan
ts
.
DEFAULT_CLUSTER_NAME
,
"5555"
,
"5555.k1"
,
"5555.v1"
);
configItems
[
0
]
=
assembleConfigItem
(
100
,
Con
figCons
ts
.
DEFAULT_CLUSTER_NAME
,
"6666"
,
"6666.k1"
,
"6666.v1"
);
configItems
[
1
]
=
assembleConfigItem
(
100
,
Con
figCons
ts
.
DEFAULT_CLUSTER_NAME
,
"6666"
,
"6666.k2"
,
"6666.v2"
);
configItems
[
2
]
=
assembleConfigItem
(
100
,
Con
figCons
ts
.
DEFAULT_CLUSTER_NAME
,
"6666"
,
"6666.k3"
,
"6666.v3"
);
configItems
[
3
]
=
assembleConfigItem
(
100
,
Con
figCons
ts
.
DEFAULT_CLUSTER_NAME
,
"5555"
,
"5555.k1"
,
"5555.v1"
);
configItems
[
4
]
=
assembleConfigItem
(
101
,
"cluster1"
,
"6666"
,
"6666.k1"
,
"6666.v1"
);
return
configItems
;
}
...
...
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