karaf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (KARAF-5667) Installing the audit-log feature never ends
Date Thu, 15 Mar 2018 17:29:00 GMT

    [ https://issues.apache.org/jira/browse/KARAF-5667?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16400768#comment-16400768
] 

ASF GitHub Bot commented on KARAF-5667:
---------------------------------------

gnodet closed pull request #470: [KARAF-5667] Installing the audit-log feature never ends
URL: https://github.com/apache/karaf/pull/470
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 5ef8870f57..8ac3e3bcb6 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
@@ -152,6 +152,7 @@ protected void doStart() throws Exception {
                     bundleContext.getBundle(),
                     bundleContext,
                     systemBundleContext,
+                    getTrackedServiceRef(ConfigurationAdmin.class).getBundle(),
                     configInstaller,
                     dg);
         register(RegionDigraphPersistence.class, () -> installSupport.saveDigraph());
@@ -326,6 +327,7 @@ protected void doStop() {
         if (installSupport != null) {
             installSupport.unregister();
             installSupport.saveDigraph();
+            installSupport = null;
         }
     }
 
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 fb31a7a462..9dc06a4852 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
@@ -85,6 +85,7 @@ void replaceDigraph(Map<String, Map<String, Map<String, Set<String>>>>
policies,
     class FrameworkInfo {
         public Bundle ourBundle;
         public Bundle systemBundle;
+        public Bundle cmBundle;
         public int initialBundleStartLevel;
         public int currentStartLevel;
         public Map<Long, Bundle> bundles = new HashMap<>();
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 24c2fbfcad..5b0c7e67df 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
@@ -68,6 +68,7 @@
     
     private final RegionDigraph digraph;
     private final Bundle ourBundle;
+    private final Bundle cmBundle;
     private final BundleContext ourBundleContext;
     private final FeatureConfigInstaller configInstaller;
     
@@ -85,11 +86,13 @@
     public BundleInstallSupportImpl(Bundle ourBundle,
                    BundleContext ourBundleContext,
                    BundleContext systemBundleContext,
+                   Bundle cmBundle,
                    FeatureConfigInstaller configInstaller,
                    RegionDigraph digraph) {
         this.ourBundle = ourBundle;
         this.ourBundleContext = ourBundleContext;
         this.systemBundleContext = systemBundleContext;
+        this.cmBundle = cmBundle;
         this.configInstaller = configInstaller;
         this.digraph = digraph;
         if (systemBundleContext != null) {
@@ -102,6 +105,7 @@ public BundleInstallSupportImpl(Bundle ourBundle,
     public void unregister() {
         if (hookRegistration != null) {
             hookRegistration.unregister();
+            hookRegistration = null;
         }
     }
     
@@ -315,6 +319,7 @@ public FrameworkInfo getInfo() {
         for (Bundle bundle : systemBundleContext.getBundles()) {
             info.bundles.put(bundle.getBundleId(), bundle);
         }
+        info.cmBundle = cmBundle;
         info.systemBundle = info.bundles.get(0L);
         return info;
     }
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java
b/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java
index dab5f60bda..14086e734c 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java
@@ -79,6 +79,7 @@
 import org.osgi.resource.Wire;
 import org.osgi.service.repository.Repository;
 import org.osgi.service.resolver.Resolver;
+import org.osgi.util.tracker.ServiceTracker;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -176,6 +177,8 @@ public PartialDeploymentException(Set<String> missing) {
 
         /** A {@link Bundle} providing {@link FeaturesService} */
         public Bundle serviceBundle;
+        /** A {@link Bundle} providing {@link org.osgi.service.cm.ConfigurationAdmin} service
*/
+        public Bundle configadminBundle;
         /** {@link org.osgi.framework.startlevel.FrameworkStartLevel#getInitialBundleStartLevel()}
*/
         public int initialBundleStartLevel;
         /** {@link org.osgi.framework.startlevel.FrameworkStartLevel#getStartLevel()} */
@@ -662,6 +665,7 @@ public void deploy(DeploymentState dstate, DeploymentRequest request)
throws Exc
         // #10: send events
         //
         Bundle serviceBundle = dstate.serviceBundle;
+        Bundle configadminBundle = dstate.configadminBundle;
         //
         // Handle updates on the FeaturesService bundle
         //
@@ -727,6 +731,7 @@ public void deploy(DeploymentState dstate, DeploymentRequest request)
throws Exc
         if (!noRefresh) {
             Set<Bundle> toRefreshToStopEarly = new HashSet<>(toRefresh.keySet());
             toRefreshToStopEarly.remove(dstate.serviceBundle);
+            toRefreshToStopEarly.remove(dstate.configadminBundle);
             toStop.addAll(toRefreshToStopEarly);
             toStart.addAll(toRefreshToStopEarly);
         }
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 c6626a326f..ce36d0d5fe 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
@@ -983,6 +983,7 @@ private void doProvisionInThread(final Map<String, Set<String>>
requirements,
         dstate.state = state;
         FrameworkInfo info = installSupport.getInfo();
         dstate.serviceBundle = info.ourBundle;
+        dstate.configadminBundle = info.cmBundle;
         dstate.initialBundleStartLevel = info.initialBundleStartLevel;
         dstate.currentStartLevel = info.currentStartLevel;
         dstate.bundles = info.bundles;
@@ -1030,6 +1031,10 @@ private void doProvision(Map<String, Set<String>> requirements,
               /
                     } else {
                         throw new Exception("Deployment aborted due to loop in missing prerequisites:
" + e.getMissing());
                     }
+                } catch (Throwable t) {
+                    // Print stack trace to stdout, there may be no log anymore
+                    t.printStackTrace();
+                    throw t;
                 }
             }
         }
diff --git a/util/src/main/java/org/apache/karaf/util/tracker/BaseActivator.java b/util/src/main/java/org/apache/karaf/util/tracker/BaseActivator.java
index c2c7204eba..d562ba1d57 100644
--- a/util/src/main/java/org/apache/karaf/util/tracker/BaseActivator.java
+++ b/util/src/main/java/org/apache/karaf/util/tracker/BaseActivator.java
@@ -37,11 +37,7 @@
 import java.util.stream.Stream;
 import java.util.stream.StreamSupport;
 
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -338,6 +334,14 @@ protected void trackService(String className, String filter) throws InvalidSynta
         return clazz.cast(tracker.getService());
     }
 
+    protected <T> ServiceReference<T> getTrackedServiceRef(Class<T> clazz)
{
+        SingleServiceTracker tracker = trackers.get(clazz.getName());
+        if (tracker == null) {
+            throw new IllegalStateException("Service not tracked for class " + clazz);
+        }
+        return tracker.getServiceReference();
+    }
+
     /**
      * Called in {@link #doStart()}.
      *
diff --git a/util/src/main/java/org/apache/karaf/util/tracker/SingleServiceTracker.java b/util/src/main/java/org/apache/karaf/util/tracker/SingleServiceTracker.java
index 0c52575ec8..b4393512b7 100644
--- a/util/src/main/java/org/apache/karaf/util/tracker/SingleServiceTracker.java
+++ b/util/src/main/java/org/apache/karaf/util/tracker/SingleServiceTracker.java
@@ -37,7 +37,7 @@
     private final BundleContext ctx;
     private final String className;
     private final AtomicReference<T> service = new AtomicReference<>();
-    private final AtomicReference<ServiceReference> ref = new AtomicReference<>();
+    private final AtomicReference<ServiceReference<T>> ref = new AtomicReference<>();
     private final AtomicBoolean open = new AtomicBoolean(false);
     private final BiConsumer<T, T> serviceListener;
     private final String filterString;
@@ -88,7 +88,8 @@ public void open() {
     public void serviceChanged(ServiceEvent event) {
         if (open.get()) {
             if (event.getType() == ServiceEvent.UNREGISTERING) {
-                ServiceReference deadRef = event.getServiceReference();
+                @SuppressWarnings("unchecked")
+                ServiceReference<T> deadRef = (ServiceReference) event.getServiceReference();
                 if (deadRef.equals(ref.get())) {
                     findMatchingReference(deadRef);
                 }
@@ -98,22 +99,23 @@ public void serviceChanged(ServiceEvent event) {
         }
     }
 
-    private void findMatchingReference(ServiceReference original) {
+    private void findMatchingReference(ServiceReference<T> original) {
         try {
             boolean clear = true;
-            ServiceReference[] refs = ctx.getServiceReferences(className, filterString);
+            ServiceReference<?>[] refs = ctx.getServiceReferences(className, filterString);
             if (refs != null && refs.length > 0) {
                 if (refs.length > 1) {
                     Arrays.sort(refs);
                 }
                 @SuppressWarnings("unchecked")
-                T service = (T) ctx.getService(refs[0]);
+                ServiceReference<T> r = (ServiceReference) refs[0];
+                T service = ctx.getService(r);
                 if (service != null) {
                     clear = false;
 
                     // We do the unget out of the lock so we don't exit this class while
holding a lock.
-                    if (!update(original, refs[0], service)) {
-                        ctx.ungetService(refs[0]);
+                    if (!update(original, r, service)) {
+                        ctx.ungetService(r);
                     }
                 }
             } else if (original == null) {
@@ -128,7 +130,7 @@ private void findMatchingReference(ServiceReference original) {
         }
     }
 
-    private boolean update(ServiceReference deadRef, ServiceReference newRef, T service)
{
+    private boolean update(ServiceReference<T> deadRef, ServiceReference<T> newRef,
T service) {
         boolean result = false;
         T prev = null;
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Installing the audit-log feature never ends
> -------------------------------------------
>
>                 Key: KARAF-5667
>                 URL: https://issues.apache.org/jira/browse/KARAF-5667
>             Project: Karaf
>          Issue Type: Bug
>            Reporter: Guillaume Nodet
>            Assignee: Guillaume Nodet
>            Priority: Critical
>             Fix For: 4.2.0
>
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message