Search in sources :

Example 6 with Version

use of org.onosproject.core.Version in project onos by opennetworkinglab.

the class UpgradeManagerTest method createUpgradeManager.

/**
 * Creates a new upgrade manager to test.
 *
 * @param version the local node version
 * @param state the initial upgrade state
 * @param versions a list of controller node versions
 * @return the activated upgrade manager
 */
@SuppressWarnings("unchecked")
private UpgradeManager createUpgradeManager(Version version, Upgrade state, List<Version> versions) {
    UpgradeManager upgradeManager = new UpgradeManager();
    injectEventDispatcher(upgradeManager, new TestEventDispatcher());
    upgradeManager.membershipService = new MembershipServiceAdapter() {

        @Override
        public MembershipGroup getLocalGroup() {
            return getGroups().stream().filter(group -> group.version().equals(version)).findFirst().get();
        }

        @Override
        public Collection<MembershipGroup> getGroups() {
            AtomicInteger nodeCounter = new AtomicInteger();
            Map<Version, Set<Member>> groups = Maps.newHashMap();
            versions.stream().forEach(version -> {
                groups.computeIfAbsent(version, k -> Sets.newHashSet()).add(new Member(NodeId.nodeId(String.valueOf(nodeCounter.getAndIncrement())), version));
            });
            return Maps.transformEntries(groups, MembershipGroup::new).values();
        }
    };
    upgradeManager.clusterService = new ClusterServiceAdapter() {

        @Override
        public Set<ControllerNode> getNodes() {
            AtomicInteger nodeCounter = new AtomicInteger();
            return versions.stream().map(v -> {
                int nodeId = nodeCounter.getAndIncrement();
                return new DefaultControllerNode(NodeId.nodeId(String.valueOf(nodeId)), IpAddress.valueOf("127.0.0.1"), nodeId);
            }).collect(Collectors.toSet());
        }

        @Override
        public ControllerNode getNode(NodeId nodeId) {
            return getNodes().stream().filter(node -> node.id().equals(nodeId)).findFirst().orElse(null);
        }

        @Override
        public Version getVersion(NodeId nodeId) {
            return versions.get(Integer.parseInt(nodeId.id()));
        }
    };
    upgradeManager.versionService = new VersionServiceAdapter() {

        @Override
        public Version version() {
            return version;
        }
    };
    upgradeManager.coordinationService = new CoordinationServiceAdapter() {

        @Override
        public <V> AtomicValueBuilder<V> atomicValueBuilder() {
            return new AtomicValueBuilder<V>() {

                @Override
                public AsyncAtomicValue<V> build() {
                    return new AsyncAtomicValueAdapter() {

                        @Override
                        public AtomicValue asAtomicValue() {
                            return new AtomicValueAdapter() {

                                private Object value = state;

                                @Override
                                public void set(Object value) {
                                    this.value = value;
                                }

                                @Override
                                public Object get() {
                                    return value;
                                }

                                @Override
                                public boolean compareAndSet(Object expect, Object update) {
                                    if ((value == null && expect == null) || (value != null && value.equals(expect))) {
                                        value = update;
                                        return true;
                                    }
                                    return false;
                                }
                            };
                        }
                    };
                }
            };
        }
    };
    upgradeManager.activate();
    return upgradeManager;
}
Also used : Arrays(java.util.Arrays) NetTestTools.injectEventDispatcher(org.onosproject.net.NetTestTools.injectEventDispatcher) Member(org.onosproject.cluster.Member) ClusterServiceAdapter(org.onosproject.cluster.ClusterServiceAdapter) ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) MembershipGroup(org.onosproject.cluster.MembershipGroup) TestEventDispatcher(org.onosproject.common.event.impl.TestEventDispatcher) AtomicValue(org.onosproject.store.service.AtomicValue) AtomicValueBuilder(org.onosproject.store.service.AtomicValueBuilder) Upgrade(org.onosproject.upgrade.Upgrade) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Version(org.onosproject.core.Version) Assert.fail(org.junit.Assert.fail) AsyncAtomicValue(org.onosproject.store.service.AsyncAtomicValue) IpAddress(org.onlab.packet.IpAddress) NodeId(org.onosproject.cluster.NodeId) VersionServiceAdapter(org.onosproject.core.VersionServiceAdapter) AtomicValueAdapter(org.onosproject.store.service.AtomicValueAdapter) ClusterEvent(org.onosproject.cluster.ClusterEvent) CoordinationServiceAdapter(org.onosproject.store.service.CoordinationServiceAdapter) Collection(java.util.Collection) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) AsyncAtomicValueAdapter(org.onosproject.store.service.AsyncAtomicValueAdapter) Sets(com.google.common.collect.Sets) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Assert.assertEquals(org.junit.Assert.assertEquals) MembershipServiceAdapter(org.onosproject.cluster.MembershipServiceAdapter) Set(java.util.Set) ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) AtomicValue(org.onosproject.store.service.AtomicValue) AsyncAtomicValue(org.onosproject.store.service.AsyncAtomicValue) AsyncAtomicValue(org.onosproject.store.service.AsyncAtomicValue) CoordinationServiceAdapter(org.onosproject.store.service.CoordinationServiceAdapter) Version(org.onosproject.core.Version) Member(org.onosproject.cluster.Member) TestEventDispatcher(org.onosproject.common.event.impl.TestEventDispatcher) MembershipServiceAdapter(org.onosproject.cluster.MembershipServiceAdapter) AtomicValueBuilder(org.onosproject.store.service.AtomicValueBuilder) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) AtomicValueAdapter(org.onosproject.store.service.AtomicValueAdapter) AsyncAtomicValueAdapter(org.onosproject.store.service.AsyncAtomicValueAdapter) AsyncAtomicValueAdapter(org.onosproject.store.service.AsyncAtomicValueAdapter) MembershipGroup(org.onosproject.cluster.MembershipGroup) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClusterServiceAdapter(org.onosproject.cluster.ClusterServiceAdapter) NodeId(org.onosproject.cluster.NodeId) Collection(java.util.Collection) VersionServiceAdapter(org.onosproject.core.VersionServiceAdapter) Map(java.util.Map)

