Revert "Changed vm stats to be collected through the xs http connection"

This reverts commit e82e142b14bd8d806c70bca4ffc0a3e220795dd9.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/14ee68cf
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/14ee68cf
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/14ee68cf

Branch: refs/heads/4.2
Commit: 14ee68cfcf8b2122c23a316dbd7c44f9f1331175
Parents: aee7603
Author: Anthony Xu <anthony...@citrix.com>
Authored: Wed Nov 13 19:00:14 2013 -0800
Committer: Anthony Xu <anthony...@citrix.com>
Committed: Wed Nov 13 19:00:14 2013 -0800

----------------------------------------------------------------------
 .../xen/resource/CitrixResourceBase.java        | 72 +++++++++++++-------
 1 file changed, 47 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/14ee68cf/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 85c57c5..1666c93 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,6 +25,7 @@ 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;
@@ -48,7 +49,6 @@ 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,7 +57,6 @@ 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;
@@ -2804,16 +2803,41 @@ public abstract class CitrixResourceBase implements 
ServerResource, HypervisorRe
         /*
          * Note: 1 => called from host, hence host stats 2 => called from vm, 
hence vm stats
          */
-        Document doc = null;
+        String stats = "";
 
         try {
-            doc = getStatsRawXML(conn, flag == 1 ? true : false);
+            if (flag == 1) {
+                stats = getHostStatsRawXML(conn);
+            }
+            if (flag == 2) {
+                stats = getVmStatsRawXML(conn);
+            }
         } catch (Exception e1) {
             s_logger.warn("Error whilst collecting raw stats from plugin: ", 
e1);
             return null;
         }
 
-        if (doc == null) {         //stats are null when the host plugin call 
fails (host down state)
+        // 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");
             return null;
         }
 
@@ -2884,47 +2908,45 @@ public abstract class CitrixResourceBase implements 
ServerResource, HypervisorRe
 
     }
 
-    protected Document getStatsRawXML(Connection conn, boolean host) {
+    protected String getHostStatsRawXML(Connection conn) {
         Date currentDate = new Date();
         String urlStr = "http://"; + _host.ip + "/rrd_updates?";
         urlStr += "session_id=" + conn.getSessionReference();
-        urlStr += "&host=" + (host ? "true" : "false");
+        urlStr += "&host=" + "true";
         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();
-            in = new BufferedReader(new 
InputStreamReader(uc.getInputStream()));
-            InputSource statsSource = new InputSource(in);
-            return 
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(statsSource);
+            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();
         } 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;

Reply via email to