Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
discovery
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
谢捷峰
discovery
Commits
52317fdc
Commit
52317fdc
authored
Jun 23, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
重构类结构
parent
c6c62f83
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
27 additions
and
33 deletions
+27
-33
discovery-plugin-admin-center/src/main/java/com/nepxion/discovery/plugin/admincenter/endpoint/AdminEndpoint.java
+1
-1
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/ConfigSubscriber.java
+12
-23
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/configuration/ConfigAutoConfiguration.java
+3
-3
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/loader/AbstractConfigLoader.java
+7
-1
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/loader/ConfigLoader.java
+3
-3
discovery-springcloud-example-a/src/main/java/com/nepxion/discovery/plugin/example/impl/DiscoveryConfigLoader.java
+1
-2
No files found.
discovery-plugin-admin-center/src/main/java/com/nepxion/discovery/plugin/admincenter/endpoint/AdminEndpoint.java
View file @
52317fdc
...
...
@@ -60,7 +60,7 @@ public class AdminEndpoint implements MvcEndpoint, ApplicationContextAware, Envi
public
Object
filter
(
@RequestParam
(
"serviceId"
)
String
serviceId
,
@RequestParam
(
"ip"
)
String
ip
)
{
Boolean
discoveryControlEnabled
=
environment
.
getProperty
(
PluginConstant
.
SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED
,
Boolean
.
class
);
if
(!
discoveryControlEnabled
)
{
return
new
ResponseEntity
<>(
Collections
.
singletonMap
(
"Message"
,
"
Admin endpoint
is disabled"
),
HttpStatus
.
NOT_FOUND
);
return
new
ResponseEntity
<>(
Collections
.
singletonMap
(
"Message"
,
"
Discovery control
is disabled"
),
HttpStatus
.
NOT_FOUND
);
}
pluginCache
.
put
(
serviceId
,
ip
);
...
...
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/Config
Retriev
er.java
→
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/Config
Subscrib
er.java
View file @
52317fdc
...
...
@@ -29,8 +29,8 @@ import com.nepxion.eventbus.annotation.EventBus;
import
com.nepxion.eventbus.core.Event
;
@EventBus
public
class
Config
Retriev
er
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
Config
Retriev
er
.
class
);
public
class
Config
Subscrib
er
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
Config
Subscrib
er
.
class
);
@Value
(
"${"
+
ConfigConstant
.
SPRING_APPLICATION_DISCOVERY_REMOTE_CONFIG_ENABLED
+
":false}"
)
private
Boolean
remoteConfigEnabled
;
...
...
@@ -42,26 +42,16 @@ public class ConfigRetriever {
private
ConfigParser
configParser
;
@PostConstruct
public
void
initialize
()
throws
PluginException
{
public
void
initialize
()
{
LOG
.
info
(
"********** {} config starts to initialize **********"
,
remoteConfigEnabled
?
"Remote"
:
"Local"
);
InputStream
inputStream
=
null
;
try
{
if
(
remoteConfigEnabled
)
{
inputStream
=
configLoader
.
getRemoteInputStream
();
}
else
{
inputStream
=
configLoader
.
getLocalInputStream
();
}
parse
(
inputStream
);
}
catch
(
IOException
e
)
{
throw
new
PluginException
(
e
);
}
catch
(
DocumentException
e
)
{
throw
new
PluginException
(
e
);
}
finally
{
if
(
inputStream
!=
null
)
{
IOUtils
.
closeQuietly
(
inputStream
);
}
}
}
@Subscribe
...
...
@@ -73,8 +63,16 @@ public class ConfigRetriever {
LOG
.
info
(
"********** Remote config change has been retrieved **********"
);
InputStream
inputStream
=
(
InputStream
)
event
.
getSource
();
try
{
parse
(
inputStream
);
}
private
void
parse
(
InputStream
inputStream
)
{
if
(
inputStream
==
null
)
{
throw
new
PluginException
(
"Failed to load "
+
(
remoteConfigEnabled
?
"remote"
:
"local"
)
+
" config, no input stream returns"
);
}
try
{
configParser
.
parse
(
inputStream
);
}
catch
(
IOException
e
)
{
throw
new
PluginException
(
e
);
}
catch
(
DocumentException
e
)
{
...
...
@@ -85,12 +83,4 @@ public class ConfigRetriever {
}
}
}
private
void
parse
(
InputStream
inputStream
)
throws
DocumentException
,
IOException
{
if
(
inputStream
==
null
)
{
throw
new
PluginException
(
"Failed to load "
+
(
remoteConfigEnabled
?
"remote"
:
"local"
)
+
" config, no input stream returns"
);
}
configParser
.
parse
(
inputStream
);
}
}
\ No newline at end of file
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/configuration/ConfigAutoConfiguration.java
View file @
52317fdc
...
...
@@ -14,7 +14,7 @@ import org.springframework.context.annotation.Configuration;
import
com.nepxion.discovery.plugin.configcenter.ConfigParser
;
import
com.nepxion.discovery.plugin.configcenter.ConfigPublisher
;
import
com.nepxion.discovery.plugin.configcenter.Config
Retriev
er
;
import
com.nepxion.discovery.plugin.configcenter.Config
Subscrib
er
;
@Configuration
public
class
ConfigAutoConfiguration
{
...
...
@@ -24,8 +24,8 @@ public class ConfigAutoConfiguration {
}
@Bean
public
Config
Retriever
configRetriev
er
()
{
return
new
Config
Retriev
er
();
public
Config
Subscriber
configSubscrib
er
()
{
return
new
Config
Subscrib
er
();
}
@Bean
...
...
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/loader/AbstractConfigLoader.java
View file @
52317fdc
...
...
@@ -16,12 +16,14 @@ import org.apache.commons.lang3.StringUtils;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationContext
;
import
com.nepxion.discovery.plugin.framework.exception.PluginException
;
public
abstract
class
AbstractConfigLoader
implements
ConfigLoader
{
@Autowired
private
ApplicationContext
applicationContext
;
@Override
public
InputStream
getLocalInputStream
()
throws
IOException
{
public
InputStream
getLocalInputStream
()
{
String
localContextPath
=
getLocalContextPath
();
if
(
StringUtils
.
isEmpty
(
localContextPath
))
{
return
null
;
...
...
@@ -29,7 +31,11 @@ public abstract class AbstractConfigLoader implements ConfigLoader {
String
localFilePath
=
applicationContext
.
getEnvironment
().
resolvePlaceholders
(
localContextPath
);
try
{
return
applicationContext
.
getResource
(
localFilePath
).
getInputStream
();
}
catch
(
IOException
e
)
{
throw
new
PluginException
(
e
);
}
}
protected
abstract
String
getLocalContextPath
();
...
...
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/loader/ConfigLoader.java
View file @
52317fdc
...
...
@@ -9,11 +9,10 @@ package com.nepxion.discovery.plugin.configcenter.loader;
* @version 1.0
*/
import
java.io.IOException
;
import
java.io.InputStream
;
public
interface
ConfigLoader
{
InputStream
getLocalInputStream
()
throws
IOException
;
InputStream
getLocalInputStream
();
InputStream
getRemoteInputStream
()
throws
IOException
;
InputStream
getRemoteInputStream
();
}
\ No newline at end of file
discovery-springcloud-example-a/src/main/java/com/nepxion/discovery/plugin/example/impl/DiscoveryConfigLoader.java
View file @
52317fdc
...
...
@@ -12,7 +12,6 @@ package com.nepxion.discovery.plugin.example.impl;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
com.nepxion.discovery.plugin.configcenter.loader.AbstractConfigLoader
;
...
...
@@ -20,7 +19,7 @@ import com.nepxion.discovery.plugin.configcenter.loader.AbstractConfigLoader;
// 模拟从本地配置或远程配置中心获取配置
public
class
DiscoveryConfigLoader
extends
AbstractConfigLoader
{
@Override
public
InputStream
getRemoteInputStream
()
throws
IOException
{
public
InputStream
getRemoteInputStream
()
{
// 本地文件模拟代替远程文件
return
getInputStream
(
"src/main/resources/rule1.xml"
);
}
...
...
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