Sanjay S
Committed by Gerrit Code Review

Modified to accommodate code review comments.

Change-Id: I391db0afe13d862706b5592e60e83b725d99e672
...@@ -129,7 +129,7 @@ ...@@ -129,7 +129,7 @@
129 <bundle>mvn:org.onosproject/onos-core-common/@ONOS-VERSION</bundle> 129 <bundle>mvn:org.onosproject/onos-core-common/@ONOS-VERSION</bundle>
130 <bundle>mvn:org.onosproject/onos-core-trivial/@ONOS-VERSION</bundle> 130 <bundle>mvn:org.onosproject/onos-core-trivial/@ONOS-VERSION</bundle>
131 </feature> 131 </feature>
132 - 132 +
133 <feature name="onos-netconf" version="@FEATURE-VERSION" 133 <feature name="onos-netconf" version="@FEATURE-VERSION"
134 description="ONOS Netconf providers"> 134 description="ONOS Netconf providers">
135 <feature>onos-api</feature> 135 <feature>onos-api</feature>
......
...@@ -41,7 +41,7 @@ import com.tailf.jnc.SSHSession; ...@@ -41,7 +41,7 @@ import com.tailf.jnc.SSHSession;
41 * necessary information to connect and execute NETCONF operations. 41 * necessary information to connect and execute NETCONF operations.
42 */ 42 */
43 public class NetconfDevice { 43 public class NetconfDevice {
44 - private static final Logger log = getLogger(NetconfDevice.class); 44 + private final Logger log = getLogger(NetconfDevice.class);
45 45
46 /** 46 /**
47 * The Device State is used to determine whether the device is active or 47 * The Device State is used to determine whether the device is active or
...@@ -51,9 +51,9 @@ public class NetconfDevice { ...@@ -51,9 +51,9 @@ public class NetconfDevice {
51 public static enum DeviceState { 51 public static enum DeviceState {
52 /* Used to specify Active state of the device */ 52 /* Used to specify Active state of the device */
53 ACTIVE, 53 ACTIVE,
54 - /* Used to specify In Active state of the device */ 54 + /* Used to specify inactive state of the device */
55 INACTIVE, 55 INACTIVE,
56 - /* Used to specify In Valid state of the device */ 56 + /* Used to specify invalid state of the device */
57 INVALID 57 INVALID
58 } 58 }
59 59
...@@ -99,13 +99,11 @@ public class NetconfDevice { ...@@ -99,13 +99,11 @@ public class NetconfDevice {
99 } 99 }
100 // Send hello message to retrieve capabilities. 100 // Send hello message to retrieve capabilities.
101 } catch (IOException e) { 101 } catch (IOException e) {
102 - NetconfDevice.log 102 + log.error("Fatal Error while creating connection to the device: "
103 - .error("Fatal Error while creating connection to the device: " 103 + + deviceInfo(), e);
104 - + deviceInfo(), e);
105 throw e; 104 throw e;
106 } catch (JNCException e) { 105 } catch (JNCException e) {
107 - NetconfDevice.log.error("Failed to connect to the device: " 106 + log.error("Failed to connect to the device: " + deviceInfo(), e);
108 - + deviceInfo(), e);
109 throw e; 107 throw e;
110 } 108 }
111 109
...@@ -118,14 +116,10 @@ public class NetconfDevice { ...@@ -118,14 +116,10 @@ public class NetconfDevice {
118 ssh = new SSHSession(sshConnection); 116 ssh = new SSHSession(sshConnection);
119 String helloRequestXML = INPUT_HELLO_XML_MSG.trim(); 117 String helloRequestXML = INPUT_HELLO_XML_MSG.trim();
120 118
121 - if (NetconfDevice.log.isDebugEnabled()) { 119 + log.debug("++++++++++++++++++++++++++++++++++Sending Hello: "
122 - NetconfDevice.log 120 + + sshConnection.getGanymedConnection().getHostname()
123 - .debug("++++++++++++++++++++++++++++++++++Sending Hello: " 121 + + "++++++++++++++++++++++++++++++++++");
124 - + sshConnection.getGanymedConnection() 122 + printPrettyXML(helloRequestXML);
125 - .getHostname()
126 - + "++++++++++++++++++++++++++++++++++");
127 - printPrettyXML(helloRequestXML);
128 - }
129 ssh.print(helloRequestXML); 123 ssh.print(helloRequestXML);
130 // ssh.print(endCharSeq); 124 // ssh.print(endCharSeq);
131 ssh.flush(); 125 ssh.flush();
...@@ -139,8 +133,7 @@ public class NetconfDevice { ...@@ -139,8 +133,7 @@ public class NetconfDevice {
139 if (ssh.ready()) { 133 if (ssh.ready()) {
140 StringBuffer readOne = ssh.readOne(); 134 StringBuffer readOne = ssh.readOne();
141 if (readOne == null) { 135 if (readOne == null) {
142 - NetconfDevice.log 136 + log.error("The Hello Contains No Capabilites");
143 - .error("The Hello Contains No Capabilites");
144 throw new JNCException( 137 throw new JNCException(
145 JNCException.SESSION_ERROR, 138 JNCException.SESSION_ERROR,
146 "server does not support NETCONF base capability: " 139 "server does not support NETCONF base capability: "
...@@ -148,39 +141,31 @@ public class NetconfDevice { ...@@ -148,39 +141,31 @@ public class NetconfDevice {
148 } else { 141 } else {
149 xmlResponse = readOne.toString().trim(); 142 xmlResponse = readOne.toString().trim();
150 143
151 - if (NetconfDevice.log.isDebugEnabled()) { 144 + log.debug("++++++++++++++++++++++++++++++++++Reading Capabilities: "
152 - NetconfDevice.log 145 + + sshConnection.getGanymedConnection()
153 - .debug("++++++++++++++++++++++++++++++++++Reading Capabilities: " 146 + .getHostname()
154 - + sshConnection.getGanymedConnection() 147 + + "++++++++++++++++++++++++++++++++++");
155 - .getHostname()
156 - + "++++++++++++++++++++++++++++++++++");
157 148
158 - printPrettyXML(xmlResponse); 149 + printPrettyXML(xmlResponse);
159 - }
160 processCapabilities(xmlResponse); 150 processCapabilities(xmlResponse);
161 } 151 }
162 } 152 }
163 reachable = true; 153 reachable = true;
164 } catch (IOException e) { 154 } catch (IOException e) {
165 - NetconfDevice.log 155 + log.error("Fatal Error while sending Hello Message to the device: "
166 - .error("Fatal Error while sending Hello Message to the device: " 156 + + deviceInfo(), e);
167 - + deviceInfo(), e);
168 } catch (JNCException e) { 157 } catch (JNCException e) {
169 - NetconfDevice.log 158 + log.error("Fatal Error while sending Hello Message to the device: "
170 - .error("Fatal Error while sending Hello Message to the device: " 159 + + deviceInfo(), e);
171 - + deviceInfo(), e);
172 } finally { 160 } finally {
173 - if (NetconfDevice.log.isDebugEnabled()) { 161 + log.debug("Closing the session after successful execution");
174 - NetconfDevice.log
175 - .debug("Closing the session after successful execution");
176 - }
177 ssh.close(); 162 ssh.close();
178 } 163 }
179 } 164 }
180 165
181 private void processCapabilities(String xmlResponse) throws JNCException { 166 private void processCapabilities(String xmlResponse) throws JNCException {
182 if (xmlResponse.isEmpty()) { 167 if (xmlResponse.isEmpty()) {
183 - NetconfDevice.log.error("The capability response cannot be empty"); 168 + log.error("The capability response cannot be empty");
184 throw new JNCException( 169 throw new JNCException(
185 JNCException.SESSION_ERROR, 170 JNCException.SESSION_ERROR,
186 "server does not support NETCONF base capability: " 171 "server does not support NETCONF base capability: "
...@@ -192,8 +177,7 @@ public class NetconfDevice { ...@@ -192,8 +177,7 @@ public class NetconfDevice {
192 Element rootElement = doc.getRootElement(); 177 Element rootElement = doc.getRootElement();
193 processCapabilities(rootElement); 178 processCapabilities(rootElement);
194 } catch (Exception e) { 179 } catch (Exception e) {
195 - NetconfDevice.log.error("ERROR while parsing the XML " 180 + log.error("ERROR while parsing the XML " + xmlResponse);
196 - + xmlResponse);
197 } 181 }
198 } 182 }
199 183
...@@ -218,12 +202,9 @@ public class NetconfDevice { ...@@ -218,12 +202,9 @@ public class NetconfDevice {
218 Document doc = new SAXBuilder().build(new StringReader(xmlstring)); 202 Document doc = new SAXBuilder().build(new StringReader(xmlstring));
219 XMLOutputter xmOut = new XMLOutputter(Format.getPrettyFormat()); 203 XMLOutputter xmOut = new XMLOutputter(Format.getPrettyFormat());
220 String outputString = xmOut.outputString(doc); 204 String outputString = xmOut.outputString(doc);
221 - if (NetconfDevice.log.isDebugEnabled()) { 205 + log.debug(outputString);
222 - NetconfDevice.log.debug(outputString);
223 - }
224 } catch (Exception e) { 206 } catch (Exception e) {
225 - NetconfDevice.log.error("ERROR while parsing the XML " + xmlstring, 207 + log.error("ERROR while parsing the XML " + xmlstring, e);
226 - e);
227 208
228 } 209 }
229 } 210 }
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
32 <description>ONOS Netconf protocol adapters</description> 32 <description>ONOS Netconf protocol adapters</description>
33 33
34 <modules> 34 <modules>
35 - <module>device</module> 35 + <module>device</module>
36 </modules> 36 </modules>
37 37
38 <dependencies> 38 <dependencies>
......