1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 package org.apache.hadoop.vaidya; 19 20 import org.apache.hadoop.vaidya.util.XMLUtils; 21 import org.w3c.dom.Document; 22 import org.w3c.dom.Element; 23 import javax.xml.parsers.DocumentBuilder; 24 import javax.xml.parsers.DocumentBuilderFactory; 25 import javax.xml.parsers.ParserConfigurationException; 26 27 28 /** 29 * This is a base driver class for job diagnostics. Various specialty drivers that 30 * tests specific aspects of job problems e.g. PostExPerformanceDiagnoser extends the 31 * this base class. 32 * 33 */ 34 public class JobDiagnoser { 35 36 /* 37 * XML document containing report elements, one for each rule tested 38 */ 39 private Document _report; 40 41 /* 42 * @report : returns report document 43 */ getReport()44 public Document getReport() { 45 return this._report; 46 } 47 48 49 /** 50 * Constructor. It initializes the report document. 51 */ JobDiagnoser()52 public JobDiagnoser () throws Exception { 53 54 /* 55 * Initialize the report document, make it ready to add the child report elements 56 */ 57 DocumentBuilder builder = null; 58 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 59 try{ 60 builder = factory.newDocumentBuilder(); 61 this._report = builder.newDocument(); 62 } catch (ParserConfigurationException e) { 63 e.printStackTrace(); 64 } 65 66 // Insert Root Element 67 Element root = (Element) this._report.createElement("PostExPerformanceDiagnosticReport"); 68 this._report.appendChild(root); 69 } 70 71 /* 72 * Print the report document to console 73 */ printReport()74 public void printReport() { 75 XMLUtils.printDOM(this._report); 76 } 77 78 /* 79 * Save the report document the specified report file 80 * @param reportfile : path of report file. 81 */ saveReport(String filename)82 public void saveReport(String filename) { 83 XMLUtils.writeXmlToFile(filename, this._report); 84 } 85 } 86