Add info logging and improve error reporting in clustering-it
[controller.git] / opendaylight / md-sal / samples / clustering-test-app / provider / src / main / java / org / opendaylight / controller / clustering / it / provider / impl / WriteTransactionsHandler.java
index e2418dc84bff0c6c2b2f32dae9df7deeda172e44..eb552b4d940c3bc3ee06aa0553912815795bc247 100644 (file)
@@ -9,7 +9,6 @@
 package org.opendaylight.controller.clustering.it.provider.impl;
 
 import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.SettableFuture;
 import java.util.LinkedHashSet;
@@ -129,7 +128,7 @@ public abstract class WriteTransactionsHandler extends AbstractTransactionHandle
 
     public static ListenableFuture<RpcResult<WriteTransactionsOutput>> start(final DOMDataBroker domDataBroker,
             final WriteTransactionsInput input) {
-        LOG.debug("Starting write-transactions.");
+        LOG.info("Starting write transactions with input {}", input);
 
         final String id = input.getId();
         final MapEntryNode entry = ImmutableNodes.mapEntryBuilder(ID_INT, ID, id)
@@ -152,9 +151,10 @@ public abstract class WriteTransactionsHandler extends AbstractTransactionHandle
             // If we get optimistic lock here it means id-ints already exists and we can continue.
             LOG.debug("Got an optimistic lock when writing initial top level list element.", e);
         } catch (final TransactionCommitFailedException | TimeoutException e) {
-            LOG.warn("Unable to ensure IdInts list for id: {} exists.", id, e);
-            return Futures.immediateFuture(RpcResultBuilder.<WriteTransactionsOutput>failed()
-                    .withError(RpcError.ErrorType.APPLICATION, "Unexpected-exception", e).build());
+            LOG.error("Error writing top-level path {}: {}", ID_INTS_YID, containerNode, e);
+            return RpcResultBuilder.<WriteTransactionsOutput>failed().withError(RpcError.ErrorType.APPLICATION,
+                String.format("Could not start write transactions - error writing top-level path %s:  %s",
+                    ID_INTS_YID, containerNode), e).buildFuture();
         }
 
         tx = domDataBroker.newWriteOnlyTransaction();
@@ -163,9 +163,10 @@ public abstract class WriteTransactionsHandler extends AbstractTransactionHandle
         try {
             tx.submit().get(INIT_TX_TIMEOUT_SECONDS, TimeUnit.SECONDS);
         } catch (InterruptedException | ExecutionException | TimeoutException e) {
-            LOG.warn("Unable to ensure IdInts list for id: {} exists.", id, e);
-            return Futures.immediateFuture(RpcResultBuilder.<WriteTransactionsOutput>failed()
-                    .withError(RpcError.ErrorType.APPLICATION, "Unexpected-exception", e).build());
+            LOG.error("Error writing top-level path {}: {}", idListItem, entry, e);
+            return RpcResultBuilder.<WriteTransactionsOutput>failed().withError(RpcError.ErrorType.APPLICATION,
+                String.format("Could not start write transactions - error writing list entry path %s: %s",
+                    idListItem, entry), e).buildFuture();
         }
 
         LOG.debug("Filling the item list with initial values.");
@@ -174,14 +175,16 @@ public abstract class WriteTransactionsHandler extends AbstractTransactionHandle
 
         final YangInstanceIdentifier itemListId = idListItem.node(ITEM);
         tx = domDataBroker.newWriteOnlyTransaction();
-        tx.put(LogicalDatastoreType.CONFIGURATION, itemListId, mapBuilder.build());
+        final MapNode itemListNode = mapBuilder.build();
+        tx.put(LogicalDatastoreType.CONFIGURATION, itemListId, itemListNode);
 
         try {
             tx.submit().get(INIT_TX_TIMEOUT_SECONDS, TimeUnit.SECONDS);
         } catch (InterruptedException | ExecutionException | TimeoutException e) {
-            LOG.warn("Unable to fill the initial item list.", e);
-            return Futures.immediateFuture(RpcResultBuilder.<WriteTransactionsOutput>failed()
-                    .withError(RpcError.ErrorType.APPLICATION, "Unexpected-exception", e).build());
+            LOG.error("Error filling initial item list path {}: {}", itemListId, itemListNode, e);
+            return RpcResultBuilder.<WriteTransactionsOutput>failed().withError(RpcError.ErrorType.APPLICATION,
+                String.format("Could not start write transactions - error filling initial item list path %s: %s",
+                    itemListId, itemListNode), e).buildFuture();
         }
 
         final WriteTransactionsHandler handler;
@@ -192,6 +195,8 @@ public abstract class WriteTransactionsHandler extends AbstractTransactionHandle
         }
 
         handler.doStart();
+
+        LOG.info("Write transactions successfully started");
         return handler.completionFuture;
     }