You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2012/10/30 18:16:43 UTC

svn commit: r1403784 - in /karaf/cellar/branches/cellar-2.3.x: assembly/src/main/resources/ bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/ core/src/main/java/org/apache/karaf/cellar/core/ core/src/main/java/org/apache/karaf/cellar/core/cont...

Author: jbonofre
Date: Tue Oct 30 17:16:43 2012
New Revision: 1403784

URL: http://svn.apache.org/viewvc?rev=1403784&view=rev
Log:
[KARAF-1414] Add persistency of the producer

Modified:
    karaf/cellar/branches/cellar-2.3.x/assembly/src/main/resources/node.cfg
    karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/ListBundleCommand.java
    karaf/cellar/branches/cellar-2.3.x/core/src/main/java/org/apache/karaf/cellar/core/Configurations.java
    karaf/cellar/branches/cellar-2.3.x/core/src/main/java/org/apache/karaf/cellar/core/control/ProducerSwitchCommandHandler.java
    karaf/cellar/branches/cellar-2.3.x/features/pom.xml
    karaf/cellar/branches/cellar-2.3.x/features/src/main/java/org/apache/karaf/cellar/features/shell/FeatureCommandSupport.java
    karaf/cellar/branches/cellar-2.3.x/hazelcast/src/main/resources/OSGI-INF/blueprint/blueprint.xml

Modified: karaf/cellar/branches/cellar-2.3.x/assembly/src/main/resources/node.cfg
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/assembly/src/main/resources/node.cfg?rev=1403784&r1=1403783&r2=1403784&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/assembly/src/main/resources/node.cfg (original)
+++ karaf/cellar/branches/cellar-2.3.x/assembly/src/main/resources/node.cfg Tue Oct 30 17:16:43 2012
@@ -1 +1 @@
-groups=default
\ No newline at end of file
+groups = default
\ No newline at end of file

