BUG-2560 Canonical write to remote netconf devices
[controller.git] / opendaylight / md-sal / sal-netconf-connector / src / main / java / org / opendaylight / controller / sal / connect / netconf / util / NetconfRpcFutureCallback.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. 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
9 package org.opendaylight.controller.sal.connect.netconf.util;
10
11 import com.google.common.util.concurrent.FutureCallback;
12 import org.opendaylight.controller.sal.connect.netconf.sal.tx.WriteRunningTx;
13 import org.opendaylight.controller.sal.connect.util.RemoteDeviceId;
14 import org.opendaylight.yangtools.yang.common.RpcResult;
15 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 /**
20  * Simple Netconf rpc logging callback
21  */
22 public class NetconfRpcFutureCallback implements FutureCallback<RpcResult<CompositeNode>> {
23     private static final Logger LOG  = LoggerFactory.getLogger(WriteRunningTx.class);
24
25     private final String type;
26     private final RemoteDeviceId id;
27
28     public NetconfRpcFutureCallback(final String prefix, final RemoteDeviceId id) {
29         this.type = prefix;
30         this.id = id;
31     }
32
33     @Override
34     public void onSuccess(final RpcResult<CompositeNode> result) {
35         if(result.isSuccessful()) {
36             LOG.trace("{}: " + type + " invoked successfully", id);
37         } else {
38             onUnsuccess(result);
39         }
40     }
41
42     protected void onUnsuccess(final RpcResult<CompositeNode> result) {
43         LOG.warn("{}: " + type + " invoked unsuccessfully: {}", id, result.getErrors());
44     }
45
46     @Override
47     public void onFailure(final Throwable t) {
48         LOG.warn("{}: " + type + " failed.", id, t);
49     }
50 }