Skip to content

Commit ed00427

Browse files
committed
Improve logging for CitrixResourceBase by replacing e.printStackTrace
with s_Logger.error. Automatic cleanup using the eclipse settings from Alex
1 parent 99227f7 commit ed00427

1 file changed

Lines changed: 104 additions & 133 deletions

File tree

plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java

Lines changed: 104 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,52 @@
5353
import javax.naming.ConfigurationException;
5454
import javax.xml.parsers.DocumentBuilderFactory;
5555

56-
import com.cloud.agent.api.*;
57-
import com.cloud.agent.api.to.*;
58-
import com.cloud.network.rules.FirewallRule;
59-
60-
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
61-
import org.apache.cloudstack.storage.to.TemplateObjectTO;
62-
import org.apache.cloudstack.storage.to.VolumeObjectTO;
6356
import org.apache.log4j.Logger;
6457
import org.apache.xmlrpc.XmlRpcException;
6558
import org.w3c.dom.Document;
6659
import org.w3c.dom.Node;
6760
import org.w3c.dom.NodeList;
6861
import org.xml.sax.InputSource;
6962

63+
import com.trilead.ssh2.SCPClient;
64+
import com.xensource.xenapi.Bond;
65+
import com.xensource.xenapi.Connection;
66+
import com.xensource.xenapi.Console;
67+
import com.xensource.xenapi.Host;
68+
import com.xensource.xenapi.HostCpu;
69+
import com.xensource.xenapi.HostMetrics;
70+
import com.xensource.xenapi.Network;
71+
import com.xensource.xenapi.PBD;
72+
import com.xensource.xenapi.PIF;
73+
import com.xensource.xenapi.PIF.Record;
74+
import com.xensource.xenapi.Pool;
75+
import com.xensource.xenapi.SR;
76+
import com.xensource.xenapi.Session;
77+
import com.xensource.xenapi.Task;
78+
import com.xensource.xenapi.Types;
79+
import com.xensource.xenapi.Types.BadAsyncResult;
80+
import com.xensource.xenapi.Types.BadServerResponse;
81+
import com.xensource.xenapi.Types.ConsoleProtocol;
82+
import com.xensource.xenapi.Types.IpConfigurationMode;
83+
import com.xensource.xenapi.Types.OperationNotAllowed;
84+
import com.xensource.xenapi.Types.SrFull;
85+
import com.xensource.xenapi.Types.VbdType;
86+
import com.xensource.xenapi.Types.VmBadPowerState;
87+
import com.xensource.xenapi.Types.VmPowerState;
88+
import com.xensource.xenapi.Types.XenAPIException;
89+
import com.xensource.xenapi.VBD;
90+
import com.xensource.xenapi.VBDMetrics;
91+
import com.xensource.xenapi.VDI;
92+
import com.xensource.xenapi.VIF;
93+
import com.xensource.xenapi.VLAN;
94+
import com.xensource.xenapi.VM;
95+
import com.xensource.xenapi.VMGuestMetrics;
96+
import com.xensource.xenapi.XenAPIObject;
97+
98+
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
99+
import org.apache.cloudstack.storage.to.TemplateObjectTO;
100+
import org.apache.cloudstack.storage.to.VolumeObjectTO;
101+
70102
import com.cloud.agent.IAgentControl;
71103
import com.cloud.agent.api.Answer;
72104
import com.cloud.agent.api.AttachIsoCommand;
@@ -208,8 +240,12 @@
208240
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
209241
import com.cloud.agent.api.storage.ResizeVolumeAnswer;
210242
import com.cloud.agent.api.storage.ResizeVolumeCommand;
243+
import com.cloud.agent.api.to.DataStoreTO;
244+
import com.cloud.agent.api.to.DataTO;
245+
import com.cloud.agent.api.to.DiskTO;
211246
import com.cloud.agent.api.to.FirewallRuleTO;
212247
import com.cloud.agent.api.to.IpAddressTO;
248+
import com.cloud.agent.api.to.NfsTO;
213249
import com.cloud.agent.api.to.NicTO;
214250
import com.cloud.agent.api.to.PortForwardingRuleTO;
215251
import com.cloud.agent.api.to.S3TO;
@@ -264,82 +300,6 @@
264300
import com.cloud.vm.VirtualMachine;
265301
import com.cloud.vm.VirtualMachine.State;
266302
import com.cloud.vm.snapshot.VMSnapshot;
267-
import com.trilead.ssh2.SCPClient;
268-
import com.xensource.xenapi.Bond;
269-
import com.xensource.xenapi.Connection;
270-
import com.xensource.xenapi.Console;
271-
import com.xensource.xenapi.Host;
272-
import com.xensource.xenapi.HostCpu;
273-
import com.xensource.xenapi.HostMetrics;
274-
import com.xensource.xenapi.Network;
275-
import com.xensource.xenapi.PBD;
276-
import com.xensource.xenapi.PIF;
277-
import com.xensource.xenapi.PIF.Record;
278-
import com.xensource.xenapi.Pool;
279-
import com.xensource.xenapi.SR;
280-
import com.xensource.xenapi.Session;
281-
import com.xensource.xenapi.Task;
282-
import com.xensource.xenapi.Types;
283-
import com.xensource.xenapi.Types.BadAsyncResult;
284-
import com.xensource.xenapi.Types.BadServerResponse;
285-
import com.xensource.xenapi.Types.ConsoleProtocol;
286-
import com.xensource.xenapi.Types.IpConfigurationMode;
287-
import com.xensource.xenapi.Types.OperationNotAllowed;
288-
import com.xensource.xenapi.Types.SrFull;
289-
import com.xensource.xenapi.Types.VbdType;
290-
import com.xensource.xenapi.Types.VmBadPowerState;
291-
import com.xensource.xenapi.Types.VmPowerState;
292-
import com.xensource.xenapi.Types.XenAPIException;
293-
import com.xensource.xenapi.VBD;
294-
import com.xensource.xenapi.VBDMetrics;
295-
import com.xensource.xenapi.VDI;
296-
import com.xensource.xenapi.VIF;
297-
import com.xensource.xenapi.VLAN;
298-
import com.xensource.xenapi.VM;
299-
import com.xensource.xenapi.VMGuestMetrics;
300-
import com.xensource.xenapi.XenAPIObject;
301-
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
302-
import org.apache.log4j.Logger;
303-
import org.apache.xmlrpc.XmlRpcException;
304-
import org.w3c.dom.Document;
305-
import org.w3c.dom.Node;
306-
import org.w3c.dom.NodeList;
307-
import org.xml.sax.InputSource;
308-
309-
import javax.ejb.Local;
310-
import javax.naming.ConfigurationException;
311-
import javax.xml.parsers.DocumentBuilderFactory;
312-
import java.beans.BeanInfo;
313-
import java.beans.IntrospectionException;
314-
import java.beans.Introspector;
315-
import java.beans.PropertyDescriptor;
316-
import java.io.BufferedReader;
317-
import java.io.File;
318-
import java.io.FileInputStream;
319-
import java.io.IOException;
320-
import java.io.InputStream;
321-
import java.io.InputStreamReader;
322-
import java.io.StringReader;
323-
import java.lang.reflect.InvocationTargetException;
324-
import java.net.URI;
325-
import java.net.URISyntaxException;
326-
import java.net.URL;
327-
import java.net.URLConnection;
328-
import java.util.ArrayList;
329-
import java.util.Arrays;
330-
import java.util.Collections;
331-
import java.util.Date;
332-
import java.util.HashMap;
333-
import java.util.HashSet;
334-
import java.util.Iterator;
335-
import java.util.LinkedList;
336-
import java.util.List;
337-
import java.util.Map;
338-
import java.util.Properties;
339-
import java.util.Queue;
340-
import java.util.Random;
341-
import java.util.Set;
342-
import java.util.UUID;
343303

