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
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
197 additions
and
59 deletions
+197
-59
pom.xml
apollo-biz/pom.xml
+47
-32
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
+4
-2
ServiceController.java
...trip/apollo/metaservice/controller/ServiceController.java
+38
-25
pom.xml
pom.xml
+30
-0
No files found.
apollo-biz/pom.xml
View file @
fe7cd269
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
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"
>
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<parent>
<artifactId>
apollo
</artifactId>
<artifactId>
apollo
</artifactId>
<groupId>
com.ctrip.apollo
</groupId>
<groupId>
com.ctrip.apollo
</groupId>
<version>
0.0.1-SNAPSHOT
</version>
<version>
0.0.1-SNAPSHOT
</version>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
apollo-biz
</artifactId>
<artifactId>
apollo-biz
</artifactId>
<name>
Apollo Biz
</name>
<name>
Apollo Biz
</name>
<packaging>
jar
</packaging>
<packaging>
jar
</packaging>
<dependencies>
<dependency>
<groupId>
com.ctrip.apollo
</groupId>
<artifactId>
apollo-core
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-jpa
</artifactId>
</dependency>
<dependency>
<groupId>
com.h2database
</groupId>
<artifactId>
h2
</artifactId>
</dependency>
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<scope>
runtime
</scope>
</dependency>
</dependencies>
<dependencies>
<dependency>
<groupId>
com.ctrip.apollo
</groupId>
<artifactId>
apollo-core
</artifactId>
</dependency>
<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>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
</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;
...
@@ -3,6 +3,7 @@ package com.ctrip.apollo;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.cloud.netflix.eureka.server.EnableEurekaServer
;
import
org.springframework.cloud.netflix.eureka.server.EnableEurekaServer
;
import
org.springframework.context.ConfigurableApplicationContext
;
/**
/**
* Spring boot application entry point
* Spring boot application entry point
...
@@ -13,8 +14,9 @@ import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
...
@@ -13,8 +14,9 @@ import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@EnableEurekaServer
@EnableEurekaServer
public
class
ServerApplication
{
public
class
ServerApplication
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
new
SpringApplicationBuilder
(
ServerApplication
.
class
).
web
(
true
).
run
(
args
);
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;
...
@@ -8,8 +8,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
@RestController
@RestController
@RequestMapping
(
"/services"
)
@RequestMapping
(
"/services"
)
...
@@ -22,42 +23,54 @@ public class ServiceController {
...
@@ -22,42 +23,54 @@ public class ServiceController {
@RequestMapping
(
"/meta"
)
@RequestMapping
(
"/meta"
)
public
List
<
ServiceDTO
>
getMetaService
()
{
public
List
<
ServiceDTO
>
getMetaService
()
{
List
<
InstanceInfo
>
instances
=
discoveryService
.
getMetaServiceInstances
();
List
<
InstanceInfo
>
instances
=
discoveryService
.
getMetaServiceInstances
();
List
<
ServiceDTO
>
result
=
new
ArrayList
<
ServiceDTO
>();
List
<
ServiceDTO
>
result
=
instances
.
stream
().
map
(
new
Function
<
InstanceInfo
,
ServiceDTO
>()
{
for
(
InstanceInfo
instance
:
instances
)
{
ServiceDTO
service
=
new
ServiceDTO
();
@Override
service
.
setAppName
(
instance
.
getAppName
());
public
ServiceDTO
apply
(
InstanceInfo
instance
)
{
service
.
setInstanceId
(
instance
.
getInstanceId
());
ServiceDTO
service
=
new
ServiceDTO
();
service
.
setHomepageUrl
(
instance
.
getHomePageUrl
());
service
.
setAppName
(
instance
.
getAppName
());
result
.
add
(
service
);
service
.
setInstanceId
(
instance
.
getInstanceId
());
}
service
.
setHomepageUrl
(
instance
.
getHomePageUrl
());
return
service
;
}
}).
collect
(
Collectors
.
toList
());
return
result
;
return
result
;
}
}
@RequestMapping
(
"/config"
)
@RequestMapping
(
"/config"
)
public
List
<
ServiceDTO
>
getConfigService
()
{
public
List
<
ServiceDTO
>
getConfigService
()
{
List
<
InstanceInfo
>
instances
=
discoveryService
.
getConfigServiceInstances
();
List
<
InstanceInfo
>
instances
=
discoveryService
.
getConfigServiceInstances
();
List
<
ServiceDTO
>
result
=
new
ArrayList
<
ServiceDTO
>();
List
<
ServiceDTO
>
result
=
instances
.
stream
().
map
(
new
Function
<
InstanceInfo
,
ServiceDTO
>()
{
for
(
InstanceInfo
instance
:
instances
)
{
ServiceDTO
service
=
new
ServiceDTO
();
@Override
service
.
setAppName
(
instance
.
getAppName
());
public
ServiceDTO
apply
(
InstanceInfo
instance
)
{
service
.
setInstanceId
(
instance
.
getInstanceId
());
ServiceDTO
service
=
new
ServiceDTO
();
service
.
setHomepageUrl
(
instance
.
getHomePageUrl
());
service
.
setAppName
(
instance
.
getAppName
());
result
.
add
(
service
);
service
.
setInstanceId
(
instance
.
getInstanceId
());
}
service
.
setHomepageUrl
(
instance
.
getHomePageUrl
());
return
service
;
}
}).
collect
(
Collectors
.
toList
());
return
result
;
return
result
;
}
}
@RequestMapping
(
"/admin"
)
@RequestMapping
(
"/admin"
)
public
List
<
ServiceDTO
>
getAdminService
()
{
public
List
<
ServiceDTO
>
getAdminService
()
{
List
<
InstanceInfo
>
instances
=
discoveryService
.
getAdminServiceInstances
();
List
<
InstanceInfo
>
instances
=
discoveryService
.
getAdminServiceInstances
();
List
<
ServiceDTO
>
result
=
new
ArrayList
<
ServiceDTO
>();
List
<
ServiceDTO
>
result
=
instances
.
stream
().
map
(
new
Function
<
InstanceInfo
,
ServiceDTO
>()
{
for
(
InstanceInfo
instance
:
instances
)
{
ServiceDTO
service
=
new
ServiceDTO
();
@Override
service
.
setAppName
(
instance
.
getAppName
());
public
ServiceDTO
apply
(
InstanceInfo
instance
)
{
service
.
setInstanceId
(
instance
.
getInstanceId
());
ServiceDTO
service
=
new
ServiceDTO
();
service
.
setHomepageUrl
(
instance
.
getHomePageUrl
());
service
.
setAppName
(
instance
.
getAppName
());
result
.
add
(
service
);
service
.
setInstanceId
(
instance
.
getInstanceId
());
}
service
.
setHomepageUrl
(
instance
.
getHomePageUrl
());
return
service
;
}
}).
collect
(
Collectors
.
toList
());
return
result
;
return
result
;
}
}
}
}
pom.xml
View file @
fe7cd269
...
@@ -274,6 +274,36 @@
...
@@ -274,6 +274,36 @@
</plugins>
</plugins>
</build>
</build>
</profile>
</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>
</profiles>
<repositories>
<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