Search in sources :

Example 1 with Pattern

use of org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.Pattern in project controller by opendaylight.

the class EventSourceTopic method notifyExistingNodes.

private void notifyExistingNodes(final EventSourceTopology eventSourceTopology) {
    LOG.debug("Notify existing nodes");
    final Pattern nodeRegex = this.nodeIdPattern;
    final ReadOnlyTransaction tx = eventSourceTopology.getDataBroker().newReadOnlyTransaction();
    final ListenableFuture<Optional<Topology>> future = tx.read(LogicalDatastoreType.OPERATIONAL, EventSourceTopology.EVENT_SOURCE_TOPOLOGY_PATH);
    Futures.addCallback(future, new FutureCallback<Optional<Topology>>() {

        @Override
        public void onSuccess(@Nonnull final Optional<Topology> data) {
            if (data.isPresent()) {
                final List<Node> nodes = data.get().getNode();
                if (nodes != null) {
                    for (final Node node : nodes) {
                        if (nodeRegex.matcher(node.getNodeId().getValue()).matches()) {
                            notifyNode(EventSourceTopology.EVENT_SOURCE_TOPOLOGY_PATH.child(Node.class, node.getKey()));
                        }
                    }
                }
            }
            tx.close();
        }

        @Override
        public void onFailure(final Throwable ex) {
            LOG.error("Can not notify existing nodes", ex);
            tx.close();
        }
    }, MoreExecutors.directExecutor());
}
Also used : NotificationPattern(org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.NotificationPattern) Pattern(java.util.regex.Pattern) Optional(com.google.common.base.Optional) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) List(java.util.List) Topology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology)

Example 2 with Pattern

use of org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.Pattern in project controller by opendaylight.

the class EventSourceTopologyTest method closeTest.

@Test
public void closeTest() throws Exception {
    constructorTestHelper();
    topicTestHelper();
    Map<TopicId, EventSourceTopic> localMap = getEventSourceTopicMap();
    TopicId topicIdMock = mock(TopicId.class);
    EventSourceTopic eventSourceTopic = EventSourceTopic.create(new NotificationPattern("foo"), "pattern", eventSourceTopology);
    localMap.put(topicIdMock, eventSourceTopic);
    eventSourceTopology.close();
    verify(aggregatorRpcReg, times(1)).close();
    verify(listenerRegistrationMock, times(1)).close();
}
Also used : NotificationPattern(org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.NotificationPattern) TopicId(org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.TopicId) Test(org.junit.Test)

Example 3 with Pattern

use of org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.Pattern in project controller by opendaylight.

the class EventSourceTopologyTest method destroyTopicTest.

@Test
public void destroyTopicTest() throws Exception {
    topicTestHelper();
    TopicId topicId = new TopicId("topic-id-007");
    Map<TopicId, EventSourceTopic> localMap = getEventSourceTopicMap();
    EventSourceTopic eventSourceTopic = EventSourceTopic.create(new NotificationPattern("foo"), "pattern", eventSourceTopology);
    localMap.put(topicId, eventSourceTopic);
    DestroyTopicInput input = new DestroyTopicInputBuilder().setTopicId(topicId).build();
    eventSourceTopology.destroyTopic(input);
    verify(listenerRegistrationMock, times(1)).close();
}
Also used : NotificationPattern(org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.NotificationPattern) DestroyTopicInput(org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.DestroyTopicInput) TopicId(org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.TopicId) DestroyTopicInputBuilder(org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.DestroyTopicInputBuilder) Test(org.junit.Test)

Example 4 with Pattern

use of org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.Pattern in project controller by opendaylight.

the class EventSourceTopologyTest method topicTestHelper.

