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.base.Optional;
11 import com.google.common.util.concurrent.CheckedFuture;
12 import com.google.common.util.concurrent.FluentFuture;
13 import com.google.common.util.concurrent.Futures;
14 import java.util.Objects;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.opendaylight.controller.md.sal.common.api.data.AsyncWriteTransaction;
17 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
18 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
19 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
20 import org.opendaylight.mdsal.common.api.CommitInfo;
21 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
23 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
28 * Implementation of ProxyTransactionFacade that fails each request.
30 * @author Thomas Pantelis
32 class FailedProxyTransactionFacade implements ProxyTransactionFacade {
33 private static final Logger LOG = LoggerFactory.getLogger(FailedProxyTransactionFacade.class);
35 private final RemoteDeviceId id;
36 private final Throwable failure;
38 FailedProxyTransactionFacade(final RemoteDeviceId id, final Throwable failure) {
39 this.id = Objects.requireNonNull(id);
40 this.failure = Objects.requireNonNull(failure);
44 public Object getIdentifier() {
49 public boolean cancel() {
54 public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(final LogicalDatastoreType store,
55 final YangInstanceIdentifier path) {
56 LOG.debug("{}: Read {} {} - failure", id, store, path, failure);
57 return Futures.immediateFailedCheckedFuture(ReadFailedException.MAPPER.apply(
58 failure instanceof Exception ? (Exception)failure : new ReadFailedException("read", failure)));
62 public CheckedFuture<Boolean, ReadFailedException> exists(final LogicalDatastoreType store,
63 final YangInstanceIdentifier path) {
64 LOG.debug("{}: Exists {} {} - failure", id, store, path, failure);
65 return Futures.immediateFailedCheckedFuture(ReadFailedException.MAPPER.apply(
66 failure instanceof Exception ? (Exception)failure : new ReadFailedException("read", failure)));
70 public void delete(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
71 LOG.debug("{}: Delete {} {} - failure", id, store, path, failure);
75 public void put(final LogicalDatastoreType store, final YangInstanceIdentifier path,
76 final NormalizedNode<?, ?> data) {
77 LOG.debug("{}: Put {} {} - failure", id, store, path, failure);
81 public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path,
82 final NormalizedNode<?, ?> data) {
83 LOG.debug("{}: Merge {} {} - failure", id, store, path, failure);
87 public @NonNull FluentFuture<? extends @NonNull CommitInfo> commit() {
88 LOG.debug("{}: Commit - failure", id, failure);
89 return FluentFuture.from(Futures.immediateFailedFuture(failure instanceof Exception
90 ? AsyncWriteTransaction.SUBMIT_EXCEPTION_MAPPER.apply((Exception)failure)
91 : new TransactionCommitFailedException("commit", failure)));