You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by an...@apache.org on 2014/03/27 02:04:20 UTC
git commit: updated refs/heads/4.4 to b4d3aac
Repository: cloudstack
Updated Branches:
refs/heads/4.4 15d798d88 -> b4d3aac74
get rrd through http directly instead of xapi plugins
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/b4d3aac7
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/b4d3aac7
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/b4d3aac7
Branch: refs/heads/4.4
Commit: b4d3aac74d9eccbc1219618aafb27d4d809d657b
Parents: 15d798d
Author: Anthony Xu <an...@citrix.com>
Authored: Wed Mar 26 18:02:52 2014 -0700
Committer: Anthony Xu <an...@citrix.com>
Committed: Wed Mar 26 18:02:52 2014 -0700
----------------------------------------------------------------------
.../xen/resource/CitrixResourceBase.java | 95 ++++++++++----------
scripts/vm/hypervisor/xenserver/hostvmstats.py | 61 -------------
scripts/vm/hypervisor/xenserver/vmops | 12 +--
scripts/vm/hypervisor/xenserver/xcposs/patch | 1 -
scripts/vm/hypervisor/xenserver/xcpserver/patch | 1 -
.../vm/hypervisor/xenserver/xenserver56/patch | 1 -
.../hypervisor/xenserver/xenserver56fp1/patch | 1 -
.../vm/hypervisor/xenserver/xenserver60/patch | 1 -
.../vm/hypervisor/xenserver/xenserver62/patch | 1 -
9 files changed, 51 insertions(+), 123 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b4d3aac7/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 3115cbe..7f5eb1a 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
@@ -216,17 +216,19 @@ 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 javax.ejb.Local;
import javax.naming.ConfigurationException;
import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
import java.io.BufferedReader;
import java.io.File;
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;
import java.net.URL;
@@ -2529,46 +2531,65 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
return new GetVmDiskStatsAnswer(cmd, null, null, null);
}
- protected Object[] getRRDData(Connection conn, int flag) {
-
- /*
- * Note: 1 => called from host, hence host stats 2 => called from vm, hence vm stats
- */
- String stats = "";
+ 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=" + (host ? "true" : "false");
+ urlStr += "&cf=" + _consolidationFunction;
+ urlStr += "&interval=" + _pollingIntervalInSeconds;
+ urlStr += "&start=" + (currentDate.getTime() / 1000 - 1000 - 100);
+
+ URL url;
+ BufferedReader in = null;
try {
- 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);
+ 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);
+ } 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);
+ }
+ }
}
+ }
- // 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);
+ protected Object[] getRRDData(Connection conn, int flag) {
+ /*
+ * Note: 1 => called from host, hence host stats 2 => called from vm, hence vm stats
+ */
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);
+ doc = getStatsRawXML(conn, flag == 1 ? true : false);
+ } catch (Exception e1) {
+ s_logger.warn("Error whilst collecting raw stats from plugin: ", e1);
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;
}
@@ -2592,7 +2613,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
}
}
- return new Object[] {numRows, numColumns, legend, dataNode};
+ return new Object[] { numRows, numColumns, legend, dataNode };
}
protected String getXMLNodeValue(Node n) {
@@ -2630,22 +2651,6 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
}
- protected String getHostStatsRawXML(Connection conn) {
- Date currentDate = new Date();
- String startTime = String.valueOf(currentDate.getTime() / 1000 - 1000);
-
- return callHostPlugin(conn, "vmops", "gethostvmstats", "collectHostStats", String.valueOf("true"), "consolidationFunction", _consolidationFunction, "interval",
- String.valueOf(_pollingIntervalInSeconds), "startTime", startTime);
- }
-
- 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;
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b4d3aac7/scripts/vm/hypervisor/xenserver/hostvmstats.py
----------------------------------------------------------------------
diff --git a/scripts/vm/hypervisor/xenserver/hostvmstats.py b/scripts/vm/hypervisor/xenserver/hostvmstats.py
deleted file mode 100644
index 61cf2de..0000000
--- a/scripts/vm/hypervisor/xenserver/hostvmstats.py
+++ /dev/null
@@ -1,61 +0,0 @@
-#!/usr/bin/python
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-# $Id: hostvmstats.py 10054 2010-06-29 22:09:31Z abhishek $ $HeadURL: svn://svn.lab.vmops.com/repos/vmdev/java/scripts/vm/hypervisor/xenserver/hostvmstats.py $
-
-import XenAPI
-import urllib
-import time
-import logging
-import logging.handlers
-
-LOG_FILENAME = '/tmp/xapilog'
-logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)
-stats_logger = logging.getLogger('statsLogger')
-stats_logger.setLevel(logging.DEBUG)
-
-#handler with maxBytes=10MiB
-handler = logging.handlers.RotatingFileHandler(LOG_FILENAME, maxBytes=10*1024*1024, backupCount=5)
-stats_logger.addHandler(handler)
-
-def get_stats(session, collect_host_stats, consolidation_function, interval, start_time):
- try:
-
- if collect_host_stats == "true" :
- url = "http://localhost/rrd_updates?"
- url += "session_id=" + session._session
- url += "&host=" + collect_host_stats
- url += "&cf=" + consolidation_function
- url += "&interval=" + str(interval)
- url += "&start=" + str(int(time.time())-100)
- else :
- url = "http://localhost/rrd_updates?"
- url += "session_id=" + session._session
- url += "&host=" + collect_host_stats
- url += "&cf=" + consolidation_function
- url += "&interval=" + str(interval)
- url += "&start=" + str(int(time.time())-100)
-
- stats_logger.debug("Calling URL: %s",url)
- sock = urllib.URLopener().open(url)
- xml = sock.read()
- sock.close()
- stats_logger.debug("Size of returned XML: %s",len(xml))
- return xml
- except Exception,e:
- stats_logger.exception("get_stats() failed")
- raise
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b4d3aac7/scripts/vm/hypervisor/xenserver/vmops
----------------------------------------------------------------------
diff --git a/scripts/vm/hypervisor/xenserver/vmops b/scripts/vm/hypervisor/xenserver/vmops
index 4174ef2..38e368b 100755
--- a/scripts/vm/hypervisor/xenserver/vmops
+++ b/scripts/vm/hypervisor/xenserver/vmops
@@ -27,7 +27,6 @@ if os.path.exists("/opt/xensource/sm"):
if os.path.exists("/usr/lib/xcp/sm"):
sys.path.extend(["/usr/lib/xcp/sm/", "/usr/local/sbin/", "/sbin/"])
import base64
-import hostvmstats
import socket
import stat
import tempfile
@@ -62,15 +61,6 @@ def add_to_VCPUs_params_live(session, args):
return 'true'
@echo
-def gethostvmstats(session, args):
- collect_host_stats = args['collectHostStats']
- consolidation_function = args['consolidationFunction']
- interval = args['interval']
- start_time = args['startTime']
- result = hostvmstats.get_stats(session, collect_host_stats, consolidation_function, interval, start_time)
- return result
-
-@echo
def setup_iscsi(session, args):
uuid=args['uuid']
try:
@@ -1502,7 +1492,7 @@ def network_rules(session, args):
logging.debug("Failed to network rule !")
if __name__ == "__main__":
- XenAPIPlugin.dispatch({"pingtest": pingtest, "setup_iscsi":setup_iscsi, "gethostvmstats": gethostvmstats,
+ XenAPIPlugin.dispatch({"pingtest": pingtest, "setup_iscsi":setup_iscsi,
"getgateway": getgateway, "preparemigration": preparemigration,
"setIptables": setIptables, "pingdomr": pingdomr, "pingxenserver": pingxenserver,
"routerProxy": routerProxy,
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b4d3aac7/scripts/vm/hypervisor/xenserver/xcposs/patch
----------------------------------------------------------------------
diff --git a/scripts/vm/hypervisor/xenserver/xcposs/patch b/scripts/vm/hypervisor/xenserver/xcposs/patch
index 08da883..561d7b6 100644
--- a/scripts/vm/hypervisor/xenserver/xcposs/patch
+++ b/scripts/vm/hypervisor/xenserver/xcposs/patch
@@ -31,7 +31,6 @@ vmops=..,0755,/usr/lib/xcp/plugins
ovsgre=..,0755,/usr/lib/xcp/plugins
ovstunnel=..,0755,/usr/lib/xcp/plugins
vmopsSnapshot=..,0755,/usr/lib/xcp/plugins
-hostvmstats.py=..,0755,/usr/lib/xcp/sm
systemvm.iso=../../../../../vms,0644,/usr/share/xcp/packages/iso/
id_rsa.cloud=../../../systemvm,0600,/root/.ssh
network_info.sh=..,0755,/opt/cloud/bin
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b4d3aac7/scripts/vm/hypervisor/xenserver/xcpserver/patch
----------------------------------------------------------------------
diff --git a/scripts/vm/hypervisor/xenserver/xcpserver/patch b/scripts/vm/hypervisor/xenserver/xcpserver/patch
index 2376424..0f9d9a0 100644
--- a/scripts/vm/hypervisor/xenserver/xcpserver/patch
+++ b/scripts/vm/hypervisor/xenserver/xcpserver/patch
@@ -31,7 +31,6 @@ NFSSR.py=/opt/xensource/sm
vmops=..,0755,/etc/xapi.d/plugins
ovstunnel=..,0755,/etc/xapi.d/plugins
vmopsSnapshot=..,0755,/etc/xapi.d/plugins
-hostvmstats.py=..,0755,/opt/xensource/sm
systemvm.iso=../../../../../vms,0644,/opt/xensource/packages/iso
id_rsa.cloud=../../../systemvm,0600,/root/.ssh
network_info.sh=..,0755,/opt/cloud/bin
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b4d3aac7/scripts/vm/hypervisor/xenserver/xenserver56/patch
----------------------------------------------------------------------
diff --git a/scripts/vm/hypervisor/xenserver/xenserver56/patch b/scripts/vm/hypervisor/xenserver/xenserver56/patch
index 16dcb57..e24136d 100644
--- a/scripts/vm/hypervisor/xenserver/xenserver56/patch
+++ b/scripts/vm/hypervisor/xenserver/xenserver56/patch
@@ -30,7 +30,6 @@ NFSSR.py=/opt/xensource/sm
vmops=..,0755,/etc/xapi.d/plugins
vmopsSnapshot=..,0755,/etc/xapi.d/plugins
cloudstack_pluginlib.py=..,0755,/etc/xapi.d/plugins
-hostvmstats.py=..,0755,/opt/xensource/sm
systemvm.iso=../../../../../vms,0644,/opt/xensource/packages/iso
id_rsa.cloud=../../../systemvm,0600,/root/.ssh
network_info.sh=..,0755,/opt/cloud/bin
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b4d3aac7/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch
----------------------------------------------------------------------
diff --git a/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch b/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch
index 11bda07..5e15598 100644
--- a/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch
+++ b/scripts/vm/hypervisor/xenserver/xenserver56fp1/patch
@@ -30,7 +30,6 @@ NFSSR.py=/opt/xensource/sm
vmops=..,0755,/etc/xapi.d/plugins
vmopsSnapshot=..,0755,/etc/xapi.d/plugins
cloudstack_pluginlib.py=..,0755,/etc/xapi.d/plugins
-hostvmstats.py=..,0755,/opt/xensource/sm
systemvm.iso=../../../../../vms,0644,/opt/xensource/packages/iso
id_rsa.cloud=../../../systemvm,0600,/root/.ssh
network_info.sh=..,0755,/opt/cloud/bin
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b4d3aac7/scripts/vm/hypervisor/xenserver/xenserver60/patch
----------------------------------------------------------------------
diff --git a/scripts/vm/hypervisor/xenserver/xenserver60/patch b/scripts/vm/hypervisor/xenserver/xenserver60/patch
index 662327b..84472a6 100644
--- a/scripts/vm/hypervisor/xenserver/xenserver60/patch
+++ b/scripts/vm/hypervisor/xenserver/xenserver60/patch
@@ -34,7 +34,6 @@ cloudstack_plugins.conf=..,0644,/etc/xensource
cloudstack_pluginlib.py=..,0755,/etc/xapi.d/plugins
ovstunnel=..,0755,/etc/xapi.d/plugins
vmopsSnapshot=..,0755,/etc/xapi.d/plugins
-hostvmstats.py=..,0755,/opt/xensource/sm
systemvm.iso=../../../../../vms,0644,/opt/xensource/packages/iso
id_rsa.cloud=../../../systemvm,0600,/root/.ssh
network_info.sh=..,0755,/opt/cloud/bin
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b4d3aac7/scripts/vm/hypervisor/xenserver/xenserver62/patch
----------------------------------------------------------------------
diff --git a/scripts/vm/hypervisor/xenserver/xenserver62/patch b/scripts/vm/hypervisor/xenserver/xenserver62/patch
index 05c619b..4ac2968 100644
--- a/scripts/vm/hypervisor/xenserver/xenserver62/patch
+++ b/scripts/vm/hypervisor/xenserver/xenserver62/patch
@@ -34,7 +34,6 @@ cloudstack_plugins.conf=..,0644,/etc/xensource
cloudstack_pluginlib.py=..,0755,/etc/xapi.d/plugins
ovstunnel=..,0755,/etc/xapi.d/plugins
cloud-plugin-storage=,0755,/etc/xapi.d/plugins
-hostvmstats.py=..,0755,/opt/xensource/sm
systemvm.iso=../../../../../vms,0644,/opt/xensource/packages/iso
id_rsa.cloud=../../../systemvm,0600,/root/.ssh
network_info.sh=..,0755,/opt/cloud/bin