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
fe7cd269
Commit
fe7cd269
authored
Apr 05, 2016
by
Yiming Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Ctrip Titan DataSource Support
parent
6888ff73
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
153 additions
and
15 deletions
+153
-15
pom.xml
apollo-biz/pom.xml
+19
-4
TitanCondition.java
.../java/com/ctrip/apollo/biz/datasource/TitanCondition.java
+19
-0
TitanEntityManager.java
...a/com/ctrip/apollo/biz/datasource/TitanEntityManager.java
+29
-0
TitanSettings.java
...n/java/com/ctrip/apollo/biz/datasource/TitanSettings.java
+30
-0
ServerApplication.java
...ice/src/main/java/com/ctrip/apollo/ServerApplication.java
+3
-1
ServiceController.java
...trip/apollo/metaservice/controller/ServiceController.java
+23
-10
pom.xml
pom.xml
+30
-0
No files found.
apollo-biz/pom.xml
View file @
fe7cd269
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
apollo
</artifactId>
...
...
@@ -20,16 +19,32 @@
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-jpa
</artifactId>
<exclusions>
<exclusion>
<artifactId>
logback-classic
</artifactId>
<groupId>
ch.qos.logback
</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<profiles>
<profile>
<id>
local
</id>
<dependencies>
<dependency>
<groupId>
com.h2database
</groupId>
<artifactId>
h2
</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>
ctrip
</id>
<dependencies>
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<scope>
runtime
</scope>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
apollo-biz/src/main/java/com/ctrip/apollo/biz/datasource/TitanCondition.java
0 → 100644
View file @
fe7cd269
package
com
.
ctrip
.
apollo
.
biz
.
datasource
;
import
org.springframework.context.annotation.Condition
;
import
org.springframework.context.annotation.ConditionContext
;
import
org.springframework.core.type.AnnotatedTypeMetadata
;
import
com.ctrip.apollo.core.utils.StringUtils
;
public
class
TitanCondition
implements
Condition
{
@Override
public
boolean
matches
(
ConditionContext
context
,
AnnotatedTypeMetadata
metadata
)
{
if
(!
StringUtils
.
isEmpty
(
context
.
getEnvironment
().
getProperty
(
"titan.url"
)))
{
return
true
;
}
return
false
;
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/datasource/TitanEntityManager.java
0 → 100644
View file @
fe7cd269
package
com
.
ctrip
.
apollo
.
biz
.
datasource
;
import
java.lang.reflect.Method
;
import
javax.sql.DataSource
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Conditional
;
import
org.springframework.stereotype.Component
;
@Component
@Conditional
(
TitanCondition
.
class
)
public
class
TitanEntityManager
{
@Autowired
private
TitanSettings
settings
;
@SuppressWarnings
({
"rawtypes"
,
"unchecked"
})
@Bean
public
DataSource
datasource
()
throws
Exception
{
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
,
new
String
[]
{
settings
.
getTitanDbname
(),
settings
.
getTitanUrl
()}));
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/datasource/TitanSettings.java
0 → 100644
View file @
fe7cd269
package
com
.
ctrip
.
apollo
.
biz
.
datasource
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
@Component
public
class
TitanSettings
{
@Value
(
"${titan.url:}"
)
private
String
titanUrl
;
@Value
(
"${titan.dbname:}"
)
private
String
titanDbname
;
public
String
getTitanUrl
()
{
return
titanUrl
;
}
public
void
setTitanUrl
(
String
titanUrl
)
{
this
.
titanUrl
=
titanUrl
;
}
public
String
getTitanDbname
()
{
return
titanDbname
;
}
public
void
setTitanDbname
(
String
titanDbname
)
{
this
.
titanDbname
=
titanDbname
;
}
}
apollo-configservice/src/main/java/com/ctrip/apollo/ServerApplication.java
View file @
fe7cd269
...
...
@@ -3,6 +3,7 @@ package com.ctrip.apollo;
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
;
/**
* Spring boot application entry point
...
...
@@ -13,7 +14,8 @@ import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@EnableEurekaServer
public
class
ServerApplication
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
ConfigurableApplicationContext
context
=
new
SpringApplicationBuilder
(
ServerApplication
.
class
).
web
(
true
).
run
(
args
);
}
...
...
apollo-configservice/src/main/java/com/ctrip/apollo/metaservice/controller/ServiceController.java
View file @
fe7cd269
...
...
@@ -8,8 +8,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
@RestController
@RequestMapping
(
"/services"
)
...
...
@@ -22,42 +23,54 @@ public class ServiceController {
@RequestMapping
(
"/meta"
)
public
List
<
ServiceDTO
>
getMetaService
()
{
List
<
InstanceInfo
>
instances
=
discoveryService
.
getMetaServiceInstances
();
List
<
ServiceDTO
>
result
=
new
ArrayList
<
ServiceDTO
>();
for
(
InstanceInfo
instance
:
instances
)
{
List
<
ServiceDTO
>
result
=
instances
.
stream
().
map
(
new
Function
<
InstanceInfo
,
ServiceDTO
>()
{
@Override
public
ServiceDTO
apply
(
InstanceInfo
instance
)
{
ServiceDTO
service
=
new
ServiceDTO
();
service
.
setAppName
(
instance
.
getAppName
());
service
.
setInstanceId
(
instance
.
getInstanceId
());
service
.
setHomepageUrl
(
instance
.
getHomePageUrl
());
result
.
add
(
service
)
;
return
service
;
}
}).
collect
(
Collectors
.
toList
());
return
result
;
}
@RequestMapping
(
"/config"
)
public
List
<
ServiceDTO
>
getConfigService
()
{
List
<
InstanceInfo
>
instances
=
discoveryService
.
getConfigServiceInstances
();
List
<
ServiceDTO
>
result
=
new
ArrayList
<
ServiceDTO
>();
for
(
InstanceInfo
instance
:
instances
)
{
List
<
ServiceDTO
>
result
=
instances
.
stream
().
map
(
new
Function
<
InstanceInfo
,
ServiceDTO
>()
{
@Override
public
ServiceDTO
apply
(
InstanceInfo
instance
)
{
ServiceDTO
service
=
new
ServiceDTO
();
service
.
setAppName
(
instance
.
getAppName
());
service
.
setInstanceId
(
instance
.
getInstanceId
());
service
.
setHomepageUrl
(
instance
.
getHomePageUrl
());
result
.
add
(
service
)
;
return
service
;
}
}).
collect
(
Collectors
.
toList
());
return
result
;
}
@RequestMapping
(
"/admin"
)
public
List
<
ServiceDTO
>
getAdminService
()
{
List
<
InstanceInfo
>
instances
=
discoveryService
.
getAdminServiceInstances
();
List
<
ServiceDTO
>
result
=
new
ArrayList
<
ServiceDTO
>();
for
(
InstanceInfo
instance
:
instances
)
{
List
<
ServiceDTO
>
result
=
instances
.
stream
().
map
(
new
Function
<
InstanceInfo
,
ServiceDTO
>()
{
@Override
public
ServiceDTO
apply
(
InstanceInfo
instance
)
{
ServiceDTO
service
=
new
ServiceDTO
();
service
.
setAppName
(
instance
.
getAppName
());
service
.
setInstanceId
(
instance
.
getInstanceId
());
service
.
setHomepageUrl
(
instance
.
getHomePageUrl
());
result
.
add
(
service
)
;
return
service
;
}
}).
collect
(
Collectors
.
toList
());
return
result
;
}
}
pom.xml
View file @
fe7cd269
...
...
@@ -274,6 +274,36 @@
</plugins>
</build>
</profile>
<profile>
<id>
local
</id>
<activation>
<activeByDefault>
true
</activeByDefault>
</activation>
</profile>
<profile>
<id>
ctrip
</id>
<dependencies>
<dependency>
<groupId>
com.ctrip.platform
</groupId>
<artifactId>
ctrip-dal-client
</artifactId>
<version>
1.0.1.6
</version>
<exclusions>
<exclusion>
<artifactId>
logback-core
</artifactId>
<groupId>
ch.qos.logback
</groupId>
</exclusion>
<exclusion>
<artifactId>
logback-classic
</artifactId>
<groupId>
ch.qos.logback
</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
ch.qos.logback
</groupId>
<artifactId>
logback-classic
</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
<repositories>
...
...
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