From d3af119863bd525e085495d01d329dd4384275cd Mon Sep 17 00:00:00 2001 From: Jesse Jaggars Date: Tue, 10 Jan 2012 16:38:53 -0600 Subject: adding a tree of all zipped deployments --- sos/plugins/as7.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/sos/plugins/as7.py b/sos/plugins/as7.py index d5abea22..5c7a7b3a 100644 --- a/sos/plugins/as7.py +++ b/sos/plugins/as7.py @@ -2,6 +2,7 @@ import os import re import zipfile import urllib2 +import tempfile try: import json @@ -282,6 +283,23 @@ class AS7(Plugin, IndependentPlugin): 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() + try: + zf = zipfile.ZipFile(path) + zf.extractall(path=tmp_dir) + zf.close() + tree = DirTree(tmp_dir).as_string() + self.addStringAsFile(tree, "%s.tree.txt" % os.path.basename(path)) + except zipfile.BadZipfile: + pass + os.rmdir(tmp_dir) + + def setup(self): ## We need to know where JBoss is installed and if we can't find it we -- cgit From 9046f1851cbcff30c1684b6a60d87ac1d0e33789 Mon Sep 17 00:00:00 2001 From: Jesse Jaggars Date: Mon, 6 Feb 2012 10:29:48 -0600 Subject: Renaming eap6 plugin to as7 adding deployed archive listing to as7 plugin --- Makefile | 9 ++++---- sos/plugins/as7.py | 65 +++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 55 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index a4b8513f..1e1b249a 100644 --- a/Makefile +++ b/Makefile @@ -79,14 +79,15 @@ gpgkey: po: clean mkdir -p $(PO_DIR) for po in `ls po/*.po`; do \ - $(MSGCAT) -p -o $(PO_DIR)/$$(basename $$po | awk -F. '{print $$1}').properties $$po; \ + $(MSGCAT) -p -o $(PO_DIR)/sos_$$(basename $$po | awk -F. '{print $$1}').properties $$po; \ done; \ - cp $(PO_DIR)/en.properties $(PO_DIR)/en_US.properties + cp $(PO_DIR)/sos_en.properties $(PO_DIR)/sos_en_US.properties + cp $(PO_DIR)/sos_en.properties $(PO_DIR)/sos.properties -eap6: po +as7: po cp -r sos/* $(SRC_BUILD)/sos/ - find $(SRC_BUILD)/sos/plugins/ -not -name "*eap6.py" -not -name "*__init__.py" -type f -delete + find $(SRC_BUILD)/sos/plugins/ -not -name "*as7.py" -not -name "*__init__.py" -type f -delete zip: po zip -r $(ZIP_DEST) sos 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): -- cgit