aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sos/plugins/as7.py65
1 files changed, 50 insertions, 15 deletions
diff --git a/sos/plugins/as7.py b/sos/plugins/as7.py
index 5c7a7b3a..c31696ef 100644
--- a/sos/plugins/as7.py
+++ b/sos/plugins/as7.py
@@ -1,8 +1,11 @@
import os
+import sys
import re
import zipfile
import urllib2
import tempfile
+from xml.etree import ElementTree
+from itertools import chain
try:
import json
@@ -138,7 +141,6 @@ class AS7(Plugin, IndependentPlugin):
else:
self.addAlert("WARN: No jars found in JBoss system path (" + self.__jbossHome + ").")
-
def query(self, request_obj):
try:
return self.query_java(request_obj)
@@ -275,29 +277,62 @@ class AS7(Plugin, IndependentPlugin):
self.addForbiddenPath(os.path.join(confDir, 'mgmt-users.properties'))
self.doCopyFileOrDir(confDir, sub=(self.__jbossHome, 'JBOSSHOME'))
- ## Log dir next
- logDir = os.path.join(path, "log")
- for logFile in find("*", logDir):
+ for logFile in find("*.log", path):
self.addCopySpecLimit(logFile,
self.getOption("logsize"),
sub=(self.__jbossHome, 'JBOSSHOME'))
- for deployment in find("*", os.path.join(path, "deployments")):
- self._get_tree_from_deployment(deployment)
-
-
- def _get_tree_from_deployment(self, path):
- tmp_dir = tempfile.mkdtemp()
+ deployment_info = self.__get_deployment_info(confDir)
+ deployments = self.__get_deployments(path)
+ for deployment in deployments:
+ self.__get_listing_from_deployment(deployment, deployment_info)
+
+ def __get_deployment_info(self, dir_):
+ """Gets the deployment name to sha1 mapping for all deployments defined
+ in configs under dir_"""
+ deployment_info = {}
+ for config in find("*.xml", dir_):
+ root = ElementTree.parse(config).getroot()
+ # the namespace is harder to fetch than it should be
+ ns = root.tag.rpartition("}")[0]
+ ns += "}"
+ for deployment in root.findall("./%sdeployments/%sdeployment" % (ns, ns)):
+ name = deployment.attrib.get("name")
+ sha1 = deployment.getchildren()[0].attrib.get("sha1")
+ deployment_info[sha1] = name
+ return deployment_info
+
+ def __get_deployments(self, path):
+ return list(chain(
+ find("*", os.path.join(path, "deployments")),
+ find("content", path)))
+
+ def __get_listing_from_deployment(self, path, mapping):
try:
zf = zipfile.ZipFile(path)
- zf.extractall(path=tmp_dir)
+ contents = []
+ for zipinfo in zf.infolist():
+ if zipinfo.filename.endswith("/"):
+ continue
+ contents.append((zipinfo.filename, zipinfo.file_size))
zf.close()
- tree = DirTree(tmp_dir).as_string()
- self.addStringAsFile(tree, "%s.tree.txt" % os.path.basename(path))
- except zipfile.BadZipfile:
+ contents.sort()
+ output = "\n".join(["%s:%d" % (fn, fs) for fn, fs in contents])
+
+ path_to = path.replace(self.__jbossHome, '')
+ if 'content' in path:
+ path_to = path_to.strip(os.path.sep).rstrip("content")
+ path_to = os.path.join(*path_to.split(os.path.sep)[:-2])
+ sha1 = "".join(path.split(os.path.sep)[-3:-1])
+ name = mapping.get(sha1, sha1)
+ else:
+ path_to, name = os.path.split(path_to)
+
+ self.addStringAsFile(output, os.path.join(path_to, "%s.txt" % name))
+ except:
+ # this is probably not a zipfile so we don't care
pass
- os.rmdir(tmp_dir)
def setup(self):