344304
/**
345305
* CitrixResourceBase encapsulates the calls to the XenServer Xapi process
@@ -430,7 +390,7 @@ public boolean equals(String type) {
430390
}
431391

432392
public XsHost getHost() {
433-
return this._host;
393+
return _host;
434394
}
435395

436396
protected boolean cleanupHaltedVms(Connection conn) throws XenAPIException, XmlRpcException {
@@ -665,7 +625,7 @@ public Answer executeRequest(Command cmd) {
665625
} else if (clazz == CheckS2SVpnConnectionsCommand.class) {
666626
return execute((CheckS2SVpnConnectionsCommand) cmd);
667627
} else if (cmd instanceof StorageSubSystemCommand) {
668-
return this.storageHandler.handleStorageCommands((StorageSubSystemCommand)cmd);
628+
return storageHandler.handleStorageCommands((StorageSubSystemCommand)cmd);
669629
} else if (clazz == CreateVMSnapshotCommand.class) {
670630
return execute((CreateVMSnapshotCommand)cmd);
671631
} else if (clazz == DeleteVMSnapshotCommand.class) {
@@ -753,7 +713,7 @@ public ScaleVmAnswer execute(ScaleVmCommand cmd) {
753713
}
754714

755715
for (VM vm : vms) {
756-
VM.Record vmr = vm.getRecord(conn);
716+
vm.getRecord(conn);
757717
try {
758718
scaleVM(conn, vm, vmSpec, host);
759719
} catch (Exception e) {
@@ -964,12 +924,16 @@ private synchronized Network setupvSwitchNetwork(Connection conn) {
964924
vswitchNw = networks.iterator().next();
965925
}
966926

967-
enableXenServerNetwork(conn, vswitchNw, "vswitch", "vswicth network");
927+
enableXenServerNetwork(conn, vswitchNw, "vswitch", "vswitch network");
968928
_host.vswitchNetwork = vswitchNw;
969929
}
970930
return _host.vswitchNetwork;
971-
} catch (Exception e) {
972-
e.printStackTrace();
931+
} catch (BadServerResponse e) {
932+
s_logger.error("Failed to setup vswitch network", e);
933+
} catch (XenAPIException e) {
934+
s_logger.error("Failed to setup vswitch network", e);
935+
} catch (XmlRpcException e) {
936+
s_logger.error("Failed to setup vswitch network", e);
973937
}
974938

975939
return null;
@@ -3040,14 +3004,11 @@ protected HashMap<String, Pair<String, State>> getAllVms(Connection conn) {
30403004
try {
30413005
host_uuid = host.getUuid(conn);
30423006
} catch (BadServerResponse e) {
3043-
// TODO Auto-generated catch block
3044-
e.printStackTrace();
3007+
s_logger.error("Failed to get host uuid for host " + host.toWireString(), e);
30453008
} catch (XenAPIException e) {
3046-
// TODO Auto-generated catch block
3047-
e.printStackTrace();
3009+
s_logger.error("Failed to get host uuid for host " + host.toWireString(), e);
30483010
} catch (XmlRpcException e) {
3049-
// TODO Auto-generated catch block
3050-
e.printStackTrace();
3011+
s_logger.error("Failed to get host uuid for host " + host.toWireString(), e);
30513012
}
30523013
vmStates.put(record.nameLabel, new Pair<String, State>(host_uuid, state));
30533014
}
@@ -3539,7 +3500,7 @@ record = vm.getRecord(conn);
35393500
s_logger.warn("There are no Consoles available to the vm : " + record.nameDescription);
35403501
return -1;
35413502
}
3542-
Iterator<Console> i = consoles.iterator();
3503+
consoles.iterator();
35433504
} catch (XenAPIException e) {
35443505
String msg = "Unable to get vnc-port due to " + e.toString();
35453506
s_logger.warn(msg, e);
@@ -5778,39 +5739,36 @@ private Answer execute(OvsDeleteFlowCommand cmd) {
57785739
} else {
57795740
return new Answer(cmd, false, result);
57805741
}
5781-
} catch (Exception e) {
5782-
e.printStackTrace();
5742+
} catch (BadServerResponse e) {
5743+
s_logger.error("Failed to delete flow", e);
5744+
} catch (XenAPIException e) {
5745+
s_logger.error("Failed to delete flow", e);
5746+
} catch (XmlRpcException e) {
5747+
s_logger.error("Failed to delete flow", e);
57835748
}
57845749
return new Answer(cmd, false, "failed to delete flow for " + cmd.getVmName());
57855750
}
57865751

57875752
private List<Pair<String, Long>> ovsFullSyncStates() {
57885753
Connection conn = getConnection();
5789-
try {
5790-
String result = callHostPlugin(conn, "ovsgre", "ovs_get_vm_log", "host_uuid", _host.uuid);
5791-
String [] logs = result != null ?result.split(";"): new String [0];
5792-
List<Pair<String, Long>> states = new ArrayList<Pair<String, Long>>();
5793-
for (String log: logs){
5794-
String [] info = log.split(",");
5795-
if (info.length != 5) {
5796-
s_logger.warn("Wrong element number in ovs log(" + log +")");
5797-
continue;
5798-
}
5799-
5800-
//','.join([bridge, vmName, vmId, seqno, tag])
5801-
try {
5802-
states.add(new Pair<String,Long>(info[0], Long.parseLong(info[3])));
5803-
} catch (NumberFormatException nfe) {
5804-
states.add(new Pair<String,Long>(info[0], -1L));
5805-
}
5754+
String result = callHostPlugin(conn, "ovsgre", "ovs_get_vm_log", "host_uuid", _host.uuid);
5755+
String [] logs = result != null ?result.split(";"): new String [0];
5756+
List<Pair<String, Long>> states = new ArrayList<Pair<String, Long>>();
5757+
for (String log: logs){
5758+
String [] info = log.split(",");
5759+
if (info.length != 5) {
5760+
s_logger.warn("Wrong element number in ovs log(" + log +")");
5761+
continue;
58065762
}
58075763

5808-
return states;
5809-
} catch (Exception e) {
5810-
e.printStackTrace();
5764+
//','.join([bridge, vmName, vmId, seqno, tag])
5765+
try {
5766+
states.add(new Pair<String,Long>(info[0], Long.parseLong(info[3])));
5767+
} catch (NumberFormatException nfe) {
5768+
states.add(new Pair<String,Long>(info[0], -1L));
5769+
}
58115770
}
5812-
5813-
return null;
5771+
return states;
58145772
}
58155773

58165774
private OvsSetTagAndFlowAnswer execute(OvsSetTagAndFlowCommand cmd) {
@@ -5835,8 +5793,12 @@ private OvsSetTagAndFlowAnswer execute(OvsSetTagAndFlowCommand cmd) {
58355793
} else {
58365794
return new OvsSetTagAndFlowAnswer(cmd, false, result);
58375795
}
5838-
} catch (Exception e) {
5839-
e.printStackTrace();
5796+
} catch (BadServerResponse e) {
5797+
s_logger.error("Failed to set tag and flow", e);
5798+
} catch (XenAPIException e) {
5799+
s_logger.error("Failed to set tag and flow", e);
5800+
} catch (XmlRpcException e) {
5801+
s_logger.error("Failed to set tag and flow", e);
58405802
}
58415803

58425804
return new OvsSetTagAndFlowAnswer(cmd, false, "EXCEPTION");
@@ -5849,18 +5811,24 @@ private OvsFetchInterfaceAnswer execute(OvsFetchInterfaceCommand cmd) {
58495811
s_logger.debug("Will look for network with name-label:" + label + " on host " + _host.ip);
58505812
Connection conn = getConnection();
58515813
try {
5852-
XsLocalNetwork nw = this.getNetworkByName(conn, label);
5814+
XsLocalNetwork nw = getNetworkByName(conn, label);
58535815
s_logger.debug("Network object:" + nw.getNetwork().getUuid(conn));
58545816
PIF pif = nw.getPif(conn);
58555817
Record pifRec = pif.getRecord(conn);
58565818
s_logger.debug("PIF object:" + pifRec.uuid + "(" + pifRec.device + ")");
58575819
return new OvsFetchInterfaceAnswer(cmd, true, "Interface " + pifRec.device + " retrieved successfully",
58585820
pifRec.IP, pifRec.netmask, pifRec.MAC);
5859-
} catch (Exception e) {
5860-
e.printStackTrace();
5821+
} catch (BadServerResponse e) {
5822+
s_logger.error("An error occurred while fetching the interface for " +
5823+
label + " on host " + _host.ip , e);
5824+
return new OvsFetchInterfaceAnswer(cmd, false, "EXCEPTION:" + e.getMessage());
5825+
} catch (XenAPIException e) {
58615826
s_logger.error("An error occurred while fetching the interface for " +
5862-
label + " on host " + _host.ip + ":" + e.toString() +
5863-
"(" + e.getClass() + ")");
5827+
label + " on host " + _host.ip , e);
5828+
return new OvsFetchInterfaceAnswer(cmd, false, "EXCEPTION:" + e.getMessage());
5829+
} catch (XmlRpcException e) {
5830+
s_logger.error("An error occurred while fetching the interface for " +
5831+
label + " on host " + _host.ip, e);
58645832
return new OvsFetchInterfaceAnswer(cmd, false, "EXCEPTION:" + e.getMessage());
58655833
}
58665834
}
@@ -5885,12 +5853,15 @@ private OvsCreateGreTunnelAnswer execute(OvsCreateGreTunnelCommand cmd) {
58855853
} else {
58865854
return new OvsCreateGreTunnelAnswer(cmd, true, result, _host.ip, bridge, Integer.parseInt(res[1]));
58875855
}
5888-
} catch (Exception e) {
5889-
e.printStackTrace();
5856+
} catch (BadServerResponse e) {
58905857
s_logger.error("An error occurred while creating a GRE tunnel to " +
5891-
cmd.getRemoteIp() + " on host " + _host.ip + ":" + e.getMessage() +
5892-
"(" + e.getClass() + ")");
5893-
5858+
cmd.getRemoteIp() + " on host " + _host.ip , e);
5859+
} catch (XenAPIException e) {
5860+
s_logger.error("An error occurred while creating a GRE tunnel to " +
5861+
cmd.getRemoteIp() + " on host " + _host.ip , e);
5862+
} catch (XmlRpcException e) {
5863+
s_logger.error("An error occurred while creating a GRE tunnel to " +
5864+
cmd.getRemoteIp() + " on host " + _host.ip , e);
58945865
}
58955866

58965867
return new OvsCreateGreTunnelAnswer(cmd, false, "EXCEPTION", _host.ip, bridge);
@@ -6139,7 +6110,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
61396110

61406111
CheckXenHostInfo();
61416112

6142-
this.storageHandler = getStorageHandler();
6113+
storageHandler = getStorageHandler();
61436114
return true;
61446115

61456116
}

0 commit comments

Comments
 (0)