Add support of new a NetconfDataTreeService in clustered netconf
[netconf.git] / netconf / netconf-topology-singleton / src / main / java / org / opendaylight / netconf / topology / singleton / impl / netconf / FailedProxyNetconfServiceFacade.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netconf.topology.singleton.impl.netconf;
9
10 import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION;
11 import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.OPERATIONAL;
12
13 import com.google.common.util.concurrent.ListenableFuture;
14 import java.util.Collections;
15 import java.util.List;
16 import java.util.Objects;
17 import java.util.Optional;
18 import org.eclipse.jdt.annotation.NonNull;
19 import org.opendaylight.mdsal.common.api.CommitInfo;
20 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
21 import org.opendaylight.mdsal.common.api.ReadFailedException;
22 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
23 import org.opendaylight.netconf.api.ModifyAction;
24 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
25 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
26 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
27 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 public class FailedProxyNetconfServiceFacade implements ProxyNetconfServiceFacade {
32     private static final Logger LOG = LoggerFactory.getLogger(FailedProxyNetconfServiceFacade.class);
33
34     private final RemoteDeviceId id;
35     private final Throwable failure;
36
37     public FailedProxyNetconfServiceFacade(final RemoteDeviceId id, final Throwable failure) {
38         this.id = Objects.requireNonNull(id);
39         this.failure = Objects.requireNonNull(failure);
40     }
41
42     @Override
43     public List<ListenableFuture<? extends DOMRpcResult>> lock() {
44         LOG.debug("{}: Lock - failure", id, failure);
45         return Collections.singletonList(
46             FluentFutures.immediateFailedFluentFuture(new NetconfServiceFailedException("lock", failure)));
47     }
48
49     @Override
50     public void unlock() {
51         LOG.debug("{}: Unlock - failure", id, failure);
52     }
53
54     @Override
55     public void discardChanges() {
56         LOG.debug("{}: Discard changes - failure", id, failure);
57     }
58
59     @Override
60     public ListenableFuture<Optional<NormalizedNode<?, ?>>> get(YangInstanceIdentifier path) {
61         LOG.debug("{}: Get {} {} - failure", id, OPERATIONAL, path, failure);
62         return FluentFutures.immediateFailedFluentFuture(new ReadFailedException("get", failure));
63     }
64
65     @Override
66     public ListenableFuture<Optional<NormalizedNode<?, ?>>> getConfig(YangInstanceIdentifier path) {
67         LOG.debug("{}: GetConfig {} {} - failure", id, CONFIGURATION, path, failure);
68         return FluentFutures.immediateFailedFluentFuture(new ReadFailedException("getConfig", failure));
69     }
70
71     @Override
72     public ListenableFuture<? extends DOMRpcResult> merge(LogicalDatastoreType store, YangInstanceIdentifier path,
73                                                           NormalizedNode<?, ?> data,
74                                                           Optional<ModifyAction> defaultOperation) {
75         LOG.debug("{}: Merge {} {} - failure", id, store, path, failure);
76         return FluentFutures.immediateFailedFluentFuture(new NetconfServiceFailedException("merge", failure));
77     }
78
79     @Override
80     public ListenableFuture<? extends DOMRpcResult> replace(LogicalDatastoreType store, YangInstanceIdentifier path,
81                                                             NormalizedNode<?, ?> data,
82                                                             Optional<ModifyAction> defaultOperation) {
83         LOG.debug("{}: Replace {} {} - failure", id, store, path, failure);
84         return FluentFutures.immediateFailedFluentFuture(new NetconfServiceFailedException("replace", failure));
85     }
86
87     @Override
88     public ListenableFuture<? extends DOMRpcResult> create(LogicalDatastoreType store, YangInstanceIdentifier path,
89                                                            NormalizedNode<?, ?> data,
90                                                            Optional<ModifyAction> defaultOperation) {
91         LOG.debug("{}: Create {} {} - failure", id, store, path, failure);
92         return FluentFutures.immediateFailedFluentFuture(new NetconfServiceFailedException("create", failure));
93     }
94
95     @Override
96     public ListenableFuture<? extends DOMRpcResult> delete(LogicalDatastoreType store, YangInstanceIdentifier path) {
97         LOG.debug("{}: Delete {} {} - failure", id, store, path, failure);
98         return FluentFutures.immediateFailedFluentFuture(new NetconfServiceFailedException("delete", failure));
99     }
100
101     @Override
102     public ListenableFuture<? extends DOMRpcResult> remove(LogicalDatastoreType store, YangInstanceIdentifier path) {
103         LOG.debug("{}: Remove {} {} - failure", id, store, path, failure);
104         return FluentFutures.immediateFailedFluentFuture(new NetconfServiceFailedException("remove", failure));
105     }
106
107     @Override
108     public ListenableFuture<? extends CommitInfo> commit(
109         List<ListenableFuture<? extends DOMRpcResult>> resultsFutures) {
110         LOG.debug("{}: Commit - failure", id, failure);
111         return FluentFutures.immediateFailedFluentFuture(new NetconfServiceFailedException("commit", failure));
112     }
113
114     @Override
115     public @NonNull Object getDeviceId() {
116         return id;
117     }
118 }