Repository: incubator-unomi Updated Branches: refs/heads/master 94b6af7fa -> daaa332a2
UNOMI-91 : Add internal address in the cluster/node info returned Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/daaa332a Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/daaa332a Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/daaa332a Branch: refs/heads/master Commit: daaa332a2ed6b8296db881c0e7b291d81bd2a481 Parents: 94b6af7 Author: Abdelkader Midani <amid...@apache.org> Authored: Thu Apr 6 16:00:09 2017 +0200 Committer: Abdelkader Midani <amid...@apache.org> Committed: Thu Apr 6 16:00:44 2017 +0200 ---------------------------------------------------------------------- .../java/org/apache/unomi/api/ClusterNode.java | 38 ++++++++++++++++++++ .../services/services/ClusterServiceImpl.java | 19 ++++++++++ .../resources/OSGI-INF/blueprint/blueprint.xml | 4 +++ .../main/resources/org.apache.unomi.cluster.cfg | 2 ++ 4 files changed, 63 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/daaa332a/api/src/main/java/org/apache/unomi/api/ClusterNode.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/ClusterNode.java b/api/src/main/java/org/apache/unomi/api/ClusterNode.java index ba4d579..6aee44e 100644 --- a/api/src/main/java/org/apache/unomi/api/ClusterNode.java +++ b/api/src/main/java/org/apache/unomi/api/ClusterNode.java @@ -32,6 +32,8 @@ public class ClusterNode implements Serializable { private int publicPort; private String secureHostAddress; private int securePort; + private String internalHostAddress; + private int internalPort; private long uptime; private boolean master; private boolean data; @@ -133,6 +135,42 @@ public class ClusterNode implements Serializable { } /** + * Retrieves the secure host address which uses the HTTP/HTTPS protocol for communications between clients and the context server. + * + * @return the secure host address + */ + public String getInternalHostAddress() { + return internalHostAddress; + } + + /** + * Sets the internal host address which uses the HTTP/HTTPS protocol for communications between clients and the context server. + * + * @param internalHostAddress the internal host address + */ + public void setInternalHostAddress(String internalHostAddress) { + this.internalHostAddress = internalHostAddress; + } + + /** + * Retrieves the internal port. + * + * @return the internal port + */ + public int getInternalPort() { + return internalPort; + } + + /** + * Sets the internal port. + * + * @param internalPort the internal port + */ + public void setInternalPort(int internalPort) { + this.internalPort = internalPort; + } + + /** * Retrieves the load average for the last minute, five minutes and fifteen minutes. * * @return an array of {@code double} containing, in order and starting from index {@code 0}, the load average for the last minute, last five minutes and last fifteen minutes http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/daaa332a/services/src/main/java/org/apache/unomi/services/services/ClusterServiceImpl.java ---------------------------------------------------------------------- diff --git a/services/src/main/java/org/apache/unomi/services/services/ClusterServiceImpl.java b/services/src/main/java/org/apache/unomi/services/services/ClusterServiceImpl.java index 0e9744c..4055080 100644 --- a/services/src/main/java/org/apache/unomi/services/services/ClusterServiceImpl.java +++ b/services/src/main/java/org/apache/unomi/services/services/ClusterServiceImpl.java @@ -51,6 +51,7 @@ public class ClusterServiceImpl implements ClusterService { public static final String KARAF_CELLAR_CLUSTER_NODE_CONFIGURATION = "org.apache.unomi.nodes"; public static final String KARAF_CLUSTER_CONFIGURATION_PUBLIC_ENDPOINTS = "publicEndpoints"; public static final String KARAF_CLUSTER_CONFIGURATION_SECURE_ENDPOINTS = "secureEndpoints"; + public static final String KARAF_CLUSTER_CONFIGURATION_INTERNAL_ENDPOINTS = "internalEndpoints"; private ClusterManager karafCellarClusterManager; private EventProducer karafCellarEventProducer; @@ -64,6 +65,8 @@ public class ClusterServiceImpl implements ClusterService { private String port; private String secureAddress; private String securePort; + private String internalAddress; + private String internalPort; private Map<String,JMXConnector> jmxConnectors = new LinkedHashMap<>(); @@ -121,6 +124,14 @@ public class ClusterServiceImpl implements ClusterService { this.securePort = securePort; } + public void setInternalAddress(String internalAddress) { + this.internalAddress = internalAddress; + } + + public void setInternalPort(String internalPort) { + this.internalPort = internalPort; + } + public void init() { if (karafCellarEventProducer != null && karafCellarClusterManager != null) { @@ -193,9 +204,11 @@ public class ClusterServiceImpl implements ClusterService { Properties karafCellarClusterNodeConfiguration = clusterConfigurations.get(KARAF_CELLAR_CLUSTER_NODE_CONFIGURATION); Map<String, String> publicNodeEndpoints = new TreeMap<>(); Map<String, String> secureNodeEndpoints = new TreeMap<>(); + Map<String, String> internalNodeEndpoints = new TreeMap<>(); if (karafCellarClusterNodeConfiguration != null) { publicNodeEndpoints = getMapProperty(karafCellarClusterNodeConfiguration, KARAF_CLUSTER_CONFIGURATION_PUBLIC_ENDPOINTS, thisKarafNode.getId() + "=" + address + ":" + port); secureNodeEndpoints = getMapProperty(karafCellarClusterNodeConfiguration, KARAF_CLUSTER_CONFIGURATION_SECURE_ENDPOINTS, thisKarafNode.getId() + "=" + secureAddress + ":" + securePort); + internalNodeEndpoints = getMapProperty(karafCellarClusterNodeConfiguration, KARAF_CLUSTER_CONFIGURATION_INTERNAL_ENDPOINTS, thisKarafNode.getId() + "=" + internalAddress + ":" + internalPort); } for (org.apache.karaf.cellar.core.Node karafCellarNode : karafCellarNodes) { ClusterNode clusterNode = new ClusterNode(); @@ -213,6 +226,12 @@ public class ClusterServiceImpl implements ClusterService { clusterNode.setMaster(false); clusterNode.setData(false); } + String internalEndpoint = internalNodeEndpoints.get(karafCellarNode.getId()); + if (internalEndpoint != null) { + String[] internalEndpointParts = internalEndpoint.split(":"); + clusterNode.setInternalHostAddress(internalEndpointParts[0]); + clusterNode.setInternalPort(Integer.parseInt(internalEndpointParts[1])); + } try { String serviceUrl = "service:jmx:rmi:///jndi/rmi://"+karafCellarNode.getHost() + ":"+karafJMXPort+"/karaf-root"; JMXConnector jmxConnector = getJMXConnector(serviceUrl); http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/daaa332a/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml ---------------------------------------------------------------------- diff --git a/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml index c5dfdd6..fa2d3dd 100644 --- a/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ b/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -44,6 +44,8 @@ <cm:property name="contextserver.port" value="8181"/> <cm:property name="contextserver.secureAddress" value="localhost"/> <cm:property name="contextserver.securePort" value="9443"/> + <cm:property name="contextserver.internalAddress" value="127.0.0.1"/> + <cm:property name="contextserver.internalPort" value="8181"/> </cm:default-properties> </cm:property-placeholder> @@ -162,6 +164,8 @@ <property name="port" value="${cluster.contextserver.port}"/> <property name="secureAddress" value="${cluster.contextserver.secureAddress}"/> <property name="securePort" value="${cluster.contextserver.securePort}"/> + <property name="internalAddress" value="${cluster.contextserver.internalAddress}"/> + <property name="internalPort" value="${cluster.contextserver.internalPort}"/> <property name="persistenceService" ref="persistenceService"/> <property name="karafCellarClusterManager" ref="karafCellarClusterManager" /> <property name="karafCellarEventProducer" ref="karafCellarEventProducer" /> http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/daaa332a/services/src/main/resources/org.apache.unomi.cluster.cfg ---------------------------------------------------------------------- diff --git a/services/src/main/resources/org.apache.unomi.cluster.cfg b/services/src/main/resources/org.apache.unomi.cluster.cfg index f2bf05a..f4beddf 100644 --- a/services/src/main/resources/org.apache.unomi.cluster.cfg +++ b/services/src/main/resources/org.apache.unomi.cluster.cfg @@ -22,3 +22,5 @@ contextserver.address=localhost contextserver.port=8181 contextserver.secureAddress=localhost contextserver.securePort=9443 +contextserver.internalAddress=127.0.0.1 +contextserver.internalPort=8181