1616// under the License.
1717package com .cloud .hypervisor .xen .resource ;
1818
19- import java .io .File ;
20- import java .util .ArrayList ;
21- import java .util .List ;
22- import java .util .Set ;
23-
24- import javax .ejb .Local ;
25-
26- import org .apache .log4j .Logger ;
27- import org .apache .xmlrpc .XmlRpcException ;
28-
29- import com .xensource .xenapi .Connection ;
30- import com .xensource .xenapi .Host ;
31- import com .xensource .xenapi .Network ;
32- import com .xensource .xenapi .PIF ;
33- import com .xensource .xenapi .Types .IpConfigurationMode ;
34- import com .xensource .xenapi .Types .XenAPIException ;
35- import com .xensource .xenapi .VLAN ;
36- import com .xensource .xenapi .VM ;
37-
3819import com .cloud .agent .api .Answer ;
3920import com .cloud .agent .api .CheckOnHostAnswer ;
4021import com .cloud .agent .api .CheckOnHostCommand ;
4526import com .cloud .agent .api .NetworkUsageCommand ;
4627import com .cloud .agent .api .StartupCommand ;
4728import com .cloud .resource .ServerResource ;
29+ import com .cloud .utils .ExecutionResult ;
4830import com .cloud .utils .exception .CloudRuntimeException ;
4931import com .cloud .utils .script .Script ;
5032import com .cloud .utils .ssh .SSHCmdHelper ;
33+ import com .xensource .xenapi .Connection ;
34+ import com .xensource .xenapi .Host ;
35+ import com .xensource .xenapi .Network ;
36+ import com .xensource .xenapi .PIF ;
37+ import com .xensource .xenapi .Types .IpConfigurationMode ;
38+ import com .xensource .xenapi .Types .XenAPIException ;
39+ import com .xensource .xenapi .VLAN ;
40+ import com .xensource .xenapi .VM ;
41+ import org .apache .log4j .Logger ;
42+ import org .apache .xmlrpc .XmlRpcException ;
43+
44+ import javax .ejb .Local ;
45+ import java .io .File ;
46+ import java .util .ArrayList ;
47+ import java .util .List ;
48+ import java .util .Set ;
5149
5250@ Local (value = ServerResource .class )
5351public class XenServer56Resource extends CitrixResourceBase {
@@ -178,11 +176,15 @@ protected NetworkUsageAnswer VPCNetworkUsage(NetworkUsageCommand cmd) {
178176 return new NetworkUsageAnswer (cmd , "success" , 0L , 0L );
179177 }
180178
181- String result = executeInVR (cmd .getPrivateIP (), "vpc_netusage.sh" , args ).getDetails ();
179+ ExecutionResult result = executeInVR (cmd .getPrivateIP (), "vpc_netusage.sh" , args );
180+ String detail = result .getDetails ();
181+ if (!result .isSuccess ()) {
182+ throw new Exception (" vpc network usage plugin call failed " );
183+ }
182184 if (option .equals ("get" ) || option .equals ("vpn" )) {
183185 long [] stats = new long [2 ];
184- if (result != null ) {
185- String [] splitResult = result .split (":" );
186+ if (detail != null ) {
187+ String [] splitResult = detail .split (":" );
186188 int i = 0 ;
187189 while (i < splitResult .length - 1 ) {
188190 stats [0 ] += (new Long (splitResult [i ++])).longValue ();
@@ -191,9 +193,6 @@ protected NetworkUsageAnswer VPCNetworkUsage(NetworkUsageCommand cmd) {
191193 return new NetworkUsageAnswer (cmd , "success" , stats [0 ], stats [1 ]);
192194 }
193195 }
194- if (result == null || result .isEmpty ()) {
195- throw new Exception (" vpc network usage plugin call failed " );
196- }
197196 return new NetworkUsageAnswer (cmd , "success" , 0L , 0L );
198197 } catch (Exception ex ) {
199198 s_logger .warn ("Failed to get network usage stats due to " , ex );
0 commit comments