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 @NonNull FluentFuture<CommitInfo> completionFuture;
34 private final RemoteDeviceId id;
35 private final Throwable failure;
37 FailedProxyTransactionFacade(final RemoteDeviceId id, final Throwable failure) {
38 this.id = Objects.requireNonNull(id);
39 this.failure = Objects.requireNonNull(failure);
40 completionFuture = FluentFutures.immediateFailedFluentFuture(
41 failure instanceof TransactionCommitFailedException commitFailed ? commitFailed
42 : new TransactionCommitFailedException("commit", failure));
46 public Object getIdentifier() {
51 public FluentFuture<?> completionFuture() {
52 return completionFuture;
56 public boolean cancel() {
61 public FluentFuture<Optional<NormalizedNode>> read(final LogicalDatastoreType store,
62 final YangInstanceIdentifier path) {
63 LOG.debug("{}: Read {} {} - failure", id, store, path, failure);
64 return FluentFutures.immediateFailedFluentFuture(ReadFailedException.MAPPER.apply(
65 failure instanceof Exception ? (Exception)failure : new ReadFailedException("read", failure)));
69 public FluentFuture<Boolean> exists(final LogicalDatastoreType store,
70 final YangInstanceIdentifier path) {
71 LOG.debug("{}: Exists {} {} - failure", id, store, path, failure);
72 return FluentFutures.immediateFailedFluentFuture(ReadFailedException.MAPPER.apply(
73 failure instanceof Exception ? (Exception)failure : new ReadFailedException("read", failure)));
77 public void delete(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
78 LOG.debug("{}: Delete {} {} - failure", id, store, path, failure);
82 public void put(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode data) {
83 LOG.debug("{}: Put {} {} - failure", id, store, path, failure);
87 public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode data) {
88 LOG.debug("{}: Merge {} {} - failure", id, store, path, failure);
92 public FluentFuture<CommitInfo> commit() {
93 LOG.debug("{}: Commit - failure", id, failure);
94 return completionFuture;