karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject karaf git commit: Centralize digraph functionality
Date Tue, 16 May 2017 19:17:35 GMT
Repository: karaf
Updated Branches:
  refs/heads/master bb0e9b77e -> 2e8c6ee44


Centralize digraph functionality


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

Branch: refs/heads/master
Commit: 2e8c6ee443be93c5d85c80d5d0b2a59afd615aca
Parents: bb0e9b7
Author: Christian Schneider <chris@die-schneider.net>
Authored: Tue May 16 21:17:28 2017 +0200
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Tue May 16 21:17:28 2017 +0200

----------------------------------------------------------------------
 .../karaf/features/internal/osgi/Activator.java | 25 +++++---------
 .../features/internal/region/DigraphHelper.java | 36 +++++++++++++++++---
 .../internal/service/BundleInstallSupport.java  |  5 ++-
 .../service/BundleInstallSupportImpl.java       | 13 +++++--
 .../internal/service/FeaturesServiceImpl.java   | 29 +++-------------
 .../assembly/AssemblyDeployCallback.java        |  8 ++++-
 .../org/apache/karaf/tooling/VerifyMojo.java    |  7 +++-
 7 files changed, 73 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/2e8c6ee4/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 da5eeb3..1d0db3d 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
@@ -91,8 +91,8 @@ public class Activator extends BaseActivator {
 
     private ServiceTracker<FeaturesListener, FeaturesListener> featuresListenerTracker;
     private FeaturesServiceImpl featuresService;
-    private StandardRegionDigraph digraph;
     private StandardManageableRegionDigraph digraphMBean;
+    private BundleInstallSupport installSupport;
 
     public Activator() {
         // Special case here, as we don't want the activator to wait for current job to finish,
@@ -130,7 +130,7 @@ public class Activator extends BaseActivator {
         }
 
         // RegionDigraph
-        StandardRegionDigraph dg = digraph = DigraphHelper.loadDigraph(bundleContext);
+        StandardRegionDigraph dg = DigraphHelper.loadDigraph(bundleContext);
         register(ResolverHookFactory.class, dg.getResolverHookFactory());
         register(CollisionHook.class, CollisionHookHelper.getCollisionHook(dg));
         register(org.osgi.framework.hooks.bundle.FindHook.class, dg.getBundleFindHook());
@@ -138,7 +138,6 @@ public class Activator extends BaseActivator {
         register(org.osgi.framework.hooks.service.FindHook.class, dg.getServiceFindHook());
         register(org.osgi.framework.hooks.service.EventHook.class, dg.getServiceEventHook());
         register(RegionDigraph.class, dg);
-        register(RegionDigraphPersistence.class, this::doPersistRegionDigraph);
 
         if (getBoolean("digraphMBean", FeaturesService.DEFAULT_DIGRAPH_MBEAN)) {
             StandardManageableRegionDigraph dgmb = digraphMBean = new StandardManageableRegionDigraph(dg,
"org.apache.karaf", bundleContext);
@@ -209,10 +208,13 @@ public class Activator extends BaseActivator {
         };
         BundleContext systemBundleContext = bundleContext.getBundle(0).getBundleContext();
         FeatureConfigInstaller configInstaller = configurationAdmin != null ? new FeatureConfigInstaller(configurationAdmin,
configCfgStore) : null;
-        BundleInstallSupport installSupport = new BundleInstallSupportImpl(bundleContext.getBundle(),
+        installSupport = new BundleInstallSupportImpl(
+                    bundleContext.getBundle(),
+                    bundleContext,
                     systemBundleContext,
                     configInstaller,
                     dg);
+        register(RegionDigraphPersistence.class, () -> installSupport.saveState());
         featuresService = new FeaturesServiceImpl(
                 bundleContext.getBundle(),
                 bundleContext,
@@ -285,19 +287,8 @@ public class Activator extends BaseActivator {
             featuresService.stop();
             featuresService = null;
         }
-        if (digraph != null) {
-            doPersistRegionDigraph();
-            digraph = null;
-        }
-    }
-
-    private void doPersistRegionDigraph() {
-        if (digraph != null) {
-            try {
-                DigraphHelper.saveDigraph(bundleContext, digraph);
-            } catch (Exception e) {
-                // Ignore
-            }
+        if (installSupport != null) {
+            installSupport.saveState();
         }
     }
 

http://git-wip-us.apache.org/repos/asf/karaf/blob/2e8c6ee4/features/core/src/main/java/org/apache/karaf/features/internal/region/DigraphHelper.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/region/DigraphHelper.java
b/features/core/src/main/java/org/apache/karaf/features/internal/region/DigraphHelper.java
index 71c77e2..5706fc8 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/region/DigraphHelper.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/region/DigraphHelper.java
@@ -16,6 +16,8 @@
  */
 package org.apache.karaf.features.internal.region;
 
+import static org.apache.karaf.features.internal.util.MapUtils.addToMapSet;
+
 import java.io.DataInputStream;
 import java.io.File;
 import java.io.FileInputStream;
@@ -46,7 +48,7 @@ import org.osgi.framework.InvalidSyntaxException;
 
 public final class DigraphHelper {
 
-    private static final String DIGRAPH_FILE = "digraph.json";
+    public static final String DIGRAPH_FILE = "digraph.json";
 
     private static final String REGIONS = "regions";
     private static final String EDGES = "edges";
@@ -95,10 +97,9 @@ public final class DigraphHelper {
         return digraph;
     }
 
-    public static void saveDigraph(BundleContext bundleContext, RegionDigraph digraph) throws
IOException {
-        File digraphFile = bundleContext.getDataFile(DIGRAPH_FILE);
+    public static void saveDigraph(File outFile, RegionDigraph digraph) {
         try (
-                FileOutputStream out = new FileOutputStream(digraphFile)
+            FileOutputStream out = new FileOutputStream(outFile)
         ) {
             saveDigraph(digraph, out);
         } catch (Exception e) {
@@ -157,4 +158,31 @@ public final class DigraphHelper {
         JsonWriter.write(out, json);
     }
 
+    public static Map<String, Set<Long>> getBundlesPerRegion(RegionDigraph digraph)
{
+        Map<String, Set<Long>> bundlesPerRegion = new HashMap<>();
+        for (Region region : digraph.getRegions()) {
+            bundlesPerRegion.put(region.getName(), new HashSet<>(region.getBundleIds()));
+        }
+        return bundlesPerRegion;
+    }
+    
+    public static Map<String, Map<String, Map<String, Set<String>>>>
getPolicies(RegionDigraph digraph) {
+        Map<String, Map<String, Map<String, Set<String>>>> filtersPerRegion
= new HashMap<>();
+        
+        for (Region region : digraph.getRegions()) {
+            Map<String, Map<String, Set<String>>> edges = new HashMap<>();
+            for (RegionDigraph.FilteredRegion fr : digraph.getEdges(region)) {
+                Map<String, Set<String>> policy = new HashMap<>();
+                Map<String, Collection<String>> current = fr.getFilter().getSharingPolicy();
+                for (String ns : current.keySet()) {
+                    for (String f : current.get(ns)) {
+                        addToMapSet(policy, ns, f);
+                    }
+                }
+                edges.put(fr.getRegion().getName(), policy);
+            }
+            filtersPerRegion.put(region.getName(), edges);
+        }
+        return filtersPerRegion;
+    }
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/2e8c6ee4/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupport.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupport.java
b/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupport.java
index 66bbc17..5003515 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupport.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupport.java
@@ -16,6 +16,7 @@
  */
 package org.apache.karaf.features.internal.service;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Collection;
@@ -56,7 +57,7 @@ public interface BundleInstallSupport {
                         Map<String, Set<Long>> bundles)
         throws BundleException, InvalidSyntaxException;
 
-    void saveState() throws IOException;
+    void saveState();
 
     RegionDigraph getDiGraphCopy() throws BundleException;
     
@@ -64,4 +65,6 @@ public interface BundleInstallSupport {
     
     void installLibraries(Feature feature) throws IOException;
 
+    File getDataFile(String name);
+
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/2e8c6ee4/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupportImpl.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupportImpl.java
b/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupportImpl.java
index 5de6166..6b9d1f9 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupportImpl.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/BundleInstallSupportImpl.java
@@ -62,6 +62,7 @@ public class BundleInstallSupportImpl implements BundleInstallSupport {
     
     private final RegionDigraph digraph;
     private final Bundle ourBundle;
+    private final BundleContext ourBundleContext;
     private final FeatureConfigInstaller configInstaller;
     
     /**
@@ -73,10 +74,12 @@ public class BundleInstallSupportImpl implements BundleInstallSupport
{
     private final BundleContext systemBundleContext;
     
     public BundleInstallSupportImpl(Bundle ourBundle,
+                   BundleContext ourBundleContext,
                    BundleContext systemBundleContext,
                    FeatureConfigInstaller configInstaller,
                    RegionDigraph digraph) {
         this.ourBundle = ourBundle;
+        this.ourBundleContext = ourBundleContext;
         this.systemBundleContext = systemBundleContext;
         this.configInstaller = configInstaller;
         this.digraph = digraph;
@@ -281,8 +284,8 @@ public class BundleInstallSupportImpl implements BundleInstallSupport
{
      * @see org.apache.karaf.features.internal.service.Regions#saveState()
      */
     @Override
-    public void saveState() throws IOException {
-        DigraphHelper.saveDigraph(ourBundle.getBundleContext(), digraph);
+    public void saveState() {
+        DigraphHelper.saveDigraph(getDataFile(DigraphHelper.DIGRAPH_FILE), digraph);
     }
     
     /* (non-Javadoc)
@@ -304,4 +307,10 @@ public class BundleInstallSupportImpl implements BundleInstallSupport
{
     public void installLibraries(Feature feature) {
         // TODO: install libraries
     }
+
+    @Override
+    public File getDataFile(String fileName) {
+        return ourBundleContext.getDataFile(fileName);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/2e8c6ee4/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 d3b332b..b28328d 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
@@ -62,10 +62,10 @@ import org.apache.karaf.features.Repository;
 import org.apache.karaf.features.RepositoryEvent;
 import org.apache.karaf.features.internal.download.DownloadManager;
 import org.apache.karaf.features.internal.download.DownloadManagers;
+import org.apache.karaf.features.internal.region.DigraphHelper;
 import org.apache.karaf.features.internal.util.JsonReader;
 import org.apache.karaf.features.internal.util.JsonWriter;
 import org.apache.karaf.util.collections.CopyOnWriteArrayIdentityList;
-import org.eclipse.equinox.region.Region;
 import org.eclipse.equinox.region.RegionDigraph;
 import org.ops4j.pax.url.mvn.MavenResolver;
 import org.ops4j.pax.url.mvn.MavenResolvers;
@@ -81,7 +81,6 @@ import org.slf4j.LoggerFactory;
 
 import static org.apache.karaf.features.internal.service.StateStorage.toStringStringSetMap;
 import static org.apache.karaf.features.internal.util.MapUtils.add;
-import static org.apache.karaf.features.internal.util.MapUtils.addToMapSet;
 import static org.apache.karaf.features.internal.util.MapUtils.copy;
 import static org.apache.karaf.features.internal.util.MapUtils.remove;
 
@@ -1029,29 +1028,11 @@ public class FeaturesServiceImpl implements FeaturesService, Deployer.DeployCall
                 dstate.features.put(id, feature);
             }
         }
-        // Region -> bundles mapping
-        // Region -> policy mapping
-        dstate.bundlesPerRegion = new HashMap<>();
-        dstate.filtersPerRegion = new HashMap<>();
-        RegionDigraph clone = installSupport.getDiGraphCopy();
-        for (Region region : clone.getRegions()) {
-            // Get bundles
-            dstate.bundlesPerRegion.put(region.getName(), new HashSet<>(region.getBundleIds()));
-            // Get policies
-            Map<String, Map<String, Set<String>>> edges = new HashMap<>();
-            for (RegionDigraph.FilteredRegion fr : clone.getEdges(region)) {
-                Map<String, Set<String>> policy = new HashMap<>();
-                Map<String, Collection<String>> current = fr.getFilter().getSharingPolicy();
-                for (String ns : current.keySet()) {
-                    for (String f : current.get(ns)) {
-                        addToMapSet(policy, ns, f);
-                    }
-                }
-                edges.put(fr.getRegion().getName(), policy);
-            }
-            dstate.filtersPerRegion.put(region.getName(), edges);
+        RegionDigraph regionDigraph = installSupport.getDiGraphCopy();
+        if (regionDigraph != null) {
+            dstate.bundlesPerRegion = DigraphHelper.getBundlesPerRegion(regionDigraph);
+            dstate.filtersPerRegion = DigraphHelper.getPolicies(regionDigraph);
         }
-        // Return
         return dstate;
     }
 

http://git-wip-us.apache.org/repos/asf/karaf/blob/2e8c6ee4/profile/src/main/java/org/apache/karaf/profile/assembly/AssemblyDeployCallback.java
----------------------------------------------------------------------
diff --git a/profile/src/main/java/org/apache/karaf/profile/assembly/AssemblyDeployCallback.java
b/profile/src/main/java/org/apache/karaf/profile/assembly/AssemblyDeployCallback.java
index 78506ee..0440182 100644
--- a/profile/src/main/java/org/apache/karaf/profile/assembly/AssemblyDeployCallback.java
+++ b/profile/src/main/java/org/apache/karaf/profile/assembly/AssemblyDeployCallback.java
@@ -16,6 +16,7 @@
  */
 package org.apache.karaf.profile.assembly;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.file.Files;
@@ -316,11 +317,16 @@ public class AssemblyDeployCallback implements Deployer.DeployCallback,
BundleIn
     }
 
     @Override
-    public void saveState() throws IOException {
+    public void saveState() {
     }
 
     @Override
     public RegionDigraph getDiGraphCopy() throws BundleException {
         return null;
     }
+
+    @Override
+    public File getDataFile(String name) {
+        return null;
+    }
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/2e8c6ee4/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/VerifyMojo.java
----------------------------------------------------------------------
diff --git a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/VerifyMojo.java
b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/VerifyMojo.java
index c1d2714..8a3b7d4 100644
--- a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/VerifyMojo.java
+++ b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/VerifyMojo.java
@@ -874,13 +874,18 @@ public class VerifyMojo extends MojoSupport {
         }
 
         @Override
-        public void saveState() throws IOException {
+        public void saveState() {
         }
 
         @Override
         public RegionDigraph getDiGraphCopy() throws BundleException {
             return null;
         }
+
+        @Override
+        public File getDataFile(String name) {
+            return null;
+        }
     }
 
     public class MavenResolverLog extends org.apache.felix.resolver.Logger {


Mime
View raw message