FileDocCategorySizeDatePackage
Harvester.javaAPI DocGlassfish v2 API10234Fri May 04 22:34:44 BST 2007com.sun.enterprise.diagnostics.collect

Harvester

public abstract class Harvester extends Object implements Collector
Responsible for configuring various collectors based on diagnostic service configuration and colleting diagnostic information for the entire report.
author
Manisha Umbarje

Fields Summary
protected ReportConfig
config
protected ReportTarget
target
private List
collectors
private ChecksumCollector
checksumCollector
private SystemInfoCollector
systemInfoCollector
private FilesCollector
installationLogCollector
protected static final Logger
logger
Constructors Summary
public Harvester(ReportConfig config)
Creates instance of Harvester

param
config combined representation of CLIOptions and ReportTarget


                     
       
        if (config != null) {
            this.config = config;
            this.target = config.getTarget();
        }
    
Methods Summary
public voidaddCollector(Collector obj)

        if(obj != null)
            collectors.add(obj);
    
protected voidaddCustomerInputCollector()

        if (config.getCLIOptions().getCustomerInput() != null ||
                config.getCLIOptions().getCustomerInputFile() != null) {
            addCollector(new CustomerInputCollector(
                    config.getCLIOptions().getCustomerInputFile(),
                    config.getCLIOptions().getCustomerInput(),
                    target.getIntermediateReportDir(),
                    config.getExecutionContext().isLocal()));
        }
    
protected voidaddFilesCollector(boolean captureInstallationLog, java.lang.String dataType)

        if(captureInstallationLog) {
            if(installationLogCollector == null) {
                String installationRoot = DiagnosticServiceHelper.getInstallationRoot();
                List<String> files = new ArrayList(2);
                String[] logFiles =
                        new File(installationRoot).list(new FilenameFilter() {
                   public boolean accept(File folder, String name)  {
                       if( (name.contains(Constants.INSTALLATION_LOG_PREFIX)) ||
                               (name.contains(Constants.SJSAS_INSTALLATION_LOG_PREFIX)))
                           return true;
                       return false;
                   }
                });
                files.addAll(Arrays.asList(logFiles));

                installationLogCollector = new FilesCollector(installationRoot,
                    target.getIntermediateReportDir(),files,  dataType);
                addCollector(installationLogCollector);
            }
        }
    
protected voidaddInstallationCheckSumCollector()

        if(checksumCollector == null) {
            checksumCollector = new ChecksumCollector(
                            DiagnosticServiceHelper.getInstallationRoot(),
                            target.getIntermediateReportDir());
            addCollector(checksumCollector);
        }
    
protected voidaddMonitoringInfoCollector(java.lang.String reportDir, java.lang.String path, java.lang.String instanceName)

        if(path == null)
            path = "";
        reportDir= reportDir + File.separator + path + File.separator +
                instanceName;
        addCollector(new MonitoringInfoCollector(path, instanceName, reportDir));
    
protected voidaddMonitoringInfoCollectors(java.lang.String path, java.util.List instances)

        String reportDir = target.getIntermediateReportDir();
        Iterator<String> iterator = instances.iterator();

        while (iterator.hasNext()) {
            String instanceName = iterator.next();
            addMonitoringInfoCollector(reportDir, path,instanceName);
        }
    
public abstract voidaddRemoteCollectors()

protected voidaddSystemInfoCollector(boolean captureSystemInfoEnabled)

        if(captureSystemInfoEnabled) {
            String reportDir = config.getTarget().getIntermediateReportDir();
            if(systemInfoCollector == null) {
                systemInfoCollector = new SystemInfoCollector(reportDir);
                //Add the collector only once.
                addCollector(systemInfoCollector);
            }
        }
    
private Datacapture(Collector obj)
Invoke collector to capture information

param
obj collector

        try {
             return obj.capture();
        } catch (Throwable de) {
            logger.log(Level.WARNING,
                    "diagnostic-service.error_collecting_data" ,
                    new Object[]{de.getMessage()});
        }
        return null;
    
public Datacapture()
Invoke various collectors to capture diagnostic data

        WritableDataImpl dataImpl = new WritableDataImpl();
        Iterator<Collector> list = collectors.iterator();
        while(list.hasNext()) {
            Data dataObj = capture(list.next());
            if(dataObj != null)
                dataImpl.addChild(dataObj);
        }
        if (!dataImpl.getChildren().hasNext()) {
            //no data has been collected by any of the collectors.
            DiagnosticException e = new DiagnosticException("No Diagnostic data has been collected");
            logger.log(Level.WARNING, "diagnostic-service.no_data_collected");
            throw e;
        }
        return dataImpl;
    
public voidinitialize()
Initialize collectors

        collectors = new ArrayList(8);
        addCustomerInputCollector();
        //addInstallationCheckSumCollector();
        initializeInstanceCollectors(config.getInstanceConfigurations());
        addRemoteCollectors();
        //addSystemInfoCollector();
    
protected voidinitializeInstanceCollectors(java.util.Iterator iterator)
Initialize instance collectors

        while(iterator.hasNext()) {
            ServiceConfig serviceConfig = iterator.next();
            String repositoryDir = serviceConfig.getRepositoryDir() ;
            String reportDir = target.getIntermediateReportDir();

            if(!(serviceConfig.getInstanceName().equals(Constants.SERVER)))
                reportDir = reportDir+ File.separator +
                    serviceConfig.getInstanceName();

            if(serviceConfig.isCaptureChecksumEnabled()) {
                addInstallationCheckSumCollector();
                ChecksumCollector collector = new ChecksumCollector(
                        repositoryDir,
                        reportDir);
                addCollector(collector);
            }

            if(serviceConfig.isVerifyDomainEnabled()) {
                DomainXMLVerificationCollector domainXMLCollector
                         = new DomainXMLVerificationCollector(repositoryDir,
                         reportDir);
                 addCollector(domainXMLCollector);
            }

            addCollector(new ConfigCollector(repositoryDir, reportDir));
            //If minLogLevel != OFF, add collector
            if(!(serviceConfig.getMinLogLevel() == Level.OFF.intValue())) {
                Collector collectorObj = new LogCollector(
                        config.getCLIOptions().getStartDate(),
                        config.getCLIOptions().getEndDate(),
                        reportDir, serviceConfig );
                if (collectorObj != null)
                    addCollector(collectorObj);
            }

            if(serviceConfig.isCaptureAppDDEnabled()) {
                addCollector(new AppInfoCollector(repositoryDir, reportDir));
            }

            addFilesCollector(serviceConfig.isCaptureInstallLogEnabled(),
                    DataType.INSTALLATION_LOG);
            addSystemInfoCollector(serviceConfig.isCaptureSystemInfoEnabled());
        }