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.client.mdsal.api.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() {
52 public FluentFuture<Optional<NormalizedNode>> read(final LogicalDatastoreType store,
53 final YangInstanceIdentifier path) {
54 LOG.debug("{}: Read {} {} - failure", id, store, path, failure);
55 return FluentFutures.immediateFailedFluentFuture(ReadFailedException.MAPPER.apply(
56 failure instanceof Exception ? (Exception)failure : new ReadFailedException("read", failure)));
60 public FluentFuture<Boolean> exists(final LogicalDatastoreType store,
61 final YangInstanceIdentifier path) {
62 LOG.debug("{}: Exists {} {} - failure", id, store, path, failure);
63 return FluentFutures.immediateFailedFluentFuture(ReadFailedException.MAPPER.apply(
64 failure instanceof Exception ? (Exception)failure : new ReadFailedException("read", failure)));
68 public void delete(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
69 LOG.debug("{}: Delete {} {} - failure", id, store, path, failure);
73 public void put(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode data) {
74 LOG.debug("{}: Put {} {} - failure", id, store, path, failure);
78 public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode data) {
79 LOG.debug("{}: Merge {} {} - failure", id, store, path, failure);
83 public @NonNull FluentFuture<? extends @NonNull CommitInfo> commit() {
84 LOG.debug("{}: Commit - failure", id, failure);
85 final TransactionCommitFailedException txCommitEx;
86 if (failure instanceof TransactionCommitFailedException) {
87 txCommitEx = (TransactionCommitFailedException) failure;
89 txCommitEx = new TransactionCommitFailedException("commit", failure);
91 return FluentFutures.immediateFailedFluentFuture(txCommitEx);