Bulk merge of l2gw changes
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / l2gw / recovery / impl / L2GatewayInstanceRecoveryHandler.java
index aeb1e8ec6f98be6a32c239da09cf56bd4468f4df..d1edcf4722b9bf696bb181a0873e4dcccba51928 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.netvirt.elan.l2gw.recovery.impl;
 
+import static org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION;
+
 import java.util.List;
 import java.util.Optional;
 import java.util.concurrent.ExecutionException;
@@ -14,7 +16,6 @@ import javax.inject.Inject;
 import javax.inject.Singleton;
 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
 import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.mdsal.binding.util.Datastore;
 import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner;
 import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
@@ -67,38 +68,27 @@ public class L2GatewayInstanceRecoveryHandler implements ServiceRecoveryInterfac
         } catch (ExecutionException | InterruptedException e) {
             LOG.error("recoverService: Exception while reading L2gateway DS for the entity {}", entityId, e);
         }
+        L2gateway l2gateway = l2gatewayOptional.get();
 
-        if (l2gatewayOptional.isPresent()) {
-            L2gateway l2gateway = l2gatewayOptional.get();
-
-            List<L2gatewayConnection> l2gatewayConnections = l2GatewayConnectionUtils
-                .getL2GwConnectionsByL2GatewayId(uuid);
-            // Do a delete of l2 gateway connection instances.
-            //No null check required since l2gatewayConnections is known to be non-null.
-            LOG.info("Deleting all l2 gateway connections of l2 gateway instance {}",
-                l2gateway.key());
-            for (L2gatewayConnection l2gatewayConnection : l2gatewayConnections) {
-                InstanceIdentifier<L2gatewayConnection> identifier = InstanceIdentifier
-                    .create(Neutron.class)
+        List<L2gatewayConnection> l2gatewayConnections = l2GatewayConnectionUtils.getL2GwConnectionsByL2GatewayId(uuid);
+        // Do a delete of l2 gateway connection instances.
+        //No null check required since l2gatewayConnections is known to be non-null.
+        LOG.info("Deleting all l2 gateway connections of l2 gateway instance {}", l2gateway.key());
+        for (L2gatewayConnection l2gatewayConnection: l2gatewayConnections) {
+            final InstanceIdentifier<L2gatewayConnection> iid = InstanceIdentifier.builder(Neutron.class)
                     .child(L2gatewayConnections.class)
-                    .child(L2gatewayConnection.class, l2gatewayConnection.key());
-                try {
-                    LOG.info("Deleting l2 gateway connection {}", l2gatewayConnection.key());
-                    managedNewTransactionRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION,
-                        tx -> tx.delete(identifier)).get();
-                    LOG.info("Recreating l2 gateway connection {}", l2gatewayConnection.key());
-                    managedNewTransactionRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION,
-                        tx -> tx.put(identifier, l2gatewayConnection)).get();
-                } catch (InterruptedException | ExecutionException e) {
-                    LOG.error("Service recovery failed for l2gw {}", entityId);
-                }
-            }
-            LOG.info("Finished recreation of all l2 gateway connections of l2 gateway instance {}",
-                l2gateway.key());
+                    .child(L2gatewayConnection.class, l2gatewayConnection.key()).build();
+            LOG.info("Deleting l2 gateway connection {}",l2gatewayConnection.key());
+            managedNewTransactionRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+                tx -> tx.delete(iid));
+            LOG.info("Recreating l2 gateway connection {}",l2gatewayConnection.key());
+            managedNewTransactionRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION,
+                tx -> tx.put(iid, l2gatewayConnection));
         }
+        LOG.info("Finished recreation of all l2 gateway connections of l2 gateway instance {}", l2gateway.key());
     }
 
     public String buildServiceRegistryKey() {
         return NetvirtL2gwNode.class.toString();
     }
-}
\ No newline at end of file
+}