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
7ea0ac2a
Commit
7ea0ac2a
authored
Apr 27, 2016
by
Jason Song
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #149 from yiming187/build_env
Support build parameters by env
parents
29b8f4c4
b908fd9b
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
148 additions
and
63 deletions
+148
-63
.gitignore
.gitignore
+2
-4
application.yml
apollo-adminservice/src/main/resources/application.yml
+3
-1
pom.xml
apollo-biz/pom.xml
+8
-0
TitanCondition.java
.../java/com/ctrip/apollo/biz/datasource/TitanCondition.java
+5
-1
TitanSettings.java
...n/java/com/ctrip/apollo/biz/datasource/TitanSettings.java
+46
-13
application-ctrip.properties
apollo-biz/src/main/resources/application-ctrip.properties
+7
-0
application.properties
apollo-biz/src/main/resources/application.properties
+10
-0
ConfigUtil.java
...lient/src/main/java/com/ctrip/apollo/util/ConfigUtil.java
+2
-25
application.yml
apollo-configservice/src/main/resources/application.yml
+2
-0
MetaDomainConsts.java
...src/main/java/com/ctrip/apollo/core/MetaDomainConsts.java
+24
-10
EnvUtils.java
...e/src/main/java/com/ctrip/apollo/core/enums/EnvUtils.java
+29
-0
apollo-env.properties
apollo-core/src/main/resources/apollo-env.properties
+4
-5
MetaDomainTest.java
...e/src/test/java/com/ctrip/apollo/core/MetaDomainTest.java
+1
-1
application.yml
apollo-portal/src/main/resources/application.yml
+3
-1
pom.xml
pom.xml
+2
-2
No files found.
.gitignore
View file @
7ea0ac2a
...
...
@@ -25,7 +25,4 @@ target
# git
*.orig
dev
fat
uat
prd
application-dev.properties
\ No newline at end of file
apollo-adminservice/src/main/resources/application.yml
View file @
7ea0ac2a
spring
:
application
:
name
:
apollo-adminservice
profiles
:
active
:
ctrip
server
:
port
:
${port:8090}
...
...
apollo-biz/pom.xml
View file @
7ea0ac2a
...
...
@@ -36,4 +36,12 @@
<scope>
test
</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>
src/main/resources
</directory>
<filtering>
true
</filtering>
</resource>
</resources>
</build>
</project>
apollo-biz/src/main/java/com/ctrip/apollo/biz/datasource/TitanCondition.java
View file @
7ea0ac2a
...
...
@@ -10,7 +10,11 @@ public class TitanCondition implements Condition {
@Override
public
boolean
matches
(
ConditionContext
context
,
AnnotatedTypeMetadata
metadata
)
{
if
(!
StringUtils
.
isEmpty
(
context
.
getEnvironment
().
getProperty
(
"titan.url"
)))
{
if
(!
StringUtils
.
isEmpty
(
context
.
getEnvironment
().
getProperty
(
"fat.titan.url"
)))
{
return
true
;
}
else
if
(!
StringUtils
.
isEmpty
(
context
.
getEnvironment
().
getProperty
(
"uat.titan.url"
)))
{
return
true
;
}
else
if
(!
StringUtils
.
isEmpty
(
context
.
getEnvironment
().
getProperty
(
"pro.titan.url"
)))
{
return
true
;
}
return
false
;
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/datasource/TitanSettings.java
View file @
7ea0ac2a
...
...
@@ -3,28 +3,61 @@ package com.ctrip.apollo.biz.datasource;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
com.ctrip.apollo.core.enums.Env
;
import
com.ctrip.apollo.core.enums.EnvUtils
;
import
com.ctrip.framework.foundation.Foundation
;
@Component
public
class
TitanSettings
{
@Value
(
"${titan.url:}"
)
private
String
t
itanUrl
;
@Value
(
"${
fat.
titan.url:}"
)
private
String
fatT
itanUrl
;
@Value
(
"${
titan.dbname
:}"
)
private
String
titanDbname
;
@Value
(
"${
uat.titan.url
:}"
)
private
String
uatTitanUrl
;
public
String
getTitanUrl
()
{
return
titanUrl
;
}
@Value
(
"${pro.titan.url:}"
)
private
String
proTitanUrl
;
@Value
(
"${fat.titan.dbname:}"
)
private
String
fatTitanDbname
;
public
void
setTitanUrl
(
String
titanUrl
)
{
this
.
titanUrl
=
titanUrl
;
@Value
(
"${uat.titan.dbname:}"
)
private
String
uatTitanDbname
;
@Value
(
"${pro.titan.dbname:}"
)
private
String
proTitanDbname
;
public
String
getTitanUrl
()
{
Env
env
=
EnvUtils
.
transformEnv
(
Foundation
.
server
().
getEnvType
());
switch
(
env
)
{
case
FAT:
case
FWS:
return
fatTitanUrl
;
case
UAT:
return
uatTitanUrl
;
case
TOOLS:
case
PRO:
return
proTitanUrl
;
default
:
return
""
;
}
}
public
String
getTitanDbname
()
{
return
titanDbname
;
Env
env
=
EnvUtils
.
transformEnv
(
Foundation
.
server
().
getEnvType
());
switch
(
env
)
{
case
FAT:
case
FWS:
return
fatTitanDbname
;
case
UAT:
return
uatTitanDbname
;
case
TOOLS:
case
PRO:
return
proTitanDbname
;
default
:
return
""
;
}
}
public
void
setTitanDbname
(
String
titanDbname
)
{
this
.
titanDbname
=
titanDbname
;
}
}
apollo-biz/src/main/resources/application-ctrip.properties
0 → 100644
View file @
7ea0ac2a
# Titan Datasource (Ctrip only)
fat.titan.url
=
${fat_titan_url}
fat.titan.dbname
=
${fat_titan_dbname}
uat.titan.url
=
${uat_titan_url}
uat.titan.dbname
=
${uat_titan_dbname}
pro.titan.url
=
${pro_titan_url}
pro.titan.dbname
=
${pro_titan_dbname}
apollo-biz/src/main/resources/application.properties
0 → 100644
View file @
7ea0ac2a
# DataSource
spring.datasource.testWhileIdle
=
true
spring.datasource.testOnBorrow
=
true
spring.datasource.validationQuery
=
SELECT 1
# Naming strategy
spring.jpa.hibernate.naming_strategy
=
org.hibernate.cfg.EJB3NamingStrategy
spring.jpa.hibernate.globally_quoted_identifiers
=
true
spring.jpa.properties.hibernate.globally_quoted_identifiers
=
true
spring.jpa.properties.hibernate.show_sql
=
true
apollo-client/src/main/java/com/ctrip/apollo/util/ConfigUtil.java
View file @
7ea0ac2a
package
com
.
ctrip
.
apollo
.
util
;
import
com.google.common.base.Preconditions
;
import
com.google.common.base.Strings
;
import
com.ctrip.apollo.core.ConfigConsts
;
import
com.ctrip.apollo.core.MetaDomainConsts
;
import
com.ctrip.apollo.core.enums.Env
;
import
com.ctrip.apollo.core.enums.EnvUtils
;
import
com.ctrip.framework.foundation.Foundation
;
import
org.unidal.lookup.annotation.Named
;
...
...
@@ -60,34 +60,11 @@ public class ConfigUtil {
* @throws IllegalStateException if env is set
*/
public
Env
getApolloEnv
()
{
Env
env
=
transformEnv
(
Foundation
.
server
().
getEnvType
());
Env
env
=
EnvUtils
.
transformEnv
(
Foundation
.
server
().
getEnvType
());
Preconditions
.
checkState
(
env
!=
null
,
"env is not set"
);
return
env
;
}
private
Env
transformEnv
(
String
envName
)
{
if
(
Strings
.
isNullOrEmpty
(
envName
))
{
return
null
;
}
switch
(
envName
.
toUpperCase
())
{
case
"LPT"
:
return
Env
.
LPT
;
case
"FAT"
:
case
"FWS"
:
return
Env
.
FAT
;
case
"UAT"
:
return
Env
.
UAT
;
case
"PRO"
:
return
Env
.
PRO
;
case
"DEV"
:
return
Env
.
DEV
;
case
"LOCAL"
:
return
Env
.
LOCAL
;
default
:
return
null
;
}
}
public
String
getMetaServerDomainName
()
{
return
MetaDomainConsts
.
getDomain
(
getApolloEnv
());
}
...
...
apollo-configservice/src/main/resources/application.yml
View file @
7ea0ac2a
spring
:
application
:
name
:
apollo-configservice
profiles
:
active
:
ctrip
server
:
port
:
${port:8080}
...
...
apollo-core/src/main/java/com/ctrip/apollo/core/MetaDomainConsts.java
View file @
7ea0ac2a
...
...
@@ -7,24 +7,38 @@ import java.util.Properties;
import
com.ctrip.apollo.core.enums.Env
;
import
com.ctrip.apollo.core.utils.ResourceUtils
;
/**
* The meta domain will load the meta server from System environment first, if not exist, will load
* from apollo-env.properties. If neither exists, will load the default meta url.
*
* Currently, apollo supports local/dev/fat/uat/lpt/pro environments.
*/
@SuppressWarnings
({
"rawtypes"
,
"unchecked"
})
public
class
MetaDomainConsts
{
private
static
Map
<
Env
,
String
>
domains
=
new
HashMap
<>();
private
static
Map
<
Env
,
Object
>
domains
=
new
HashMap
<>();
public
static
final
String
DEFAULT_META_URL
=
"http://localhost:8080"
;
static
{
Properties
prop
=
new
Properties
();
prop
=
ResourceUtils
.
readConfigFile
(
"apollo-env.properties"
,
prop
);
domains
.
put
(
Env
.
LOCAL
,
prop
.
getProperty
(
"local.meta"
,
"http://localhost:8080"
));
domains
.
put
(
Env
.
DEV
,
prop
.
getProperty
(
"dev.meta"
));
domains
.
put
(
Env
.
FAT
,
prop
.
getProperty
(
"fat.meta"
));
domains
.
put
(
Env
.
FWS
,
prop
.
getProperty
(
"fws.meta"
));
domains
.
put
(
Env
.
UAT
,
prop
.
getProperty
(
"uat.meta"
));
domains
.
put
(
Env
.
LPT
,
prop
.
getProperty
(
"lpt.meta"
));
domains
.
put
(
Env
.
TOOLS
,
prop
.
getProperty
(
"tools.meta"
));
domains
.
put
(
Env
.
PRO
,
prop
.
getProperty
(
"pro.meta"
));
Map
env
=
System
.
getProperties
();
domains
.
put
(
Env
.
LOCAL
,
env
.
getOrDefault
(
"local_meta"
,
prop
.
getProperty
(
"local.meta"
,
DEFAULT_META_URL
)));
domains
.
put
(
Env
.
DEV
,
env
.
getOrDefault
(
"dev_meta"
,
prop
.
getProperty
(
"dev.meta"
,
DEFAULT_META_URL
)));
domains
.
put
(
Env
.
FAT
,
env
.
getOrDefault
(
"fat_meta"
,
prop
.
getProperty
(
"fat.meta"
,
DEFAULT_META_URL
)));
domains
.
put
(
Env
.
UAT
,
env
.
getOrDefault
(
"uat_meta"
,
prop
.
getProperty
(
"uat.meta"
,
DEFAULT_META_URL
)));
domains
.
put
(
Env
.
LPT
,
env
.
getOrDefault
(
"lpt_meta"
,
prop
.
getProperty
(
"lpt.meta"
,
DEFAULT_META_URL
)));
domains
.
put
(
Env
.
PRO
,
env
.
getOrDefault
(
"pro_meta"
,
prop
.
getProperty
(
"pro.meta"
,
DEFAULT_META_URL
)));
}
public
static
String
getDomain
(
Env
env
)
{
return
domains
.
get
(
env
);
return
String
.
valueOf
(
domains
.
get
(
env
)
);
}
}
apollo-core/src/main/java/com/ctrip/apollo/core/enums/EnvUtils.java
0 → 100644
View file @
7ea0ac2a
package
com
.
ctrip
.
apollo
.
core
.
enums
;
import
com.ctrip.apollo.core.utils.StringUtils
;
public
final
class
EnvUtils
{
public
static
Env
transformEnv
(
String
envName
)
{
if
(
StringUtils
.
isBlank
(
envName
))
{
return
null
;
}
switch
(
envName
.
toUpperCase
())
{
case
"LPT"
:
return
Env
.
LPT
;
case
"FAT"
:
case
"FWS"
:
return
Env
.
FAT
;
case
"UAT"
:
return
Env
.
UAT
;
case
"PRO"
:
return
Env
.
PRO
;
case
"DEV"
:
return
Env
.
DEV
;
case
"LOCAL"
:
return
Env
.
LOCAL
;
default
:
return
null
;
}
}
}
apollo-core/src/main/resources/apollo-env.properties
View file @
7ea0ac2a
local.meta
=
http://localhost:8080
dev.meta
=
${dev}
fat.meta
=
${fat}
uat.meta
=
${uat}
lpt.meta
=
${lpt}
pro.meta
=
${pro}
dev.meta
=
${dev_meta}
fat.meta
=
${fat_meta}
uat.meta
=
${uat_meta}
pro.meta
=
${pro_meta}
apollo-core/src/test/java/com/ctrip/apollo/core/MetaDomainTest.java
View file @
7ea0ac2a
...
...
@@ -11,6 +11,6 @@ public class MetaDomainTest {
public
void
testGetMetaDomain
()
{
Assert
.
assertEquals
(
"http://localhost:8080"
,
MetaDomainConsts
.
getDomain
(
Env
.
LOCAL
));
Assert
.
assertEquals
(
"http://dev:8080"
,
MetaDomainConsts
.
getDomain
(
Env
.
DEV
));
Assert
.
assert
Null
(
MetaDomainConsts
.
getDomain
(
Env
.
PRO
));
Assert
.
assert
Equals
(
MetaDomainConsts
.
DEFAULT_META_URL
,
MetaDomainConsts
.
getDomain
(
Env
.
PRO
));
}
}
apollo-portal/src/main/resources/application.yml
View file @
7ea0ac2a
...
...
@@ -4,7 +4,9 @@ server:
spring
:
application
:
name
:
apollo-portal
profiles
:
active
:
ctrip
logging
:
level
:
org.springframework.cloud
:
'
DEBUG'
...
...
pom.xml
View file @
7ea0ac2a
...
...
@@ -124,12 +124,12 @@
<dependency>
<groupId>
com.ctrip.framework
</groupId>
<artifactId>
framework-foundation
</artifactId>
<version>
1.1.
4
</version>
<version>
1.1.
5
</version>
</dependency>
<dependency>
<groupId>
com.dianping.cat
</groupId>
<artifactId>
cat-client
</artifactId>
<version>
1.
4.6
</version>
<version>
1.
5.0
</version>
</dependency>
<dependency>
<groupId>
com.ctrip.platform
</groupId>
...
...
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