Search in sources :

Example 1 with Notify

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Notify in project cxf by apache.

the class NotificationBroker method notify.

public void notify(Referencable publisher, String topic, Object msg) {
    getBroker();
    if (this.context != null) {
        try {
            DOMResult result = new DOMResult();
            context.createMarshaller().marshal(msg, result);
            msg = result.getNode();
            if (msg instanceof Document) {
                msg = ((Document) msg).getDocumentElement();
            }
        } catch (JAXBException e) {
        // ignore, we'll try and let the runtime handle it as is
        }
    }
    Notify notify = new Notify();
    NotificationMessageHolderType holder = new NotificationMessageHolderType();
    if (publisher != null) {
        holder.setProducerReference(publisher.getEpr());
    }
    if (topic != null) {
        TopicExpressionType topicExp = new TopicExpressionType();
        topicExp.getContent().add(topic);
        holder.setTopic(topicExp);
    }
    holder.setMessage(new NotificationMessageHolderType.Message());
    holder.getMessage().setAny(msg);
    notify.getNotificationMessage().add(holder);
    getBroker().notify(notify);
}
Also used : DOMResult(javax.xml.transform.dom.DOMResult) Notify(org.oasis_open.docs.wsn.b_2.Notify) TopicExpressionType(org.oasis_open.docs.wsn.b_2.TopicExpressionType) JAXBException(javax.xml.bind.JAXBException) Document(org.w3c.dom.Document) NotificationMessageHolderType(org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType)

Example 2 with Notify

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Notify in project cxf by apache.

the class JmsPullPoint method getMessages.

