// Hidden on purpose
}
- /**
- * Add callback to the future object.
- *
- * @param listenableFuture
- * future object
- * @param txType
- * type of operation (READ, POST, PUT, DELETE)
- * @param dataFactory
- * factory setting result
- * @throws RestconfDocumentedException
- * if the Future throws an exception
- */
- // FIXME: this is a *synchronous operation* and has to die
- static <T> void addCallback(final ListenableFuture<T> listenableFuture, final String txType,
- final FutureDataFactory<? super T> dataFactory) throws RestconfDocumentedException {
- addCallback(listenableFuture, txType, dataFactory, null);
- }
-
/**
* Add callback to the future object and close transaction chain.
*
import com.google.common.util.concurrent.FluentFuture;
import com.google.common.util.concurrent.ListenableFuture;
import java.net.URI;
+import java.util.concurrent.ExecutionException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;
}
/**
- * Check if items do NOT already exists at specified {@code path}. Throws {@link RestconfDocumentedException} if
- * data already exists.
+ * Check if items do NOT already exists at specified {@code path}.
*
- * @param isExistsFuture if checked data exists
- * @param path Path to be checked
+ * @param existsFuture if checked data exists
+ * @param path Path to be checked
+ * @throws RestconfDocumentedException if data already exists.
*/
- public static void checkItemDoesNotExists(final ListenableFuture<Boolean> isExistsFuture,
+ public static void checkItemDoesNotExists(final ListenableFuture<Boolean> existsFuture,
final YangInstanceIdentifier path) {
- final FutureDataFactory<Boolean> response = new FutureDataFactory<>();
- FutureCallbackTx.addCallback(isExistsFuture, POST_TX_TYPE, response);
+ final boolean exists;
+ try {
+ exists = existsFuture.get();
+ } catch (ExecutionException e) {
+ throw new RestconfDocumentedException("Failed to access " + path, e);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RestconfDocumentedException("Interrupted while accessing " + path, e);
+ }
- if (response.result) {
+ if (exists) {
LOG.trace("Operation via Restconf was not executed because data at {} already exists", path);
throw new RestconfDocumentedException(
"Data already exists", ErrorType.PROTOCOL, ErrorTag.DATA_EXISTS, path);
package org.opendaylight.restconf.nb.rfc8040.rests.utils;
import com.google.common.util.concurrent.FluentFuture;
-import com.google.common.util.concurrent.ListenableFuture;
+import java.util.concurrent.ExecutionException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.opendaylight.mdsal.common.api.CommitInfo;
final RestconfStrategy strategy, final WriteDataParams params) {
final YangInstanceIdentifier path = payload.getInstanceIdentifierContext().getInstanceIdentifier();
- final ListenableFuture<Boolean> existsFuture = strategy.exists(LogicalDatastoreType.CONFIGURATION, path);
- final FutureDataFactory<Boolean> existsResponse = new FutureDataFactory<>();
- FutureCallbackTx.addCallback(existsFuture, PUT_TX_TYPE, existsResponse);
+ final var existsFuture = strategy.exists(LogicalDatastoreType.CONFIGURATION, path);
+ final boolean exists;
+ try {
+ exists = existsFuture.get();
+ } catch (ExecutionException e) {
+ throw new RestconfDocumentedException("Failed to access " + path, e);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RestconfDocumentedException("Interrupted while accessing " + path, e);
+ }
final ResponseFactory responseFactory =
- new ResponseFactory(existsResponse.result ? Status.NO_CONTENT : Status.CREATED);
+ new ResponseFactory(exists ? Status.NO_CONTENT : Status.CREATED);
final FluentFuture<? extends CommitInfo> submitData = submitData(path, schemaContext, strategy,
payload.getData(), params);
//This method will close transactionChain if any