2 * Copyright (c) 2015 Huawei Technologies 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
9 package org.opendaylight.groupbasedpolicy.renderer.faas;
11 import static com.google.common.base.Preconditions.checkNotNull;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
17 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
18 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
19 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
20 import org.opendaylight.groupbasedpolicy.util.IidFactory;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Prefix;
24 import org.opendaylight.yangtools.concepts.ListenerRegistration;
25 import org.opendaylight.yangtools.yang.binding.DataObject;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 public class FaasEndpointManagerListener implements DataChangeListener, AutoCloseable {
32 private static final Logger LOG = LoggerFactory.getLogger(FaasEndpointManagerListener.class);
34 private final ListenerRegistration<DataChangeListener> registerListener;
36 public FaasEndpointManagerListener(DataBroker dataProvider) {
37 this.registerListener = checkNotNull(dataProvider).registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
38 IidFactory.endpointsIidWildcard(), this, AsyncDataBroker.DataChangeScope.SUBTREE);
42 public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
44 for (DataObject dao : change.getCreatedData().values()) {
45 if (dao instanceof Endpoint) {
46 LOG.debug("Created Endpoint {}", (Endpoint) dao);
47 } else if (dao instanceof EndpointL3) {
48 LOG.debug("Created EndpointL3 {}", (EndpointL3) dao);
49 } else if (dao instanceof EndpointL3Prefix) {
50 LOG.debug("Created EndpointL3Prefix {}", (EndpointL3Prefix) dao);
54 Map<InstanceIdentifier<?>, DataObject> dao = change.getUpdatedData();
55 for (Map.Entry<InstanceIdentifier<?>, DataObject> entry : dao.entrySet()) {
56 if (entry.getValue() instanceof Endpoint) {
57 LOG.debug("Updated Endpoint {}", (Endpoint) dao);
58 } else if (entry.getValue() instanceof EndpointL3) {
59 LOG.debug("Updated EndpointL3 {}", (EndpointL3) dao);
60 } else if (entry.getValue() instanceof EndpointL3Prefix) {
61 LOG.debug("Updated EndpointL3Prefix {}", (EndpointL3Prefix) dao);
65 for (InstanceIdentifier<?> iid : change.getRemovedPaths()) {
66 DataObject old = change.getOriginalData().get(iid);
70 if (old instanceof Endpoint) {
71 LOG.debug("Removed Endpoint {}", (Endpoint) old);
72 } else if (old instanceof EndpointL3) {
73 LOG.debug("Removed EndpointL3 {}", (EndpointL3) old);
74 } else if (old instanceof EndpointL3Prefix) {
75 LOG.debug("Removed EndpointL3Prefix {}", (EndpointL3Prefix) old);
81 public void close() throws Exception {
82 if (registerListener != null)
83 registerListener.close();