2 * Copyright (c) 2017 Intel Corporation and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netvirt.qosservice;
10 import javax.annotation.PostConstruct;
11 import javax.inject.Inject;
12 import javax.inject.Singleton;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase;
16 import org.opendaylight.genius.srm.RecoverableListener;
17 import org.opendaylight.genius.srm.ServiceRecoveryRegistry;
18 import org.opendaylight.netvirt.qosservice.recovery.QosServiceRecoveryHandler;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.Networks;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.qos.ext.rev160613.QosNetworkExtension;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
28 public class QosNeutronNetworkChangeListener extends AsyncClusteredDataTreeChangeListenerBase<Network,
29 QosNeutronNetworkChangeListener> implements RecoverableListener {
30 private static final Logger LOG = LoggerFactory.getLogger(QosNeutronNetworkChangeListener.class);
31 private final DataBroker dataBroker;
32 private final QosNeutronUtils qosNeutronUtils;
35 public QosNeutronNetworkChangeListener(final DataBroker dataBroker,
36 final QosNeutronUtils qosNeutronUtils,
37 final ServiceRecoveryRegistry serviceRecoveryRegistry,
38 final QosServiceRecoveryHandler qosServiceRecoveryHandler) {
39 super(Network.class, QosNeutronNetworkChangeListener.class);
40 this.dataBroker = dataBroker;
41 this.qosNeutronUtils = qosNeutronUtils;
42 serviceRecoveryRegistry.addRecoverableListener(qosServiceRecoveryHandler.buildServiceRegistryKey(),
44 LOG.debug("{} created", getClass().getSimpleName());
50 LOG.debug("{} init and registerListener done", getClass().getSimpleName());
54 public void registerListener() {
55 registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
59 protected InstanceIdentifier<Network> getWildCardPath() {
60 return InstanceIdentifier.create(Neutron.class).child(Networks.class).child(Network.class);
64 protected QosNeutronNetworkChangeListener getDataTreeChangeListener() {
65 return QosNeutronNetworkChangeListener.this;
69 protected void remove(InstanceIdentifier<Network> instanceIdentifier, Network network) {
70 qosNeutronUtils.removeFromNetworkCache(network);
74 protected void update(InstanceIdentifier<Network> instanceIdentifier, Network original, Network update) {
75 qosNeutronUtils.addToNetworkCache(update);
77 QosNetworkExtension updateQos = update.augmentation(QosNetworkExtension.class);
78 QosNetworkExtension originalQos = original.augmentation(QosNetworkExtension.class);
79 if (originalQos == null && updateQos != null) {
80 // qosservice policy add
81 qosNeutronUtils.addToQosNetworksCache(updateQos.getQosPolicyId(), update);
82 qosNeutronUtils.handleNeutronNetworkQosUpdate(update, updateQos.getQosPolicyId());
83 } else if (originalQos != null && updateQos != null
84 && !originalQos.getQosPolicyId().equals(updateQos.getQosPolicyId())) {
85 // qosservice policy update
86 qosNeutronUtils.removeFromQosNetworksCache(originalQos.getQosPolicyId(), original);
87 qosNeutronUtils.addToQosNetworksCache(updateQos.getQosPolicyId(), update);
88 qosNeutronUtils.handleNeutronNetworkQosUpdate(update, updateQos.getQosPolicyId());
89 } else if (originalQos != null && updateQos == null) {
90 // qosservice policy delete
91 qosNeutronUtils.handleNeutronNetworkQosRemove(original, originalQos.getQosPolicyId());
92 qosNeutronUtils.removeFromQosNetworksCache(originalQos.getQosPolicyId(), original);
97 protected void add(InstanceIdentifier<Network> instanceIdentifier, Network network) {
98 qosNeutronUtils.addToNetworkCache(network);
100 QosNetworkExtension networkQos = network.augmentation(QosNetworkExtension.class);
101 if (networkQos != null) {
102 qosNeutronUtils.addToQosNetworksCache(networkQos.getQosPolicyId(), network);
103 qosNeutronUtils.handleNeutronNetworkQosUpdate(network, networkQos.getQosPolicyId());