diff options
author | Ashlee Young <ashlee@wildernessvoice.com> | 2015-11-05 14:00:42 -0800 |
---|---|---|
committer | Ashlee Young <ashlee@wildernessvoice.com> | 2015-11-05 14:00:42 -0800 |
commit | b34f82bf11934fc6b938ef997d536a7ccea76c36 (patch) | |
tree | 10559ebf65962abb741883ca9d23aec241ced504 /framework/src/onos/core/net/src/main/java/org | |
parent | 2cdecb8c41956d7dd8ab5d59591ebc21f3c64a9e (diff) |
Updates ONOS tree to checkin id ca9cc8e28eba18da77f4fa021fb7c3a3f76e5d44
upstream.
Change-Id: I49f8e41733afea8101ec50c0102213c8d18949ae
Signed-off-by: Ashlee Young <ashlee@wildernessvoice.com>
Diffstat (limited to 'framework/src/onos/core/net/src/main/java/org')
4 files changed, 43 insertions, 13 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..a9e928e5 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); @@ -235,6 +248,7 @@ public class ApplicationManager 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 +261,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); + } + } + } + } diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/core/impl/CoreManager.java b/framework/src/onos/core/net/src/main/java/org/onosproject/core/impl/CoreManager.java index f4d560a4..ec99c18b 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/core/impl/CoreManager.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/core/impl/CoreManager.java @@ -24,6 +24,7 @@ import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.ReferenceCardinality; import org.apache.felix.scr.annotations.Service; import org.onlab.util.SharedExecutors; +import org.onosproject.app.ApplicationService; import org.onosproject.cfg.ComponentConfigService; import org.onosproject.core.ApplicationId; import org.onosproject.core.ApplicationIdStore; @@ -48,7 +49,7 @@ import java.util.Set; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Strings.isNullOrEmpty; import static org.onosproject.security.AppGuard.checkPermission; -import static org.onosproject.security.AppPermission.Type.*; +import static org.onosproject.security.AppPermission.Type.APP_READ; @@ -71,6 +72,9 @@ public class CoreManager implements CoreService { protected IdBlockStore idBlockStore; @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected ApplicationService appService; + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected ComponentConfigService cfgService; @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) @@ -111,28 +115,24 @@ public class CoreManager implements CoreService { @Override public Version version() { checkPermission(APP_READ); - return version; } @Override public Set<ApplicationId> getAppIds() { checkPermission(APP_READ); - return applicationIdStore.getAppIds(); } @Override public ApplicationId getAppId(Short id) { checkPermission(APP_READ); - return applicationIdStore.getAppId(id); } @Override public ApplicationId getAppId(String name) { checkPermission(APP_READ); - return applicationIdStore.getAppId(name); } @@ -144,6 +144,13 @@ public class CoreManager implements CoreService { } @Override + public ApplicationId registerApplication(String name, Runnable preDeactivate) { + ApplicationId id = registerApplication(name); + appService.registerDeactivateHook(id, preDeactivate); + return id; + } + + @Override public IdGenerator getIdGenerator(String topic) { IdBlockAllocator allocator = new StoreBasedIdBlockAllocator(topic, idBlockStore); return new BlockAllocatorBasedIdGenerator(allocator); @@ -185,10 +192,10 @@ public class CoreManager implements CoreService { */ private static Integer getIntegerProperty(Dictionary<?, ?> properties, String propertyName) { - Integer value = null; + Integer value; try { String s = (String) properties.get(propertyName); - value = isNullOrEmpty(s) ? value : Integer.parseInt(s.trim()); + value = isNullOrEmpty(s) ? null : Integer.parseInt(s.trim()); } catch (NumberFormatException | ClassCastException e) { value = null; } diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceManager.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceManager.java index 10fe75ea..1f55b157 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceManager.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceManager.java @@ -55,9 +55,6 @@ public final class ResourceManager implements ResourceService, ResourceAdminServ checkNotNull(consumer); checkNotNull(resources); - // TODO: implement support of resource hierarchy - // allocation for a particular resource implies allocations for all of the sub-resources need to be done - boolean success = store.allocate(resources, consumer); if (!success) { return ImmutableList.of(); diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceRegistrar.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceRegistrar.java index 4067d017..143f8c2b 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceRegistrar.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceRegistrar.java @@ -36,7 +36,7 @@ import static org.onlab.util.Tools.groupedThreads; /** * A class registering resources when they are detected. */ -@Component(immediate = true, enabled = false) +@Component(immediate = true) @Beta public final class ResourceRegistrar { |