import static com.google.common.base.Verify.verifyNotNull;
import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION;
-import static org.opendaylight.restconf.nb.rfc8040.rests.utils.DeleteDataTransactionUtil.DELETE_TX_TYPE;
import static org.opendaylight.restconf.nb.rfc8040.rests.utils.PostDataTransactionUtil.checkItemDoesNotExists;
import com.google.common.util.concurrent.FluentFuture;
import java.util.Collection;
import java.util.Map;
+import java.util.concurrent.ExecutionException;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.mdsal.common.api.CommitInfo;
import org.opendaylight.mdsal.common.api.ReadFailedException;
import org.opendaylight.mdsal.dom.api.DOMDataBroker;
import org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.nb.rfc8040.rests.utils.DeleteDataTransactionUtil;
import org.opendaylight.restconf.nb.rfc8040.rests.utils.TransactionUtil;
import org.opendaylight.yangtools.yang.common.ErrorTag;
import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
final class MdsalRestconfTransaction extends RestconfTransaction {
+ private static final Logger LOG = LoggerFactory.getLogger(MdsalRestconfTransaction.class);
+
private DOMDataTreeReadWriteTransaction rwTx;
MdsalRestconfTransaction(final DOMDataBroker dataBroker) {
@Override
public void delete(final YangInstanceIdentifier path) {
- final FluentFuture<Boolean> isExists = verifyNotNull(rwTx).exists(CONFIGURATION, path);
- DeleteDataTransactionUtil.checkItemExists(isExists, path, DELETE_TX_TYPE);
+ final var existsFuture = verifyNotNull(rwTx).exists(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);
+ }
+
+ if (!exists) {
+ LOG.trace("Operation via Restconf was not executed because data at {} does not exist", path);
+ throw new RestconfDocumentedException("Data does not exist", ErrorType.PROTOCOL, ErrorTag.DATA_MISSING,
+ path);
+ }
+
rwTx.delete(CONFIGURATION, path);
}
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfTransaction;
-import org.opendaylight.yangtools.yang.common.ErrorTag;
-import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* Util class for delete specific data in config DS.
*/
public final class DeleteDataTransactionUtil {
- private static final Logger LOG = LoggerFactory.getLogger(DeleteDataTransactionUtil.class);
- public static final String DELETE_TX_TYPE = "DELETE";
-
private DeleteDataTransactionUtil() {
// Hidden on purpose
}
final FluentFuture<? extends CommitInfo> future = transaction.commit();
final ResponseFactory response = new ResponseFactory(Status.NO_CONTENT);
//This method will close transactionChain if any
- FutureCallbackTx.addCallback(future, DELETE_TX_TYPE, response, path);
+ FutureCallbackTx.addCallback(future, "DELETE", response, path);
return response.build();
}
-
- /**
- * Check if items already exists at specified {@code path}. Throws {@link RestconfDocumentedException} if
- * data does NOT already exists.
- *
- * @param isExistsFuture if checked data exists
- * @param path Path to be checked
- * @param operationType Type of operation (READ, POST, PUT, DELETE...)
- */
- public static void checkItemExists(final FluentFuture<Boolean> isExistsFuture,
- final YangInstanceIdentifier path,
- final String operationType) {
- final FutureDataFactory<Boolean> response = new FutureDataFactory<>();
- FutureCallbackTx.addCallback(isExistsFuture, operationType, response);
-
- if (!response.result) {
- LOG.trace("Operation via Restconf was not executed because data at {} does not exist", path);
- throw new RestconfDocumentedException(
- "Data does not exist", ErrorType.PROTOCOL, ErrorTag.DATA_MISSING, path);
- }
- }
}