Example 7 with Version

use of org.onosproject.core.Version in project onos by opennetworkinglab.

the class SimpleMastershipStore method activate.

@Activate
public void activate() {
    if (clusterService == null) {
        // just for ease of unit test
        final ControllerNode instance = new DefaultControllerNode(new NodeId("local"), IpAddress.valueOf("127.0.0.1"));
        clusterService = new ClusterService() {

            private final Instant creationTime = Instant.now();

            @Override
            public ControllerNode getLocalNode() {
                return instance;
            }

            @Override
            public Set<ControllerNode> getNodes() {
                return ImmutableSet.of(instance);
            }

            @Override
            public Set<Node> getConsensusNodes() {
                return ImmutableSet.of();
            }

            @Override
            public ControllerNode getNode(NodeId nodeId) {
                if (instance.id().equals(nodeId)) {
                    return instance;
                }
                return null;
            }

            @Override
            public State getState(NodeId nodeId) {
                if (instance.id().equals(nodeId)) {
                    return State.ACTIVE;
                } else {
                    return State.INACTIVE;
                }
            }

            @Override
            public Version getVersion(NodeId nodeId) {
                if (instance.id().equals(nodeId)) {
                    return versionService.version();
                }
                return null;
            }

            @Override
            public Instant getLastUpdatedInstant(NodeId nodeId) {
                return creationTime;
            }

            @Override
            public void addListener(ClusterEventListener listener) {
            }

            @Override
            public void removeListener(ClusterEventListener listener) {
            }
        };
    }
    log.info("Started");
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) HashSet(java.util.HashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Version(org.onosproject.core.Version) State(org.onosproject.cluster.ControllerNode.State) Instant(java.time.Instant) NodeId(org.onosproject.cluster.NodeId) ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) ClusterEventListener(org.onosproject.cluster.ClusterEventListener) Activate(org.osgi.service.component.annotations.Activate)

