1 package org.opendaylight.groupbasedpolicy.renderer.faas;
4 * Copyright (c) 2015 Huawei Technologies and others. All rights reserved.
6 * This program and the accompanying materials are made available under the
7 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
8 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 import static com.google.common.base.Preconditions.checkNotNull;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
16 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
17 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
18 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
19 import org.opendaylight.groupbasedpolicy.util.IidFactory;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Prefix;
23 import org.opendaylight.yangtools.concepts.ListenerRegistration;
24 import org.opendaylight.yangtools.yang.binding.DataObject;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 public class FaasEndpointManagerListener implements DataChangeListener, AutoCloseable {
31 private static final Logger LOG = LoggerFactory.getLogger(FaasEndpointManagerListener.class);
33 private final ListenerRegistration<DataChangeListener> registerListener;
35 public FaasEndpointManagerListener(DataBroker dataProvider) {
36 this.registerListener = checkNotNull(dataProvider).registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
37 IidFactory.endpointsIidWildcard(), this, AsyncDataBroker.DataChangeScope.SUBTREE);
41 public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
43 for (DataObject dao : change.getCreatedData().values()) {
44 if (dao instanceof Endpoint) {
45 LOG.debug("Created Endpoint {}", (Endpoint) dao);
46 } else if (dao instanceof EndpointL3) {
47 LOG.debug("Created EndpointL3 {}", (EndpointL3) dao);
48 } else if (dao instanceof EndpointL3Prefix) {
49 LOG.debug("Created EndpointL3Prefix {}", (EndpointL3Prefix) dao);
53 Map<InstanceIdentifier<?>, DataObject> dao = change.getUpdatedData();
54 for (Map.Entry<InstanceIdentifier<?>, DataObject> entry : dao.entrySet()) {
55 if (entry.getValue() instanceof Endpoint) {
56 LOG.debug("Updated Endpoint {}", (Endpoint) dao);
57 } else if (entry.getValue() instanceof EndpointL3) {
58 LOG.debug("Updated EndpointL3 {}", (EndpointL3) dao);
59 } else if (entry.getValue() instanceof EndpointL3Prefix) {
60 LOG.debug("Updated EndpointL3Prefix {}", (EndpointL3Prefix) dao);
64 for (InstanceIdentifier<?> iid : change.getRemovedPaths()) {
65 DataObject old = change.getOriginalData().get(iid);
69 if (old instanceof Endpoint) {
70 LOG.debug("Removed Endpoint {}", (Endpoint) old);
71 } else if (old instanceof EndpointL3) {
72 LOG.debug("Removed EndpointL3 {}", (EndpointL3) old);
73 } else if (old instanceof EndpointL3Prefix) {
74 LOG.debug("Removed EndpointL3Prefix {}", (EndpointL3Prefix) old);
80 public void close() throws Exception {
81 if (registerListener != null)
82 registerListener.close();