You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by io...@apache.org on 2011/12/02 23:49:40 UTC

svn commit: r1209758 - in /karaf/cellar/branches/cellar-2.2.x: ./ assembly/src/main/resources/ hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/ hazelcast/src/test/java/org/apache/karaf/cellar/hazelcast/factory/

Author: iocanel
Date: Fri Dec  2 22:49:39 2011
New Revision: 1209758

URL: http://svn.apache.org/viewvc?rev=1209758&view=rev
Log:
Merged from trunk
[KARAF-1079] Fixed Hazlecast configuration manager to properly create sets from configuration properties. Added a unit tests that checks the isUpdated method of the configuratio manager. Added missing license headers. [from revision 1209753]

Added:
    karaf/cellar/branches/cellar-2.2.x/hazelcast/src/test/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastConfigurationManagerTest.java
      - copied unchanged from r1209753, karaf/cellar/trunk/hazelcast/src/test/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastConfigurationManagerTest.java
Modified:
    karaf/cellar/branches/cellar-2.2.x/   (props changed)
    karaf/cellar/branches/cellar-2.2.x/assembly/src/main/resources/hazelcast.xml
    karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastConfigurationManager.java
    karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastServiceFactory.java

Propchange: karaf/cellar/branches/cellar-2.2.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Dec  2 22:49:39 2011
@@ -1 +1 @@
-/karaf/cellar/trunk:1101991,1102000,1103447,1103456,1125012,1125040,1131478,1142446,1149693,1150108,1160898,1161074,1161494,1161515,1161766,1162249,1162252,1162321,1162327,1162356-1162357,1162390,1162397,1162399,1164077,1164523,1164989,1164994,1166403,1166434,1181287,1186085,1202090,1202105,1202108,1202111,1203975,1204173,1204184,1204209,1205187,1209264
+/karaf/cellar/trunk:1101991,1102000,1103447,1103456,1125012,1125040,1131478,1142446,1149693,1150108,1160898,1161074,1161494,1161515,1161766,1162249,1162252,1162321,1162327,1162356-1162357,1162390,1162397,1162399,1164077,1164523,1164989,1164994,1166403,1166434,1181287,1186085,1202090,1202105,1202108,1202111,1203975,1204173,1204184,1204209,1205187,1209264,1209753

Modified: karaf/cellar/branches/cellar-2.2.x/assembly/src/main/resources/hazelcast.xml
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/assembly/src/main/resources/hazelcast.xml?rev=1209758&r1=1209757&r2=1209758&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/assembly/src/main/resources/hazelcast.xml (original)
+++ karaf/cellar/branches/cellar-2.2.x/assembly/src/main/resources/hazelcast.xml Fri Dec  2 22:49:39 2011
@@ -3,8 +3,8 @@
            xmlns="http://www.hazelcast.com/schema/config"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <group>
-        <name>dev</name>
-        <password>dev-pass</password>
+        <name>cellar</name>
+        <password>pass</password>
     </group>
     <network>
         <port auto-increment="true">5701</port>

Modified: karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastConfigurationManager.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastConfigurationManager.java?rev=1209758&r1=1209757&r2=1209758&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastConfigurationManager.java (original)
+++ karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastConfigurationManager.java Fri Dec  2 22:49:39 2011
@@ -1,3 +1,16 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
 package org.apache.karaf.cellar.hazelcast.factory;
 
 import java.util.ArrayList;
@@ -30,15 +43,15 @@ public class HazelcastConfigurationManag
     public static final String TCPIP_ENABLED="tcpIpEnabled";
     public static final String TCPIP_MEMBERS="tcpIpMembers";
 
-    private String username = GroupConfig.DEFAULT_GROUP_NAME;
-    private String password = GroupConfig.DEFAULT_GROUP_PASSWORD;
+    private String username = "cellar";
+    private String password = "pass";
 
     private boolean multicastEnabled = MulticastConfig.DEFAULT_ENABLED;
     private String multicastGroup = MulticastConfig.DEFAULT_MULTICAST_GROUP;
     private int multicastPort = MulticastConfig.DEFAULT_MULTICAST_PORT;
     private int multicastTimeoutSeconds = MulticastConfig.DEFAULT_MULTICAST_TIMEOUT_SECONDS;
 
