Commit 770f14b1 by Nepxion

增加在线查看配置功能

parent 26ce3bfd
...@@ -152,6 +152,12 @@ public class DiscoveryConfigSubscriber { ...@@ -152,6 +152,12 @@ public class DiscoveryConfigSubscriber {
利用Post执行http://IP:PORT/admin/config,发送的内容即规则XML 利用Post执行http://IP:PORT/admin/config,发送的内容即规则XML
``` ```
## 查看配置
使用者可以通过Rest方式主动向一个微服务推送配置信息,但该方式只能每次推送到一个微服务上
```xml
利用Get执行http://IP:PORT/admin/view
```
## 示例 ## 示例
### B服务实现 ### B服务实现
B服务的两个实例B1、B2和B3采用标准的Spring Cloud入口,参考discovery-springcloud-example-b1、discovery-springcloud-example-b2和discovery-springcloud-example-b3工程 B服务的两个实例B1、B2和B3采用标准的Spring Cloud入口,参考discovery-springcloud-example-b1、discovery-springcloud-example-b2和discovery-springcloud-example-b3工程
......
...@@ -34,6 +34,7 @@ import org.springframework.web.bind.annotation.RequestMethod; ...@@ -34,6 +34,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import com.nepxion.discovery.plugin.framework.constant.PluginConstant; import com.nepxion.discovery.plugin.framework.constant.PluginConstant;
import com.nepxion.discovery.plugin.framework.entity.RuleEntity;
import com.nepxion.discovery.plugin.framework.event.PluginPublisher; import com.nepxion.discovery.plugin.framework.event.PluginPublisher;
import com.nepxion.discovery.plugin.framework.exception.PluginException; import com.nepxion.discovery.plugin.framework.exception.PluginException;
...@@ -50,6 +51,9 @@ public class AdminEndpoint extends AbstractMvcEndpoint implements ApplicationCon ...@@ -50,6 +51,9 @@ public class AdminEndpoint extends AbstractMvcEndpoint implements ApplicationCon
@Autowired @Autowired
private PluginPublisher pluginPublisher; private PluginPublisher pluginPublisher;
@Autowired
private RuleEntity ruleEntity;
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public AdminEndpoint(ServiceRegistry serviceRegistry) { public AdminEndpoint(ServiceRegistry serviceRegistry) {
super("/admin", true, true); super("/admin", true, true);
...@@ -84,6 +88,17 @@ public class AdminEndpoint extends AbstractMvcEndpoint implements ApplicationCon ...@@ -84,6 +88,17 @@ public class AdminEndpoint extends AbstractMvcEndpoint implements ApplicationCon
return "success"; return "success";
} }
@RequestMapping(path = "view", method = RequestMethod.GET)
@ResponseBody
@ManagedOperation
public Object view() {
if (registration == null) {
throw new PluginException("No registration found");
}
return ruleEntity.getContent();
}
@RequestMapping(path = "status", method = RequestMethod.POST) @RequestMapping(path = "status", method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ManagedOperation @ManagedOperation
......
...@@ -77,16 +77,18 @@ public class ConfigParser extends Dom4JParser { ...@@ -77,16 +77,18 @@ public class ConfigParser extends Dom4JParser {
} }
} }
String text = getText();
try { try {
reentrantReadWriteLock.writeLock().lock(); reentrantReadWriteLock.writeLock().lock();
ruleEntity.setRegisterEntity(registerEntity); ruleEntity.setRegisterEntity(registerEntity);
ruleEntity.setDiscoveryEntity(discoveryEntity); ruleEntity.setDiscoveryEntity(discoveryEntity);
ruleEntity.setContent(text);
} finally { } finally {
reentrantReadWriteLock.writeLock().unlock(); reentrantReadWriteLock.writeLock().unlock();
} }
LOG.info("Rule entity=\n{}", ruleEntity); LOG.info("Rule xml=\n{}", text);
} }
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
......
...@@ -102,7 +102,9 @@ public class ConfigSubscriber { ...@@ -102,7 +102,9 @@ public class ConfigSubscriber {
} }
try { try {
configParser.parse(inputStream); String content = IOUtils.toString(inputStream, PluginConstant.ENCODING_UTF_8);
configParser.parse(content);
} catch (IOException e) { } catch (IOException e) {
throw new PluginException(e); throw new PluginException(e);
} catch (DocumentException e) { } catch (DocumentException e) {
......
...@@ -19,39 +19,55 @@ import org.dom4j.DocumentException; ...@@ -19,39 +19,55 @@ import org.dom4j.DocumentException;
import org.dom4j.Element; import org.dom4j.Element;
public abstract class Dom4JParser { public abstract class Dom4JParser {
private String text;
private File file;
private InputStream inputStream;
public void parse(String text) throws DocumentException { public void parse(String text) throws DocumentException {
Document document = Dom4JReader.getDocument(text); Document document = Dom4JReader.getDocument(text);
this.text = text;
parse(document); parse(document);
} }
public void parseFormat(String text) throws DocumentException, UnsupportedEncodingException { public void parseFormat(String text) throws DocumentException, UnsupportedEncodingException {
Document document = Dom4JReader.getFormatDocument(text); Document document = Dom4JReader.getFormatDocument(text);
this.text = text;
parse(document); parse(document);
} }
public void parse(File file) throws DocumentException, IOException, UnsupportedEncodingException { public void parse(File file) throws DocumentException, IOException, UnsupportedEncodingException {
Document document = Dom4JReader.getDocument(file); Document document = Dom4JReader.getDocument(file);
this.file = file;
parse(document); parse(document);
} }
public void parseFormat(File file) throws DocumentException, IOException, UnsupportedEncodingException { public void parseFormat(File file) throws DocumentException, IOException, UnsupportedEncodingException {
Document document = Dom4JReader.getFormatDocument(file); Document document = Dom4JReader.getFormatDocument(file);
this.file = file;
parse(document); parse(document);
} }
public void parse(InputStream inputStream) throws DocumentException, IOException { public void parse(InputStream inputStream) throws DocumentException, IOException {
Document document = Dom4JReader.getDocument(inputStream); Document document = Dom4JReader.getDocument(inputStream);
this.inputStream = inputStream;
parse(document); parse(document);
} }
public void parseFormat(InputStream inputStream) throws DocumentException, IOException, UnsupportedEncodingException { public void parseFormat(InputStream inputStream) throws DocumentException, IOException, UnsupportedEncodingException {
Document document = Dom4JReader.getFormatDocument(inputStream); Document document = Dom4JReader.getFormatDocument(inputStream);
this.inputStream = inputStream;
parse(document); parse(document);
} }
...@@ -61,5 +77,17 @@ public abstract class Dom4JParser { ...@@ -61,5 +77,17 @@ public abstract class Dom4JParser {
parseRoot(rootElement); parseRoot(rootElement);
} }
public String getText() {
return text;
}
public File getFile() {
return file;
}
public InputStream getInputStream() {
return inputStream;
}
protected abstract void parseRoot(Element element); protected abstract void parseRoot(Element element);
} }
\ No newline at end of file
...@@ -21,6 +21,7 @@ public class RuleEntity implements Serializable { ...@@ -21,6 +21,7 @@ public class RuleEntity implements Serializable {
private RegisterEntity registerEntity; private RegisterEntity registerEntity;
private DiscoveryEntity discoveryEntity; private DiscoveryEntity discoveryEntity;
private String content;
public RegisterEntity getRegisterEntity() { public RegisterEntity getRegisterEntity() {
return registerEntity; return registerEntity;
...@@ -38,6 +39,14 @@ public class RuleEntity implements Serializable { ...@@ -38,6 +39,14 @@ public class RuleEntity implements Serializable {
this.discoveryEntity = discoveryEntity; this.discoveryEntity = discoveryEntity;
} }
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
@Override @Override
public int hashCode() { public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this); return HashCodeBuilder.reflectionHashCode(this);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment