Search in sources :

Example 1 with APP_INSTALLED

use of org.onosproject.app.ApplicationEvent.Type.APP_INSTALLED in project onos by opennetworkinglab.

the class DistributedApplicationStore method fetchBits.

/**
 * Fetches the bits from the cluster peers.
 */
private void fetchBits(Application app, boolean delegateInstallation) {
    ControllerNode localNode = clusterService.getLocalNode();
    CountDownLatch latch = new CountDownLatch(1);
    // FIXME: send message with name & version to make sure we don't get served old bits
    log.info("Downloading bits for application {} for version : {}", app.id().name(), app.version());
    for (ControllerNode node : clusterService.getNodes()) {
        if (latch.getCount() == 0) {
            break;
        }
        if (node.equals(localNode)) {
            continue;
        }
        clusterCommunicator.sendAndReceive(app.id().name(), APP_BITS_REQUEST, s -> s.getBytes(Charsets.UTF_8), Function.identity(), node.id()).whenCompleteAsync((bits, error) -> {
            if (error == null && latch.getCount() > 0) {
                saveApplication(new ByteArrayInputStream(bits));
                log.info("Downloaded bits for application {} from node {}", app.id().name(), node.id());
                latch.countDown();
                if (delegateInstallation) {
                    if (log.isTraceEnabled()) {
                        log.trace("Delegate installation for {}", app.id());
                    }
                    notifyDelegate(new ApplicationEvent(APP_INSTALLED, app));
                }
            } else if (error != null) {
                log.warn("Unable to fetch bits for application {} from node {}", app.id().name(), node.id());
            }
        }, messageHandlingExecutor);
    }
    try {
        if (!latch.await(FETCH_TIMEOUT_MS, MILLISECONDS)) {
            log.warn("Unable to fetch bits for application {}", app.id().name());
        }
    } catch (InterruptedException e) {
        log.warn("Interrupted while fetching bits for application {}", app.id().name());
        Thread.currentThread().interrupt();
    }
}
Also used : ConsistentMap(org.onosproject.store.service.ConsistentMap) CoreService(org.onosproject.core.CoreService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) ApplicationIdStore(org.onosproject.app.ApplicationIdStore) StorageService(org.onosproject.store.service.StorageService) ByteArrayInputStream(java.io.ByteArrayInputStream) ApplicationEvent(org.onosproject.app.ApplicationEvent) ApplicationId(org.onosproject.core.ApplicationId) MessageSubject(org.onosproject.store.cluster.messaging.MessageSubject) Version(org.onosproject.core.Version) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) ApplicationException(org.onosproject.app.ApplicationException) Serializer(org.onosproject.store.service.Serializer) ImmutableSet(com.google.common.collect.ImmutableSet) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Versioned(org.onosproject.store.service.Versioned) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) APP_ACTIVATED(org.onosproject.app.ApplicationEvent.Type.APP_ACTIVATED) APP_UNINSTALLED(org.onosproject.app.ApplicationEvent.Type.APP_UNINSTALLED) ClusterCommunicationService(org.onosproject.store.cluster.messaging.ClusterCommunicationService) Optional(java.util.Optional) ClusterService(org.onosproject.cluster.ClusterService) RevisionType(org.onosproject.store.service.RevisionType) DEACTIVATED(org.onosproject.store.app.DistributedApplicationStore.InternalState.DEACTIVATED) ApplicationState(org.onosproject.app.ApplicationState) StorageException(org.onosproject.store.service.StorageException) APP_PERMISSIONS_CHANGED(org.onosproject.app.ApplicationEvent.Type.APP_PERMISSIONS_CHANGED) INSTALLED(org.onosproject.store.app.DistributedApplicationStore.InternalState.INSTALLED) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Multimap(com.google.common.collect.Multimap) Tools.randomDelay(org.onlab.util.Tools.randomDelay) Function(java.util.function.Function) ControllerNode(org.onosproject.cluster.ControllerNode) MapEventListener(org.onosproject.store.service.MapEventListener) Permission(org.onosproject.security.Permission) Component(org.osgi.service.component.annotations.Component) APP_DEACTIVATED(org.onosproject.app.ApplicationEvent.Type.APP_DEACTIVATED) Lists(com.google.common.collect.Lists) APP_INSTALLED(org.onosproject.app.ApplicationEvent.Type.APP_INSTALLED) ACTIVATED(org.onosproject.store.app.DistributedApplicationStore.InternalState.ACTIVATED) Multimaps.newSetMultimap(com.google.common.collect.Multimaps.newSetMultimap) VersionService(org.onosproject.core.VersionService) ApplicationDescription(org.onosproject.app.ApplicationDescription) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Activate(org.osgi.service.component.annotations.Activate) ExecutorService(java.util.concurrent.ExecutorService) Multimaps.synchronizedSetMultimap(com.google.common.collect.Multimaps.synchronizedSetMultimap) Application(org.onosproject.core.Application) DefaultApplication(org.onosproject.core.DefaultApplication) Charsets(com.google.common.base.Charsets) Logger(org.slf4j.Logger) Topic(org.onosproject.store.service.Topic) MoreObjects(com.google.common.base.MoreObjects) Throwables(com.google.common.base.Throwables) IOException(java.io.IOException) ApplicationStoreDelegate(org.onosproject.app.ApplicationStoreDelegate) Maps(com.google.common.collect.Maps) Status(org.onosproject.store.service.DistributedPrimitive.Status) ApplicationArchive(org.onosproject.common.app.ApplicationArchive) ByteStreams.toByteArray(com.google.common.io.ByteStreams.toByteArray) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ApplicationStore(org.onosproject.app.ApplicationStore) MapEvent(org.onosproject.store.service.MapEvent) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Preconditions(com.google.common.base.Preconditions) Reference(org.osgi.service.component.annotations.Reference) InputStream(java.io.InputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ApplicationEvent(org.onosproject.app.ApplicationEvent) ControllerNode(org.onosproject.cluster.ControllerNode) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

Charsets (com.google.common.base.Charsets)1 MoreObjects (com.google.common.base.MoreObjects)1 Preconditions (com.google.common.base.Preconditions)1 Throwables (com.google.common.base.Throwables)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Multimap (com.google.common.collect.Multimap)1 Multimaps.newSetMultimap (com.google.common.collect.Multimaps.newSetMultimap)1 Multimaps.synchronizedSetMultimap (com.google.common.collect.Multimaps.synchronizedSetMultimap)1 Sets (com.google.common.collect.Sets)1 ByteStreams.toByteArray (com.google.common.io.ByteStreams.toByteArray)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1