Example 8 with Version

use of org.onosproject.core.Version in project onos by opennetworkinglab.

the class SummaryCommand method doExecute.

@Override
protected void doExecute() {
    IpAddress nodeIp = get(ClusterService.class).getLocalNode().ip();
    Version version = get(CoreService.class).version();
    long numNodes = activeNodes(get(ClusterService.class).getNodes());
    int numDevices = get(DeviceService.class).getDeviceCount();
    int numLinks = get(LinkService.class).getLinkCount();
    int numHosts = get(HostService.class).getHostCount();
    int numScc = get(TopologyService.class).currentTopology().clusterCount();
    int numFlows = get(FlowRuleService.class).getFlowRuleCount();
    long numIntents = get(IntentService.class).getIntentCount();
    String clusterId = get(ClusterMetadataService.class).getClusterMetadata().getName();
    if (outputJson()) {
        print("%s", new ObjectMapper().createObjectNode().put("node", nodeIp.toString()).put("version", version.toString()).put("clusterId", clusterId).put("nodes", numNodes).put("devices", numDevices).put("links", numLinks).put("hosts", numHosts).put("SCC(s)", numScc).put("flows", numFlows).put("intents", numIntents));
    } else {
        print("node=%s, version=%s clusterId=%s", nodeIp, version, clusterId);
        print("nodes=%d, devices=%d, links=%d, hosts=%d, SCC(s)=%s, flows=%d, intents=%d", numNodes, numDevices, numLinks, numHosts, numScc, numFlows, numIntents);
    }
}
Also used : HostService(org.onosproject.net.host.HostService) IntentService(org.onosproject.net.intent.IntentService) Version(org.onosproject.core.Version) DeviceService(org.onosproject.net.device.DeviceService) CoreService(org.onosproject.core.CoreService) IpAddress(org.onlab.packet.IpAddress) FlowRuleService(org.onosproject.net.flow.FlowRuleService) LinkService(org.onosproject.net.link.LinkService) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 9 with Version

use of org.onosproject.core.Version in project onos by opennetworkinglab.

the class NodesListCommand method doExecute.

@Override
protected void doExecute() {
    ClusterAdminService service = get(ClusterAdminService.class);
    List<ControllerNode> nodes = newArrayList(service.getNodes());
    Collections.sort(nodes, Comparators.NODE_COMPARATOR);
    if (outputJson()) {
        print("%s", json(service, nodes));
    } else {
        ControllerNode self = service.getLocalNode();
        for (ControllerNode node : nodes) {
            String timeAgo = service.localStatus(node.id());
            Version version = service.getVersion(node.id());
            print(FMT, node.id(), node.ip(), node.tcpPort(), service.getState(node.id()), version == null ? "unknown" : version, timeAgo, node.equals(self) ? "*" : "");
        }
    }
}
Also used : Version(org.onosproject.core.Version) ClusterAdminService(org.onosproject.cluster.ClusterAdminService) ControllerNode(org.onosproject.cluster.ControllerNode)

Example 10 with Version

use of org.onosproject.core.Version 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

Version (org.onosproject.core.Version)15 Test (org.junit.Test)7 ControllerNode (org.onosproject.cluster.ControllerNode)5 Set (java.util.Set)3 IpAddress (org.onlab.packet.IpAddress)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Maps (com.google.common.collect.Maps)2 Sets (com.google.common.collect.Sets)2 List (java.util.List)2 DefaultControllerNode (org.onosproject.cluster.DefaultControllerNode)2 NodeId (org.onosproject.cluster.NodeId)2 CoreService (org.onosproject.core.CoreService)2 DeviceService (org.onosproject.net.device.DeviceService)2 FlowRuleService (org.onosproject.net.flow.FlowRuleService)2 HostService (org.onosproject.net.host.HostService)2 IntentService (org.onosproject.net.intent.IntentService)2 LinkService (org.onosproject.net.link.LinkService)2 Permission (org.onosproject.security.Permission)2