2 * Copyright (c) 2018 Inocybe Technologies and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.topology.singleton.impl.tx;
10 import com.google.common.util.concurrent.FluentFuture;
11 import java.util.Objects;
12 import java.util.Optional;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.mdsal.common.api.CommitInfo;
15 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
16 import org.opendaylight.mdsal.common.api.ReadFailedException;
17 import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
18 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
19 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * Implementation of ProxyTransactionFacade that fails each request.
28 * @author Thomas Pantelis
30 class FailedProxyTransactionFacade implements ProxyTransactionFacade {
31 private static final Logger LOG = LoggerFactory.getLogger(FailedProxyTransactionFacade.class);
33 private final RemoteDeviceId id;
34 private final Throwable failure;
36 FailedProxyTransactionFacade(final RemoteDeviceId id, final Throwable failure) {
37 this.id = Objects.requireNonNull(id);
38 this.failure = Objects.requireNonNull(failure);
42 public Object getIdentifier() {
47 public boolean cancel() {
57 public FluentFuture<Optional<NormalizedNode<?, ?>>> read(final LogicalDatastoreType store,
58 final YangInstanceIdentifier path) {
59 LOG.debug("{}: Read {} {} - failure", id, store, path, failure);
60 return FluentFutures.immediateFailedFluentFuture(ReadFailedException.MAPPER.apply(
61 failure instanceof Exception ? (Exception)failure : new ReadFailedException("read", failure)));
65 public FluentFuture<Boolean> exists(final LogicalDatastoreType store,
66 final YangInstanceIdentifier path) {
67 LOG.debug("{}: Exists {} {} - failure", id, store, path, failure);
68 return FluentFutures.immediateFailedFluentFuture(ReadFailedException.MAPPER.apply(
69 failure instanceof Exception ? (Exception)failure : new ReadFailedException("read", failure)));
73 public void delete(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
74 LOG.debug("{}: Delete {} {} - failure", id, store, path, failure);
78 public void put(final LogicalDatastoreType store, final YangInstanceIdentifier path,
79 final NormalizedNode<?, ?> data) {
80 LOG.debug("{}: Put {} {} - failure", id, store, path, failure);
84 public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path,
85 final NormalizedNode<?, ?> data) {
86 LOG.debug("{}: Merge {} {} - failure", id, store, path, failure);
90 public @NonNull FluentFuture<? extends @NonNull CommitInfo> commit() {
91 LOG.debug("{}: Commit - failure", id, failure);
92 final TransactionCommitFailedException txCommitEx;
93 if (failure instanceof TransactionCommitFailedException) {
94 txCommitEx = (TransactionCommitFailedException) failure;
96 txCommitEx = new TransactionCommitFailedException("commit", failure);
98 return FluentFutures.immediateFailedFluentFuture(txCommitEx);