Repopulate router, port and floating ip related caches
[ovsdb.git] / utils / mdsal-utils / src / main / java / org / opendaylight / ovsdb / utils / mdsal / utils / NeutronModelsDataStoreHelper.java
1 /*
2  * Copyright (c) 2015 Brocade Communications Systems, 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.ovsdb.utils.mdsal.utils;
9
10 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
11 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.Routers;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.PortKey;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 public class NeutronModelsDataStoreHelper {
23
24     private static final Logger LOG = LoggerFactory.getLogger(MdsalUtils.class);
25     private DataBroker databroker = null;
26     private MdsalUtils mdsalClient = null;
27
28     /**
29      * Class constructor setting the data broker.
30      *
31      * @param dataBroker the {@link org.opendaylight.controller.md.sal.binding.api.DataBroker}
32      */
33     public NeutronModelsDataStoreHelper(DataBroker dataBroker) {
34         this.databroker = dataBroker;
35         this.mdsalClient = new MdsalUtils(this.databroker);
36     }
37
38     public Routers readAllNeutronRouters() {
39         Routers routers = this.mdsalClient.read(LogicalDatastoreType.CONFIGURATION, getNeutrounRoutersPath());
40         if(routers != null ) {
41             LOG.debug("{} routers present in data store", routers.getRouter()!=null? routers.getRouter().size():0);
42         }
43         return routers;
44     }
45
46     public Ports readAllNeutronPorts() {
47         Ports ports = this.mdsalClient.read(LogicalDatastoreType.CONFIGURATION, getNeutrounPortsPath());
48         if(ports != null ) {
49             LOG.debug("{} ports present in data store", ports.getPort()!=null? ports.getPort().size():0);
50         }
51         return ports;
52     }
53     public Port readNeutronPort(Uuid portId) {
54         Port mdsalPort = this.mdsalClient.read(LogicalDatastoreType.CONFIGURATION, getNeutronPortPath(portId));
55         if (mdsalPort != null) {
56             LOG.debug("Port {} fetched from config data store for router interface {}",mdsalPort, portId);
57         }
58         return mdsalPort;
59     }
60
61     private InstanceIdentifier<Routers> getNeutrounRoutersPath() {
62         return InstanceIdentifier
63                 .create(Neutron.class)
64                 .child(Routers.class);
65     }
66
67     private InstanceIdentifier<Ports> getNeutrounPortsPath() {
68         return InstanceIdentifier
69                 .create(Neutron.class)
70                 .child(Ports.class);
71     }
72
73     private InstanceIdentifier<Port> getNeutronPortPath(Uuid portId) {
74         return InstanceIdentifier
75                 .create(Neutron.class)
76                 .child(Ports.class)
77                 .child(Port.class,new PortKey(portId));
78     }
79 }