Bug 2834: Fix Restconf POST to wait for completion 00/16500/1
authorRyan Goulding <ryandgoulding@gmail.com>
Fri, 13 Mar 2015 20:39:47 +0000 (16:39 -0400)
committerRyan Goulding <ryandgoulding@gmail.com>
Fri, 13 Mar 2015 20:42:02 +0000 (16:42 -0400)
This changeset introduces a blocking mechanism for Restconf POST to ensure that
the transaction completes before a response is returned, as is consistent with
Restconf PUT behavior.  checkedGet() is utilized to ensure write transaction
completion.

Change-Id: I3a7d7a388d1b3d6eb3d80a9d0880abe0b6657583
Signed-off-by: Ryan Goulding <ryandgoulding@gmail.com>
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPostOperationTest.java

index d0653409c8f23249d3a4de9f8629649ab0689884..c8585a2abef2f905811f0d3f133e5a65cb7b3f9a 100644 (file)
@@ -952,11 +952,10 @@ public class RestconfImpl implements RestconfService {
             if (mountPoint != null) {
                 normalizedII = new DataNormalizer(mountPoint.getSchemaContext()).toNormalized(iiWithData
                         .getInstanceIdentifier());
-                broker.commitConfigurationDataPost(mountPoint, normalizedII, datastoreNormalizedData);
-
+                broker.commitConfigurationDataPost(mountPoint, normalizedII, datastoreNormalizedData).checkedGet();
             } else {
                 normalizedII = controllerContext.toNormalized(iiWithData.getInstanceIdentifier());
-                broker.commitConfigurationDataPost(normalizedII, datastoreNormalizedData);
+                broker.commitConfigurationDataPost(normalizedII, datastoreNormalizedData).checkedGet();
             }
         } catch(RestconfDocumentedException e) {
             throw e;
index 97cd67d34b70095a1571c1384e4a0e46c61f155a..e7bb5b5710bcaf1a59b57e39abdf7cae19b34c9e 100644 (file)
@@ -16,7 +16,6 @@ import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 import static org.opendaylight.controller.sal.restconf.impl.test.RestOperationUtils.XML;
-
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.Futures;
@@ -40,6 +39,7 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.controller.sal.rest.api.Draft02;
@@ -244,7 +244,7 @@ public class RestPostOperationTest extends JerseyTest {
         initMocking();
 
         when(brokerFacade.commitConfigurationDataPost(any(YangInstanceIdentifier.class), any(NormalizedNode.class)))
-                .thenReturn(null);
+                .thenReturn(Futures.<Void, TransactionCommitFailedException>immediateCheckedFuture(null));
 
         String URI_1 = "/config";
         assertEquals(204, post(URI_1, Draft02.MediaTypes.DATA + XML, xmlTestInterface));