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
2aa333d8
Commit
2aa333d8
authored
Jul 08, 2016
by
Jason Song
Committed by
GitHub
Jul 08, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #317 from qmwu2000/master
add ApolloDataSourceProvider
parents
39455953
de3b726c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
0 deletions
+80
-0
pom.xml
apollo-client/pom.xml
+8
-0
ApolloDataSourceProvider.java
...m/ctrip/framework/apollo/ds/ApolloDataSourceProvider.java
+72
-0
No files found.
apollo-client/pom.xml
View file @
2aa333d8
...
...
@@ -65,5 +65,13 @@
<scope>
test
</scope>
</dependency>
<!-- end of test -->
<!-- dal-jdbc -->
<dependency>
<groupId>
org.unidal.framework
</groupId>
<artifactId>
dal-jdbc
</artifactId>
<version>
2.4.0
</version>
<scope>
provided
</scope>
</dependency>
<!-- end of dal-jdbc -->
</dependencies>
</project>
apollo-client/src/main/java/com/ctrip/framework/apollo/ds/ApolloDataSourceProvider.java
0 → 100644
View file @
2aa333d8
package
com
.
ctrip
.
framework
.
apollo
.
ds
;
import
org.codehaus.plexus.logging.LogEnabled
;
import
org.codehaus.plexus.logging.Logger
;
import
org.unidal.dal.jdbc.datasource.DataSourceProvider
;
import
org.unidal.dal.jdbc.datasource.model.entity.DataSourcesDef
;
import
org.unidal.dal.jdbc.datasource.model.transform.DefaultSaxParser
;
import
org.unidal.lookup.annotation.Named
;
import
com.ctrip.framework.apollo.ConfigFile
;
import
com.ctrip.framework.apollo.ConfigService
;
import
com.ctrip.framework.apollo.core.enums.ConfigFileFormat
;
import
com.ctrip.framework.foundation.Foundation
;
/**
* Data source provider based on Apollo configuration service.
* <p>
*
* Use following component definition to replace default
* <code>DataSourceProvider</code>:
* <p>
* <code><pre>
* public List<Component> defineComponents() {
* List<Component> all = new ArrayList<>();
*
* all.add(A(ApolloDataSourceProvider.class));
*
* return all;
* }
* </pre></code>
*
* <b>WARNING:</b> all defined <code>DataSourceProvider</code> components will
* be taken affect. DO NOT define unused <code>DataSourceProvider</code>
* component.
*/
@Named
(
type
=
DataSourceProvider
.
class
,
value
=
"apollo"
)
public
class
ApolloDataSourceProvider
implements
DataSourceProvider
,
LogEnabled
{
private
Logger
m_logger
;
private
DataSourcesDef
m_def
;
@Override
public
DataSourcesDef
defineDatasources
()
{
if
(
m_def
==
null
)
{
ConfigFile
file
=
ConfigService
.
getConfigFile
(
"datasources"
,
ConfigFileFormat
.
XML
);
String
appId
=
Foundation
.
app
().
getAppId
();
String
envType
=
Foundation
.
server
().
getEnvType
();
if
(
file
.
hasContent
())
{
String
content
=
file
.
getContent
();
m_logger
.
info
(
String
.
format
(
"Found datasources.xml from Apollo(env=%s, app.id=%s)!"
,
envType
,
appId
));
try
{
m_def
=
DefaultSaxParser
.
parse
(
content
);
}
catch
(
Exception
e
)
{
throw
new
IllegalStateException
(
String
.
format
(
"Error when parsing datasources.xml from Apollo(env=%s, app.id=%s)!"
,
envType
,
appId
),
e
);
}
}
else
{
m_logger
.
warn
(
String
.
format
(
"Can't get datasources.xml from Apollo(env=%s, app.id=%s)!"
,
envType
,
appId
));
m_def
=
new
DataSourcesDef
();
}
}
return
m_def
;
}
@Override
public
void
enableLogging
(
Logger
logger
)
{
m_logger
=
logger
;
}
}
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