diff options
Diffstat (limited to 'framework/src/onos/core/net/src/main/java/org/onosproject/app/impl/ApplicationManager.java')
-rw-r--r-- | framework/src/onos/core/net/src/main/java/org/onosproject/app/impl/ApplicationManager.java | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/app/impl/ApplicationManager.java b/framework/src/onos/core/net/src/main/java/org/onosproject/app/impl/ApplicationManager.java index 161659f9..d09eb1f1 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/app/impl/ApplicationManager.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/app/impl/ApplicationManager.java @@ -15,6 +15,7 @@ */ package org.onosproject.app.impl; +import com.google.common.collect.Maps; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Deactivate; @@ -30,20 +31,21 @@ import org.onosproject.app.ApplicationService; import org.onosproject.app.ApplicationState; import org.onosproject.app.ApplicationStore; import org.onosproject.app.ApplicationStoreDelegate; -import org.onosproject.event.AbstractListenerManager; import org.onosproject.core.Application; import org.onosproject.core.ApplicationId; +import org.onosproject.event.AbstractListenerManager; import org.onosproject.security.Permission; import org.onosproject.security.SecurityUtil; import org.slf4j.Logger; import java.io.InputStream; +import java.util.Map; import java.util.Set; import static com.google.common.base.Preconditions.checkNotNull; import static org.onosproject.app.ApplicationEvent.Type.*; -import static org.onosproject.security.AppPermission.Type.*; import static org.onosproject.security.AppGuard.checkPermission; +import static org.onosproject.security.AppPermission.Type.APP_READ; import static org.slf4j.LoggerFactory.getLogger; /** @@ -69,6 +71,9 @@ public class ApplicationManager private boolean initializing; + // Application supplied hooks for pre-activation processing. + private final Map<String, Runnable> deactivateHooks = Maps.newConcurrentMap(); + @Activate public void activate() { eventDispatcher.addSink(ApplicationEvent.class, listenerRegistry); @@ -122,6 +127,14 @@ public class ApplicationManager } @Override + public void registerDeactivateHook(ApplicationId appId, Runnable hook) { + checkPermission(APP_READ); + checkNotNull(appId, APP_ID_NULL); + checkNotNull(hook, "Hook cannot be null"); + deactivateHooks.put(appId.name(), hook); + } + + @Override public Application install(InputStream appDescStream) { checkNotNull(appDescStream, "Application archive stream cannot be null"); Application app = store.create(appDescStream); @@ -199,6 +212,7 @@ public class ApplicationManager // The following methods are fully synchronized to guard against remote vs. // locally induced feature service interactions. + // Installs all feature repositories required by the specified app. private synchronized boolean installAppArtifacts(Application app) throws Exception { if (app.featuresRepo().isPresent() && featuresService.getRepository(app.featuresRepo().get()) == null) { @@ -208,6 +222,7 @@ public class ApplicationManager return false; } + // Uninstalls all the feature repositories required by the specified app. private synchronized boolean uninstallAppArtifacts(Application app) throws Exception { if (app.featuresRepo().isPresent() && featuresService.getRepository(app.featuresRepo().get()) != null) { @@ -217,6 +232,7 @@ public class ApplicationManager return false; } + // Installs all features that define the specified app. private synchronized boolean installAppFeatures(Application app) throws Exception { boolean changed = false; for (String name : app.features()) { @@ -233,8 +249,10 @@ public class ApplicationManager return changed; } + // Uninstalls all features that define the specified app. private synchronized boolean uninstallAppFeatures(Application app) throws Exception { boolean changed = false; + invokeHook(deactivateHooks.get(app.id().name()), app.id()); for (String name : app.features()) { Feature feature = featuresService.getFeature(name); if (feature != null && featuresService.isInstalled(feature)) { @@ -247,4 +265,16 @@ public class ApplicationManager return changed; } + // Invokes the specified function, if not null. + private void invokeHook(Runnable hook, ApplicationId appId) { + if (hook != null) { + try { + hook.run(); + } catch (Exception e) { + log.warn("Deactivate hook for application {} encountered an error", + appId.name(), e); + } + } + } + } |