BUG-2314 Migrate netconf-connector to NormalizedNode
[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.md.sal.dom.api.DOMRpcResult;
13 import org.opendaylight.controller.sal.connect.netconf.sal.tx.WriteRunningTx;
14 import org.opendaylight.controller.sal.connect.util.RemoteDeviceId;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 /**
19  * Simple Netconf rpc logging callback
20  */
21 public class NetconfRpcFutureCallback implements FutureCallback<DOMRpcResult> {
22     private static final Logger LOG  = LoggerFactory.getLogger(WriteRunningTx.class);
23
24     private final String type;
25     private final RemoteDeviceId id;
26
27     public NetconfRpcFutureCallback(final String prefix, final RemoteDeviceId id) {
28         this.type = prefix;
29         this.id = id;
30     }
31
32     @Override
33     public void onSuccess(final DOMRpcResult result) {
34         if(result.getErrors().isEmpty()) {
35             LOG.trace("{}: " + type + " invoked successfully", id);
36         } else {
37             onUnsuccess(result);
38         }
39     }
40
41     protected void onUnsuccess(final DOMRpcResult result) {
42         LOG.warn("{}: " + type + " invoked unsuccessfully: {}", id, result.getErrors());
43     }
44
45     @Override
46     public void onFailure(final Throwable t) {
47         LOG.warn("{}: " + type + " failed.", id, t);
48     }
49 }