c01d91866755b5fa73692d740fbf50d64c61ee08
[netvirt.git] / ipv6service / impl / src / main / java / org / opendaylight / netvirt / ipv6service / NeutronRouterChangeListener.java
1 /*
2  * Copyright (c) 2016, 2017 Red Hat, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netvirt.ipv6service;
9
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.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.Routers;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 @Singleton
24 public class NeutronRouterChangeListener extends AsyncClusteredDataTreeChangeListenerBase<Router,
25         NeutronRouterChangeListener> {
26     private static final Logger LOG = LoggerFactory.getLogger(NeutronRouterChangeListener.class);
27     private final DataBroker dataBroker;
28     private final IfMgr ifMgr;
29
30     @Inject
31     public NeutronRouterChangeListener(final DataBroker dataBroker, IfMgr ifMgr) {
32         this.dataBroker = dataBroker;
33         this.ifMgr = ifMgr;
34     }
35
36     @PostConstruct
37     public void init() {
38         LOG.info("{} init", getClass().getSimpleName());
39         registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
40     }
41
42     @Override
43     protected InstanceIdentifier<Router> getWildCardPath() {
44         return InstanceIdentifier.create(Neutron.class).child(Routers.class).child(Router.class);
45     }
46
47     @Override
48     protected void add(InstanceIdentifier<Router> identifier, Router input) {
49         LOG.info("Add Router notification handler is invoked {}.", input.getUuid());
50         ifMgr.addRouter(input.getUuid(), input.getName(), input.getTenantId());
51     }
52
53     @Override
54     protected void remove(InstanceIdentifier<Router> identifier, Router input) {
55         LOG.info("Remove Router notification handler is invoked {}.", input.getUuid());
56         ifMgr.removeRouter(input.getUuid());
57     }
58
59     @Override
60     protected void update(InstanceIdentifier<Router> identifier, Router original, Router update) {
61         LOG.debug("Update Router notification handler is invoked. Original: {}, Updated: {}.", original, update);
62     }
63
64     @Override
65     protected NeutronRouterChangeListener getDataTreeChangeListener() {
66         return NeutronRouterChangeListener.this;
67     }
68
69 }