Fix logger constant name and remove unused logger constants
[neutron.git] / transcriber / src / main / java / org / opendaylight / neutron / transcriber / NeutronRouterInterface.java
index 32a4d83c3937b7d4bc296d058722458fc9ab5322..e8102ff2c5d0c26a01022450a103076631f54c50 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.neutron.transcriber;
 
 import java.lang.reflect.Method;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map.Entry;
@@ -20,11 +21,22 @@ import java.util.concurrent.ConcurrentMap;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.neutron.spi.INeutronRouterCRUD;
 import org.opendaylight.neutron.spi.NeutronRouter;
+import org.opendaylight.neutron.spi.NeutronRouter_Interface;
+import org.opendaylight.neutron.spi.NeutronRouter_NetworkReference;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev141002.routers.attributes.Routers;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev141002.routers.attributes.routers.Router;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev141002.routers.attributes.routers.RouterBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev141002.routers.attributes.routers.router.ExternalGatewayInfo;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev141002.routers.attributes.routers.router.ExternalGatewayInfoBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev141002.routers.attributes.routers.router.Interfaces;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev141002.routers.attributes.routers.router.external_gateway_info.ExternalFixedIps;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150325.Neutron;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class NeutronRouterInterface extends  AbstractNeutronInterface implements INeutronRouterCRUD {
-    private static final Logger logger = LoggerFactory.getLogger(NeutronRouterInterface.class);
+public class NeutronRouterInterface extends  AbstractNeutronInterface<Router, NeutronRouter> implements INeutronRouterCRUD {
+    private static final Logger LOGGER = LoggerFactory.getLogger(NeutronRouterInterface.class);
     private ConcurrentMap<String, NeutronRouter> routerDB  = new ConcurrentHashMap<String, NeutronRouter>();
     // methods needed for creating caches
 
@@ -52,7 +64,7 @@ public class NeutronRouterInterface extends  AbstractNeutronInterface implements
                         toMethod.invoke(target, value);
                     }
                 } catch (Exception e) {
-                    e.printStackTrace();
+                    LOGGER.error(e.getMessage());
                     return false;
                 }
             }
@@ -83,7 +95,7 @@ public class NeutronRouterInterface extends  AbstractNeutronInterface implements
             NeutronRouter router = entry.getValue();
             allRouters.add(router);
         }
-        logger.debug("Exiting getAllRouters, Found {} Routers", allRouters.size());
+        LOGGER.debug("Exiting getAllRouters, Found {} Routers", allRouters.size());
         List<NeutronRouter> ans = new ArrayList<NeutronRouter>();
         ans.addAll(allRouters);
         return ans;
@@ -95,6 +107,7 @@ public class NeutronRouterInterface extends  AbstractNeutronInterface implements
             return false;
         }
         routerDB.putIfAbsent(input.getID(), input);
+        addMd(input);
         return true;
     }
 
@@ -104,6 +117,7 @@ public class NeutronRouterInterface extends  AbstractNeutronInterface implements
             return false;
         }
         routerDB.remove(uuid);
+        removeMd(toMd(uuid));
         return true;
     }
 
@@ -113,7 +127,11 @@ public class NeutronRouterInterface extends  AbstractNeutronInterface implements
             return false;
         }
         NeutronRouter target = routerDB.get(uuid);
-        return overwrite(target, delta);
+        boolean rc = overwrite(target, delta);
+        if (rc) {
+            updateMd(routerDB.get(uuid));
+        }
+        return rc;
     }
 
     @Override
@@ -125,4 +143,77 @@ public class NeutronRouterInterface extends  AbstractNeutronInterface implements
         return (target.getInterfaces().size() > 0);
     }
 
+    @Override
+    protected Router toMd(NeutronRouter router) {
+
+        RouterBuilder routerBuilder = new RouterBuilder();
+
+        if (router.getRouterUUID() != null) {
+            routerBuilder.setUuid(toUuid(router.getRouterUUID()));
+        }
+        if (router.getName() != null) {
+            routerBuilder.setName(router.getName());
+        }
+        if (router.getTenantID() != null && !router.getTenantID().isEmpty()) {
+            routerBuilder.setTenantId(toUuid(router.getTenantID()));
+        }
+        if (router.getStatus() != null) {
+            routerBuilder.setStatus(router.getStatus());
+        }
+        if (router.getGatewayPortId() != null && !router.getGatewayPortId().isEmpty()) {
+            routerBuilder.setGatewayPortId(toUuid(router.getGatewayPortId()));
+        }
+        routerBuilder.setAdminStateUp(router.getAdminStateUp());
+        routerBuilder.setDistribted(router.getDistributed());
+        if (router.getRoutes() != null) {
+            List<String> routes = new ArrayList<String>();
+            for (String route : router.getRoutes()) {
+                routes.add(route);
+            }
+            routerBuilder.setRoutes(routes);
+        }
+        if (router.getExternalGatewayInfo() != null) {
+            ExternalGatewayInfo externalGatewayInfo = null;
+            List<NeutronRouter_NetworkReference> neutronRouter_NetworkReferences = new ArrayList<NeutronRouter_NetworkReference>();
+            neutronRouter_NetworkReferences.add(router.getExternalGatewayInfo());
+            for (NeutronRouter_NetworkReference externalGatewayInfos : neutronRouter_NetworkReferences) {
+                ExternalGatewayInfoBuilder builder = new ExternalGatewayInfoBuilder();
+                builder.setEnableSnat(externalGatewayInfos.getEnableSNAT());
+                builder.setExternalNetworkId(toUuid(externalGatewayInfos.getNetworkID()));
+                List<ExternalFixedIps> externalFixedIps = new ArrayList<ExternalFixedIps>();
+                for (int i = 0; i < externalFixedIps.size(); i++) {
+                    externalFixedIps.add((ExternalFixedIps) externalGatewayInfos.getExternalFixedIPs().get(i));
+                }
+                builder.setExternalFixedIps(externalFixedIps);
+                externalGatewayInfo = builder.build();
+            }
+            routerBuilder.setExternalGatewayInfo(externalGatewayInfo);
+        }
+        if (router.getInterfaces() != null) {
+            HashMap<String, NeutronRouter_Interface> mapInterfaces = new HashMap<String, NeutronRouter_Interface>();
+            List<Interfaces> interfaces = new ArrayList<Interfaces>();
+            for (Entry<String, NeutronRouter_Interface> entry : mapInterfaces.entrySet()) {
+                interfaces.add((Interfaces) entry.getValue());
+            }
+            routerBuilder.setInterfaces(interfaces);
+        }
+        if (router.getID() != null) {
+            routerBuilder.setUuid(toUuid(router.getID()));
+        } else {
+            LOGGER.warn("Attempting to write neutron router without UUID");
+        }
+        return routerBuilder.build();
+    }
+
+    @Override
+    protected InstanceIdentifier<Router> createInstanceIdentifier(Router router) {
+        return InstanceIdentifier.create(Neutron.class).child(Routers.class).child(Router.class, router.getKey());
+    }
+
+    @Override
+    protected Router toMd(String uuid) {
+        RouterBuilder routerBuilder = new RouterBuilder();
+        routerBuilder.setUuid(toUuid(uuid));
+        return routerBuilder.build();
+    }
 }