1 23 package com.sun.enterprise.diagnostics.collect; 24 25 import com.sun.enterprise.diagnostics.*; 26 import com.sun.enterprise.diagnostics.util.DiagnosticServiceHelper; 27 import com.sun.logging.LogDomains; 28 29 import java.util.List ; 30 import java.util.Iterator ; 31 import java.util.ArrayList ; 32 import java.util.logging.Logger ; 33 import java.util.logging.Level ; 34 import java.io.File ; 35 import java.io.FilenameFilter ; 36 import java.util.Arrays ; 37 38 44 public abstract class Harvester implements Collector { 45 46 protected ReportConfig config; 47 protected ReportTarget target; 48 private List <Collector> collectors; 49 private ChecksumCollector checksumCollector; 50 51 private SystemInfoCollector systemInfoCollector ; 52 private FilesCollector installationLogCollector; 53 protected static Logger logger = 54 LogDomains.getLogger(LogDomains.ADMIN_LOGGER); 55 56 60 public Harvester(ReportConfig config) { 61 if (config != null) { 62 this.config = config; 63 this.target = config.getTarget(); 64 } 65 } 66 67 70 public Data capture() { 71 WritableDataImpl dataImpl = new WritableDataImpl(); 72 Iterator <Collector> list = collectors.iterator(); 73 while(list.hasNext()) { 74 Data dataObj = capture(list.next()); 75 if(dataObj != null) 76 dataImpl.addChild(dataObj); 77 } 78 return dataImpl; 79 } 80 81 public void addCollector(Collector obj) { 82 if(obj != null) 83 collectors.add(obj); 84 } 85 86 public abstract void addRemoteCollectors() ; 87 88 91 public void initialize() { 92 collectors = new ArrayList (8); 93 addCustomerInputCollector(); 94 initializeInstanceCollectors(config.getInstanceConfigurations()); 96 addRemoteCollectors(); 97 } 99 100 103 protected void initializeInstanceCollectors( 104 Iterator <ServiceConfig> iterator) { 105 while(iterator.hasNext()) { 106 ServiceConfig serviceConfig = iterator.next(); 107 String repositoryDir = serviceConfig.getRepositoryDir() ; 108 String reportDir = target.getIntermediateReportDir(); 109 110 if(!(serviceConfig.getInstanceName().equals(Constants.SERVER))) 111 reportDir = reportDir+ File.separator + 112 serviceConfig.getInstanceName(); 113 114 if(serviceConfig.isCaptureChecksumEnabled()) { 115 addInstallationCheckSumCollector(); 116 ChecksumCollector collector = new ChecksumCollector( 117 repositoryDir, 118 reportDir); 119 addCollector(collector); 120 } 121 122 if(serviceConfig.isVerifyDomainEnabled()) { 123 DomainXMLVerificationCollector domainXMLCollector 124 = new DomainXMLVerificationCollector(repositoryDir, 125 reportDir); 126 addCollector(domainXMLCollector); 127 } 128 129 addCollector(new ConfigCollector(repositoryDir, reportDir)); 130 if(!(serviceConfig.getMinLogLevel() == Level.OFF.intValue())) { 132 Collector collectorObj = new LogCollector( 133 config.getCLIOptions().getStartDate(), 134 config.getCLIOptions().getEndDate(), 135 reportDir, serviceConfig ); 136 if (collectorObj != null) 137 addCollector(collectorObj); 138 } 139 140 if(serviceConfig.isCaptureAppDDEnabled()) { 141 addCollector(new AppInfoCollector(repositoryDir, reportDir)); 142 } 143 144 addFilesCollector(serviceConfig.isCaptureInstallLogEnabled(), 145 DataType.INSTALLATION_LOG); 146 addSystemInfoCollector(serviceConfig.isCaptureSystemInfoEnabled()); 147 } 148 } 149 150 protected void addFilesCollector(boolean captureInstallationLog, String dataType) { 151 if(captureInstallationLog) { 152 if(installationLogCollector == null) { 153 String installationRoot = DiagnosticServiceHelper.getInstallationRoot(); 154 List <String > files = new ArrayList (2); 155 String [] logFiles = 156 new File (installationRoot).list(new FilenameFilter () { 157 public boolean accept(File folder, String name) { 158 if( (name.contains(Constants.INSTALLATION_LOG_PREFIX)) || 159 (name.contains(Constants.SJSAS_INSTALLATION_LOG_PREFIX))) 160 return true; 161 return false; 162 } 163 }); 164 files.addAll(Arrays.asList(logFiles)); 165 166 installationLogCollector = new FilesCollector(installationRoot, 167 target.getIntermediateReportDir(),files, dataType); 168 addCollector(installationLogCollector); 169 } 170 } 171 } 172 173 protected void addCustomerInputCollector() { 174 if (config.getCLIOptions().getCustomerInput() != null || 175 config.getCLIOptions().getCustomerInputFile() != null) { 176 addCollector(new CustomerInputCollector( 177 config.getCLIOptions().getCustomerInputFile(), 178 config.getCLIOptions().getCustomerInput(), 179 target.getIntermediateReportDir(), 180 config.getExecutionContext().isLocal())); 181 } 182 } 183 184 protected void addInstallationCheckSumCollector() { 185 if(checksumCollector == null) { 186 checksumCollector = new ChecksumCollector( 187 DiagnosticServiceHelper.getInstallationRoot(), 188 target.getIntermediateReportDir()); 189 addCollector(checksumCollector); 190 } 191 } 192 193 protected void addMonitoringInfoCollectors(String path, List <String > instances) { 194 String reportDir = target.getIntermediateReportDir(); 195 Iterator <String > iterator = instances.iterator(); 196 197 while (iterator.hasNext()) { 198 String instanceName = iterator.next(); 199 addMonitoringInfoCollector(reportDir, path,instanceName); 200 } 201 } 202 203 protected void addMonitoringInfoCollector(String reportDir, 204 String path, String instanceName) { 205 if(path == null) 206 path = ""; 207 reportDir= reportDir + File.separator + path + File.separator + 208 instanceName; 209 addCollector(new MonitoringInfoCollector(path, instanceName, reportDir)); 210 } 211 212 protected void addSystemInfoCollector(boolean captureSystemInfoEnabled){ 213 if(captureSystemInfoEnabled) { 214 String reportDir = config.getTarget().getIntermediateReportDir(); 215 if(systemInfoCollector == null) { 216 systemInfoCollector = new SystemInfoCollector(reportDir); 217 addCollector(systemInfoCollector); 219 } 220 } 221 } 222 223 227 private Data capture(Collector obj) { 228 try { 229 return obj.capture(); 230 } catch (Throwable de) { 231 logger.log(Level.WARNING, 232 "diagnostic-service.error_collecting_data" , 233 new Object []{de.getMessage()}); 234 } 235 return null; 236 } 237 } 238 | Popular Tags |