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 2015/03/17 17:26:14 UTC

[1/2] karaf-cellar git commit: [KARAF-3615] Cluster bundles now keep bundle ID, version and symbolic name

Repository: karaf-cellar
Updated Branches:
  refs/heads/master 79389c8a9 -> f9a2725a4


[KARAF-3615] Cluster bundles now keep bundle ID, version and symbolic name


Project: http://git-wip-us.apache.org/repos/asf/karaf-cellar/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf-cellar/commit/4b9dc081
Tree: http://git-wip-us.apache.org/repos/asf/karaf-cellar/tree/4b9dc081
Diff: http://git-wip-us.apache.org/repos/asf/karaf-cellar/diff/4b9dc081

Branch: refs/heads/master
Commit: 4b9dc081e9bb570318e4ebb8e5447ee52261f756
Parents: 79389c8
Author: Jean-Baptiste Onofré <jb...@apache.org>
Authored: Tue Mar 17 17:16:14 2015 +0100
Committer: Jean-Baptiste Onofré <jb...@apache.org>
Committed: Tue Mar 17 17:22:00 2015 +0100

----------------------------------------------------------------------
 .../apache/karaf/cellar/bundle/BundleState.java | 27 +++++++
 .../karaf/cellar/bundle/BundleSynchronizer.java | 15 ++--
 .../cellar/bundle/LocalBundleListener.java      |  3 +
 .../internal/CellarBundleMBeanImpl.java         | 81 ++++++++++----------
 .../bundle/shell/BundleCommandSupport.java      | 28 +++----
 .../bundle/shell/InstallBundleCommand.java      |  3 +
 .../cellar/bundle/shell/ListBundleCommand.java  | 52 ++++++-------
 7 files changed, 119 insertions(+), 90 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/4b9dc081/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleState.java