private void topicTestHelper() throws Exception {
    constructorTestHelper();
    createTopicInputMock = mock(CreateTopicInput.class);
    eventSourceTopology = new EventSourceTopology(dataBrokerMock, rpcProviderRegistryMock);
    NotificationPattern notificationPattern = new NotificationPattern("value1");
    doReturn(notificationPattern).when(createTopicInputMock).getNotificationPattern();
    Pattern pattern = new Pattern("valuePattern1");
    doReturn(pattern).when(createTopicInputMock).getNodeIdPattern();
    listenerRegistrationMock = mock(ListenerRegistration.class);
    doReturn(listenerRegistrationMock).when(dataBrokerMock).registerDataTreeChangeListener(any(DataTreeIdentifier.class), any(EventSourceTopic.class));
    ReadOnlyTransaction readOnlyTransactionMock = mock(ReadOnlyTransaction.class);
    doReturn(readOnlyTransactionMock).when(dataBrokerMock).newReadOnlyTransaction();
    CheckedFuture checkedFutureMock = mock(CheckedFuture.class);
    doReturn(checkedFutureMock).when(readOnlyTransactionMock).read(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class));
    Optional optionalMock = mock(Optional.class);
    doReturn(optionalMock).when(checkedFutureMock).checkedGet();
    doReturn(true).when(optionalMock).isPresent();
    Topology topologyMock = mock(Topology.class);
    doReturn(topologyMock).when(optionalMock).get();
    Node nodeMock = mock(Node.class);
    List<Node> nodeList = new ArrayList<>();
    nodeList.add(nodeMock);
    doReturn(nodeList).when(topologyMock).getNode();
    NodeId nodeId = new NodeId("nodeIdValue1");
    doReturn(nodeId).when(nodeMock).getNodeId();
}
Also used : Pattern(org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.Pattern) NotificationPattern(org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.NotificationPattern) Optional(com.google.common.base.Optional) ListenerRegistration(org.opendaylight.yangtools.concepts.ListenerRegistration) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) ArrayList(java.util.ArrayList) Topology(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology) NotificationPattern(org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.NotificationPattern) DataTreeIdentifier(org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier) CreateTopicInput(org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.CreateTopicInput) ReadOnlyTransaction(org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier) CheckedFuture(com.google.common.util.concurrent.CheckedFuture)

Example 5 with Pattern

use of org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.Pattern in project netvirt by opendaylight.

the class SubnetRouteInterfaceStateChangeListener method getSubnetId.

@Nonnull
protected List<Uuid> getSubnetId(Interface intrf) {
    List<Uuid> listSubnetIds = new ArrayList<>();
    if (!NeutronUtils.isUuid(intrf.getName())) {
        LOG.debug("SubnetRouteInterfaceListener: Interface {} doesn't have valid uuid pattern", intrf.getName());
        return listSubnetIds;
    }
    PortOpDataEntry portOpEntry = subOpDpnManager.getPortOpDataEntry(intrf.getName());
    if (portOpEntry != null) {
        List<Uuid> subnet = portOpEntry.getSubnetIds();
        if (subnet != null) {
            return subnet;
        }
        return listSubnetIds;
    }
    LOG.trace("SubnetRouteInterfaceListener : Received Port {} event for {} that is not part of subnetRoute", intrf.getOperStatus(), intrf.getName());
    Port port = neutronVpnManager.getNeutronPort(intrf.getName());
    if (port == null) {
        return listSubnetIds;
    }
    List<FixedIps> portIps = port.getFixedIps();
    if (port.getFixedIps() != null) {
        for (FixedIps portIp : portIps) {
            listSubnetIds.add(portIp.getSubnetId());
        }
    }
    return listSubnetIds;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) PortOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.port.op.data.PortOpDataEntry) Port(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port) ArrayList(java.util.ArrayList) FixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps) Nonnull(javax.annotation.Nonnull)

Aggregations

Optional (com.google.common.base.Optional)3 NotificationPattern (org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.NotificationPattern)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Nonnull (javax.annotation.Nonnull)2 Test (org.junit.Test)2 ReadOnlyTransaction (org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)2 TopicId (org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.TopicId)2 RouterInterface (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.RouterInterface)2 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)2 CheckedFuture (com.google.common.util.concurrent.CheckedFuture)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 JdkFutureAdapters (com.google.common.util.concurrent.JdkFutureAdapters)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 BigInteger (java.math.BigInteger)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1