2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.netconf;
10 import static java.util.Objects.requireNonNull;
11 import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION;
12 import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.OPERATIONAL;
14 import com.google.common.util.concurrent.ListenableFuture;
15 import java.util.List;
16 import java.util.Optional;
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
19 import org.opendaylight.mdsal.common.api.ReadFailedException;
20 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
21 import org.opendaylight.netconf.api.ModifyAction;
22 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
23 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
25 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 public class FailedProxyNetconfServiceFacade implements ProxyNetconfServiceFacade {
30 private static final Logger LOG = LoggerFactory.getLogger(FailedProxyNetconfServiceFacade.class);
32 private final @NonNull RemoteDeviceId id;
33 private final @NonNull Throwable failure;
35 public FailedProxyNetconfServiceFacade(final RemoteDeviceId id, final Throwable failure) {
36 this.id = requireNonNull(id);
37 this.failure = requireNonNull(failure);
41 public ListenableFuture<DOMRpcResult> lock() {
42 LOG.debug("{}: Lock - failure", id, failure);
43 return serviceFailed("lock");
47 public ListenableFuture<DOMRpcResult> unlock() {
48 LOG.debug("{}: Unlock - failure", id, failure);
49 return serviceFailed("unlock");
53 public ListenableFuture<DOMRpcResult> discardChanges() {
54 LOG.debug("{}: Discard changes - failure", id, failure);
55 return serviceFailed("discard changes");
59 public ListenableFuture<Optional<NormalizedNode>> get(final YangInstanceIdentifier path) {
60 LOG.debug("{}: Get {} {} - failure", id, OPERATIONAL, path, failure);
61 return readFailed("get");
65 public ListenableFuture<Optional<NormalizedNode>> get(final YangInstanceIdentifier path,
66 final List<YangInstanceIdentifier> fields) {
67 LOG.debug("{}: Get {} {} with fields {} - failure", id, OPERATIONAL, path, fields, failure);
68 return readFailed("get");
72 public ListenableFuture<Optional<NormalizedNode>> getConfig(final YangInstanceIdentifier path) {
73 LOG.debug("{}: GetConfig {} {} - failure", id, CONFIGURATION, path, failure);
74 return readFailed("getConfig");
78 public ListenableFuture<Optional<NormalizedNode>> getConfig(final YangInstanceIdentifier path,
79 final List<YangInstanceIdentifier> fields) {
80 LOG.debug("{}: GetConfig {} {} with fields {} - failure", id, CONFIGURATION, path, fields, failure);
81 return readFailed("getConfig");
85 public ListenableFuture<? extends DOMRpcResult> merge(final LogicalDatastoreType store,
86 final YangInstanceIdentifier path, final NormalizedNode data,
87 final Optional<ModifyAction> defaultOperation) {
88 LOG.debug("{}: Merge {} {} - failure", id, store, path, failure);
89 return serviceFailed("merge");
93 public ListenableFuture<? extends DOMRpcResult> replace(final LogicalDatastoreType store,
94 final YangInstanceIdentifier path, final NormalizedNode data,
95 final Optional<ModifyAction> defaultOperation) {
96 LOG.debug("{}: Replace {} {} - failure", id, store, path, failure);
97 return serviceFailed("replace");
101 public ListenableFuture<? extends DOMRpcResult> create(final LogicalDatastoreType store,
102 final YangInstanceIdentifier path, final NormalizedNode data,
103 final Optional<ModifyAction> defaultOperation) {
104 LOG.debug("{}: Create {} {} - failure", id, store, path, failure);
105 return serviceFailed("create");
109 public ListenableFuture<? extends DOMRpcResult> delete(final LogicalDatastoreType store,
110 final YangInstanceIdentifier path) {
111 LOG.debug("{}: Delete {} {} - failure", id, store, path, failure);
112 return serviceFailed("delete");
116 public ListenableFuture<? extends DOMRpcResult> remove(final LogicalDatastoreType store,
117 final YangInstanceIdentifier path) {
118 LOG.debug("{}: Remove {} {} - failure", id, store, path, failure);
119 return serviceFailed("remove");
123 public ListenableFuture<? extends DOMRpcResult> commit() {
124 LOG.debug("{}: Commit - failure", id, failure);
125 return serviceFailed("commit");
129 public Object getDeviceId() {
133 private <T> ListenableFuture<T> readFailed(final String operation) {
134 return FluentFutures.immediateFailedFluentFuture(new ReadFailedException(operation, failure));
137 private <T> ListenableFuture<T> serviceFailed(final String operation) {
138 return FluentFutures.immediateFailedFluentFuture(new NetconfServiceFailedException(operation, failure));