----------------------------------------------------------------------
diff --git a/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleState.java b/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleState.java
index 64f287f..df6154a 100644
--- a/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleState.java
+++ b/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleState.java
@@ -22,11 +22,22 @@ public class BundleState implements Serializable {
 
     private static final long serialVersionUID = 5933673686648413918L;
 
+    private long id;
     private String name;
+    private String symbolicName;
+    private String version;
     private String location;
     private int status;
     private byte[] data;
 
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
     public String getName() {
         return name;
     }
@@ -35,6 +46,22 @@ public class BundleState implements Serializable {
         this.name = name;
     }
 
+    public String getSymbolicName() {
+        return symbolicName;
+    }
+
+    public void setSymbolicName(String symbolicName) {
+        this.symbolicName = symbolicName;
+    }
+
+    public String getVersion() {
+        return version;
+    }
+
+    public void setVersion(String version) {
+        this.version = version;
+    }
+
     public String getLocation() {
         return location;
     }

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/4b9dc081/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSynchronizer.java
----------------------------------------------------------------------
diff --git a/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSynchronizer.java b/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSynchronizer.java
index 851ded0..b8278e2 100644
--- a/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSynchronizer.java
+++ b/bundle/src/main/java/org/apache/karaf/cellar/bundle/BundleSynchronizer.java
@@ -146,6 +146,7 @@ public class BundleSynchronizer extends BundleSupport implements Synchronizer {
 
                 bundles = bundleContext.getBundles();
                 for (Bundle bundle : bundles) {
+                    long bundleId = bundle.getBundleId();
                     String symbolicName = bundle.getSymbolicName();
                     String version = bundle.getVersion().toString();
                     String bundleLocation = bundle.getLocation();
@@ -159,10 +160,13 @@ public class BundleSynchronizer extends BundleSupport implements Synchronizer {
                         // get the bundle name or location.
                         String name = (String) bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_NAME);
                         // if there is no name, then default to symbolic name.
-                        name = (name == null) ? bundle.getSymbolicName() : name;
+                        name = (name == null) ? symbolicName : name;
                         // if there is no symbolic name, resort to location.
                         name = (name == null) ? bundle.getLocation() : name;
+                        bundleState.setId(bundleId);
                         bundleState.setName(name);
+                        bundleState.setSymbolicName(symbolicName);
+                        bundleState.setVersion(version);
                         bundleState.setLocation(bundleLocation);
 
                         if (status == Bundle.ACTIVE)
@@ -180,14 +184,7 @@ public class BundleSynchronizer extends BundleSupport implements Synchronizer {
 
                         bundleState.setStatus(status);
 
-                        BundleState existingState = clusterBundles.get(id);
-
-                        if (existingState == null ||
-                                !existingState.getLocation().equals(bundleState.getLocation()) ||
-                                existingState.getStatus() != bundleState.getStatus()) {
-                            // update the distributed map
-                            clusterBundles.put(id, bundleState);
-                        }
+                        clusterBundles.put(id, bundleState);
 
                     } else LOGGER.trace("CELLAR BUNDLE: bundle {} is marked BLOCKED OUTBOUND for cluster group {}", bundleLocation, groupName);
                 }

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/4b9dc081/bundle/src/main/java/org/apache/karaf/cellar/bundle/LocalBundleListener.java
----------------------------------------------------------------------
diff --git a/bundle/src/main/java/org/apache/karaf/cellar/bundle/LocalBundleListener.java b/bundle/src/main/java/org/apache/karaf/cellar/bundle/LocalBundleListener.java
index 59dd72b..c5473f9 100644
--- a/bundle/src/main/java/org/apache/karaf/cellar/bundle/LocalBundleListener.java
+++ b/bundle/src/main/java/org/apache/karaf/cellar/bundle/LocalBundleListener.java
@@ -106,7 +106,10 @@ public class LocalBundleListener extends BundleSupport implements SynchronousBun
                                 if (state == null) {
                                     state = new BundleState();
                                 }
+                                state.setId(event.getBundle().getBundleId());
                                 state.setName(name);
+                                state.setVersion(version);
+                                state.setSymbolicName(symbolicName);
                                 state.setStatus(type);
                                 state.setLocation(bundleLocation);
                                 clusterBundles.put(symbolicName + "/" + version, state);

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/4b9dc081/bundle/src/main/java/org/apache/karaf/cellar/bundle/management/internal/CellarBundleMBeanImpl.java
----------------------------------------------------------------------
diff --git a/bundle/src/main/java/org/apache/karaf/cellar/bundle/management/internal/CellarBundleMBeanImpl.java b/bundle/src/main/java/org/apache/karaf/cellar/bundle/management/internal/CellarBundleMBeanImpl.java
index f962995..225b99e 100644
--- a/bundle/src/main/java/org/apache/karaf/cellar/bundle/management/internal/CellarBundleMBeanImpl.java
+++ b/bundle/src/main/java/org/apache/karaf/cellar/bundle/management/internal/CellarBundleMBeanImpl.java
@@ -32,10 +32,7 @@ import javax.management.NotCompliantMBeanException;
 import javax.management.StandardMBean;
 import javax.management.openmbean.*;
 import java.net.URL;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.jar.JarInputStream;
 import java.util.jar.Manifest;
 import java.util.regex.Matcher;
@@ -129,9 +126,10 @@ public class CellarBundleMBeanImpl extends StandardMBean implements CellarBundle
         if (manifest == null) {
             throw new IllegalArgumentException("Bundle location " + location + " doesn't seem correct");
         }
-        String name = manifest.getMainAttributes().getValue("Bundle-SymbolicName");
+        String name = manifest.getMainAttributes().getValue("Bundle-Name");
+        String symbolicName = manifest.getMainAttributes().getValue("Bundle-SymbolicName");
         if (name == null) {
-            name = manifest.getMainAttributes().getValue("Bundle-SymbolicName");
+            name = symbolicName;
         }
         if (name == null) {
             name = location;
@@ -146,6 +144,9 @@ public class CellarBundleMBeanImpl extends StandardMBean implements CellarBundle
             Map<String, BundleState> clusterBundles = clusterManager.getMap(Constants.BUNDLE_MAP + Configurations.SEPARATOR + groupName);
             BundleState state = new BundleState();
             state.setName(name);
+            state.setSymbolicName(symbolicName);
+            state.setVersion(version);
+            state.setId(clusterBundles.size());
             state.setLocation(location);
             if (start) {
                 state.setStatus(BundleEvent.STARTED);
@@ -388,21 +389,14 @@ public class CellarBundleMBeanImpl extends StandardMBean implements CellarBundle
         ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
         Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
         try {
-            Map<String, ExtendedBundleState> bundles = gatherBundles(groupName);
-            int id = 0;
-            for (String bundle : bundles.keySet()) {
-                String[] tokens = bundle.split("/");
-                String name = null;
-                String version = null;
-                if (tokens.length == 2) {
-                    name = tokens[0];
-                    version = tokens[1];
-                } else {
-                    name = bundle;
-                }
-                ExtendedBundleState state = bundles.get(bundle);
+            Map<String, ExtendedBundleState> allBundles = gatherBundles(groupName);
+
+            List<ExtendedBundleState> bundles = new ArrayList<ExtendedBundleState>(allBundles.values());
+            Collections.sort(bundles, new BundleStateComparator());
+
+            for (ExtendedBundleState bundle : bundles) {
                 String status;
-                switch (state.getStatus()) {
+                switch (bundle.getStatus()) {
                     case BundleEvent.INSTALLED:
                         status = "Installed";
                         break;
@@ -430,8 +424,8 @@ public class CellarBundleMBeanImpl extends StandardMBean implements CellarBundle
                 }
 
                 String located = "";
-                boolean local = state.isLocal();
-                boolean cluster = state.isCluster();
+                boolean local = bundle.isLocal();
+                boolean cluster = bundle.isCluster();
                 if (local && cluster)
                     located = "cluster/local";
                 if (local && !cluster)
@@ -440,8 +434,8 @@ public class CellarBundleMBeanImpl extends StandardMBean implements CellarBundle
                     located = "cluster";
 
                 String blocked = "";
-                boolean inbound = support.isAllowed(group, Constants.CATEGORY, state.getLocation(), EventType.INBOUND);
-                boolean outbound = support.isAllowed(group, Constants.CATEGORY, state.getLocation(), EventType.OUTBOUND);
+                boolean inbound = support.isAllowed(group, Constants.CATEGORY, bundle.getLocation(), EventType.INBOUND);
+                boolean outbound = support.isAllowed(group, Constants.CATEGORY, bundle.getLocation(), EventType.OUTBOUND);
                 if (!inbound && !outbound)
                     blocked = "in/out";
                 if (!inbound && outbound)
@@ -451,9 +445,8 @@ public class CellarBundleMBeanImpl extends StandardMBean implements CellarBundle
 
                 CompositeData data = new CompositeDataSupport(compositeType,
                         new String[]{"id", "name", "version", "status", "location", "located", "blocked"},
-                        new Object[]{id, name, version, status, state.getLocation(), located, blocked});
+                        new Object[]{bundle.getId(), bundle.getName(), bundle.getVersion(), status, bundle.getLocation(), located, blocked});
                 table.put(data);
-                id++;
             }
         } finally {
             Thread.currentThread().setContextClassLoader(originalClassLoader);
@@ -474,31 +467,29 @@ public class CellarBundleMBeanImpl extends StandardMBean implements CellarBundle
         return bundles;
     }
 
-    protected void addMatchingBundles(String id, List<String> bundles, Map<String, ExtendedBundleState> clusterBundles) {
+    protected void addMatchingBundles(String nameId, List<String> bundles, Map<String, ExtendedBundleState> clusterBundles) {
 
         // id is a number
         Pattern pattern = Pattern.compile("^\\d+$");
-        Matcher matcher = pattern.matcher(id);
+        Matcher matcher = pattern.matcher(nameId);
         if (matcher.find()) {
-            int idInt = Integer.parseInt(id);
-            int index = 0;
+            int idInt = Integer.parseInt(nameId);
             for (String bundle : clusterBundles.keySet()) {
-                if (index == idInt) {
+                if (clusterBundles.get(bundle).getId() == idInt) {
                     bundles.add(bundle);
                     break;
                 }
-                index++;
             }
             return;
         }
 
         // id as a number range
         pattern = Pattern.compile("^(\\d+)-(\\d+)$");
-        matcher = pattern.matcher(id);
+        matcher = pattern.matcher(nameId);
         if (matcher.find()) {
-            int index = id.indexOf('-');
-            long startId = Long.parseLong(id.substring(0, index));
-            long endId = Long.parseLong(id.substring(index + 1));
+            int index = nameId.indexOf('-');
+            long startId = Long.parseLong(nameId.substring(0, index));
+            long endId = Long.parseLong(nameId.substring(index + 1));
             if (startId < endId) {
                 int bundleIndex = 0;
                 for (String bundle : clusterBundles.keySet()) {
@@ -511,10 +502,10 @@ public class CellarBundleMBeanImpl extends StandardMBean implements CellarBundle
             return;
         }
 
-        int index = id.indexOf('/');
+        int index = nameId.indexOf('/');
         if (index != -1) {
             // id is name/version
-            String[] idSplit = id.split("/");
+            String[] idSplit = nameId.split("/");
             String name = idSplit[0];
             String version = idSplit[1];
             for (String bundle : clusterBundles.keySet()) {
@@ -549,7 +540,7 @@ public class CellarBundleMBeanImpl extends StandardMBean implements CellarBundle
 
         // id is just name
         // regex support on the name
-        Pattern namePattern = Pattern.compile(id);
+        Pattern namePattern = Pattern.compile(nameId);
         // looking for bundle using only the name
         for (String bundle : clusterBundles.keySet()) {
             BundleState state = clusterBundles.get(bundle);
@@ -583,7 +574,10 @@ public class CellarBundleMBeanImpl extends StandardMBean implements CellarBundle
         for (String key : clusterBundles.keySet()) {
             BundleState state = clusterBundles.get(key);
             ExtendedBundleState extendedState = new ExtendedBundleState();
+            extendedState.setId(state.getId());
             extendedState.setName(state.getName());
+            extendedState.setVersion(state.getVersion());
+            extendedState.setSymbolicName(state.getSymbolicName());
             extendedState.setStatus(state.getStatus());
             extendedState.setLocation(state.getLocation());
             extendedState.setData(state.getData());
@@ -607,7 +601,10 @@ public class CellarBundleMBeanImpl extends StandardMBean implements CellarBundle
                 name = (name == null) ? bundle.getSymbolicName() : name;
                 // if there is no symbolic name, resort to location.
                 name = (name == null) ? bundle.getLocation() : name;
+                extendedState.setId(bundle.getBundleId());
                 extendedState.setName(name);
+                extendedState.setVersion(bundle.getVersion().toString());
+                extendedState.setSymbolicName(bundle.getSymbolicName());
                 extendedState.setLocation(bundle.getLocation());
                 int status = bundle.getState();
                 if (status == Bundle.ACTIVE)
@@ -654,4 +651,10 @@ public class CellarBundleMBeanImpl extends StandardMBean implements CellarBundle
         }
     }
 
+    class BundleStateComparator implements Comparator<BundleState> {
+        public int compare(BundleState b1, BundleState b2) {
+            return (int) (b1.getId() - b2.getId());
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/4b9dc081/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/BundleCommandSupport.java
----------------------------------------------------------------------
diff --git a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/BundleCommandSupport.java b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/BundleCommandSupport.java
index 6e7f98e..ad3b0af 100644
--- a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/BundleCommandSupport.java
+++ b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/BundleCommandSupport.java
@@ -59,31 +59,29 @@ public abstract class BundleCommandSupport extends CellarCommandSupport {
         return bundles;
     }
 
-    protected void addMatchingBundles(String id, List<String> bundles, Map<String, ExtendedBundleState> clusterBundles) {
+    protected void addMatchingBundles(String nameId, List<String> bundles, Map<String, ExtendedBundleState> clusterBundles) {
 
         // id is a number
         Pattern pattern = Pattern.compile("^\\d+$");
-        Matcher matcher = pattern.matcher(id);
+        Matcher matcher = pattern.matcher(nameId);
         if (matcher.find()) {
-            int idInt = Integer.parseInt(id);
-            int index = 0;
+            int id = Integer.parseInt(nameId);
             for (String bundle : clusterBundles.keySet()) {
-                if (index == idInt) {
+                if (clusterBundles.get(bundle).getId() == id) {
                     bundles.add(bundle);
                     break;
                 }
-                index++;
             }
             return;
         }
 
         // id as a number range
         pattern = Pattern.compile("^(\\d+)-(\\d+)$");
-        matcher = pattern.matcher(id);
+        matcher = pattern.matcher(nameId);
         if (matcher.find()) {
-            int index = id.indexOf('-');
-            long startId = Long.parseLong(id.substring(0, index));
-            long endId = Long.parseLong(id.substring(index + 1));
+            int index = nameId.indexOf('-');
+            long startId = Long.parseLong(nameId.substring(0, index));
+            long endId = Long.parseLong(nameId.substring(index + 1));
             if (startId < endId) {
                 int bundleIndex = 0;
                 for (String bundle : clusterBundles.keySet()) {
@@ -96,10 +94,10 @@ public abstract class BundleCommandSupport extends CellarCommandSupport {
             return;
         }
 
-        int index = id.indexOf('/');
+        int index = nameId.indexOf('/');
         if (index != -1) {
             // id is name/version
-            String[] idSplit = id.split("/");
+            String[] idSplit = nameId.split("/");
             String name = idSplit[0];
             String version = idSplit[1];
             for (String bundle : clusterBundles.keySet()) {
@@ -134,7 +132,7 @@ public abstract class BundleCommandSupport extends CellarCommandSupport {
 
         // id is just name
         // regex support on the name
-        Pattern namePattern = Pattern.compile(id);
+        Pattern namePattern = Pattern.compile(nameId);
         // looking for bundle using only the name
         for (String bundle : clusterBundles.keySet()) {
             BundleState state = clusterBundles.get(bundle);
@@ -168,9 +166,11 @@ public abstract class BundleCommandSupport extends CellarCommandSupport {
         for (String key : clusterBundles.keySet()) {
             BundleState state = clusterBundles.get(key);
             ExtendedBundleState extendedState = new ExtendedBundleState();
+            extendedState.setId(state.getId());
             extendedState.setName(state.getName());
             extendedState.setStatus(state.getStatus());
             extendedState.setLocation(state.getLocation());
+            extendedState.setVersion(state.getVersion());
             // extendedState.setData(state.getData());
             extendedState.setCluster(true);
             extendedState.setLocal(false);
@@ -193,7 +193,9 @@ public abstract class BundleCommandSupport extends CellarCommandSupport {
                 name = (name == null) ? bundle.getSymbolicName() : name;
                 // if there is no symbolic name, resort to location.
                 name = (name == null) ? bundle.getLocation() : name;
+                extendedState.setId(bundle.getBundleId());
                 extendedState.setName(name);
+                extendedState.setVersion(bundle.getVersion().toString());
                 extendedState.setLocation(bundle.getLocation());
                 int status = bundle.getState();
                 if (status == Bundle.ACTIVE)

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/4b9dc081/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/InstallBundleCommand.java
----------------------------------------------------------------------
diff --git a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/InstallBundleCommand.java b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/InstallBundleCommand.java
index 64c594d..dfbc62b 100644
--- a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/InstallBundleCommand.java
+++ b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/InstallBundleCommand.java
@@ -98,6 +98,9 @@ public class InstallBundleCommand extends CellarCommandSupport {
                     Map<String, BundleState> clusterBundles = clusterManager.getMap(Constants.BUNDLE_MAP + Configurations.SEPARATOR + groupName);
                     BundleState state = new BundleState();
                     state.setName(name);
+                    state.setSymbolicName(symbolicName);
+                    state.setVersion(version);
+                    state.setId(clusterBundles.size());
                     state.setLocation(url);
                     if (start) {
                         state.setStatus(BundleEvent.STARTED);

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/4b9dc081/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/ListBundleCommand.java
----------------------------------------------------------------------
diff --git a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/ListBundleCommand.java b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/ListBundleCommand.java
index 7b4241d..165d5de 100644
--- a/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/ListBundleCommand.java
+++ b/bundle/src/main/java/org/apache/karaf/cellar/bundle/shell/ListBundleCommand.java
@@ -13,6 +13,7 @@
  */
 package org.apache.karaf.cellar.bundle.shell;
 
+import org.apache.karaf.cellar.bundle.BundleState;
 import org.apache.karaf.cellar.bundle.Constants;
 import org.apache.karaf.cellar.core.CellarSupport;
 import org.apache.karaf.cellar.core.Group;
@@ -22,10 +23,10 @@ import org.apache.karaf.shell.commands.Option;
 import org.apache.karaf.shell.table.ShellTable;
 import org.osgi.framework.BundleEvent;
 
-import java.util.Map;
+import java.util.*;
 
 @Command(scope = "cluster", name = "bundle-list", description = "List the bundles in a cluster group")
-public class ListBundleCommand extends  BundleCommandSupport {
+public class ListBundleCommand extends BundleCommandSupport {
 
     @Option(name = "-s", aliases = {}, description = "Shows the symbolic name", required = false, multiValued = false)
     boolean showSymbolicName;
@@ -60,8 +61,8 @@ public class ListBundleCommand extends  BundleCommandSupport {
         Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
 
         try {
-            Map<String, ExtendedBundleState> bundles = gatherBundles();
-            if (bundles != null && !bundles.isEmpty()) {
+            Map<String, ExtendedBundleState> allBundles = gatherBundles();
+            if (allBundles != null && !allBundles.isEmpty()) {
                 System.out.println(String.format("Bundles in cluster group " + groupName));
 
                 ShellTable table = new ShellTable();
@@ -78,21 +79,12 @@ public class ListBundleCommand extends  BundleCommandSupport {
                     table.column("Name");
                 }
 
-                int id = 0;
-                for (String bundle : bundles.keySet()) {
-                    String[] tokens = bundle.split("/");
-                    String symbolicName = null;
-                    String version = null;
-                    if (tokens.length == 2) {
-                        symbolicName = tokens[0];
-                        version = tokens[1];
-                    } else {
-                        symbolicName = bundle;
-                        version = "";
-                    }
-                    ExtendedBundleState state = bundles.get(bundle);
+                List<ExtendedBundleState> bundles = new ArrayList<ExtendedBundleState>(allBundles.values());
+                Collections.sort(bundles, new BundleStateComparator());
+
+                for (ExtendedBundleState bundle : bundles) {
                     String status;
-                    switch (state.getStatus()) {
+                    switch (bundle.getStatus()) {
                         case BundleEvent.INSTALLED:
                             status = "Installed";
                             break;
@@ -120,30 +112,27 @@ public class ListBundleCommand extends  BundleCommandSupport {
                     }
 
                     String located = "";
-                    boolean cluster = state.isCluster();
-                    boolean local = state.isLocal();
+                    boolean cluster = bundle.isCluster();
+                    boolean local = bundle.isLocal();
                     if (cluster && local)
                         located = "cluster/local";
                     if (cluster && !local) {
                         located = "cluster";
                         if (onlyLocal) {
-                            id++;
                             continue;
                         }
                     }
                     if (local && !cluster) {
                         located = "local";
                         if (onlyCluster) {
-                            id++;
                             continue;
                         }
                     }
 
                     String blocked = "";
-                    boolean inbound = support.isAllowed(group, Constants.CATEGORY, state.getLocation(), EventType.INBOUND);
-                    boolean outbound = support.isAllowed(group, Constants.CATEGORY, state.getLocation(), EventType.OUTBOUND);
+                    boolean inbound = support.isAllowed(group, Constants.CATEGORY, bundle.getLocation(), EventType.INBOUND);
+                    boolean outbound = support.isAllowed(group, Constants.CATEGORY, bundle.getLocation(), EventType.OUTBOUND);
                     if (inbound && outbound && onlyBlocked) {
-                        id++;
                         continue;
                     }
                     if (!inbound && !outbound)
@@ -154,15 +143,14 @@ public class ListBundleCommand extends  BundleCommandSupport {
                         blocked = "out";
 
                     if (showLocation) {
-                        table.addRow().addContent(id, status, located, blocked, version, state.getLocation());
+                        table.addRow().addContent(bundle.getId(), status, located, blocked, bundle.getVersion(), bundle.getLocation());
                     } else {
                         if (showSymbolicName) {
-                            table.addRow().addContent(id, status, located, blocked, version, symbolicName);
+                            table.addRow().addContent(bundle.getId(), status, located, blocked, bundle.getVersion(), bundle.getSymbolicName());
                         } else {
-                            table.addRow().addContent(id, status, located, blocked, version, state.getName());
+                            table.addRow().addContent(bundle.getId(), status, located, blocked, bundle.getVersion(), bundle.getName());
                         }
                     }
-                    id++;
                 }
 
                 table.print(System.out);
@@ -176,4 +164,10 @@ public class ListBundleCommand extends  BundleCommandSupport {
         return null;
     }
 
+    class BundleStateComparator implements Comparator<BundleState> {
+        public int compare(BundleState b1, BundleState b2) {
+            return (int) (b1.getId() - b2.getId());
+        }
+    }
+
 }


[2/2] karaf-cellar git commit: [KARAF-3615] Fix the features repo push exception catching

Posted by jb...@apache.org.
[KARAF-3615] Fix the features repo push exception catching


Project: http://git-wip-us.apache.org/repos/asf/karaf-cellar/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf-cellar/commit/f9a2725a
Tree: http://git-wip-us.apache.org/repos/asf/karaf-cellar/tree/f9a2725a
Diff: http://git-wip-us.apache.org/repos/asf/karaf-cellar/diff/f9a2725a

Branch: refs/heads/master
Commit: f9a2725a424f5678d0bc8be49a5bb722c9ea07b3
Parents: 4b9dc08
Author: Jean-Baptiste Onofré <jb...@apache.org>
Authored: Tue Mar 17 17:25:43 2015 +0100
Committer: Jean-Baptiste Onofré <jb...@apache.org>
Committed: Tue Mar 17 17:25:43 2015 +0100

----------------------------------------------------------------------
 .../apache/karaf/cellar/features/LocalFeaturesListener.java    | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/f9a2725a/features/src/main/java/org/apache/karaf/cellar/features/LocalFeaturesListener.java
----------------------------------------------------------------------
diff --git a/features/src/main/java/org/apache/karaf/cellar/features/LocalFeaturesListener.java b/features/src/main/java/org/apache/karaf/cellar/features/LocalFeaturesListener.java
index 26c5f50..98a7e2e 100644
--- a/features/src/main/java/org/apache/karaf/cellar/features/LocalFeaturesListener.java
+++ b/features/src/main/java/org/apache/karaf/cellar/features/LocalFeaturesListener.java
@@ -138,7 +138,11 @@ public class LocalFeaturesListener extends FeaturesSupport implements org.apache
                         // update the features repositories in the cluster group
                         if (RepositoryEvent.EventType.RepositoryAdded.equals(type)) {
                             if (!clusterRepositories.containsKey(event.getRepository().getURI().toString())) {
-                                clusterRepositories.put(event.getRepository().getURI().toString(), event.getRepository().getName());
+                                try {
+                                    clusterRepositories.put(event.getRepository().getURI().toString(), event.getRepository().getName());
+                                } catch (Exception e) {
+                                    // nothing to do
+                                }
                             }
                             // update the features in the cluster group
                             Map<String, FeatureState> clusterFeatures = clusterManager.getMap(Constants.FEATURES_MAP + Configurations.SEPARATOR + group.getName());