You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2014/04/25 17:26:34 UTC

[1/4] git commit: [KARAF-2942] A couple more features/core JDK7 enhancement

Repository: karaf
Updated Branches:
  refs/heads/master 1c63a097e -> 3610b1dd8


[KARAF-2942] A couple more features/core JDK7 enhancement

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

Branch: refs/heads/master
Commit: aa729204dee764c247387d1115e47b68f79a34a0
Parents: 1c63a09
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Fri Apr 25 16:47:05 2014 +0200
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Fri Apr 25 17:06:19 2014 +0200

----------------------------------------------------------------------
 .../karaf/features/internal/osgi/Activator.java       |  8 ++++----
 .../internal/service/FeaturesServiceImpl.java         |  7 +++++--
 .../karaf/features/internal/service/StateStorage.java | 14 +++++++-------
 3 files changed, 16 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/aa729204/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java b/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java
index 4066dfa..8dbbf7c 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java
@@ -94,7 +94,7 @@ public class Activator extends BaseActivator {
                 logger.warn("Error reading configuration file " + configFile.toString(), e);
             }
         }
-        Dictionary<String, String> props = new Hashtable<String, String>();
+        Dictionary<String, String> props = new Hashtable<>();
         for (Map.Entry<String, String> entry : configuration.entrySet()) {
             props.put(entry.getKey(), entry.getValue());
         }