@Override
protected List<NotificationMessageHolderType> getMessages(int max) throws ResourceUnknownFault, UnableToGetMessagesFault {
    try {
        if (max == 0) {
            max = 256;
        }
        initSession();
        List<NotificationMessageHolderType> messages = new ArrayList<>();
        for (int i = 0; i < max; i++) {
            Message msg = null;
            synchronized (consumerSession) {
                msg = consumer.receiveNoWait();
            }
            if (msg == null) {
                break;
            }
            TextMessage txtMsg = (TextMessage) msg;
            StringReader reader = new StringReader(txtMsg.getText());
            XMLStreamReader xreader = StaxUtils.createXMLStreamReader(reader);
            Notify notify = (Notify) jaxbContext.createUnmarshaller().unmarshal(xreader);
            try {
                xreader.close();
            } catch (XMLStreamException e) {
            // ignoreable
            }
            messages.addAll(notify.getNotificationMessage());
        }
        return messages;
    } catch (JMSException e) {
        LOGGER.log(Level.INFO, "Error retrieving messages", e);
        closeSession();
        UnableToGetMessagesFaultType fault = new UnableToGetMessagesFaultType();
        throw new UnableToGetMessagesFault("Unable to retrieve messages", fault, e);
    } catch (JAXBException e) {
        LOGGER.log(Level.INFO, "Error retrieving messages", e);
        UnableToGetMessagesFaultType fault = new UnableToGetMessagesFaultType();
        throw new UnableToGetMessagesFault("Unable to retrieve messages", fault, e);
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) Notify(org.oasis_open.docs.wsn.b_2.Notify) JAXBException(javax.xml.bind.JAXBException) ArrayList(java.util.ArrayList) JMSException(javax.jms.JMSException) NotificationMessageHolderType(org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType) AbstractPullPoint(org.apache.cxf.wsn.AbstractPullPoint) UnableToGetMessagesFaultType(org.oasis_open.docs.wsn.b_2.UnableToGetMessagesFaultType) XMLStreamException(javax.xml.stream.XMLStreamException) StringReader(java.io.StringReader) UnableToGetMessagesFault(org.oasis_open.docs.wsn.bw_2.UnableToGetMessagesFault) TextMessage(javax.jms.TextMessage)

Example 3 with Notify

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Notify in project cxf by apache.

the class JmsSubscription method onMessage.

public void onMessage(Message jmsMessage) {
    try {
        TextMessage text = (TextMessage) jmsMessage;
        XMLStreamReader reader = StaxUtils.createXMLStreamReader(new StringReader(text.getText()));
        Notify notify = (Notify) jaxbContext.createUnmarshaller().unmarshal(reader);
        reader.close();
        for (Iterator<NotificationMessageHolderType> ith = notify.getNotificationMessage().iterator(); ith.hasNext(); ) {
            NotificationMessageHolderType h = ith.next();
            Object content = h.getMessage().getAny();
            if (!(content instanceof Element)) {
                DocumentFragment doc = DOMUtils.getEmptyDocument().createDocumentFragment();
                jaxbContext.createMarshaller().marshal(content, doc);
                content = DOMUtils.getFirstElement(doc);
            }
            if (!doFilter((Element) content)) {
                ith.remove();
            } else {
                h.setTopic(topic);
                h.setSubscriptionReference(getEpr());
            }
        }
        if (!notify.getNotificationMessage().isEmpty()) {
            doNotify(notify);
        }
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "Error notifying consumer", e);
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) Notify(org.oasis_open.docs.wsn.b_2.Notify) Element(org.w3c.dom.Element) StringReader(java.io.StringReader) NotificationMessageHolderType(org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType) TextMessage(javax.jms.TextMessage) DocumentFragment(org.w3c.dom.DocumentFragment) XPathExpressionException(javax.xml.xpath.XPathExpressionException) JMSException(javax.jms.JMSException) JAXBException(javax.xml.bind.JAXBException)

Example 4 with Notify

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Notify in project netvirt by opendaylight.

the class AclInterfaceStateListener method add.

@Override
protected void add(InstanceIdentifier<Interface> key, Interface added) {
    if (!L2vlan.class.equals(added.getType())) {
        return;
    }
    org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface iface;
    iface = interfaceManager.getInterfaceInfoFromConfigDataStore(added.getName());
    if (iface == null) {
        LOG.error("No interface with name {} available in interfaceConfig, servicing interfaceState ADD" + "for ACL failed", added.getName());
        return;
    }
    InterfaceAcl aclInPort = iface.getAugmentation(InterfaceAcl.class);
    if (aclInPort == null) {
        LOG.trace("Interface {} is not an ACL Interface, ignoring ADD interfaceState event", added.getName());
        return;
    }
    AclInterface aclInterface = aclInterfaceCache.addOrUpdate(added.getName(), (prevAclInterface, builder) -> {
        builder.dpId(AclServiceUtils.getDpIdFromIterfaceState(added)).lPortTag(added.getIfIndex()).isMarkedForDelete(false);
        if (AclServiceUtils.isOfInterest(prevAclInterface)) {
            if (prevAclInterface.getSubnetIpPrefixes() == null) {
                // For upgrades
                List<IpPrefixOrAddress> subnetIpPrefixes = AclServiceUtils.getSubnetIpPrefixes(dataBroker, added.getName());
                builder.subnetIpPrefixes(subnetIpPrefixes);
            }
            SortedSet<Integer> ingressRemoteAclTags = aclServiceUtils.getRemoteAclTags(aclInPort.getSecurityGroups(), DirectionIngress.class);
            SortedSet<Integer> egressRemoteAclTags = aclServiceUtils.getRemoteAclTags(aclInPort.getSecurityGroups(), DirectionEgress.class);
            builder.ingressRemoteAclTags(ingressRemoteAclTags).egressRemoteAclTags(egressRemoteAclTags);
        }
    });
    if (AclServiceUtils.isOfInterest(aclInterface)) {
        List<Uuid> aclList = aclInterface.getSecurityGroups();
        if (aclList != null) {
            aclDataUtil.addAclInterfaceMap(aclList, aclInterface);
        }
        if (aclInterface.getElanId() == null) {
            LOG.debug("On Add event, skip ADD since ElanId is not updated");
            return;
        }
        if (aclClusterUtil.isEntityOwner()) {
            LOG.debug("On add event, notify ACL service manager to add ACL for interface: {}", aclInterface);
            aclServiceManger.notify(aclInterface, null, Action.BIND);
            if (aclList != null) {
                aclServiceUtils.addAclPortsLookup(aclInterface, aclList, aclInterface.getAllowedAddressPairs());
            }
            aclServiceManger.notify(aclInterface, null, Action.ADD);
        }
    }
}
Also used : AclInterface(org.opendaylight.netvirt.aclservice.api.utils.AclInterface) L2vlan(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan) IpPrefixOrAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.IpPrefixOrAddress) InterfaceAcl(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.InterfaceAcl) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)

Example 5 with Notify

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Notify 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)

Aggregations

Test (org.junit.Test)16 Notify (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Notify)11 MapNotify (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapNotify)8 Notification (org.opendaylight.yangtools.yang.binding.Notification)6 JAXBException (javax.xml.bind.JAXBException)5 Notify (org.oasis_open.docs.wsn.b_2.Notify)5 Open (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.Open)5 JMSException (javax.jms.JMSException)4 AclInterface (org.opendaylight.netvirt.aclservice.api.utils.AclInterface)4 MappingRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord)4 ArrayList (java.util.ArrayList)3 Message (javax.jms.Message)3 TextMessage (javax.jms.TextMessage)3 NotificationMessageHolderType (org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType)3 BGPDocumentedException (org.opendaylight.protocol.bgp.parser.BGPDocumentedException)3 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)3 OpenBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.OpenBuilder)3 Optional (com.google.common.base.Optional)2 ByteBuf (io.netty.buffer.ByteBuf)2 StringReader (java.io.StringReader)2