Repository: incubator-unomi Updated Branches: refs/heads/UNOMI-124 [created] d40d3a48a
UNOMI-124 : Introduction of private (internal address) Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/d40d3a48 Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/d40d3a48 Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/d40d3a48 Branch: refs/heads/UNOMI-124 Commit: d40d3a48a7971add77193caababa3068d6af6445 Parents: 7b758ae Author: Abdelkader Midani <[email protected]> Authored: Thu Sep 21 17:07:48 2017 +0200 Committer: Abdelkader Midani <[email protected]> Committed: Thu Sep 21 17:07:48 2017 +0200 ---------------------------------------------------------------------- .../java/org/apache/unomi/api/ClusterNode.java | 98 +++---------------- .../ImportConfigurationServiceEndPoint.java | 4 +- .../services/services/ClusterServiceImpl.java | 99 ++++++-------------- .../resources/OSGI-INF/blueprint/blueprint.xml | 14 +-- .../main/resources/org.apache.unomi.cluster.cfg | 8 +- .../markdown/versions/master/configuration.md | 14 +-- 6 files changed, 54 insertions(+), 183 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/d40d3a48/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 6aee44e..6c40ca2 100644 --- a/api/src/main/java/org/apache/unomi/api/ClusterNode.java +++ b/api/src/main/java/org/apache/unomi/api/ClusterNode.java @@ -28,12 +28,8 @@ public class ClusterNode implements Serializable { private double cpuLoad; private double[] loadAverage; - private String hostAddress; - private int publicPort; - private String secureHostAddress; - private int securePort; + private String publicHostAddress; private String internalHostAddress; - private int internalPort; private long uptime; private boolean master; private boolean data; @@ -63,81 +59,27 @@ public class ClusterNode implements Serializable { } /** - * Retrieves the host address. + * Retrieves the public host address. * - * @return the host address + * @return the public host address */ - public String getHostAddress() { - return hostAddress; + public String getPublicHostAddress() { + return publicHostAddress; } /** - * Sets the host address. + * Sets the public host address. * - * @param hostAddress the host address + * @param publicHostAddress the public host address */ - public void setHostAddress(String hostAddress) { - this.hostAddress = hostAddress; + public void setPublicHostAddress(String publicHostAddress) { + this.publicHostAddress = publicHostAddress; } /** - * Retrieves the public port. + * Retrieves the internal host address which uses the HTTP/HTTPS protocol for communications between clients and the context server. * - * @return the public port - */ - public int getPublicPort() { - return publicPort; - } - - /** - * Sets the public port. - * - * @param publicPort the public port - */ - public void setPublicPort(int publicPort) { - this.publicPort = publicPort; - } - - /** - * Retrieves the secure host address which uses the HTTPS protocol for communications between clients and the context server. - * - * @return the secure host address - */ - public String getSecureHostAddress() { - return secureHostAddress; - } - - /** - * Sets the secure host address which uses the HTTPS protocol for communications between clients and the context server. - * - * @param secureHostAddress the secure host address - */ - public void setSecureHostAddress(String secureHostAddress) { - this.secureHostAddress = secureHostAddress; - } - - /** - * Retrieves the secure port. - * - * @return the secure port - */ - public int getSecurePort() { - return securePort; - } - - /** - * Sets the secure port. - * - * @param securePort the secure port - */ - public void setSecurePort(int securePort) { - this.securePort = securePort; - } - - /** - * Retrieves the secure host address which uses the HTTP/HTTPS protocol for communications between clients and the context server. - * - * @return the secure host address + * @return the internal host address */ public String getInternalHostAddress() { return internalHostAddress; @@ -153,24 +95,6 @@ public class ClusterNode implements Serializable { } /** - * 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/d40d3a48/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ImportConfigurationServiceEndPoint.java ---------------------------------------------------------------------- diff --git a/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ImportConfigurationServiceEndPoint.java b/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ImportConfigurationServiceEndPoint.java index d480c1f..2087e53 100644 --- a/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ImportConfigurationServiceEndPoint.java +++ b/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ImportConfigurationServiceEndPoint.java @@ -82,8 +82,8 @@ public class ImportConfigurationServiceEndPoint extends AbstractConfigurationSer HttpResponse response = httpClient.execute(httpPut); if (response.getStatusLine().getStatusCode() != 200) { - logger.error("Failed to update the running config: Please check the acceccibilty to the URI: \n{}", - "http://localhost234:" + configSharingService.getProperty("internalServerPort") + "/configUpdate/importConfigAdmin"); + logger.error("Failed to update the running config: Please check the accessibility to the URI: \n{}", + "http://localhost:" + configSharingService.getProperty("internalServerPort") + "/configUpdate/importConfigAdmin"); logger.error("HTTP Status code returned {}", response.getStatusLine().getStatusCode()); throw new PartialContentException("RUNNING_CONFIG_UPDATE_FAILED"); } http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/d40d3a48/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 095e2d4..57d8d3e 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 @@ -47,13 +47,11 @@ import java.util.*; */ public class ClusterServiceImpl implements ClusterService { - private static final Logger logger = LoggerFactory.getLogger(ClusterServiceImpl.class.getName()); - 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 static final Logger logger = LoggerFactory.getLogger(ClusterServiceImpl.class.getName()); + PersistenceService persistenceService; private ClusterManager karafCellarClusterManager; private EventProducer karafCellarEventProducer; private GroupManager karafCellarGroupManager; @@ -62,16 +60,9 @@ public class ClusterServiceImpl implements ClusterService { private String karafJMXUsername = "karaf"; private String karafJMXPassword = "karaf"; private int karafJMXPort = 1099; - private String address; - private String port; - private String secureAddress; - private String securePort; + private String publicAddress; private String internalAddress; - private String internalPort; - - private Map<String,JMXConnector> jmxConnectors = new LinkedHashMap<>(); - - PersistenceService persistenceService; + private Map<String, JMXConnector> jmxConnectors = new LinkedHashMap<>(); public void setPersistenceService(PersistenceService persistenceService) { this.persistenceService = persistenceService; @@ -109,30 +100,14 @@ public class ClusterServiceImpl implements ClusterService { this.karafJMXPort = karafJMXPort; } - public void setAddress(String address) { - this.address = address; - } - - public void setPort(String port) { - this.port = port; - } - - public void setSecureAddress(String secureAddress) { - this.secureAddress = secureAddress; - } - - public void setSecurePort(String securePort) { - this.securePort = securePort; + public void setPublicAddress(String publicAddress) { + this.publicAddress = publicAddress; } public void setInternalAddress(String internalAddress) { this.internalAddress = internalAddress; } - public void setInternalPort(String internalPort) { - this.internalPort = internalPort; - } - public void init() { if (karafCellarEventProducer != null && karafCellarClusterManager != null) { @@ -167,12 +142,14 @@ public class ClusterServiceImpl implements ClusterService { if (karafCellarClusterNodeConfiguration == null) { karafCellarClusterNodeConfiguration = new Properties(); } - Map<String,String> publicEndpoints = getMapProperty(karafCellarClusterNodeConfiguration, KARAF_CLUSTER_CONFIGURATION_PUBLIC_ENDPOINTS, thisKarafNode.getId() + "=" + address + ":" + port); - Map<String,String> secureEndpoints = getMapProperty(karafCellarClusterNodeConfiguration, KARAF_CLUSTER_CONFIGURATION_SECURE_ENDPOINTS, thisKarafNode.getId() + "=" + secureAddress + ":" + securePort); - publicEndpoints.put(thisKarafNode.getId(), address + ":" + port); - secureEndpoints.put(thisKarafNode.getId(), secureAddress + ":" + securePort); + Map<String, String> publicEndpoints = getMapProperty(karafCellarClusterNodeConfiguration, KARAF_CLUSTER_CONFIGURATION_PUBLIC_ENDPOINTS, thisKarafNode.getId() + "=" + publicAddress); + publicEndpoints.put(thisKarafNode.getId(), publicAddress); setMapProperty(karafCellarClusterNodeConfiguration, KARAF_CLUSTER_CONFIGURATION_PUBLIC_ENDPOINTS, publicEndpoints); - setMapProperty(karafCellarClusterNodeConfiguration, KARAF_CLUSTER_CONFIGURATION_SECURE_ENDPOINTS, secureEndpoints); + + Map<String, String> internalEndpoints = getMapProperty(karafCellarClusterNodeConfiguration, KARAF_CLUSTER_CONFIGURATION_INTERNAL_ENDPOINTS, thisKarafNode.getId() + "=" + internalAddress); + internalEndpoints.put(thisKarafNode.getId(), internalAddress); + setMapProperty(karafCellarClusterNodeConfiguration, KARAF_CLUSTER_CONFIGURATION_INTERNAL_ENDPOINTS, internalEndpoints); + configurations.put(KARAF_CELLAR_CLUSTER_NODE_CONFIGURATION, karafCellarClusterNodeConfiguration); ClusterConfigurationEvent clusterConfigurationEvent = new ClusterConfigurationEvent(KARAF_CELLAR_CLUSTER_NODE_CONFIGURATION); clusterConfigurationEvent.setSourceGroup(group); @@ -183,7 +160,7 @@ public class ClusterServiceImpl implements ClusterService { } public void destroy() { - for (Map.Entry<String,JMXConnector> jmxConnectorEntry : jmxConnectors.entrySet()) { + for (Map.Entry<String, JMXConnector> jmxConnectorEntry : jmxConnectors.entrySet()) { String url = jmxConnectorEntry.getKey(); JMXConnector jmxConnector = jmxConnectorEntry.getValue(); try { @@ -204,36 +181,22 @@ public class ClusterServiceImpl implements ClusterService { Map<String, Properties> clusterConfigurations = karafCellarClusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + karafCellarGroupName); 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); + publicNodeEndpoints = getMapProperty(karafCellarClusterNodeConfiguration, KARAF_CLUSTER_CONFIGURATION_PUBLIC_ENDPOINTS, thisKarafNode.getId() + "=" + publicAddress); + internalNodeEndpoints = getMapProperty(karafCellarClusterNodeConfiguration, KARAF_CLUSTER_CONFIGURATION_INTERNAL_ENDPOINTS, thisKarafNode.getId() + "=" + internalAddress); } for (org.apache.karaf.cellar.core.Node karafCellarNode : karafCellarNodes) { ClusterNode clusterNode = new ClusterNode(); String publicEndpoint = publicNodeEndpoints.get(karafCellarNode.getId()); if (publicEndpoint != null) { - String[] publicEndpointParts = publicEndpoint.split(":"); - clusterNode.setHostAddress(publicEndpointParts[0]); - clusterNode.setPublicPort(Integer.parseInt(publicEndpointParts[1])); - } - String secureEndpoint = secureNodeEndpoints.get(karafCellarNode.getId()); - if (secureEndpoint != null) { - String[] secureEndpointParts = secureEndpoint.split(":"); - clusterNode.setSecureHostAddress(secureEndpointParts[0]); - clusterNode.setSecurePort(Integer.parseInt(secureEndpointParts[1])); - clusterNode.setMaster(false); - clusterNode.setData(false); + clusterNode.setPublicHostAddress(publicEndpoint); } String internalEndpoint = internalNodeEndpoints.get(karafCellarNode.getId()); if (internalEndpoint != null) { - String[] internalEndpointParts = internalEndpoint.split(":"); - clusterNode.setInternalHostAddress(internalEndpointParts[0]); - clusterNode.setInternalPort(Integer.parseInt(internalEndpointParts[1])); + clusterNode.setInternalHostAddress(internalEndpoint); } - String serviceUrl = "service:jmx:rmi:///jndi/rmi://"+karafCellarNode.getHost() + ":"+karafJMXPort+"/karaf-root"; + String serviceUrl = "service:jmx:rmi:///jndi/rmi://" + karafCellarNode.getHost() + ":" + karafJMXPort + "/karaf-root"; try { JMXConnector jmxConnector = getJMXConnector(serviceUrl); MBeanServerConnection mbsc = jmxConnector.getMBeanServerConnection(); @@ -249,7 +212,7 @@ public class ClusterServiceImpl implements ClusterService { logger.error("Error retrieving system CPU load", e); } final OperatingSystemMXBean remoteOperatingSystemMXBean = ManagementFactory.newPlatformMXBeanProxy(mbsc, ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME, OperatingSystemMXBean.class); - clusterNode.setLoadAverage(new double[] { remoteOperatingSystemMXBean.getSystemLoadAverage()}); + clusterNode.setLoadAverage(new double[]{remoteOperatingSystemMXBean.getSystemLoadAverage()}); if (systemCpuLoad != null) { clusterNode.setCpuLoad(systemCpuLoad); } @@ -260,8 +223,8 @@ public class ClusterServiceImpl implements ClusterService { handleTimeouts(serviceUrl, ce); } catch (java.rmi.ConnectException ce) { handleTimeouts(serviceUrl, ce); - } catch (java.rmi.ConnectIOException coie) { - handleTimeouts(serviceUrl, coie); + } catch (java.rmi.ConnectIOException cioe) { + handleTimeouts(serviceUrl, cioe); } catch (IOException e) { logger.error("Error retrieving remote JMX data", e); } catch (MalformedObjectNameException e) { @@ -307,10 +270,10 @@ public class ClusterServiceImpl implements ClusterService { /** * Check if a configuration is allowed. * - * @param group the cluster group. + * @param group the cluster group. * @param category the configuration category constant. - * @param pid the configuration PID. - * @param type the cluster event type. + * @param pid the configuration PID. + * @param type the cluster event type. * @return true if the cluster event type is allowed, false else. */ public boolean isClusterConfigPIDAllowed(Group group, String category, String pid, EventType type) { @@ -345,23 +308,23 @@ public class ClusterServiceImpl implements ClusterService { // if we reach this point either we didn't have a connector or it didn't validate // now let's connect to remote JMX service to retrieve information from the runtime and operating system MX beans JMXServiceURL jmxServiceURL = new JMXServiceURL(url); - Map<String,Object> environment=new HashMap<String,Object>(); + Map<String, Object> environment = new HashMap<String, Object>(); if (karafJMXUsername != null && karafJMXPassword != null) { - environment.put(JMXConnector.CREDENTIALS,new String[]{karafJMXUsername,karafJMXPassword}); + environment.put(JMXConnector.CREDENTIALS, new String[]{karafJMXUsername, karafJMXPassword}); } JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxServiceURL, environment); jmxConnectors.put(url, jmxConnector); return jmxConnector; } - private Map<String,String> getMapProperty(Properties properties, String propertyName, String defaultValue) { + private Map<String, String> getMapProperty(Properties properties, String propertyName, String defaultValue) { String propertyValue = properties.getProperty(propertyName, defaultValue); return getMapProperty(propertyValue); } private Map<String, String> getMapProperty(String propertyValue) { String[] propertyValueArray = propertyValue.split(","); - Map<String,String> propertyMapValue = new LinkedHashMap<>(); + Map<String, String> propertyMapValue = new LinkedHashMap<>(); for (String propertyValueElement : propertyValueArray) { String[] propertyValueElementPrats = propertyValueElement.split("="); propertyMapValue.put(propertyValueElementPrats[0], propertyValueElementPrats[1]); @@ -369,10 +332,10 @@ public class ClusterServiceImpl implements ClusterService { return propertyMapValue; } - private Map<String,String> setMapProperty(Properties properties, String propertyName, Map<String,String> propertyMapValue) { + private Map<String, String> setMapProperty(Properties properties, String propertyName, Map<String, String> propertyMapValue) { StringBuilder propertyValueBuilder = new StringBuilder(); int entryCount = 0; - for (Map.Entry<String,String> propertyMapValueEntry : propertyMapValue.entrySet()) { + for (Map.Entry<String, String> propertyMapValueEntry : propertyMapValue.entrySet()) { propertyValueBuilder.append(propertyMapValueEntry.getKey()); propertyValueBuilder.append("="); propertyValueBuilder.append(propertyMapValueEntry.getValue()); http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/d40d3a48/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 8bbdcc6..fafb5fd 100644 --- a/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ b/services/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -40,12 +40,8 @@ <cm:property name="jmxUsername" value="karaf" /> <cm:property name="jmxPassword" value="karaf" /> <cm:property name="jmxPort" value="1099" /> - <cm:property name="contextserver.address" value="localhost"/> - <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:property name="contextserver.publicAddress" value="https://localhost:9443"/> + <cm:property name="contextserver.internalAddress" value="http://127.0.0.1:8181"/> </cm:default-properties> </cm:property-placeholder> @@ -160,12 +156,8 @@ <bean id="clusterServiceImpl" class="org.apache.unomi.services.services.ClusterServiceImpl" init-method="init" destroy-method="destroy"> - <property name="address" value="${cluster.contextserver.address}"/> - <property name="port" value="${cluster.contextserver.port}"/> - <property name="secureAddress" value="${cluster.contextserver.secureAddress}"/> - <property name="securePort" value="${cluster.contextserver.securePort}"/> + <property name="publicAddress" value="${cluster.contextserver.publicAddress}"/> <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/d40d3a48/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 f4beddf..9bdc7af 100644 --- a/services/src/main/resources/org.apache.unomi.cluster.cfg +++ b/services/src/main/resources/org.apache.unomi.cluster.cfg @@ -18,9 +18,5 @@ group=default jmxUsername=karaf jmxPassword=karaf jmxPort=1099 -contextserver.address=localhost -contextserver.port=8181 -contextserver.secureAddress=localhost -contextserver.securePort=9443 -contextserver.internalAddress=127.0.0.1 -contextserver.internalPort=8181 +contextserver.publicAddress=https://localhost:9443 +contextserver.internalAddress=http://127.0.0.1:8181 http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/d40d3a48/src/site/markdown/versions/master/configuration.md ---------------------------------------------------------------------- diff --git a/src/site/markdown/versions/master/configuration.md b/src/site/markdown/versions/master/configuration.md index 5d776e2..7cc4c11 100644 --- a/src/site/markdown/versions/master/configuration.md +++ b/src/site/markdown/versions/master/configuration.md @@ -24,12 +24,10 @@ Changing the default configuration If you want to change the default configuration, you can perform any modification you want in the $MY_KARAF_HOME/etc directory. The context server configuration is kept in the $MY_KARAF_HOME/etc/org.apache.unomi.cluster.cfg . It defines the -addresses and port where it can be found : +addresses where it can be found : - contextserver.address=localhost - contextserver.port=8181 - contextserver.secureAddress=localhost - contextserver.securePort=9443 + contextserver.publicAddress=https://localhost:9443 + contextserver.internalAddress=http://127.0.0.1:8181 If you need to specify an Elasticsearch cluster name, or a host and port that are different than the default, it is recommended to do this BEFORE you start the server for the first time, or you will loose all the data @@ -203,10 +201,8 @@ mod_proxy. In your Unomi package directory, in /etc/org.apache.unomi.cluster.cfg for unomi.apache.org - contextserver.address=unomi.apache.org - contextserver.port=80 - contextserver.secureAddress=unomi.apache.org - contextserver.securePort=443 + contextserver.publicAddress=https://unomi.apache.org/ + contextserver.internalAddress=http://192.168.1.1:8181 and you will also need to change the contextserver.domain in the /etc/org.apache.unomi.web.cfg file