@@ -126,11 +126,11 @@ public class Activator extends BaseActivator {
 
 
         FeatureFinder featureFinder = new FeatureFinder();
-        Hashtable<String, Object> props = new Hashtable<String, Object>();
+        Hashtable<String, Object> props = new Hashtable<>();
         props.put(Constants.SERVICE_PID, FEATURES_REPOS_PID);
         register(ManagedService.class, featureFinder, props);
 
-        List<Repository> repositories = new ArrayList<Repository>();
+        List<Repository> repositories = new ArrayList<>();
         String[] resourceRepositories = getString("resourceRepositories", "").split(",");
         for (String url : resourceRepositories) {
             url = url.trim();
@@ -192,7 +192,7 @@ public class Activator extends BaseActivator {
                                 globalRepository);
         register(FeaturesService.class, featuresService);
 
-        featuresListenerTracker = new ServiceTracker<FeaturesListener, FeaturesListener>(
+        featuresListenerTracker = new ServiceTracker<>(
                 bundleContext, FeaturesListener.class, new ServiceTrackerCustomizer<FeaturesListener, FeaturesListener>() {
             @Override
             public FeaturesListener addingService(ServiceReference<FeaturesListener> reference) {

http://git-wip-us.apache.org/repos/asf/karaf/blob/aa729204/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
index 054c615..33b066f 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
@@ -1210,8 +1210,11 @@ public class FeaturesServiceImpl implements FeaturesService {
                     Resource resource = entry.getValue();
                     String uri = getUri(resource);
                     print("  " + uri, verbose);
-                    InputStream is = getBundleInputStream(resource, providers);
-                    bundle.update(is);
+                    try (
+                        InputStream is = getBundleInputStream(resource, providers)
+                    ) {
+                        bundle.update(is);
+                    }
                     toStart.add(bundle);
                     BundleInfo bi = bundleInfos.get(rde.getKey()).get(uri);
                     if (bi != null && bi.getStartLevel() > 0) {

http://git-wip-us.apache.org/repos/asf/karaf/blob/aa729204/features/core/src/main/java/org/apache/karaf/features/internal/service/StateStorage.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/StateStorage.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/StateStorage.java
index a509a9d..8168994 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/StateStorage.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/StateStorage.java
@@ -55,7 +55,7 @@ public abstract class StateStorage {
             OutputStream os = getOutputStream()
         ) {
             if (os != null) {
-                Map<String, Object> json = new HashMap<String, Object>();
+                Map<String, Object> json = new HashMap<>();
                 json.put("bootDone", state.bootDone.get());
                 json.put("repositories", state.repositories);
                 json.put("features", state.requestedFeatures);
@@ -71,7 +71,7 @@ public abstract class StateStorage {
     protected abstract OutputStream getOutputStream() throws IOException;
 
     protected Map<String, Set<String>> toStringStringSetMap(Map<?,?> map) {
-        Map<String, Set<String>> nm = new HashMap<String, Set<String>>();
+        Map<String, Set<String>> nm = new HashMap<>();
         for (Map.Entry entry : map.entrySet()) {
             nm.put(entry.getKey().toString(), toStringSet((Collection) entry.getValue()));
         }
@@ -79,7 +79,7 @@ public abstract class StateStorage {
     }
 
     protected Map<String, Set<Long>> toStringLongSetMap(Map<?,?> map) {
-        Map<String, Set<Long>> nm = new HashMap<String, Set<Long>>();
+        Map<String, Set<Long>> nm = new HashMap<>();
         for (Map.Entry entry : map.entrySet()) {
             nm.put(entry.getKey().toString(), toLongSet((Collection) entry.getValue()));
         }
@@ -87,7 +87,7 @@ public abstract class StateStorage {
     }
 
     protected Set<String> toStringSet(Collection<?> col) {
-        Set<String> ns = new TreeSet<String>();
+        Set<String> ns = new TreeSet<>();
         for (Object o : col) {
             ns.add(o.toString());
         }
@@ -95,7 +95,7 @@ public abstract class StateStorage {
     }
 
     protected Set<Long> toLongSet(Collection<?> set) {
-        Set<Long> ns = new TreeSet<Long>();
+        Set<Long> ns = new TreeSet<>();
         for (Object o : set) {
             ns.add(toLong(o));
         }
@@ -103,7 +103,7 @@ public abstract class StateStorage {
     }
 
     protected Map<Long, Long> toLongLongMap(Map<?,?> map) {
-        Map<Long, Long> nm = new HashMap<Long, Long>();
+        Map<Long, Long> nm = new HashMap<>();
         for (Map.Entry entry : map.entrySet()) {
             nm.put(toLong(entry.getKey()), toLong(entry.getValue()));
         }
@@ -111,7 +111,7 @@ public abstract class StateStorage {
     }
 
     protected Map<String, Long> toStringLongMap(Map<?,?> map) {
-        Map<String, Long> nm = new HashMap<String, Long>();
+        Map<String, Long> nm = new HashMap<>();
         for (Map.Entry entry : map.entrySet()) {
             nm.put(entry.getKey().toString(), toLong(entry.getValue()));
         }


[4/4] git commit: [KARAF-2930] Remove annoying warning when not using any global repository

Posted by gn...@apache.org.
[KARAF-2930] Remove annoying warning when not using any global repository

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

Branch: refs/heads/master
Commit: 3610b1dd8547ee3cda032b7b69237af87a9b3dd0
Parents: 400e940
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Fri Apr 25 17:13:53 2014 +0200
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Fri Apr 25 17:13:53 2014 +0200

----------------------------------------------------------------------
 .../karaf/features/internal/osgi/Activator.java       | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/3610b1dd/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java b/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java
index 8dbbf7c..81fdf49 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java
@@ -134,12 +134,14 @@ public class Activator extends BaseActivator {
         String[] resourceRepositories = getString("resourceRepositories", "").split(",");
         for (String url : resourceRepositories) {
             url = url.trim();
-            if (url.startsWith("json:")) {
-                repositories.add(new JsonRepository(url.substring("json:".length())));
-            } else if (url.startsWith("xml:")) {
-                repositories.add(new XmlRepository(url.substring("xml:".length())));
-            } else {
-                logger.warn("Unrecognized resource repository: " + url);
+            if (!url.isEmpty()) {
+                if (url.startsWith("json:")) {
+                    repositories.add(new JsonRepository(url.substring("json:".length())));
+                } else if (url.startsWith("xml:")) {
+                    repositories.add(new XmlRepository(url.substring("xml:".length())));
+                } else {
+                    logger.warn("Unrecognized resource repository: " + url);
+                }
             }
         }
         Repository globalRepository;


[3/4] git commit: [KARAF-2888] Support updates on the FeaturesService bundle itself

Posted by gn...@apache.org.
[KARAF-2888] Support updates on the FeaturesService bundle itself

This is done by updating the bundle separately and writing a file with resolution request so that when the service is restarted, the full resolution will happen

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

Branch: refs/heads/master
Commit: 400e9407db1bce65bfd5c9a5070893f4536b6e0a
Parents: c01c51d
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Fri Apr 25 17:09:18 2014 +0200
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Fri Apr 25 17:13:14 2014 +0200

----------------------------------------------------------------------
 .../internal/service/FeaturesServiceImpl.java   | 109 +++++++++++++++++--
 .../features/internal/service/StateStorage.java |  12 +-
 2 files changed, 106 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/400e9407/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
index da27397..5d40440 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
@@ -16,6 +16,9 @@
  */
 package org.apache.karaf.features.internal.service;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URI;
@@ -52,6 +55,8 @@ import org.apache.karaf.features.RepositoryEvent;
 import org.apache.karaf.features.internal.download.StreamProvider;
 import org.apache.karaf.features.internal.region.SubsystemResolver;
 import org.apache.karaf.features.internal.util.ChecksumUtils;
+import org.apache.karaf.features.internal.util.JsonReader;
+import org.apache.karaf.features.internal.util.JsonWriter;
 import org.apache.karaf.features.internal.util.Macro;
 import org.apache.karaf.features.internal.util.MapUtils;
 import org.apache.karaf.features.internal.util.MultiException;
@@ -82,6 +87,7 @@ import static org.apache.felix.resolver.Util.getSymbolicName;
 import static org.apache.felix.resolver.Util.getVersion;
 import static org.apache.karaf.features.internal.resolver.ResourceUtils.getFeatureId;
 import static org.apache.karaf.features.internal.resolver.ResourceUtils.getUri;
+import static org.apache.karaf.features.internal.service.StateStorage.toStringStringSetMap;
 import static org.apache.karaf.features.internal.util.MapUtils.addToMapSet;
 import static org.apache.karaf.features.internal.util.MapUtils.apply;
 import static org.apache.karaf.features.internal.util.MapUtils.contains;
@@ -197,6 +203,55 @@ public class FeaturesServiceImpl implements FeaturesService {
         this.updateSnaphots = updateSnaphots;
         this.globalRepository = globalRepository;
         loadState();
+        checkResolve();
+
+    }
+
+    private void checkResolve() {
+        if (bundle == null) {
+            return; // Most certainly in unit tests
+        }
+        File resolveFile = bundle.getBundleContext().getDataFile("resolve");
+        if (!resolveFile.exists()) {
+            return;
+        }
+        Map<String, Object> request;
+        try(
+            FileInputStream fis = new FileInputStream(resolveFile)
+        ) {
+            request = (Map<String, Object>) JsonReader.read(fis);
+        } catch (IOException e) {
+            LOGGER.warn("Error reading resolution request", e);
+            return;
+        }
+        Map<String, Set<String>> requestedFeatures = toStringStringSetMap((Map) request.get("features"));
+        Collection<String> opts = (Collection<String>) request.get("options");
+        EnumSet<Option> options = EnumSet.noneOf(Option.class);
+        for (String opt : opts) {
+            options.add(Option.valueOf(opt));
+        }
+        // Resolve
+        try {
+            doInstallFeaturesInThread(requestedFeatures, copyState(), options);
+        } catch (Exception e) {
+            LOGGER.warn("Error updating state", e);
+        }
+    }
+
+    private void writeResolve(Map<String, Set<String>> requestedFeatures, EnumSet<Option> options) throws IOException {
+        File resolveFile = bundle.getBundleContext().getDataFile("resolve");
+        Map<String, Object> request = new HashMap<>();
+        List<String> opts = new ArrayList<>();
+        for (Option opt : options) {
+            opts.add(opt.toString());
+        }
+        request.put("features", requestedFeatures);
+        request.put("options", opts);
+        try(
+                FileOutputStream fos = new FileOutputStream(resolveFile);
+        ) {
+            JsonWriter.write(fos, request);
+        }
     }
 
     //
@@ -1025,16 +1080,52 @@ public class FeaturesServiceImpl implements FeaturesService {
         // #10: send events
         //
 
-        // TODO: handle update on the features service itself
+        //
+        // Handle updates on the FeaturesService bundle
+        //
         RegionDeployment rootRegionDeployment = deployment.regions.get(ROOT_REGION);
-        if (rootRegionDeployment != null &&
-                (rootRegionDeployment.toUpdate.containsKey(bundle)
-                        || rootRegionDeployment.toDelete.contains(bundle))) {
-
-            LOGGER.warn("Updating or uninstalling of the FeaturesService is not supported");
-            rootRegionDeployment.toUpdate.remove(bundle);
-            rootRegionDeployment.toDelete.remove(bundle);
-
+        // We don't support uninstalling the bundle
+        if (rootRegionDeployment != null && rootRegionDeployment.toDelete.contains(bundle)) {
+            throw new UnsupportedOperationException("Uninstalling the FeaturesService bundle is not supported");
+        }
+        // If the bundle needs to be updated, do the following:
+        //  - create flag files to indicate the resolution must be continued after restart
+        //  - update the checksum and save the state
+        //  - compute bundles wired to the FeaturesService bundle that will be refreshed
+        //  - stop the bundle
+        //  - update the bundle
+        //  - refresh wired bundles
+        //  - start the bundle
+        //  - exit
+        // When restarting, the resolution will be attempted again
+        if (rootRegionDeployment != null && rootRegionDeployment.toUpdate.containsKey(bundle)) {
+            writeResolve(requestedFeatures, options);
+            // If the bundle is updated because of a different checksum,
+            // save the new checksum persistently
+            if (deployment.bundleChecksums.containsKey(bundle.getBundleId())) {
+                synchronized (lock) {
+                    this.state.bundleChecksums.put(bundle.getBundleId(), deployment.bundleChecksums.get(bundle.getBundleId()));
+                    saveState();
+                }
+            }
+            Resource resource = rootRegionDeployment.toUpdate.get(bundle);
+            String uri = getUri(resource);
+            print("The FeaturesService bundle needs is being updated with " + uri, verbose);
+            toRefresh.clear();
+            toRefresh.add(bundle);
+            computeBundlesToRefresh(toRefresh,
+                    dstate.bundles.values(),
+                    Collections.<Resource, Bundle>emptyMap(),
+                    Collections.<Resource, List<Wire>>emptyMap());
+            bundle.stop(Bundle.STOP_TRANSIENT);
+            try (
+                InputStream is = getBundleInputStream(resource, providers)
+            ) {
+                bundle.update(is);
+            }
+            refreshPackages(toRefresh);
+            bundle.start();
+            return;
         }
 
         //

http://git-wip-us.apache.org/repos/asf/karaf/blob/400e9407/features/core/src/main/java/org/apache/karaf/features/internal/service/StateStorage.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/StateStorage.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/StateStorage.java
index 8168994..e6adab0 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/StateStorage.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/StateStorage.java
@@ -70,7 +70,7 @@ public abstract class StateStorage {
     protected abstract InputStream getInputStream() throws IOException;
     protected abstract OutputStream getOutputStream() throws IOException;
 
-    protected Map<String, Set<String>> toStringStringSetMap(Map<?,?> map) {
+    static Map<String, Set<String>> toStringStringSetMap(Map<?,?> map) {
         Map<String, Set<String>> nm = new HashMap<>();
         for (Map.Entry entry : map.entrySet()) {
             nm.put(entry.getKey().toString(), toStringSet((Collection) entry.getValue()));
@@ -78,7 +78,7 @@ public abstract class StateStorage {
         return nm;
     }
 
-    protected Map<String, Set<Long>> toStringLongSetMap(Map<?,?> map) {
+    static  Map<String, Set<Long>> toStringLongSetMap(Map<?,?> map) {
         Map<String, Set<Long>> nm = new HashMap<>();
         for (Map.Entry entry : map.entrySet()) {
             nm.put(entry.getKey().toString(), toLongSet((Collection) entry.getValue()));
@@ -86,7 +86,7 @@ public abstract class StateStorage {
         return nm;
     }
 
-    protected Set<String> toStringSet(Collection<?> col) {
+    static  Set<String> toStringSet(Collection<?> col) {
         Set<String> ns = new TreeSet<>();
         for (Object o : col) {
             ns.add(o.toString());
@@ -94,7 +94,7 @@ public abstract class StateStorage {
         return ns;
     }
 
-    protected Set<Long> toLongSet(Collection<?> set) {
+    static  Set<Long> toLongSet(Collection<?> set) {
         Set<Long> ns = new TreeSet<>();
         for (Object o : set) {
             ns.add(toLong(o));
@@ -102,7 +102,7 @@ public abstract class StateStorage {
         return ns;
     }
 
-    protected Map<Long, Long> toLongLongMap(Map<?,?> map) {
+    static  Map<Long, Long> toLongLongMap(Map<?,?> map) {
         Map<Long, Long> nm = new HashMap<>();
         for (Map.Entry entry : map.entrySet()) {
             nm.put(toLong(entry.getKey()), toLong(entry.getValue()));
@@ -110,7 +110,7 @@ public abstract class StateStorage {
         return nm;
     }
 
-    protected Map<String, Long> toStringLongMap(Map<?,?> map) {
+    static Map<String, Long> toStringLongMap(Map<?,?> map) {
         Map<String, Long> nm = new HashMap<>();
         for (Map.Entry entry : map.entrySet()) {
             nm.put(entry.getKey().toString(), toLong(entry.getValue()));


[2/4] git commit: [KARAF-2888] Remove unnecessary code (bundle start levels are handled separately now)

Posted by gn...@apache.org.
[KARAF-2888] Remove unnecessary code (bundle start levels are handled separately now)

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

Branch: refs/heads/master
Commit: c01c51d14dcedea579ceabbb77ed23941a9e4c2a
Parents: aa72920
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Fri Apr 25 17:07:40 2014 +0200
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Fri Apr 25 17:07:40 2014 +0200

----------------------------------------------------------------------
 .../karaf/features/internal/service/FeaturesServiceImpl.java   | 6 ------
 1 file changed, 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/c01c51d1/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
index 33b066f..da27397 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeaturesServiceImpl.java
@@ -1216,12 +1216,6 @@ public class FeaturesServiceImpl implements FeaturesService {
                         bundle.update(is);
                     }
                     toStart.add(bundle);
-                    BundleInfo bi = bundleInfos.get(rde.getKey()).get(uri);
-                    if (bi != null && bi.getStartLevel() > 0) {
-                        // TODO: this is wrong, as it will certainly start the bundle asynchronously
-                        // TODO:
-                        bundle.adapt(BundleStartLevel.class).setStartLevel(bi.getStartLevel());
-                    }
                 }
             }
         }