Modified: karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/ListBundleCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/ListBundleCommand.java?rev=1403784&r1=1403783&r2=1403784&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/ListBundleCommand.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/ListBundleCommand.java Tue Oct 30 17:16:43 2012
@@ -55,8 +55,15 @@ public class ListBundleCommand extends C
                 System.out.println(String.format(HEADER_FORMAT, "State", "Name"));
                 for (String bundle : bundles.keySet()) {
                     String[] tokens = bundle.split("/");
-                    String name = tokens[0];
-                    String version = tokens[1];
+                    String name = null;
+                    String version = null;
+                    if (tokens.length == 2) {
+                        name = tokens[0];
+                        version = tokens[1];
+                    } else {
+                        name = bundle;
+                        version = "";
+                    }
                     BundleState state = bundles.get(bundle);
                     String status;
                     switch (state.getStatus()) {

Modified: karaf/cellar/branches/cellar-2.3.x/core/src/main/java/org/apache/karaf/cellar/core/Configurations.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/core/src/main/java/org/apache/karaf/cellar/core/Configurations.java?rev=1403784&r1=1403783&r2=1403784&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/core/src/main/java/org/apache/karaf/cellar/core/Configurations.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/core/src/main/java/org/apache/karaf/cellar/core/Configurations.java Tue Oct 30 17:16:43 2012
@@ -22,6 +22,7 @@ public class Configurations {
     public static final String GROUP = "org.apache.karaf.cellar.groups";
     public static final String GROUPS_KEY = "groups";
     public static final String NODE = "org.apache.karaf.cellar.node";
+    public static final String PRODUCER = "producer";
 
     public static final String SEPARATOR = ".";
     public static final String DELIMETER = ",";

Modified: karaf/cellar/branches/cellar-2.3.x/core/src/main/java/org/apache/karaf/cellar/core/control/ProducerSwitchCommandHandler.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/core/src/main/java/org/apache/karaf/cellar/core/control/ProducerSwitchCommandHandler.java?rev=1403784&r1=1403783&r2=1403784&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/core/src/main/java/org/apache/karaf/cellar/core/control/ProducerSwitchCommandHandler.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/core/src/main/java/org/apache/karaf/cellar/core/control/ProducerSwitchCommandHandler.java Tue Oct 30 17:16:43 2012
@@ -13,8 +13,13 @@
  */
 package org.apache.karaf.cellar.core.control;
 
+import org.apache.karaf.cellar.core.Configurations;
 import org.apache.karaf.cellar.core.Producer;
 import org.apache.karaf.cellar.core.command.CommandHandler;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+import java.util.Dictionary;
 
 /**
  * Producer switch command handler.
@@ -30,24 +35,47 @@ public class ProducerSwitchCommandHandle
      * @param command
      */
     public ProducerSwitchResult execute(ProducerSwitchCommand command) {
-        //Query
+        // query
         if (command.getStatus() == null) {
             return new ProducerSwitchResult(command.getId(), Boolean.TRUE, producer.getSwitch().getStatus().getValue());
-        }
-        //Turn on the switch
-        else if (command.getStatus().equals(SwitchStatus.ON)) {
+        } else if (command.getStatus().equals(SwitchStatus.ON)) {
+            // turn on the switch
             producer.getSwitch().turnOn();
+            // persist the change
+            persist(command.getStatus());
             return new ProducerSwitchResult(command.getId(), Boolean.TRUE, Boolean.TRUE);
-        }
-        //Turn off the switch
-        else if (command.getStatus().equals(SwitchStatus.OFF)) {
+        } else if (command.getStatus().equals(SwitchStatus.OFF)) {
+            // turn off the switch
             producer.getSwitch().turnOff();
+            // persist the change
+            persist(command.getStatus());
             return new ProducerSwitchResult(command.getId(), Boolean.TRUE, Boolean.FALSE);
         } else {
             return new ProducerSwitchResult(command.getId(), Boolean.FALSE, producer.getSwitch().getStatus().getValue());
         }
     }
 
+    /**
+     * Store the producer current status in ConfigurationAdmin.
+     *
+     * @param switchStatus the producer switch status to store.
+     */
+    private void persist(SwitchStatus switchStatus) {
+        try {
+            Configuration configuration = configurationAdmin.getConfiguration(Configurations.NODE);
+            if (configuration != null) {
+                Dictionary<String, String> properties = configuration.getProperties();
+                if (properties != null) {
+                    properties.put(Configurations.PRODUCER, switchStatus.getValue().toString());
+                    configuration.update(properties);
+                }
+            }
+            System.out.println("Updated");
+        } catch (Exception e) {
+            LOGGER.warn("Can't persist the producer status", e);
+        }
+    }
+
     public Class<ProducerSwitchCommand> getType() {
         return ProducerSwitchCommand.class;
     }

Modified: karaf/cellar/branches/cellar-2.3.x/features/pom.xml
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/features/pom.xml?rev=1403784&r1=1403783&r2=1403784&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/features/pom.xml (original)
+++ karaf/cellar/branches/cellar-2.3.x/features/pom.xml Tue Oct 30 17:16:43 2012
@@ -37,7 +37,6 @@
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <osgi.import>
             org.apache.karaf.cellar.core*;version="${project.version}",
-            org.apache.karaf.cellar.bundle*;version="${project.version}",
             org.apache.felix.service.command,
             org.apache.felix.gogo.commands,
             org.apache.karaf.shell.console;version="[2.3,3)",
@@ -59,10 +58,6 @@
             <groupId>org.apache.karaf.cellar</groupId>
             <artifactId>org.apache.karaf.cellar.core</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.apache.karaf.cellar</groupId>
-            <artifactId>org.apache.karaf.cellar.bundle</artifactId>
-        </dependency>
 
         <!-- Configuration Admin -->
         <dependency>

Modified: karaf/cellar/branches/cellar-2.3.x/features/src/main/java/org/apache/karaf/cellar/features/shell/FeatureCommandSupport.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/features/src/main/java/org/apache/karaf/cellar/features/shell/FeatureCommandSupport.java?rev=1403784&r1=1403783&r2=1403784&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/features/src/main/java/org/apache/karaf/cellar/features/shell/FeatureCommandSupport.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/features/src/main/java/org/apache/karaf/cellar/features/shell/FeatureCommandSupport.java Tue Oct 30 17:16:43 2012
@@ -13,7 +13,6 @@
  */
 package org.apache.karaf.cellar.features.shell;
 
-import org.apache.karaf.cellar.bundle.BundleState;
 import org.apache.karaf.cellar.core.CellarSupport;
 import org.apache.karaf.cellar.core.Configurations;
 import org.apache.karaf.cellar.core.Group;
@@ -21,15 +20,12 @@ import org.apache.karaf.cellar.core.even
 import org.apache.karaf.cellar.core.shell.CellarCommandSupport;
 import org.apache.karaf.cellar.features.Constants;
 import org.apache.karaf.cellar.features.FeatureInfo;
-import org.apache.karaf.features.BundleInfo;
 import org.apache.karaf.features.Feature;
 import org.apache.karaf.features.FeaturesService;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.List;
 import java.util.Map;
 
 /**
@@ -53,12 +49,18 @@ public abstract class FeatureCommandSupp
      * @param status
      */
     public Boolean updateFeatureStatus(String groupName, String feature, String version, Boolean status) {
+
+        System.out.println("Enter here");
+
         Boolean result = Boolean.FALSE;
         ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
         try {
             Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
             Group group = groupManager.findGroupByName(groupName);
             if (group == null || group.getNodes().isEmpty()) {
+
+                System.out.println("Here1");
+
                 FeatureInfo info = new FeatureInfo(feature, version);
                 Map<FeatureInfo, Boolean> features = clusterManager.getMap(Constants.FEATURES + Configurations.SEPARATOR + groupName);
                 // check the existing configuration
@@ -83,21 +85,10 @@ public abstract class FeatureCommandSupp
                     LOGGER.error("Error while browsing features", e);
                 }
 
+                System.out.println("Here2");
+
                 if (info.getVersion() != null && (info.getVersion().trim().length() > 0)) {
                     features.put(info, status);
-                    try {
-                        // update the distributed bundles map
-                        List<BundleInfo> bundles = featuresService.getFeature(info.getName(), info.getVersion()).getBundles();
-                        Map<String, BundleState> bundlesMap = clusterManager.getMap(org.apache.karaf.cellar.bundle.Constants.BUNDLE_MAP + Configurations.SEPARATOR + groupName);
-                        for (BundleInfo bundle : bundles) {
-                            BundleState state = new BundleState();
-                            state.setLocation(bundle.getLocation());
-                            state.setStatus(BundleEvent.STARTED);
-                            bundlesMap.put(bundle.toString(), state);
-                        }
-                    } catch (Exception e) {
-                        LOGGER.warn("Can't update the distributed bundles map", e);
-                    }
                     result = Boolean.TRUE;
                 }
             }

Modified: karaf/cellar/branches/cellar-2.3.x/hazelcast/src/main/resources/OSGI-INF/blueprint/blueprint.xml
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/hazelcast/src/main/resources/OSGI-INF/blueprint/blueprint.xml?rev=1403784&r1=1403783&r2=1403784&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/hazelcast/src/main/resources/OSGI-INF/blueprint/blueprint.xml (original)
+++ karaf/cellar/branches/cellar-2.3.x/hazelcast/src/main/resources/OSGI-INF/blueprint/blueprint.xml Tue Oct 30 17:16:43 2012
@@ -103,6 +103,7 @@
     <!-- Producer Switch Handler -->
     <bean id="producerSwitchCommandHandler" class="org.apache.karaf.cellar.core.control.ProducerSwitchCommandHandler">
         <property name="producer" ref="producer"/>
+        <property name="configurationAdmin" ref="configurationAdmin"/>
     </bean>
 
     <bean id="producerSwitchResultHandler" class="org.apache.karaf.cellar.core.control.ProducerSwitchResultHandler">