-    private boolean tcpIpEnabled = true;
+    private boolean tcpIpEnabled = false;
     private String tcpIpMembers = "";
     private Set<String> tcpIpMemberSet = new LinkedHashSet<String>();
     private Set<String> discoveredMemberSet = new LinkedHashSet<String>();
@@ -57,6 +70,7 @@ public class HazelcastConfigurationManag
                 if (properties.containsKey(USERNAME)) {
                     String newUsername = (String) properties.get(USERNAME);
                     if (username != null && newUsername != null && !username.endsWith(newUsername)) {
+                        LOGGER.info("Hazelcast username has been changed from {} to {}", username, newUsername);
                         this.username = newUsername;
                         updated = Boolean.TRUE;
                     }
@@ -65,20 +79,25 @@ public class HazelcastConfigurationManag
                 if (properties.containsKey(PASSWORD)) {
                     String newPassword = (String) properties.get(PASSWORD);
                     if (password != null && !password.equals(newPassword)) {
+                        LOGGER.info("Hazelcast password has been changed from {} to {}", password, newPassword);
                         this.password = newPassword;
                         updated = Boolean.TRUE;
                     }
                 }
 
-                Boolean newMulticastEnabled = Boolean.parseBoolean((String) properties.get(MULTICAST_ENABLED));
-                if (multicastEnabled != newMulticastEnabled) {
-                    this.multicastEnabled = newMulticastEnabled;
-                    updated = Boolean.TRUE;
+                if (properties.containsKey(MULTICAST_ENABLED)) {
+                    Boolean newMulticastEnabled = Boolean.parseBoolean((String) properties.get(MULTICAST_ENABLED));
+                    if (multicastEnabled != newMulticastEnabled) {
+                        LOGGER.info("Hazelcast multicastEnabled has been changed from {} to {}", multicastEnabled, newMulticastEnabled);
+                        this.multicastEnabled = newMulticastEnabled;
+                        updated = Boolean.TRUE;
+                    }
                 }
 
                 if (properties.containsKey(MULTICAST_GROUP)) {
                     String newMulticastGroup = (String) properties.get(MULTICAST_GROUP);
                     if (multicastGroup != null && newMulticastGroup != null && !multicastGroup.endsWith(newMulticastGroup)) {
+                        LOGGER.info("Hazelcast multicastGroup has been changed from {} to {}", multicastGroup, newMulticastGroup);
                         this.multicastGroup = newMulticastGroup;
                         updated = Boolean.TRUE;
                     }
@@ -89,6 +108,7 @@ public class HazelcastConfigurationManag
                     try {
                         int newMulticastPort = Integer.parseInt((String) properties.get(MULTICAST_PORT));
                         if (multicastPort != 0 && multicastPort != newMulticastPort) {
+                            LOGGER.info("Hazelcast multicastPort has been changed from {} to {}", multicastPort, newMulticastPort);
                             this.multicastPort = newMulticastPort;
                             updated = Boolean.TRUE;
                         }
@@ -101,6 +121,7 @@ public class HazelcastConfigurationManag
                     try {
                         int newMulticastTimeoutSeconds = Integer.parseInt((String) properties.get(MULTICAST_TIMEOUT_IN_SECONDS));
                         if (multicastTimeoutSeconds != 0 && multicastTimeoutSeconds != newMulticastTimeoutSeconds) {
+                            LOGGER.info("Hazelcast multicastTimeoutSeconds has been changed from {} to {}", multicastTimeoutSeconds, newMulticastTimeoutSeconds);
                             this.multicastTimeoutSeconds = newMulticastTimeoutSeconds;
                             updated = Boolean.TRUE;
                         }
@@ -112,21 +133,29 @@ public class HazelcastConfigurationManag
                 if (properties.containsKey(TCPIP_ENABLED)) {
                     Boolean newTcpIpEnabled = Boolean.parseBoolean((String) properties.get(TCPIP_ENABLED));
                     if (tcpIpEnabled != newTcpIpEnabled) {
+                        LOGGER.info("Hazelcast tcpIpEnabled has been changed from {} to {}", tcpIpEnabled, newTcpIpEnabled);
                         this.tcpIpEnabled = newTcpIpEnabled;
                         updated = Boolean.TRUE;
                     }
                 }
 
-                Set<String> newTcpIpMemberSet = createSetFromString((String) properties.get(TCPIP_MEMBERS));
-                if (tcpIpMemberSet != null && newTcpIpMemberSet != null && !collectionEquals(tcpIpMemberSet, newTcpIpMemberSet)) {
-                    tcpIpMemberSet = newTcpIpMemberSet;
-                    updated = Boolean.TRUE;
+                if (properties.containsKey(TCPIP_MEMBERS)) {
+                    Set<String> newTcpIpMemberSet = createSetFromString((String) properties.get(TCPIP_MEMBERS));
+                    if (!collectionEquals(tcpIpMemberSet, newTcpIpMemberSet)) {
+                        LOGGER.info("Hazelcast tcpIpMemberSet has been changed from {} to {}", tcpIpMemberSet, newTcpIpMemberSet);
+                        tcpIpMemberSet = newTcpIpMemberSet;
+                        updated = Boolean.TRUE;
+                    }
                 }
 
-                Set<String> newDiscoveredMemberSet = createSetFromString((String) properties.get(Discovery.DISCOVERED_MEMBERS_PROPERTY_NAME));
-                if (discoveredMemberSet != null && newDiscoveredMemberSet != null && !collectionEquals(discoveredMemberSet, newDiscoveredMemberSet)) {
-                    discoveredMemberSet = newDiscoveredMemberSet;
-                    updated = Boolean.TRUE;
+
+                if (properties.containsKey(TCPIP_MEMBERS)) {
+                    Set<String> newDiscoveredMemberSet = createSetFromString((String) properties.get(Discovery.DISCOVERED_MEMBERS_PROPERTY_NAME));
+                    if (!collectionEquals(discoveredMemberSet, newDiscoveredMemberSet)) {
+                        LOGGER.info("Hazelcast discoveredMemberSet has been changed from {} to {}", discoveredMemberSet, newDiscoveredMemberSet);
+                        discoveredMemberSet = newDiscoveredMemberSet;
+                        updated = Boolean.TRUE;
+                    }
                 }
             }
 
@@ -200,7 +229,9 @@ public class HazelcastConfigurationManag
             if (items != null && items.length > 0) {
 
                 for (String item : items) {
-                    result.add(item);
+                    if(item != null && item.length() > 0) {
+                     result.add(item.trim());
+                    }
                 }
             }
         }
@@ -214,7 +245,7 @@ public class HazelcastConfigurationManag
      * @param col2
      * @return
      */
-    private boolean collectionEquals(Collection col1, Collection col2) {
+    public boolean collectionEquals(Collection col1, Collection col2) {
         return collectionSubset(col1, col2) && collectionSubset(col2, col1);
     }
 

Modified: karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastServiceFactory.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastServiceFactory.java?rev=1209758&r1=1209757&r2=1209758&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastServiceFactory.java (original)
+++ karaf/cellar/branches/cellar-2.2.x/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastServiceFactory.java Fri Dec  2 22:49:39 2011
@@ -53,11 +53,13 @@ public class HazelcastServiceFactory  {
     }
 
     public void update(Map properties) throws InterruptedException {
+        LOGGER.info("Instance configuration updated. Checking if instance requires restarting.");
         if(configurationManager.isUpdated(properties)) {
             instnaceLatch.await();
             Config updatedConfig = configurationManager.getHazelcastConfig();
             instance.getConfig().setNetworkConfig(updatedConfig.getNetworkConfig());
             instance.getConfig().setGroupConfig(updatedConfig.getGroupConfig());
+            LOGGER.info("Restaring Hazelcast instance.");
             instance.getLifecycleService().restart();
         }
     }