You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ah...@apache.org on 2013/11/11 17:24:11 UTC
[2/5] git commit: updated refs/heads/4.2 to 1c3b9b5
Changed vm stats to be collected through the xs http connection
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/e82e142b
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/e82e142b
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/e82e142b
Branch: refs/heads/4.2
Commit: e82e142b14bd8d806c70bca4ffc0a3e220795dd9
Parents: 5e44df6
Author: Alex Huang <al...@citrix.com>
Authored: Mon Nov 11 02:24:35 2013 -0800
Committer: Alex Huang <al...@citrix.com>
Committed: Mon Nov 11 08:24:03 2013 -0800
----------------------------------------------------------------------
.../xen/resource/CitrixResourceBase.java | 72 +++++++-------------
1 file changed, 25 insertions(+), 47 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e82e142b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
index 6c75835..e3dbdd8 100644
--- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
+++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java
@@ -25,7 +25,6 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
@@ -49,6 +48,7 @@ import java.util.UUID;
import javax.ejb.Local;
import javax.naming.ConfigurationException;
import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.codec.binary.Base64;
import org.apache.log4j.Logger;
@@ -57,6 +57,7 @@ import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
import com.google.gson.Gson;
import com.trilead.ssh2.SCPClient;
@@ -2803,41 +2804,16 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
/*
* Note: 1 => called from host, hence host stats 2 => called from vm, hence vm stats
*/
- String stats = "";
+ Document doc = null;
try {
- if (flag == 1) {
- stats = getHostStatsRawXML(conn);
- }
- if (flag == 2) {
- stats = getVmStatsRawXML(conn);
- }
+ doc = getStatsRawXML(conn, flag == 1 ? true : false);
} catch (Exception e1) {
s_logger.warn("Error whilst collecting raw stats from plugin: ", e1);
return null;
}
- // s_logger.debug("The raw xml stream is:"+stats);
- // s_logger.debug("Length of raw xml is:"+stats.length());
-
- //stats are null when the host plugin call fails (host down state)
- if(stats == null) {
- return null;
- }
-
- StringReader statsReader = new StringReader(stats);
- InputSource statsSource = new InputSource(statsReader);
-
- Document doc = null;
- try {
- doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(statsSource);
- } catch (Exception e) {
- s_logger.warn("Exception caught whilst processing the document via document factory:", e);
- return null;
- }
-
- if(doc==null){
- s_logger.warn("Null document found after tryinh to parse the stats source");
+ if (doc == null) { //stats are null when the host plugin call fails (host down state)
return null;
}
@@ -2908,45 +2884,47 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
}
- protected String getHostStatsRawXML(Connection conn) {
+ protected Document getStatsRawXML(Connection conn, boolean host) {
Date currentDate = new Date();
String urlStr = "http://" + _host.ip + "/rrd_updates?";
urlStr += "session_id=" + conn.getSessionReference();
- urlStr += "&host=" + "true";
+ urlStr += "&host=" + (host ? "true" : "false");
urlStr += "&cf=" + _consolidationFunction;
urlStr += "&interval=" + _pollingIntervalInSeconds;
urlStr += "&start=" + (currentDate.getTime() / 1000 - 1000 - 100);
URL url;
+ BufferedReader in = null;
try {
url = new URL(urlStr);
url.openConnection();
URLConnection uc = url.openConnection();
- BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
- StringBuilder buff = new StringBuilder();
- String inputLine;
- while ((inputLine = in.readLine()) != null) {
- buff.append(inputLine);
- }
- in.close();
- return buff.toString();
+ in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
+ InputSource statsSource = new InputSource(in);
+ return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(statsSource);
} catch (MalformedURLException e) {
s_logger.warn("Malformed URL? come on...." + urlStr);
return null;
} catch (IOException e) {
s_logger.warn("Problems getting stats using " + urlStr, e);
return null;
+ } catch (SAXException e) {
+ s_logger.warn("Problems getting stats using " + urlStr, e);
+ return null;
+ } catch (ParserConfigurationException e) {
+ s_logger.warn("Problems getting stats using " + urlStr, e);
+ return null;
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ s_logger.warn("Unable to close the buffer ", e);
+ }
+ }
}
}
- protected String getVmStatsRawXML(Connection conn) {
- Date currentDate = new Date();
- String startTime = String.valueOf(currentDate.getTime() / 1000 - 1000);
-
- return callHostPlugin(conn, "vmops", "gethostvmstats", "collectHostStats", String.valueOf("false"), "consolidationFunction", _consolidationFunction, "interval", String
- .valueOf(_pollingIntervalInSeconds), "startTime", startTime);
- }
-
protected State convertToState(Types.VmPowerState ps) {
final State state = s_statesTable.get(ps);
return state == null ? State.Unknown : state;