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/29 21:44:49 UTC

svn commit: r1403495 - in /karaf/cellar/trunk: features/pom.xml features/src/main/java/org/apache/karaf/cellar/features/shell/FeatureCommandSupport.java management/src/main/java/org/apache/karaf/cellar/management/internal/CellarFeaturesMBeanImpl.java

Author: jbonofre
Date: Mon Oct 29 20:44:48 2012
New Revision: 1403495

URL: http://svn.apache.org/viewvc?rev=1403495&view=rev
Log:
[KARAF-1982] Cellar features handler now updates the bundles distributed map

Modified:
    karaf/cellar/trunk/features/pom.xml
    karaf/cellar/trunk/features/src/main/java/org/apache/karaf/cellar/features/shell/FeatureCommandSupport.java
    karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarFeaturesMBeanImpl.java

Modified: karaf/cellar/trunk/features/pom.xml
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/features/pom.xml?rev=1403495&r1=1403494&r2=1403495&view=diff
==============================================================================
--- karaf/cellar/trunk/features/pom.xml (original)
+++ karaf/cellar/trunk/features/pom.xml Mon Oct 29 20:44:48 2012
@@ -37,6 +37,7 @@
         <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="[3,4)",
@@ -59,6 +60,10 @@
             <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/trunk/features/src/main/java/org/apache/karaf/cellar/features/shell/FeatureCommandSupport.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/features/src/main/java/org/apache/karaf/cellar/features/shell/FeatureCommandSupport.java?rev=1403495&r1=1403494&r2=1403495&view=diff
==============================================================================
--- karaf/cellar/trunk/features/src/main/java/org/apache/karaf/cellar/features/shell/FeatureCommandSupport.java (original)
+++ karaf/cellar/trunk/features/src/main/java/org/apache/karaf/cellar/features/shell/FeatureCommandSupport.java Mon Oct 29 20:44:48 2012
@@ -13,6 +13,7 @@
  */
 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;
@@ -20,12 +21,15 @@ 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;
 
 /**
@@ -57,8 +61,8 @@ public abstract class FeatureCommandSupp
             if (group == null || group.getNodes().isEmpty()) {
                 FeatureInfo info = new FeatureInfo(feature, version);
                 Map<FeatureInfo, Boolean> features = clusterManager.getMap(Constants.FEATURES + Configurations.SEPARATOR + groupName);
-                //1st check the existing configuration
-                if (version == null || version.isEmpty()) {
+                // check the existing configuration
+                if (version == null || (version.trim().length() < 1)) {
                     for (FeatureInfo f : features.keySet()) {
                         if (f.getName().equals(feature)) {
                             version = f.getVersion();
@@ -67,7 +71,7 @@ public abstract class FeatureCommandSupp
                     }
                 }
 
-                //2nd check the Features Service.
+                // check the Features Service.
                 try {
                     for (Feature f : featuresService.listFeatures()) {
                         if (f.getName().equals(feature)) {
@@ -81,6 +85,19 @@ public abstract class FeatureCommandSupp
 
                 if (info.getVersion() != null && !info.getVersion().isEmpty()) {
                     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/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarFeaturesMBeanImpl.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarFeaturesMBeanImpl.java?rev=1403495&r1=1403494&r2=1403495&view=diff
==============================================================================
--- karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarFeaturesMBeanImpl.java (original)
+++ karaf/cellar/trunk/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarFeaturesMBeanImpl.java Mon Oct 29 20:44:48 2012
@@ -13,6 +13,7 @@
  */
 package org.apache.karaf.cellar.management.internal;
 
+import org.apache.karaf.cellar.bundle.BundleState;
 import org.apache.karaf.cellar.core.*;
 import org.apache.karaf.cellar.core.control.SwitchStatus;
 import org.apache.karaf.cellar.core.event.EventProducer;
@@ -23,6 +24,7 @@ import org.apache.karaf.cellar.features.
 import org.apache.karaf.cellar.features.RemoteRepositoryEvent;
 import org.apache.karaf.cellar.management.CellarFeaturesMBean;
 import org.apache.karaf.features.*;
+import org.osgi.framework.BundleEvent;
 import org.osgi.service.cm.ConfigurationAdmin;
 
 import javax.management.NotCompliantMBeanException;
@@ -141,6 +143,20 @@ public class CellarFeaturesMBeanImpl ext
 
             // update the distributed map
             distributedFeatures.put(feature, true);
+            // update the bundle distributed map
+            try {
+                // update the distributed bundles map
+                List<BundleInfo> bundles = featuresService.getFeature(feature.getName(), version).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) {
+                // ignore
+            }
         } finally {
             Thread.currentThread().setContextClassLoader(originalClassLoader);
         }