Author: jbonofre
Date: Mon Apr 16 06:56:21 2012
New Revision: 1326510

URL: http://svn.apache.org/viewvc?rev=1326510&view=rev
Log:
[KARAF-1248] Remove the instance config file to use only hazelcast.xml file

Modified:
    
karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/discovery/Discovery.java
    
karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/discovery/DiscoveryTask.java
    
karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastConfigurationManager.java
    
karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastServiceFactory.java
    
karaf/cellar/trunk/hazelcast/src/main/resources/OSGI-INF/blueprint/blueprint.xml
    
karaf/cellar/trunk/hazelcast/src/test/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastConfigurationManagerTest.java
    
karaf/cellar/trunk/hazelcast/src/test/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastServiceFactoryTest.java

Modified: 
karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/discovery/Discovery.java
URL: 
http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/discovery/Discovery.java?rev=1326510&r1=1326509&r2=1326510&view=diff
==============================================================================
--- 
karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/discovery/Discovery.java
 (original)
+++ 
karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/discovery/Discovery.java
 Mon Apr 16 06:56:21 2012
@@ -16,7 +16,7 @@ package org.apache.karaf.cellar.core.dis
 
 public class Discovery {
 
-    public static final String PID = "org.apache.karaf.cellar.instance";
+    public static final String PID = "org.apache.karaf.cellar.discovery";
     public static final String MEMBERS_PROPERTY_NAME = "tcpIpMembers";
     public static final String DISCOVERED_MEMBERS_PROPERTY_NAME = 
"discoveredMembers";
 

Modified: 
karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/discovery/DiscoveryTask.java
URL: 
http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/discovery/DiscoveryTask.java?rev=1326510&r1=1326509&r2=1326510&view=diff
==============================================================================
--- 
karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/discovery/DiscoveryTask.java
 (original)
+++ 
karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/discovery/DiscoveryTask.java
 Mon Apr 16 06:56:21 2012
@@ -48,6 +48,7 @@ public class DiscoveryTask implements Ru
     @Override
     public void run() {
         LOGGER.trace("CELLAR DISCOVERY: Starting the discovery task.");
+
         if (configurationAdmin != null) {
             Set<String> members = new LinkedHashSet<String>();
             if (discoveryServices != null && !discoveryServices.isEmpty()) {
@@ -56,18 +57,18 @@ public class DiscoveryTask implements Ru
                     Set<String> discovered = service.discoverMembers();
                     members.addAll(discovered);
                 }
-            try {
-                Configuration configuration = 
configurationAdmin.getConfiguration(Discovery.PID);
-                Dictionary properties = configuration.getProperties();
-                String newMemberText = 
CellarUtils.createStringFromSet(members,true);
-                String memberText = (String) 
properties.get(Discovery.MEMBERS_PROPERTY_NAME);
-                if (newMemberText != null && !newMemberText.isEmpty() && 
!newMemberText.equals(memberText)) {
-                    properties.put(Discovery.DISCOVERED_MEMBERS_PROPERTY_NAME, 
newMemberText);
-                    configuration.update(properties);
+                try {
+                    Configuration configuration = 
configurationAdmin.getConfiguration(Discovery.PID);
+                    Dictionary properties = configuration.getProperties();
+                    String newMemberText = 
CellarUtils.createStringFromSet(members, true);
+                    String memberText = (String) 
properties.get(Discovery.MEMBERS_PROPERTY_NAME);
+                    if (newMemberText != null && newMemberText.length() > 0 && 
!newMemberText.equals(memberText)) {
+                        
properties.put(Discovery.DISCOVERED_MEMBERS_PROPERTY_NAME, newMemberText);
+                        configuration.update(properties);
+                    }
+                } catch (IOException e) {
+                    LOGGER.error("Failed to update member list", e);
                 }
-            } catch (IOException e) {
-                LOGGER.error("Failed to update member list", e);
-            }
             }
         }
     }

Modified: 
karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastConfigurationManager.java
URL: 
http://svn.apache.org/viewvc/karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastConfigurationManager.java?rev=1326510&r1=1326509&r2=1326510&view=diff
==============================================================================
--- 
karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastConfigurationManager.java
 (original)
+++ 
karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastConfigurationManager.java
 Mon Apr 16 06:56:21 2012
@@ -13,156 +13,27 @@
  */
 package org.apache.karaf.cellar.hazelcast.factory;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Set;
 import com.hazelcast.config.Config;
-import com.hazelcast.config.GroupConfig;
-import com.hazelcast.config.MulticastConfig;
 import com.hazelcast.config.TcpIpConfig;
 import com.hazelcast.config.XmlConfigBuilder;
-import com.hazelcast.core.HazelcastInstance;
 import org.apache.karaf.cellar.core.discovery.Discovery;
 import org.apache.karaf.cellar.core.utils.CellarUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Set;
+
 public class HazelcastConfigurationManager {
 
     private static final transient Logger LOGGER = 
LoggerFactory.getLogger(HazelcastServiceFactory.class);
 
-    public static final String USERNAME="username";
-    public static final String PASSWORD="password";
+    private String xmlConfigLocation = System.getProperty("karaf.home") + 
"/etc/hazelcast.xml";
 
-    public static final String MULTICAST_ENABLED="multicastEnabled";
-    public static final String MULTICAST_GROUP="multicastGroup";
-    public static final String MULTICAST_PORT="multicastPort";
-    public static final String 
MULTICAST_TIMEOUT_IN_SECONDS="multicastTimeoutSeconds";
-
-    public static final String TCPIP_ENABLED="tcpIpEnabled";
-    public static final String TCPIP_MEMBERS="tcpIpMembers";
-
-    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 = false;
-    private String tcpIpMembers = "";
-    private Set<String> tcpIpMemberSet = new LinkedHashSet<String>();
     private Set<String> discoveredMemberSet = new LinkedHashSet<String>();
 
-    private String xmlConfigLocation = System.getProperty("karaf.home") + 
"/etc/hazelcast.xml";
-
     /**
-     * Creates or Updates Hazelcast Instance.
-     *
-     * @param properties
-     */
-    public boolean isUpdated(Map properties) {
-            Boolean updated = Boolean.FALSE;
-            //We need it to properly instantiate Hazelcast.
-            if (properties != null) {
-                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;
-                    }
-                }
-
-                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;
-                    }
-                }
-
-                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;
-                    }
-
-                }
-
-                if (properties.containsKey(MULTICAST_PORT)) {
-                    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;
-                        }
-                    } catch (NumberFormatException ex) {
-                        LOGGER.warn("Could not parse port number", ex);
-                    }
-                }
-
-                if (properties.containsKey(MULTICAST_TIMEOUT_IN_SECONDS)) {
-                    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;
-                        }
-                    } catch (NumberFormatException ex) {
-                        LOGGER.warn("Could not parse multicast timeout in 
seconds", ex);
-                    }
-                }
-
-                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;
-                    }
-                }
-
-                if (properties.containsKey(TCPIP_MEMBERS)) {
-                    Set<String> newTcpIpMemberSet = 
CellarUtils.createSetFromString((String) properties.get(TCPIP_MEMBERS));
-                    if (!CellarUtils.collectionEquals(tcpIpMemberSet, 
newTcpIpMemberSet)) {
-                        LOGGER.info("Hazelcast tcpIpMemberSet has been changed 
from {} to {}", tcpIpMemberSet, newTcpIpMemberSet);
-                        tcpIpMemberSet = newTcpIpMemberSet;
-                        updated = Boolean.TRUE;
-                    }
-                }
-
-
-                if 
(properties.containsKey(Discovery.DISCOVERED_MEMBERS_PROPERTY_NAME)) {
-                    Set<String> newDiscoveredMemberSet = 
CellarUtils.createSetFromString((String) 
properties.get(Discovery.DISCOVERED_MEMBERS_PROPERTY_NAME));
-                    if (!CellarUtils.collectionEquals(discoveredMemberSet, 
newDiscoveredMemberSet)) {
-                        LOGGER.info("Hazelcast discoveredMemberSet has been 
changed from {} to {}", discoveredMemberSet, newDiscoveredMemberSet);
-                        discoveredMemberSet = newDiscoveredMemberSet;
-                        updated = Boolean.TRUE;
-                    }
-                }
-            }
-
-            return updated;
-    }
-     /**
      * Builds a Hazelcast {@link com.hazelcast.config.Config}
      *
      * @return
@@ -170,51 +41,31 @@ public class HazelcastConfigurationManag
     public Config getHazelcastConfig() {
         System.setProperty("hazelcast.config", xmlConfigLocation);
         Config config = new XmlConfigBuilder().build();
-        config.setGroupConfig(buildGroupConfig());
-        
config.getNetworkConfig().getJoin().setMulticastConfig(buildMulticastConfig());
-        config.getNetworkConfig().getJoin().setTcpIpConfig(buildTcpIpConfig());
+        if (discoveredMemberSet != null) {
+            TcpIpConfig tcpIpConfig = 
config.getNetworkConfig().getJoin().getTcpIpConfig();
+            tcpIpConfig.getMembers().addAll(discoveredMemberSet);
+        }
         return config;
     }
 
     /**
-     * Builds a {@link com.hazelcast.config.GroupConfig}
+     * Updates Hazelcast Instance.
      *
-     * @return
-     */
-    public GroupConfig buildGroupConfig() {
-        GroupConfig groupConfig = new GroupConfig();
-        groupConfig.setName(username);
-        groupConfig.setPassword(password);
-        return groupConfig;
-    }
-
-    /**
-     * Builds a {@link com.hazelcast.config.MulticastConfig}
-     *
-     * @return
-     */
-    public MulticastConfig buildMulticastConfig() {
-        MulticastConfig multicastConfig = new MulticastConfig();
-        multicastConfig.setEnabled(multicastEnabled);
-        multicastConfig.setMulticastPort(multicastPort);
-        multicastConfig.setMulticastGroup(multicastGroup);
-        multicastConfig.setMulticastTimeoutSeconds(multicastTimeoutSeconds);
-        return multicastConfig;
-    }
-
-    /**
-     * Builds a {@link com.hazelcast.config.TcpIpConfig}.
-     *
-     * @return
+     * @param properties
      */
