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(RemoteDeviceId id, 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(LogicalDatastoreType store,
55 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(LogicalDatastoreType store, YangInstanceIdentifier path) {
63 LOG.debug("{}: Exists {} {} - failure {}", id, store, path, failure);
64 return Futures.immediateFailedCheckedFuture(ReadFailedException.MAPPER.apply(
65 failure instanceof Exception ? (Exception)failure : new ReadFailedException("read", failure)));
69 public void delete(LogicalDatastoreType store, YangInstanceIdentifier path) {
70 LOG.debug("{}: Delete {} {} - failure {}", id, store, path, failure);
74 public void put(LogicalDatastoreType store, YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
75 LOG.debug("{}: Put {} {} - failure {}", id, store, path, failure);
79 public void merge(LogicalDatastoreType store, YangInstanceIdentifier path, NormalizedNode<?, ?> data) {
80 LOG.debug("{}: Merge {} {} - failure {}", id, store, path, failure);
84 public @NonNull FluentFuture<? extends @NonNull CommitInfo> commit() {
85 LOG.debug("{}: Commit {} {} - failure {}", id, failure);
86 return FluentFuture.from(Futures.immediateFailedFuture(failure instanceof Exception
87 ? AsyncWriteTransaction.SUBMIT_EXCEPTION_MAPPER.apply((Exception)failure)
88 : new TransactionCommitFailedException("commit", failure)));