-    public TcpIpConfig buildTcpIpConfig() {
-        TcpIpConfig tcpIpConfig = new TcpIpConfig();
-        tcpIpConfig.setEnabled(tcpIpEnabled);
-        tcpIpConfig.setMembers(new ArrayList(tcpIpMemberSet));
-        if(discoveredMemberSet != null && !discoveredMemberSet.isEmpty() && 
tcpIpConfig.getMembers() != null) {
-            tcpIpConfig.getMembers().addAll(new 
ArrayList(discoveredMemberSet));
+    public boolean isUpdated(Map properties) {
+        Boolean updated = Boolean.FALSE;
+        if (properties != null) {
+            if 
(properties.containsKey(Discovery.DISCOVERED_MEMBERS_PROPERTY_NAME)) {
+                Set<String> newDiscoveredMemberSet = 
CellarUtils.createSetFromString((String) 
properties.get(Discovery.DISCOVERED_MEMBERS_PROPERTY_NAME));
+                if (!CellarUtils.collectionEquals(discoveredMemberSet, 
newDiscoveredMemberSet)) {
+                    LOGGER.info("Hazelcast discoveredMemberSet has been 
changed from {} to {}", discoveredMemberSet, newDiscoveredMemberSet);
+                    discoveredMemberSet = newDiscoveredMemberSet;
+                    updated = Boolean.TRUE;
+                }
+            }
         }
-        return tcpIpConfig;
+        return updated;
     }
 
 }

Modified: 
karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastServiceFactory.java
URL: 
http://svn.apache.org/viewvc/karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastServiceFactory.java?rev=1326510&r1=1326509&r2=1326510&view=diff
==============================================================================
--- 
karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastServiceFactory.java
 (original)
+++ 
karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastServiceFactory.java
 Mon Apr 16 06:56:21 2012
@@ -53,15 +53,7 @@ public class HazelcastServiceFactory  {
     }
 
     public void update(Map properties) throws InterruptedException {
-        LOGGER.info("Instance configuration updated. Checking if instance 
requires restarting.");
-        if(configurationManager.isUpdated(properties)) {
-            instanceLatch.await();
-            Config updatedConfig = configurationManager.getHazelcastConfig();
-            
instance.getConfig().setNetworkConfig(updatedConfig.getNetworkConfig());
-            
instance.getConfig().setGroupConfig(updatedConfig.getGroupConfig());
-            LOGGER.info("Restaring Hazelcast instance.");
-            instance.getLifecycleService().restart();
-        }
+        configurationManager.isUpdated(properties);
     }
 
     /**

Modified: 
karaf/cellar/trunk/hazelcast/src/main/resources/OSGI-INF/blueprint/blueprint.xml
URL: 
http://svn.apache.org/viewvc/karaf/cellar/trunk/hazelcast/src/main/resources/OSGI-INF/blueprint/blueprint.xml?rev=1326510&r1=1326509&r2=1326510&view=diff
==============================================================================
--- 
karaf/cellar/trunk/hazelcast/src/main/resources/OSGI-INF/blueprint/blueprint.xml
 (original)
+++ 
karaf/cellar/trunk/hazelcast/src/main/resources/OSGI-INF/blueprint/blueprint.xml
 Mon Apr 16 06:56:21 2012
@@ -26,7 +26,7 @@
           init-method="init" destroy-method="destroy">
         <property name="combinedClassLoader" ref="combinedClassLoader"/>
         <property name="bundleContext" ref="blueprintBundleContext"/>
-        <cm:managed-properties 
persistent-id="org.apache.karaf.cellar.instance" 
update-strategy="component-managed"
+        <cm:managed-properties 
persistent-id="org.apache.karaf.cellar.discovery" 
update-strategy="component-managed"
                                   update-method="update"/>
     </bean>
 

Modified: 
karaf/cellar/trunk/hazelcast/src/test/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastConfigurationManagerTest.java
URL: 
http://svn.apache.org/viewvc/karaf/cellar/trunk/hazelcast/src/test/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastConfigurationManagerTest.java?rev=1326510&r1=1326509&r2=1326510&view=diff
==============================================================================
--- 
karaf/cellar/trunk/hazelcast/src/test/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastConfigurationManagerTest.java
 (original)
+++ 
karaf/cellar/trunk/hazelcast/src/test/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastConfigurationManagerTest.java
 Mon Apr 16 06:56:21 2012
@@ -13,6 +13,7 @@
  */
 package org.apache.karaf.cellar.hazelcast.factory;
 
+import org.apache.karaf.cellar.core.discovery.Discovery;
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -33,7 +34,7 @@ public class HazelcastConfigurationManag
     public void testIsUpdatedWithEmptyTcpMembers()  {
         HazelcastConfigurationManager cm = new HazelcastConfigurationManager();
         Properties p = new Properties();
-        p.put(HazelcastConfigurationManager.TCPIP_MEMBERS,"");
+        p.put(Discovery.DISCOVERED_MEMBERS_PROPERTY_NAME ,"");
         Assert.assertFalse(cm.isUpdated(p));
     }
 

Modified: 
karaf/cellar/trunk/hazelcast/src/test/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastServiceFactoryTest.java
URL: 
http://svn.apache.org/viewvc/karaf/cellar/trunk/hazelcast/src/test/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastServiceFactoryTest.java?rev=1326510&r1=1326509&r2=1326510&view=diff
==============================================================================
--- 
karaf/cellar/trunk/hazelcast/src/test/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastServiceFactoryTest.java
 (original)
+++ 
karaf/cellar/trunk/hazelcast/src/test/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastServiceFactoryTest.java
 Mon Apr 16 06:56:21 2012
@@ -44,16 +44,8 @@ public class HazelcastServiceFactoryTest
         HazelcastServiceFactory factory = new HazelcastServiceFactory();
         factory.init();
         factory.getInstance();
-        factory.update(null);
         HazelcastInstance defaultInstance = 
Hazelcast.newHazelcastInstance(null);
 
-        // define the username and password as in the hazelcast-default.xml 
provided by Hazelcast
-        // without this, "cellar" instance is not in the same cluster as the 
Hazelcast default one
-        Properties properties = new Properties();
-        properties.put(HazelcastConfigurationManager.USERNAME, "dev");
-        properties.put(HazelcastConfigurationManager.PASSWORD, "dev-pass");
-        factory.update(properties);
-
         HazelcastInstance factoryInstance = factory.getInstance();
         Assert.assertEquals(true, 
factoryInstance.getCluster().getMembers().size() >= 2);
     }


Reply via email to